Skip to content

Commit 5ad82a9

Browse files
committed
ran prettier over whole js codebase
1 parent 7c31305 commit 5ad82a9

110 files changed

Lines changed: 3843 additions & 3722 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.

src/docs/js/generateApiDocs.js

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
/*
33
This script is run at build time to generate api.md - a single Markdown document containing documentation for ScriptCraft's API
44
*/
5-
function foreach(array, func){
6-
for (var i =0; i < array.length; i++){
7-
func(array[i],i,array);
5+
function foreach(array, func) {
6+
for (var i = 0; i < array.length; i++) {
7+
func(array[i], i, array);
88
}
99
}
1010
/*
1111
find - a (very) basic implementation of the unix command line tool.
1212
*/
13-
function find(dir,store,re) {
13+
function find(dir, store, re) {
1414
var files = dir.listFiles();
15-
foreach (files, function(filename){
15+
foreach(files, function(filename) {
1616
filename = '' + filename;
1717
var file = new File(filename);
1818
if (file.isDirectory()) {
19-
find(file,store,re);
19+
find(file, store, re);
2020
} else {
21-
if (typeof re == 'undefined')
22-
store.push(filename);
23-
else if (filename.match(re))
24-
store.push(filename);
21+
if (typeof re == 'undefined') store.push(filename);
22+
else if (filename.match(re)) store.push(filename);
2523
}
2624
});
2725
}
@@ -30,56 +28,50 @@ function find(dir,store,re) {
3028
(assuming the main module is in a file with the same name as the parent
3129
directory) - e.g. drone/drone.js
3230
*/
33-
function sorter( precedence ){
34-
return function(a,b)
35-
{
31+
function sorter(precedence) {
32+
return function(a, b) {
3633
// convert from Java string to JS string
37-
a = '' + a;
34+
a = '' + a;
3835
b = '' + b;
3936
var aparts = a.split(/\//);
4037
var bparts = b.split(/\//);
41-
var adir = aparts.slice(3,aparts.length-1).join('/');
42-
var afile = aparts[aparts.length-1];
43-
var bdir = bparts.slice(3,bparts.length-1).join('/');
44-
var bfile = bparts[bparts.length-1];
38+
var adir = aparts.slice(3, aparts.length - 1).join('/');
39+
var afile = aparts[aparts.length - 1];
40+
var bdir = bparts.slice(3, bparts.length - 1).join('/');
41+
var bfile = bparts[bparts.length - 1];
4542

46-
for (var i = 0;i < precedence.length; i++){
43+
for (var i = 0; i < precedence.length; i++) {
4744
var re = precedence[i];
48-
if (a.match(re) && b.match(re)){
49-
if (afile < bfile)
50-
return -1;
51-
if (afile > bfile)
52-
return 1;
45+
if (a.match(re) && b.match(re)) {
46+
if (afile < bfile) return -1;
47+
if (afile > bfile) return 1;
5348
}
54-
if (a.match(re))
55-
return -1;
56-
if (b.match(re))
57-
return 1;
49+
if (a.match(re)) return -1;
50+
if (b.match(re)) return 1;
5851
}
59-
if(adir<bdir) return -1;
60-
if(adir>bdir) return 1;
61-
afile = afile.replace(/\.js$/,'');
62-
if (afile == adir){
52+
if (adir < bdir) return -1;
53+
if (adir > bdir) return 1;
54+
afile = afile.replace(/\.js$/, '');
55+
if (afile == adir) {
6356
return -1;
64-
}
65-
else {
57+
} else {
6658
var result = 0;
67-
if (afile < bfile){
68-
result = -1;
59+
if (afile < bfile) {
60+
result = -1;
6961
}
70-
if (afile > bfile){
62+
if (afile > bfile) {
7163
result = 1;
7264
}
7365
//err.println("afile: " + afile + ", bfile:" + bfile + ",result=" + result);
74-
66+
7567
return result;
7668
}
7769
};
7870
}
7971
var err = java.lang.System.err;
80-
args = Array.prototype.slice.call(args,1);
72+
args = Array.prototype.slice.call(args, 1);
8173

82-
if (typeof importPackage == 'undefined'){
74+
if (typeof importPackage == 'undefined') {
8375
// load compatibility script
8476
load('nashorn:mozilla_compat.js');
8577
}
@@ -88,28 +80,30 @@ var dir = args[0];
8880
var io = Packages.java.io;
8981
var File = io.File;
9082
var store = [];
91-
find(new io.File(dir),store,/\/[a-zA-Z0-9_\-]+\.js$/);
83+
find(new io.File(dir), store, /\/[a-zA-Z0-9_\-]+\.js$/);
9284

93-
store.sort(sorter([
94-
/lib\/scriptcraft\.js$/,
95-
/lib\/require\.js$/,
96-
/lib\/plugin\.js$/,
97-
/lib\/events\.js$/,
98-
/lib\/events\-helper\-canary/,
99-
/lib\/events\-helper\-bukkit/,
100-
/lib\//,
101-
/modules\/drone\/index\.js/,
102-
/modules\/drone\//,
103-
/plugins\/drone\//,
104-
/modules\//,
105-
/examples\//
106-
]));
85+
store.sort(
86+
sorter([
87+
/lib\/scriptcraft\.js$/,
88+
/lib\/require\.js$/,
89+
/lib\/plugin\.js$/,
90+
/lib\/events\.js$/,
91+
/lib\/events\-helper\-canary/,
92+
/lib\/events\-helper\-bukkit/,
93+
/lib\//,
94+
/modules\/drone\/index\.js/,
95+
/modules\/drone\//,
96+
/plugins\/drone\//,
97+
/modules\//,
98+
/examples\//
99+
])
100+
);
107101

108102
var contents = [];
109-
foreach(store, function(filename){
103+
foreach(store, function(filename) {
110104
var br = new io.BufferedReader(new io.FileReader(filename));
111-
var line ;
112-
while ( (line = br.readLine()) != null){
105+
var line;
106+
while ((line = br.readLine()) != null) {
113107
contents.push(line);
114108
}
115109
br.close();
@@ -120,17 +114,16 @@ var writeComment = false;
120114
var startComment = /^\/\*{10}/;
121115
var endComment = /^\*{3}\//;
122116

123-
for (var i = 0;i < contents.length; i++){
117+
for (var i = 0; i < contents.length; i++) {
124118
var line = contents[i];
125-
if (line.match(startComment)){
119+
if (line.match(startComment)) {
126120
writeComment = true;
127121
i++;
128122
}
129-
if (line.match(endComment)){
123+
if (line.match(endComment)) {
130124
writeComment = false;
131125
}
132-
if (writeComment){
126+
if (writeComment) {
133127
java.lang.System.out.println(contents[i]);
134128
}
135129
}
136-

src/docs/js/generateEntitiesDoc.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
args = Array.prototype.slice.call(args,1);
1+
args = Array.prototype.slice.call(args, 1);
22
// [0] = type, [1] = lib.jar [2] = blockX, [3] = classX
33
var out = java.lang.System.out,
44
err = java.lang.System.err,
@@ -13,34 +13,36 @@ var content = [
1313
'When each function is called with no parameters, it will return the appropriate EntityType object. ',
1414
'For example `entities.polar_bear()` will return an `EntityType.POLAR_BEAR` object. ',
1515
'',
16-
'When each function is called with a single parameter - an entity - the entity\'s type will be compared and return true or false. ',
16+
"When each function is called with a single parameter - an entity - the entity's type will be compared and return true or false. ",
1717
'',
1818
'### Usage',
1919
'',
2020
' entities.zombie(); // returns a SpigotMC/CanaryMod EntityType.ZOMBIE enum value',
21-
' entities.zombie( mob ); // compares the entity\'s type to a zombie, returns true if mob type is zombie, false otherwise',
21+
" entities.zombie( mob ); // compares the entity's type to a zombie, returns true if mob type is zombie, false otherwise",
2222
' entities.player( self ); // at the in-game prompt this should return true (compares self to a player entity type)',
2323
' entities.rabbit( self ); // at the in-game prompt this should return false (compares self to a rabbit entity type)',
2424
'',
2525
'The following functions are provided:',
2626
''
2727
];
2828

29-
var enumVals = [], t, i, name;
29+
var enumVals = [],
30+
t,
31+
i,
32+
name;
3033
var entitytypes = org.bukkit.entity.EntityType.values();
3134
for (t in entitytypes) {
3235
if (entitytypes[t] && entitytypes[t].ordinal) {
3336
name = entitytypes[t].name();
34-
name = ('' + name).replace(/^(.*)/,function(a){ return a.toLowerCase(); });
37+
name = ('' + name).replace(/^(.*)/, function(a) {
38+
return a.toLowerCase();
39+
});
3540
enumVals.push(' * ' + name + '()');
3641
}
3742
}
3843
enumVals.sort();
3944
content = content.concat(enumVals);
4045
content.push('');
41-
for (i = 0; i< content.length; i++){
46+
for (i = 0; i < content.length; i++) {
4247
out.println(content[i]);
4348
}
44-
45-
46-

src/docs/js/generateEventsHelper.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*global args*/
2-
args = Array.prototype.slice.call(args,1);
2+
args = Array.prototype.slice.call(args, 1);
33
// [0] = type, [1] = lib.jar [2] = blockX, [3] = classX
44
var File = java.io.File,
55
FileReader = java.io.FileReader,
@@ -16,88 +16,105 @@ var content = [
1616
'/*********************',
1717
'## Events Helper Module (' + FRAMEWORK + ' version)',
1818
'The Events helper module provides a suite of functions - one for each possible event.',
19-
'For example, the events.' + args[2] + '() function is just a wrapper function which calls events.on(' + args[3] + ', callback, priority)',
19+
'For example, the events.' +
20+
args[2] +
21+
'() function is just a wrapper function which calls events.on(' +
22+
args[3] +
23+
', callback, priority)',
2024
'This module is a convenience wrapper for easily adding new event handling functions in Javascript. ',
2125
'At the in-game or server-console prompt, players/admins can type `events.` and use TAB completion ',
2226
'to choose from any of the approx. 160 different event types to listen to.',
2327
'',
2428
'### Usage',
2529
'',
26-
' events.' + args[2] + '( function( event ) { ',
27-
' echo( event.player, \'You broke a block!\'); ',
30+
' events.' + args[2] + '( function( event ) { ',
31+
" echo( event.player, 'You broke a block!'); ",
2832
' });',
2933
'',
3034
'The crucial difference is that the events module now has functions for each of the built-in events. The functions are accessible via TAB-completion so will help beginning programmers to explore the events at the server console window.',
3135
'',
3236
'***/'
3337
];
3438
var canary = false;
35-
if (FRAMEWORK == 'CanaryMod'){
39+
if (FRAMEWORK == 'CanaryMod') {
3640
canary = true;
3741
}
3842

39-
for (var i = 0; i< content.length; i++){
43+
for (var i = 0; i < content.length; i++) {
4044
out.println(content[i]);
4145
}
4246
var names = [];
43-
while ( ( entry = zis.nextEntry) != null) {
47+
while ((entry = zis.nextEntry) != null) {
4448
names.push(String(entry.name));
4549
}
4650
names.sort();
4751
names.forEach(function(name) {
4852
var re1 = /org\/bukkit\/event\/.+Event\.class$/;
49-
if (canary){
53+
if (canary) {
5054
re1 = /net\/canarymod\/hook\/.+Hook\.class$/;
5155
}
52-
if ( re1.test(name) ) {
53-
name = name.replace(/\//g,'.').replace('.class','');
54-
try {
56+
if (re1.test(name)) {
57+
name = name.replace(/\//g, '.').replace('.class', '');
58+
try {
5559
clz = java.lang.Class.forName(name);
56-
}catch ( e) {
60+
} catch (e) {
5761
err.println('Warning: could not Class.forName("' + name + '")');
5862
clz = engine.eval(name);
5963
}
6064
var isAbstract = Modifier.isAbstract(clz.getModifiers());
61-
if ( isAbstract ) {
65+
if (isAbstract) {
6266
return;
6367
}
6468
var parts = name.split('.');
6569
var shortName = null;
66-
if (canary){
67-
shortName = name.replace('net.canarymod.hook.','');
70+
if (canary) {
71+
shortName = name.replace('net.canarymod.hook.', '');
6872
}
69-
if (!canary){
70-
shortName = name.replace('org.bukkit.event.','');
73+
if (!canary) {
74+
shortName = name.replace('org.bukkit.event.', '');
7175
}
72-
var fname = parts.reverse().shift().replace(/^(.)/,function(a){
73-
return a.toLowerCase();});
74-
if (!canary){
75-
fname = fname.replace(/Event$/,'');
76+
var fname = parts
77+
.reverse()
78+
.shift()
79+
.replace(/^(.)/, function(a) {
80+
return a.toLowerCase();
81+
});
82+
if (!canary) {
83+
fname = fname.replace(/Event$/, '');
7684
}
77-
if (canary){
78-
fname = fname.replace(/Hook$/,'');
85+
if (canary) {
86+
fname = fname.replace(/Hook$/, '');
7987
}
80-
var javaDoc = canary ? 'https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/hook/' : 'https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/';
88+
var javaDoc = canary
89+
? 'https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/hook/'
90+
: 'https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/';
8191
var comment = [
8292
'/*********************',
8393
'### events.' + fname + '()',
8494
'',
8595
'#### Parameters',
8696
'',
87-
' * callback - A function which is called whenever the ['+ shortName + ' event](' + javaDoc + shortName.replace('.','/') + '.html) is fired',
97+
' * callback - A function which is called whenever the [' +
98+
shortName +
99+
' event](' +
100+
javaDoc +
101+
shortName.replace('.', '/') +
102+
'.html) is fired',
88103
'',
89104
' * priority - optional - see events.on() for more information.',
90105
'',
91106
'***/'
92107
//http://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/PlayerJoinEvent.html
93108
];
94-
for (var i = 0; i < comment.length; i++){
109+
for (var i = 0; i < comment.length; i++) {
95110
out.println(comment[i]);
96111
}
97112
out.println('exports.' + fname + ' = function(callback,priority){ ');
98-
if (canary){
99-
out.println(' return events.on(Packages.' + name + ',callback,priority);');
100-
} else {
113+
if (canary) {
114+
out.println(
115+
' return events.on(Packages.' + name + ',callback,priority);'
116+
);
117+
} else {
101118
out.println(' return events.on(' + name + ',callback,priority);');
102119
}
103120
out.println('};');

0 commit comments

Comments
 (0)