Updating a plugin

Discussion in 'Plugin Development' started by pc_h8r, Feb 22, 2013.

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

    pc_h8r

    I am currently updating a plugin called WarFighter for my personal use. The way the owner made the commands is outdated. He had methods in other classes that had the command code and the actual command in the main class. So when a player did /kd , the main class took code from the other classes method and executed that. How do I modernize that code in todays world?

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3. if ((label.equalsIgnoreCase("kd")) || (label.equalsIgnoreCase("ratio"))){
    4. this.CMD_KD.execute(sender, args);
    5. }
    6.  
     
  2. Offline

    caseif

    Move the code from the external class to the onCommand method.
     
  3. Offline

    pc_h8r

    Does the onCommand method have to be in the main class? Because when I do that, it just does the return false thing and displays the command usage.e
     
  4. Offline

    bgsteiner

    onCommand can be in its own class as I usually do because i can handle all the command contexts in one class file to keep my code clean neat and organized o ill have a commandManager.class and i tell bukkit using

    getCommand("payments").setExecutor(new PaymentCommand(this));
    and inside PaymentCommand.class I have the constructor.

    Code:
        public PaymentCommand(AutoPayments instance){
         
            this.plugin = instance;
         
        }
    and the onCommand right under that
     
  5. Offline

    pc_h8r

    Oh ok thanks. Now can you help with this error I get?


    17:47:44 [INFO] MacintoshMan issued server command: /kd
    17:47:44 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'kd' in plugin WarFighter v1.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchCommand(CraftServer.java:514)
    at net.minecraft.server.v1_4_R1.PlayerConnection.handleCommand(PlayerConnection.java:980)
    at net.minecraft.server.v1_4_R1.PlayerConnection.chat(PlayerConnection.java:898)
    at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:853)
    at net.minecraft.server.v1_4_R1.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.v1_4_R1.NetworkManager.b(NetworkManager.java:290)
    at net.minecraft.server.v1_4_R1.PlayerConnection.d(PlayerConnection.java:113)
    at net.minecraft.server.v1_4_R1.ServerConnection.b(SourceFile:39)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    at de.mrpixeldream.bukkit.tdm.cmd.CommandKD.onCommand(CommandKD.java:50)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more
     
  6. Offline

    bgsteiner

    without seeing your command code the thing that got me when I first started was calling a null variable from the command context
     
  7. Offline

    pc_h8r

    oh ok ill have a look.
     
Thread Status:
Not open for further replies.

Share This Page