Permalink
Browse files

update

  • Loading branch information...
ochristi committed Jul 13, 2011
1 parent 8e04eba commit 08fd052d5d2aa33811ad2919e1d63e11866f41a8
Showing with 44 additions and 19 deletions.
  1. +20 −9 info.js
  2. +24 −10 rem-1inv.js
View
29 info.js
@@ -12,26 +12,37 @@ importClass(Packages.java.util.HashMap);
var currentworld = player.getWorld().getWorld();
+/** World ***************************************************** */
player.print("current world: " + currentworld.getName());
+
+/** Chunks ***************************************************** */
player.print("loaded chunks: " + currentworld.getLoadedChunks().length);
+
+/** Time ***************************************************** */
player.print("time: " + currentworld.getTime());
-player.print("entities: " + currentworld.getEntities().size());
-var ent = new HashMap();
-for ( var i = 0; i < currentworld.getEntities().size(); i++) {
- var currentEntity = currentworld.getEntities().get(i).toString();
- if (!ent.containsKey(currentEntity)) {
- ent.put(currentEntity, 1);
+
+/** Entities ***************************************************** */
+var entities = currentworld.getEntities();
+player.print("entities: " + entities.size());
+var entityCount = new HashMap();
+for ( var i = 0; i < entities.size(); i++) {
+ var currentEntity = entities.get(i).toString();
+ if (!entityCount.containsKey(currentEntity)) {
+ entityCount.put(currentEntity, 1);
// player.print("new " + currentEntity);
} else {
- ent.put(currentEntity, parseInt(ent.get(currentEntity)) + 1);
+ entityCount.put(currentEntity,
+ parseInt(entityCount.get(currentEntity)) + 1);
// player.print("another " + currentEntity);
}
}
-var entries = ent.entrySet();
+var entries = entityCount.entrySet();
var iter = entries.iterator();
var entityStr = "";
while (iter.hasNext()) {
var next = iter.next();
entityStr += next.getKey() + "@" + next.getValue() + "; ";
}
-player.print(entityStr);
+player.print(entityStr);
+
+/** ... ***************************************************** */
View
@@ -1,17 +1,16 @@
/**
* craftscript
*
- * removes all -1 (or less) "infinite" items
- * from (all/specified) online players
+ * removes all -1 (or less) "infinite" items from (all/specified) online players
*
- * usage: /cs rem-1inv [regex] [?]
- * If regex pattern is omitted all players are affected.
- * A non empty second argument will only print which players are matched.
+ * usage: /cs rem-1inv [regex] [?] If regex pattern is omitted all players are
+ * affected. A non empty second argument will only print which players are
+ * matched.
*
* @author ochristi aka o0c
*/
-importClass(org.bukkit.craftbukkit.inventory.CraftItemStack);
+importClass(java.util.HashSet);
// matcher
if (argv[1] != undefined) {
@@ -22,7 +21,7 @@ if (argv[1] != undefined) {
// debug (only prints the affected players without removing items)
var debug = argv[2] != undefined;
-var affected = "";
+var affected = new HashSet();
// retrieve the current world
var world = player.getWorld().getWorld();
@@ -44,13 +43,28 @@ for ( var derp in players) {
if (!debug) {
playerInv.clear(slot);
} else {
- affected += players[derp].getName() + " ";
+ affected.add(players[derp].getName());
break;
}
}
}
}
}
-// print debug
-player.print(affected);
+var names = "";
+var iter = affected.iterator();
+while (iter.hasNext()) {
+ names += " " + iter.next();
+}
+
+// print output
+if (names != "") {
+ // debug or not
+ if (!debug) {
+ player.print("removed items from: " + names);
+ } else {
+ player.print("these players would have been affected: " + names);
+ }
+} else {
+ player.print("no players affected");
+}

0 comments on commit 08fd052

Please sign in to comment.