help|when using my plugin

Discussion in 'Plugin Development' started by alex123099, Apr 22, 2011.

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

    alex123099

    when I am trying to use my plying this is the error I get:
    22:12:25 [SEVERE] Nag author: 'alex' of 'infItems' about the following: onPlayer
    CommandPreprocess has been replaced with a new signature, (PlayerCommandPreproce
    ssEvent)

    what does it mean?
    how do I fix this?
    Thanks!
     
  2. Offline

    jamescosten

    Whats the plugin?
     
  3. Offline

    alex123099

    I made a plugin that once you place a block then you get it in your invetory in a stack of 64
    I think that thats the part that does problems:

    public

    void onPlayerCommand(PlayerChatEvent event) {
    //Make the message a string.


    String[] split = event.getMessage().split(
    " ");
    //Get the player that talked.
    Player player = event.getPlayer();

    if ((split[0].equalsIgnoreCase("/infItems"))|| (split[0].equalsIgnoreCase("/inf"))
    || (split[0].equalsIgnoreCase("/infinite"))) {
    //Run the method toggleVision for player
    plugin.toggleVision(player);
    if(split[0].equalsIgnoreCase("/infhelp"))
    plugin.instructions(player);

    event.setCancelled(true);
    }

    anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  4. Offline

    matter123

    use on command not onPlayerCommandPreprocess
     
  5. Offline

    alex123099

    it didnt help, I am still getting the same error.
    can someone give me a guide on how to make a simple up to date plugin?
    because i've seen a guide but from how it looks like, its probably old.
     
  6. Offline

    matter123

    what is the error
     
  7. Offline

    alex123099

    [SEVERE] Nag author: 'alex' of 'infItems' about the following: onPlayer
    CommandPreprocess has been replaced with a new signature, (PlayerCommandPreproce
    ssEvent)
     
  8. Offline

    RonnSama

    This.

    If possible, I would like this spelled out for me like the newb I am. I'm having the same issue. When registering my event in the pm.RegisterEvent(Event.Type.PLAYER_COMMAND .... ) is not a valid constant. The choices I really have Event.Type.PLAYER_CHAT or Event.Type.PLAYER_COMMAND_PREPROCESS.

    I've tried several variations of each but seem to end up with the server not recognizing the command. Here's a small snippet of what I have, maybe we can compare and see.

    All I'm doing now is practice to see if I can actually make a working command (as I have failed with other tutorials I've used here)

    -------------
    I know PlayerCommandPreprocessEvent is not a desired way of dealing with it, this was after several attempts I tried this, however, this isn't want is causing the error, as it appears with both PlayerChatEvent or PlayerCommandPreprocess.
    Here is where I"m getting the "Nag Author" from. If I change Event.Type.PLAYER_COMMAND_PREPROCESS to Event.Type.PLAYER_CHAT, then I don't receive the nag author error, but I don't get the access to the command the server has no clue what it is.

    But yeah, I'm a new to Bukkit coding, so if someone has any insight I'd appreciate it. Using Bukkit 709, that coincides along with the correct version of CraftBukkit (I doubled checked before I his post reply to be sure).

    The only real thing I can't figure out is how to get the server to recognize the command. The error itself I've worked around (at least in my head I have)

    Edit:
    Fixed Redneck Typing Slurs.
    *After Note: I was never able to actually access the command.
     
  9. Offline

    matter123

    insted of what youre doing
    Code:
        public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
            if (sender instanceof Player) {
                Player p=(Player)sender;
                if (cmd.getName().equalsIgnoreCase("infItems")||
                cmd.getName().equalsIgnoreCase("infinite")||
                cmd.getName().equalsIgnoreCase("inf")) {
                    plugin.toggleVision(p);
                }
                if (cmd.getName().equalsIgnoreCase("infhelp") {
                    plugin.instructions(player);
                }
            }
        }
    use this in the main class
    dont forget to add the commands in plugin.yml
     
  10. Offline

    alex123099

    I didnt really understand,
    this is my main class:
    Code:
    package com.bukkit.alex.infItems;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.HashMap;
    import org.bukkit.Server;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    
    public class infItems extends JavaPlugin{
     private final infItemsPlayerListener playerListener = new infItemsPlayerListener(this);
        private final infItemsBlockListener blockListener = new infItemsBlockListener(this);
        public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap();
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    
     @Override
     public void onDisable() {
      System.out.println("infItems Disabled");
     }
     @Override
     public void onEnable() {
      PluginManager pm = getServer().getPluginManager();
         pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
     }
       public boolean isDebugging(final Player player) {
             if (debugees.containsKey(player)) {
                 return debugees.get(player);
             } else {
                 return false;
             }
         }
         public void setDebugging(final Player player, final boolean value) {
             debugees.put(player, value);
         }
         public boolean enabled(Player player) {
       return this.basicUsers.containsKey(player);
      }
         public void toggleVision(Player player) {
       if (enabled(player)) {
        this.basicUsers.remove(player);
        player.sendMessage("Infinite items disabled");
       } else {
        this.basicUsers.put(player, null);
        player.sendMessage("Infinite items enabled.\r\nType /infhelp for instructions.");
       }
      }
                public void instructions(Player player){
                    player.sendMessage("To turn on and off the plugin type:\r\n/infItems,\r\n/infinite,\r\n/inf.");
        player.sendMessage("To get the block you want at a stack of 64 blocks, just place 1 block.");
                }
    
    }
    
    what do I need to change here?
     
  11. Offline

    matter123

    add the snippet i gave you
    and remove the player listener and its registrations
     
  12. Offline

    alex123099

    I'm new to this, so sorry for my stupid questions :)
    by player listener do you mean the toggleView function?
    and what are the registrations?
    If you can change my main class and add your snippet that would be great!
     
  13. Offline

    RonnSama

    matter123, thanks for the code response, I implemented it myself into my code, and I have no compile errors, nor any run time errors in Bukkit, however the command itself is still not recognized, I might have it done incorrectly inside the plugin.yml.

    Code:
    name: SamaTest
    main: com.ronnsama.epicrus.SamaTest
    version: 1.0
    command:
      clearinventory:
    
    Is the command declared correctly? Or is there another way, this is how I seen all I've found so far. I couldn't think of anything else, as I've dredged thru the few lines of code I have, and cannot for the life of be figure out what's wrong besides that. Thanks again.
     
  14. Offline

    matter123

    its not that hard
    Code:
    import org.bukkit.Server;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    
    public class infItems extends JavaPlugin{
        private final infItemsBlockListener blockListener = new infItemsBlockListener(this);
        public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap();
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    
     @Override
     public void onDisable() {
      System.out.println("infItems Disabled");
     }
     @Override
     public void onEnable() {
      PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
     }
       public boolean isDebugging(final Player player) {
             if (debugees.containsKey(player)) {
                 return debugees.get(player);
             } else {
                 return false;
             }
         }
         public void setDebugging(final Player player, final boolean value) {
             debugees.put(player, value);
         }
         public boolean enabled(Player player) {
       return this.basicUsers.containsKey(player);
      }
         public void toggleVision(Player player) {
       if (enabled(player)) {
        this.basicUsers.remove(player);
        player.sendMessage("Infinite items disabled");
       } else {
        this.basicUsers.put(player, null);
        player.sendMessage("Infinite items enabled.\r\nType /infhelp for instructions.");
       }
      }
                public void instructions(Player player){
                    player.sendMessage("To turn on and off the plugin type:\r\n/infItems,\r\n/infinite,\r\n/inf.");
        player.sendMessage("To get the block you want at a stack of 64 blocks, just place 1 block.");
                }
    
        public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
            if (sender instanceof Player) {
                Player p=(Player)sender;
                if (cmd.getName().equalsIgnoreCase("infItems")||
                cmd.getName().equalsIgnoreCase("infinite")||
                cmd.getName().equalsIgnoreCase("inf")) {
                    plugin.toggleVision(p);
                }
                if (cmd.getName().equalsIgnoreCase("infhelp") {
                    plugin.instructions(player);
                }
            }
        }
    }
    and remove
    infItemsPlayerListener

    note i changed you package name it was invalid

    post your main class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  15. Offline

    alex123099

    matter,
    in what you've brought me, than the objects: cmd, player, plugin dont exist
    I need to initialize them, but i dont know where and what type.
    I'm new to this, its my first time programming a plugin so...
     
  16. Offline

    RonnSama

    Code:
    package com.ronnsama.epicrus.SamaTest;
    import java.util.HashMap;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin
    
    public class SamaTest extends JavaPlugin {
    
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
        }
        public void onDisable() {
            System.out.println("Sama Test Disabled!");
        }
        public boolean isDebugging(final Player player) {
            if (debugees.containsKey(player)) {
                return debugees.get(player);
            } else {
                return false;
            }
        }
    
        public void setDebugging(final Player player, final boolean value) {
            debugees.put(player, value);
        }
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
            if( sender instanceof Player){
                Player p=(Player)sender;
                if(command.getName().equalsIgnoreCase("clearinventory")){
                    p.getInventory().clear();
                    p.sendMessage("Inven Clear");
                }
            }
            return false;
        }
    }
    
     
  17. Offline

    matter123

    they do exist cb calls the method oncommand and passes those arguments

    try this
    Code:
    package com.ronnsama.epicrus.SamaTest;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin
    
    public class SamaTest extends JavaPlugin {
    
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
        }
        public void onDisable() {
            System.out.println("Sama Test Disabled!");
        }
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
            if( sender instanceof Player){
                Player p=(Player)sender;
                if(command.getName().equalsIgnoreCase("clearinventory")){
                    p.getInventory().clear();
                    p.sendMessage("Inven Clear");
            return true;
                }
            }
            return false;
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  18. Offline

    RonnSama

    No sadly not, I tried both putting the changes in by hand and a copy & paste, they both compile w/ no errors, and no run time errors, but the server still does not recognize the command (even if I op myself, which I did to make sure)

    And I thought the HashMap was a bit much as the command doesn't toggle, so thanks for inadvertently clearing that up for me.
     
  19. Offline

    alex123099

    I tried compiling, but I have errors here:
    Code:
    public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
            if (sender instanceof Player) {
                Player p=(Player)sender;
                if (command.getName().equalsIgnoreCase("infItems")||
                command.getName().equalsIgnoreCase("infinite")||
                command.getName().equalsIgnoreCase("inf")) {
                    [I][B]plugin[/B][/I].toggleVision(p);
                    return true;
                }
                if (command.getName().equalsIgnoreCase("infhelp")) {
                  [I] [B]plugin[/B][/I].instructions(p);
                    return true;
                }
            }
            return false;
        }
    
    It doesnt find the plugin object.
    and I also receie an error in the infItemsBlockListener:
    Code:
     public void onBlockPlace(BlockPlaceEvent event) {
       Player player = event.getPlayer();
       Block block = event.getBlockPlaced();
       if(infItems.plugin.enabled(player)){
         ItemStack[] stack=new ItemStack[1];
         stack[0].setTypeId(block.getTypeId());
         stack[0].setAmount(64);
         player.getInventory().addItem(stack);
       }
      }
    
     
  20. Offline

    matter123

    use
    Code:
    this
    instead of plugin in on command and show your error
     
  21. Offline

    alex123099

    ye, and actually i dont even have to use this because its in the same class.
    and in infItemsBlockListener, the error is that there isnt any object called plugin in infItems.
    if I remove the .plugin from this line:
    Code:
    if(infItems.plugin.enabled(player)){
    
    then it tells me to turn the enabled function to static and then it doesnt work at all.

    anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  22. Offline

    matter123

    paste your whole block listener
     
  23. Offline

    alex123099

    Code:
    //All the imports
    import com.bukkit.alex.infItems.infItemsPlayerListener;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.inventory.ItemStack;
    //Start the class BasicBlockListener
    public class infItemsBlockListener extends BlockListener{
      public static infItems plugin;
      public infItemsBlockListener(infItems instance) {
          plugin = instance;
        }
      //This method is called when ever a block is placed.
      public void onBlockPlace(BlockPlaceEvent event) {
       //Get the player doing the placing
       Player player = event.getPlayer();
       //Get the block that was placed
       Block block = event.getBlockPlaced();
       //If the block is a torch and the player has the command enabled. Do this.
       if(infItemsPlayerListener.plugin.enabled(player)){
                                ItemStack[] stack=new ItemStack[1];
                                stack[0].setTypeId(block.getTypeId());
                                stack[0].setAmount(64);
                                player.getInventory().addItem(stack);
       }
      }
    }
    
    someone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  24. Offline

    matter123

    Code:
    //All the imports
    import com.bukkit.alex.infItems.infItemsPlayerListener;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.inventory.ItemStack;
    //Start the class BasicBlockListener
    public class infItemsBlockListener extends BlockListener{
      public infItems plugin;
      public infItemsBlockListener(infItems instance) {
          plugin = instance;
        }
      //This method is called when ever a block is placed.
      public void onBlockPlace(BlockPlaceEvent event) {
       //Get the player doing the placing
       Player player = event.getPlayer();
       //Get the block that was placed
       Block block = event.getBlockPlaced();
       //If the block is a torch and the player has the command enabled. Do this.
       if(plugin.enabled(player)){
                                ItemStack[] stack=new ItemStack[1];
                                stack[0].setTypeId(block.getTypeId());
                                stack[0].setAmount(64);
                                player.getInventory().addItem(stack);
       }
      }
    }
    
     
  25. Offline

    alex123099

    now it just doesnt do a thing.
    it works with no problems but once i place a block the ammount i have in a stack doesnt change
     
  26. Offline

    matter123

    show me your plugin.yml
     
  27. Offline

    alex123099

    Code:
    name: infItems
    main: com.bukkit.alex.infItems.infItems
    version: 1
    description: A Basic plugin
    authors:
    - alex
    commands:
     inf:
      usage: /inf
     infinite:
      usage: /infinite
     infhelp:
      usage: /infhelp
     infItems:
      usage: /infItems
    
     
  28. Offline

    matter123

    make main com.alex.infItems.infItems
    make all your packages com.alex.infItems
     
  29. Offline

    alex123099

    still no change
    here's all my code see if you can change it or something so it will work:
    main class:
    Code:
    
    package com.alex.infItems;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.HashMap;
    import org.bukkit.Server;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    public class infItems extends JavaPlugin{
        public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap();
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    
     @Override
     public void onDisable() {
      System.out.println("infItems Disabled");
     }
     @Override
     public void onEnable() {
       PluginManager pm = getServer().getPluginManager();
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
     }
       public boolean isDebugging(final Player player) {
             if (debugees.containsKey(player)) {
                 return debugees.get(player);
             } else {
                 return false;
             }
         }
         public void setDebugging(final Player player, final boolean value) {
             debugees.put(player, value);
         }
         public boolean enabled(Player player) {
       return this.basicUsers.containsKey(player);
      }
         public void toggleVision(Player player) {
       if (enabled(player)) {
        this.basicUsers.remove(player);
        player.sendMessage("Infinite items disabled");
       } else {
        this.basicUsers.put(player, null);
        player.sendMessage("Infinite items enabled.\r\nType /infhelp for instructions.");
       }
      }
                public void instructions(Player player){
                    player.sendMessage("To turn on and off the plugin type:\r\n/infItems,\r\n/infinite,\r\n/inf.");
        player.sendMessage("To get the block you want at a stack of 64 blocks, just place 1 block.");
                }
        public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
            if (sender instanceof Player) {
                Player p=(Player)sender;
                if (command.getName().equalsIgnoreCase("infItems")||
                command.getName().equalsIgnoreCase("infinite")||
                command.getName().equalsIgnoreCase("inf")) {
                    toggleVision(p);
                    return true;
                }
                if (command.getName().equalsIgnoreCase("infhelp")) {
                    instructions(p);
                    return true;
                }
            }
            return false;
        }
    }
    
    blockListener:
    Code:
    package com.alex.infItems;
    //All the imports
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.inventory.ItemStack;
    //Start the class BasicBlockListener
    public class infItemsBlockListener extends BlockListener{
      public infItems plugin;
      public infItemsBlockListener(infItems instance) {
          plugin = instance;
        }
      //This method is called when ever a block is placed.
      public void onBlockPlace(BlockPlaceEvent event) {
       //Get the player doing the placing
       Player player = event.getPlayer();
       //Get the block that was placed
       Block block = event.getBlockPlaced();
       //If the block is a torch and the player has the command enabled. Do this.
       if(plugin.enabled(player)){
                                ItemStack[] stack=new ItemStack[1];
                                stack[0].setTypeId(block.getTypeId());
                                stack[0].setAmount(64);
                                player.getInventory().addItem(stack);
       }
      }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  30. Offline

    matter123

    new plugin.yml?
     
Thread Status:
Not open for further replies.

Share This Page