Anonymous avatar Anonymous committed f060853

- rename giveitem to give
- copy item properties file from SPC, should fix #2, #3
- fix double "bed" name to "bed block"
- give only quantity one for items by default, 64 for blocks

Comments (0)

Files changed (8)

           <include>config.yml</include>
         </includes>
       </resource>
+      <resource>
+        <targetPath>defaults/</targetPath>
+        <filtering>true</filtering>
+        <directory>${basedir}/src/main/resources/</directory>
+        <includes>
+          <include>itemnames.properties</include>
+        </includes>
+      </resource>
     </resources>      
     <plugins>
       <plugin>

src/main/assembly/package.xml

             <outputDirectory>/ZeekTools/</outputDirectory>
             <includes>
                 <include>config.yml</include>
+                <include>itemnames.properties</include>
             </includes>
         </fileSet>
     </fileSets>		

src/main/java/com/zzzcomputing/bukkit/ZeekTools/ZeekTools.java

         public void onPlayerJoin(PlayerJoinEvent event) {
             Util.sendPlayerMessage(event.getPlayer(), "ZeekTools enabled.");
             Util.sendPlayerMessage(event.getPlayer(), "Enter '/helpzt' for help.");
+            String motd = config.getString("motd.text");
+            if (motd != null) {
+                Util.sendPlayerMessage(event.getPlayer(), motd);
+            }
         }
         
         public void onPlayerQuit(PlayerQuitEvent event) {
     }
 
     private boolean processCommand(Player player, String cmd, String [] args) {
-        if ("giveitem".equals(cmd)) {
+        if ("give".equals(cmd)) {
             new GiveCommand(this, player).execute(cmd, args);
         }
         else if ("destroy".equals(cmd)) {

src/main/java/com/zzzcomputing/bukkit/ZeekTools/commands/GiveCommand.java

 package com.zzzcomputing.bukkit.ZeekTools.commands;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
+import java.util.Properties;
 
 import org.bukkit.Material;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.plugin.java.JavaPlugin;
 
+import com.zzzcomputing.bukkit.ZeekTools.util.Logger;
 import com.zzzcomputing.bukkit.ZeekTools.util.Util;
 
 public class GiveCommand extends Command {
     static HashMap<String, Material> names;
     
     static {
+        
         names = new HashMap<String, Material>();
-        for (Material m : Material.values()) {
-            names.put(m.toString().toLowerCase().replaceAll("[\\s_-]", ""), m);
-            names.put(String.valueOf(m.getId()), m);
+        try {
+            InputStream is = GiveCommand.class.getResourceAsStream("/defaults/itemnames.properties");  
+            Properties properties = new Properties();  
+            properties.load(is);  
+            is.close();
+            for (Object strId : properties.keySet()) {
+                String name = properties.getProperty(strId.toString());
+                int id = Integer.parseInt(strId.toString());
+                Material m = Material.getMaterial(id);
+                names.put(name.toString().toLowerCase().replaceAll("[\\s_-]", ""), m);
+                names.put(String.valueOf(m.getId()), m);
+            }
+        } catch (IOException ioe) {
+            Logger.severe("Error reading properties file", ioe);
         }
     }
 
         }
         else {
             String itemname = "";
-            int amount = 64;
+            int amount = -1;
             if (args.length > 1) {
                 try {
                     amount = Integer.valueOf(args[args.length - 1]);
             itemname = itemname.toLowerCase().replaceAll("[\\s_-]", "");
             if (names.containsKey(itemname)) {
                 Material material = names.get(itemname);
+                if (amount == -1) {
+                    if (material.getId() > 255) {
+                        // default to quantity one for items
+                        amount = 1;
+                    }
+                    else {
+                        // default to quantity 64 for blocks
+                        amount = 64;
+                    }
+                }
                 player.getInventory().addItem(new ItemStack(material, amount));
             }
             else {

src/main/java/com/zzzcomputing/bukkit/ZeekTools/commands/HelpCommand.java

     }
     @Override
     public void execute(String command, String[] args) {
-        sendPlayerMessage(ChatColor.WHITE, "/giveitem <name_or_id> [quantity] - Give item by name or number");
+        sendPlayerMessage(ChatColor.WHITE, "/give <name_or_id> [quantity] - Give item by name or number");
         sendPlayerMessage(ChatColor.WHITE, "/goto <x> <y> <z> - goto coordinates");
         sendPlayerMessage(ChatColor.WHITE, "/goto <waypoint> - goto saved waypoint");
         sendPlayerMessage(ChatColor.WHITE, "/goto player <player> - goto player position");

src/main/resources/config.yml

+motd:
+    text:

src/main/resources/itemnames.properties

+#Single Player Commands - Rename item names: ITEMID=ITEMNAME
+#Sat Aug 27 18:08:42 EDT 2011
+308=iron leggings
+307=iron chestplate
+306=iron helmet
+305=chain boots
+304=chain leggings
+303=chain chestplate
+302=chain helmet
+301=leather boots
+269=wooden shovel
+300=leather pants
+268=wooden sword
+267=iron sword
+266=gold ingot
+265=iron ingot
+264=diamond
+263=coal
+262=arrow
+261=bow
+260=apple
+259=flint and steel
+258=iron axe
+257=iron pickaxe
+256=iron shovel
+96=trapdoor
+95=locked chest
+94=
+93=
+92=cake
+91=jack 'o' lantern
+90=portal
+89=glowstone
+88=soul sand
+87=netherrack
+86=pumpkin
+85=fence
+84=jukebox
+83=sugar cane
+82=clay
+81=cactus
+80=snow
+79=ice
+78=snow
+77=button
+76=redstone torch
+75=redstone torch
+74=redstone ore
+73=redstone ore
+72=pressure plate
+71=iron door
+70=pressure plate
+69=lever
+68=sign
+67=stone stairs
+66=rail
+65=ladder
+64=wooden door
+63=sign
+62=furnace
+61=furnace
+60=farmland
+59=crops
+58=crafting table
+57=block of diamond
+56=diamond ore
+55=redstone dust
+54=chest
+53=wooden stairs
+52=monster spawner
+51=fire
+50=torch
+359=shears
+358=map
+357=cookie
+356=redstone repeater
+355=bed
+354=cake
+353=sugar
+352=bone
+351=
+350=cooked fish
+49=obsidian
+48=moss stone
+47=bookshelf
+46=tnt
+45=bricks
+44=
+43=
+42=block of iron
+41=block of gold
+40=mushroom
+349=raw fish
+348=glowstone dust
+347=clock
+346=fishing rod
+345=compass
+344=egg
+343=minecart with furnace
+342=minecart with chest
+341=slimeball
+340=book
+39=mushroom
+38=rose
+37=flower
+36=
+35=wool
+34=
+33=piston
+32=
+31=
+30=cobweb
+339=paper
+338=sugar canes
+337=clay
+336=brick
+335=milk
+334=leather
+333=boat
+332=snowball
+331=redstone
+330=iron door
+299=leather tunic
+298=leather cap
+297=bread
+296=wheat
+295=seeds
+294=golden hoe
+293=diamond hoe
+292=iron hoe
+291=stone hoe
+290=wooden hoe
+29=sticky piston
+28=detector rail
+27=powered rail
+26=bed block
+25=note block
+24=sandstone
+23=dispenser
+22=lapis lazuli block
+21=lapis lazuli ore
+20=glass
+329=saddle
+328=minecart
+327=lava bucket
+326=water bucket
+325=bucket
+324=wooden door
+9=water
+323=sign
+8=water
+322=golden apple
+7=bedrock
+321=painting
+6=sapling
+320=cooked porkchop
+5=wooden planks
+289=gunpowder
+4=cobblestone
+288=feather
+3=dirt
+287=string
+2=grass
+286=golden axe
+1=stone
+285=golden pickaxe
+284=golden shovel
+283=golden sword
+282=mushroom stew
+281=bowl
+19=sponge
+280=stick
+18=leaves
+17=wood
+16=coal ore
+15=iron ore
+14=gold ore
+13=gravel
+12=sand
+11=lava
+10=lava
+319=raw porkchop
+318=flint
+317=golden boots
+316=golden leggings
+315=golden chestplate
+314=golden helmet
+313=diamond boots
+312=diamond leggings
+311=diamond chestplate
+310=diamond helmet
+279=diamond axe
+2257=music disc
+278=diamond pickaxe
+2256=music disc
+277=diamond shovel
+276=diamond sword
+275=stone axe
+274=stone pickaxe
+273=stone shovel
+272=stone sword
+271=wooden axe
+270=wooden pickaxe
+309=iron boots

src/main/resources/plugin.yml

 description: Provides some SPC-like features to Bukkit.
 author: zzzeek
 commands:
-    giveitem:
+    give:
         description: Give item.  Will give the max unless [num] given.
         usage: give <name_or_id> [num]
     destroy:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.