Fix issue #111, reorg of lib/ and (undoc'd) persistence · linuxboytoo/ScriptCraft@aefc98f · GitHub
Skip to content

Commit aefc98f

Browse files
committed
Fix issue walterhiggins#111, reorg of lib/ and (undoc'd) persistence
1 parent c77e78c commit aefc98f

18 files changed

Lines changed: 514 additions & 106 deletions

File tree

‎build.xml‎

Lines changed: 2 additions & 9 deletions

‎docs/API-Reference.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Walter Higgins
117117
* [Example Plugin #7 - Listening for events, Greet players when they join the game.](#example-plugin-7---listening-for-events-greet-players-when-they-join-the-game)
118118
* [Arrows Plugin](#arrows-plugin)
119119
* [Usage:](#usage-6)
120+
* [Spawn Plugin](#spawn-plugin)
121+
* [Usage](#usage-7)
120122
* [alias Plugin](#alias-plugin)
121123
* [Examples](#examples-2)
122124
* [Classroom Plugin](#classroom-plugin)
@@ -135,6 +137,10 @@ Walter Higgins
135137
* [Example](#example-1)
136138
* [SnowballFight mini-game](#snowballfight-mini-game)
137139
* [Description](#description-2)
140+
* [Cow Clicker Mini-Game](#cow-clicker-mini-game)
141+
* [How to Play](#how-to-play)
142+
* [Rules](#rules)
143+
* [Gameplay Mechanics](#gameplay-mechanics)
138144

139145
## Modules in Scriptcraft
140146

@@ -2340,6 +2346,18 @@ All of the above functions can take an optional player object or name
23402346
as a parameter. For example: `/js arrows.explosive('player23')` makes
23412347
player23's arrows explosive.
23422348

2349+
## Spawn Plugin
2350+
2351+
Allows in-game operators to easily spawn creatures at current location.
2352+
2353+
### Usage
2354+
2355+
/jsp spawn cow
2356+
/jsp spawn sheep
2357+
/jsp spawn wolf
2358+
2359+
See <http://jd.bukkit.org/beta/apidocs/org/bukkit/entity/EntityType.html> for a list of possible entities (creatures) which can be spawned.
2360+
23432361
## alias Plugin
23442362

23452363
The alias module lets players and server admins create their own
@@ -2621,3 +2639,44 @@ player returns to their previous mode of play (creative or
26212639
survival). Create a small arena with a couple of small buildings for
26222640
cover to make the game more fun.
26232641

2642+
## Cow Clicker Mini-Game
2643+
2644+
### How to Play
2645+
2646+
At the in-game prompt type `jsp cowclicker` to start or stop
2647+
playing. Right-Click on Cows to score points. No points for killing
2648+
cows (hint: use the same keyboard keys you'd use for opening doors).
2649+
2650+
Every time you click a cow your score increases by 1 point. Your score
2651+
is displayed in a side-bar along the right edge of of the screen.
2652+
2653+
![cow clicker](img/cowclicker.png)
2654+
2655+
### Rules
2656+
2657+
* You can join and leave the Cow Clicker game at any time by typing
2658+
`/jsp cowclicker` at the in-game prompt.
2659+
2660+
* Once you leave the game, your score is reset to zero.
2661+
2662+
* You can disconnect from the server and your score will be saved for
2663+
the next time you join.
2664+
2665+
### Gameplay Mechanics
2666+
2667+
This is meant as a trivially simple use of the [Bukkit Scoreboard
2668+
API][bukscore]. There are many things you'll want to consider when constructing
2669+
your own mini-game...
2670+
2671+
* Is the game itself a long-lived game - that is - should players and
2672+
scores be persisted (stored) between server restarts?
2673+
2674+
* What should happen when a player quits the server - should this also be
2675+
understood as quitting the mini-game?
2676+
2677+
* What should happen when a player who was previously playing the
2678+
mini-game, joins the server - should they automatically resume the
2679+
mini-game?
2680+
2681+
[bukscore]: http://jd.bukkit.org/beta/apidocs/org/bukkit/scoreboard/package-summary.html
2682+

‎docs/Using-Java-APIs-In-Javascript.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ using the more succinct...
3535
it is easier to read. The important thing to remember when using the
3636
Bukkit (or any Java API) from Javascript is that for any Java Bean, a
3737
property called `propertyName` will have a getter called
38-
`getPropertyName()` and a setter called `setPropertyName`. From this
38+
`getPropertyName()` and a setter called `setPropertyName()`. From this
3939
rule you can infer what any Bukkit class properties are. For example,
4040
the [Bukkit Player][bukpl] object has the following methods...
4141

42-
* float getWalSpeed()
42+
* float getWalkSpeed()
4343
* void setWalkSpeed(float speed)
4444

4545
... so from this you can infer that every Player object has a
@@ -61,7 +61,7 @@ the world in which a player is located...
6161
If you're new to Java and the [Bukkit API][bukapi] is the first time
6262
you've browsed Java documentation, you may be wondering where the
6363
`location` property came from - the `location` property is "inherited"
64-
by one of the Player classes super-classes. You'll see the
64+
from one of the Player class's super-classes (it's ancestors). You'll see the
6565
`getLocation()` method listed under a section titled **Methods
6666
inherited from interface org.bukkit.entity.Entity** in the
6767
[Player][bukpl] javadoc page.

‎docs/img/cowclicker.png‎

98 KB
Loading

‎docs/release-notes.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# 2014 01 12
2+
3+
## Important
4+
The ScriptCraft.jar file has been renamed scriptcraft.jar (see bug fix
5+
details below). This means that you will have to remove the existing
6+
`plugins/ScriptCraft.jar` file if present.
7+
8+
Bug Fix: On Mac OS, the plugins/scriptcraft directory is copied to
9+
plugins/ScriptCraftPlugin the 2nd time ScriptCraftPlugin is loaded.
10+
This has been fixed by changing the plugin name from ScriptCraftPlugin
11+
to scriptcraft. The jar file has also been rename from
12+
ScriptCraft.jar to scriptcraft.jar.
13+
14+
New command: `jsp spawn` lets in-game operators spawn any type of
15+
entity. For example `/jsp spawn cow` will spawn a cow at the in-game
16+
operator's current location.
17+
18+
New minigame: Cow Clicker. A simple demonstration of using Bukkit's
19+
Scoreboard API. Players click cows to score points. Scores are
20+
displayed in a side bar on screen. Players join or leave the game by
21+
typing `/jsp cowclicker` at the in-game prompt.
22+
123
# 2014 01 05
224

325
Bug Fix: On Mac OS, alias plugin caused Exceptions due to missing

‎src/docs/javascript/generateTOC.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
args = args.slice(1);
22

3+
// wph 20140105 trim not availabe in String on Mac OS.
4+
if (typeof String.prototype.trim == 'undefined'){
5+
String.prototype.trim = function(){
6+
return this.replace(/^\s+|\s+$/g,'');
7+
};
8+
}
9+
310
var template = args[0];
411

512
var BufferedReader = java.io.BufferedReader;

‎src/main/java/net/walterhiggins/scriptcraft/ScriptCraftPlugin.java‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
2929
/**
3030
* Unzips bundled javascript code.
3131
*/
32-
private void unzipJS()
32+
private void unzipJS() throws IOException
3333
{
3434
//
3535
// does the js-plugins directory exist?
3636
//
3737
File jsPlugins = new File(JS_PLUGINS_DIR);
3838
if (!jsPlugins.exists())
3939
{
40-
getLogger().finest("Directory " + JS_PLUGINS_DIR + " does not exist.");
41-
getLogger().finest("Initializing " + JS_PLUGINS_DIR + " directory with contents from plugin archive.");
42-
jsPlugins.mkdir();
40+
getLogger().info("Directory " + jsPlugins.getCanonicalPath() + " does not exist.");
41+
getLogger().info("Initializing " + jsPlugins.getCanonicalPath() + " directory with contents from plugin archive.");
42+
try{
43+
jsPlugins.mkdirs();
44+
}catch(Exception e){
45+
throw new RuntimeException("Failed to create directory " + jsPlugins.getCanonicalPath() + ":" + e.getMessage());
46+
}
4347
}
4448

4549
ZipInputStream zis = new ZipInputStream(getResource(JS_PLUGINS_ZIP));
@@ -48,7 +52,7 @@ private void unzipJS()
4852
while ( ( entry = zis.getNextEntry() ) != null)
4953
{
5054
String filename = entry.getName();
51-
//File newFile = new File(jsPlugins.getName() + File.separator + filename);
55+
5256
File newFile = new File(jsPlugins, filename);
5357

5458
//create all non exists folders
@@ -59,17 +63,23 @@ private void unzipJS()
5963
//
6064
// only write out to file if zip entry is newer than file
6165
//
66+
String reason = null;
6267
long zTime = entry.getTime();
6368
boolean unzip = false;
64-
if (!newFile.exists())
69+
if (!newFile.exists()){
70+
reason = "NE";
6571
unzip = true;
72+
}
6673
else{
6774
long fTime = newFile.lastModified();
68-
if (zTime > fTime)
75+
if (zTime > fTime){
76+
reason = "" + new Long((zTime-fTime)/3600000) + "h";
6977
unzip = true;
78+
}
79+
7080
}
7181
if (unzip){
72-
getLogger().info("Unzipping " + newFile.getCanonicalPath());
82+
getLogger().info("Unzipping " + newFile.getCanonicalPath() + " (" + reason + ")" );
7383
FileOutputStream fout = new FileOutputStream(newFile);
7484
for (int c = zis.read(); c != -1; c = zis.read()) {
7585
fout.write(c);
@@ -90,9 +100,9 @@ private void unzipJS()
90100
@Override
91101
public void onEnable()
92102
{
93-
unzipJS();
94103
FileReader reader = null;
95104
try{
105+
unzipJS();
96106
ScriptEngineManager factory = new ScriptEngineManager();
97107
File bootScript = new File(JS_PLUGINS_DIR + "/lib/scriptcraft.js");
98108
this.engine = factory.getEngineByName("JavaScript");
@@ -103,6 +113,7 @@ public void onEnable()
103113

104114
}catch(Exception e){
105115
e.printStackTrace();
116+
this.getLogger().severe(e.getMessage());
106117
}finally {
107118
if (reader != null){
108119
try {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
module.exports = function($){
3+
4+
// wph 20140105 trim not availabe in String on Mac OS.
5+
if (typeof String.prototype.trim == 'undefined'){
6+
String.prototype.trim = function(){
7+
return this.replace(/^\s+|\s+$/g,'');
8+
};
9+
}
10+
11+
$.setTimeout = function( callback, delayInMillis){
12+
/*
13+
javascript programmers familiar with setTimeout know that it expects
14+
a delay in milliseconds. However, bukkit's scheduler expects a delay in ticks
15+
(where 1 tick = 1/20th second)
16+
*/
17+
var bukkitTask = server.scheduler.runTaskLater(__plugin, callback, delayInMillis/50);
18+
return bukkitTask;
19+
};
20+
$.clearTimeout = function(bukkitTask){
21+
bukkitTask.cancel();
22+
};
23+
24+
$.setInterval = function(callback, intervalInMillis){
25+
var delay = intervalInMillis/ 50;
26+
var bukkitTask = server.scheduler.runTaskTimer(__plugin, callback, delay, delay);
27+
return bukkitTask;
28+
};
29+
$.clearInterval = function(bukkitTask){
30+
bukkitTask.cancel();
31+
};
32+
};
33+
Lines changed: 37 additions & 0 deletions

0 commit comments

Comments
 (0)