IM SO CONFUSED! SOMEONE PLEASE HELP ME!?!

Discussion in 'Bukkit Help' started by Gam3rTr0n69, Jan 24, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Gam3rTr0n69

    OK, here's my story... over the last couple of days I have been learning java to create some plugins for my server. I have learned a lot by looking at other peoples plugin sources, and I tried to make my own wool spawner by following this persons source for his. I made mine and theres no errors, but when I put it on to CraftBukkit it say's something about not being able to load plugin into null? I don't know what this means and therefore have no clue on how to fix it. If someone coule please look at my code and tell me whats wrong with it and how to fix it, it would help a lot!

    Heres my code for the .class file:
    Code:
    package com.bukkit.gam3rtr0n69.PowerCloth;
    
    import java.util.Hashtable;
    import java.util.Map;
    import java.util.logging.Logger;
    import java.util.regex.PatternSyntaxException;
    import java.io.*;
    
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    /**
     * PowerCloth for Bukkit
     *
     * @author Gam3rTr0n69
     */
    public class PowerCloth extends JavaPlugin{
        protected static final Logger log = Logger.getLogger("Minecraft");
        public Hashtable<String,Integer> colors= new Hashtable<String,Integer>();
        public PowerCloth(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File  folder, File plugin, ClassLoader cLoader) {
            super(pluginLoader, instance, desc, folder, plugin, cLoader);
            System.out.println(desc.getName() + " version " + desc.getVersion() + " initialized");
        }
        public int color_to_num(String s){
            if(colors.containsKey(s)){
                return colors.get(s);
            }
            try {
                if (s.matches("(?si)([0-9]+)")) {
                    return Integer.valueOf(s);
                } else {
                }
            } catch (PatternSyntaxException ex) {
            }
            return 0;
        }
        public void give_wool(Player player, String color, Integer amount){
            Byte data = null;
            String s= String.valueOf(color_to_num(color));
            data = Byte.valueOf(s);
            player.getInventory().all(35);
            for (int i = 0; i < amount; i++){
                player.getInventory().addItem(new ItemStack(35, (int) 64, (byte)0, data));
            }
            player.sendMessage("Server is spawning you "+(amount*64)+" "+color+" wool");
        }
        public boolean onCommand(Player player, Command command, String commandLabel, String[] args) {
            if(player.isOp()){
                String commandName = command.getName().toLowerCase();
                if(commandName.equalsIgnoreCase("cloth")){
                    if(args.length==1){
                        if(args[0].equalsIgnoreCase("list")){
                            String mi="";
                            for ( Map.Entry<String, Integer> entry : colors.entrySet() ){
                                String key = entry.getKey();
                                mi=mi+key+",";
                            }
                            player.sendMessage(mi);
                        }else{
                            give_wool(player,args[0],1);
                        }
                    }else if(args.length==2){
                        give_wool(player,args[0],Integer.valueOf(args[1]));
                    }else{
                        give_wool(player,"white",1);
                    }
                    return true;
                }
            }
            return false;
        }
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
            colors.put("orange",1);
            colors.put("white",0);
            colors.put("magenta",2);
            colors.put("light_blue",3);
            colors.put("yellow",4);
            colors.put("lime",5);
            colors.put("pink",6);
            colors.put("grey",7);
            colors.put("light_grey",8);
            colors.put("cyan",9);
            colors.put("purple",10);
            colors.put("blue",11);
            colors.put("brown",12);
            colors.put("green",13);
            colors.put("red",14);
            colors.put("black",15);
        }
        public void onDisable() {
        }
    }
    I really wanna learn java and if someone could help me out it would help me and my server out a lot!

    P.S
    If you need the entire source file (like with the plugin.yml and all that) I will try and upload it to GitHub!
     
  2. Offline

    craftersins

    You need to use a PlayerListener, you can't just use your own onCommand the way you do here afaik, it will not be called. You overrite the onPlayerCommand in the PlayerListener.
     
  3. Offline

    Gam3rTr0n69

    so all i have to do is move the onCommand boolean to a playerlistener?
     
  4. Offline

    craftersins

    Its called
    Code:
    @Override
    public void onPlayerCommand(PlayerChatEvent event) {
    // your code here
    }
    You should browse the bukkit sourcecode for more info, its the PlayerListener class.
     
  5. Offline

    Gam3rTr0n69


    ok, im still confused i did this but when i move the code from the boolean it into the onPlayerCommand void it says that player cannot be resolved?

    here is my code for the playerlistener:
    Code:
    package com.bukkit.gam3rtr0n69.PowerCloth;
    
    import java.util.Map;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.entity.Player;
    
    /**
     * Handle events for all Player related events
     * @author Gam3rTr0n69
     */
    public class PowerClothPlayerListener extends PlayerListener {
        private final PowerCloth plugin;
    
        public PowerClothPlayerListener(PowerCloth instance) {
            plugin = instance;
        }
    
        @Override
        public void onPlayerCommand(PlayerChatEvent event) {
            if(player.isOp()){
                    String commandName = command.getName().toLowerCase();
                    if(commandName.equalsIgnoreCase("cloth")){
                        if(args.length==1){
                            if(args[0].equalsIgnoreCase("list")){
                                String mi="";
                                for ( Map.Entry<String, Integer> entry : colors.entrySet() ){
                                    String key = entry.getKey();
                                    mi=mi+key+",";
                                }
                                player.sendMessage(mi);
                            }else{
                                give_wool(player,args[0],1);
                            }
                        }else if(args.length==2){
                            give_wool(player,args[0],Integer.valueOf(args[1]));
                        }else{
                            give_wool(player,"white",1);
                        }
                    }
            }
        }
    }
    What am I supposed to fix?
    P.S Thanks for the help! :D
     
  6. Offline

    craftersins

    I only check the most common errors I found and add a comment, I don't have time to go through all in detail sorry.
    Hope my notes help you a little. You should go check some PlayerListener classes.

    Code:
    package com.bukkit.gam3rtr0n69.PowerCloth;
    
    import java.util.Map;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.entity.Player;
    
    /**
     * Handle events for all Player related events
     * @author Gam3rTr0n69
     */
    public class PowerClothPlayerListener extends PlayerListener {
        private final PowerCloth plugin;
    
        public PowerClothPlayerListener(PowerCloth instance) {
            plugin = instance;
        }
    
        @Override
        public void onPlayerCommand(PlayerChatEvent event) {
            // if(player.isOp()){ use below instead
               if (event.getPlayer().isOp()) {
                     
            /*I gets messy here. you can't just write command
                     you need to get it from the event as well.
                     e.g.  
                     String[] cmdParts = event.getMessage().split(" ");
                     if (cmdParts[0].equalsIgnoreCase("/yourcommand")) {
                     cmdParts contains the command parts, like /yourcommand somevalue
                     somevalue would be in cmdParts[1]*/
                     
                    // below here you need to rewrite check the above comment
                    String commandName = command.getName().toLowerCase();
                    if(commandName.equalsIgnoreCase("cloth")){
                        if(args.length==1){
                            if(args[0].equalsIgnoreCase("list")){
                                String mi="";
                                for ( Map.Entry<String, Integer> entry : colors.entrySet() ){
                                    String key = entry.getKey();
                                    mi=mi+key+",";
                                }
                                player.sendMessage(mi);
                            }else{
                                give_wool(player,args[0],1);
                            }
                        }else if(args.length==2){
                            give_wool(player,args[0],Integer.valueOf(args[1]));
                        }else{
                            give_wool(player,"white",1);
                        }
                    }
            }
        }
    }
    
     
  7. Offline

    Gam3rTr0n69

    kk this should be the last thing i need, i read the notes and fixed everything and it all works, i was just wondering how i get it to read the colors from the main .class file? and for the give_wool command it has an error on "player"?

    here is my code: it should work... right?
    Code:
    package com.bukkit.gam3rtr0n69.PowerCloth;
    
    import java.util.Map;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.entity.Player;
    
    /**
     * Handle events for all Player related events
     * @author Gam3rTr0n69
     */
    public class PowerClothPlayerListener extends PlayerListener {
        private final PowerCloth plugin;
    
        public PowerClothPlayerListener(PowerCloth instance) {
            plugin = instance;
        }
    
        @Override
        public void onPlayerCommand(PlayerChatEvent event) {
            if (event.getPlayer().isOp()) {
    
            String[] cmdParts = event.getMessage().split(" ");
                   if (cmdParts[0].equalsIgnoreCase("/cloth")) {
                       if (cmdParts.length==1){
                           if(cmdParts[0].equalsIgnoreCase("/list")){
                               String mi ="";
                               for (Map.Entry<String, Integer> entry : colors.entrySet() ){
                                   String key = entry.getKey();
                                   mi=mi+key+",";
                               }
                               event.getPlayer().sendMessage(mi);
                           }else{
                               give_wool(player,cmdParts[0],1);
                           }
                       }else if(cmdParts.length==2){
                           give_wool(player,cmdParts[0],Integer.valueOf(cmdParts[1]));
                       }else{
                           give_wool(player,"white",1);
                       }
                   }
               }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page