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

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

    matter123

    i have no idea
     
  3. Offline

    alex123099

    well thanks for your time :)
    Say, do you know any good guides or basic plugins that are good for teaching begginers?

    ok I have managed to do that it makes all my items at max, but i have 2 problems:
    each time i use the command, it works, but gives this error:
    Code:
    02:32:12 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'infi
    niteitems' in plugin infiniteItems v1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80
    )
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:2
    54)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:650)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:613)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:607)
            at net.minecraft.server.Packet3Chat.a(SourceFile:36)
            at net.minecraft.server.NetworkManager.a(NetworkManager.java:195)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:73)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:370)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:285)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    Caused by: java.lang.NullPointerException
            at com.alex.infiniteItems.infiniteItems.onCommand(infiniteItems.java:87)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
            ... 12 more
    
    and a question, how can I do that my items always stay stacked as 64 until i toggle off the plugin?
    I have tried using a while loop but it didnt help.
    here's the code i wrote:
    Code:
    public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
             if (sender instanceof Player) {
                 Player p=(Player)sender;
                 if (command.getName().equalsIgnoreCase("infiniteitems")){
                     toggleVision(p);
                     while(enabled(p)){
                      ItemStack[] stack = p.getInventory().getContents();
                      for(int i=0;i<stack.length;i++)
                       stack[i].setAmount(64);
                     }
                     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
  4. Offline

    matter123

    while loops are bad todo that you need todo something like this

    loopthread.java
    Code:
    package com.matter123.infitems;
    
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    
    public class loopthread extends Thread{
        Player p;
        /**
         * @param p
         */
        private boolean run;
        public loopthread(Player p) {
            this.p = p;
            run=true;
        }
        /**
         * @param run the run to set
         */
        public void setRun(boolean run) {
            this.run = run;
        }
        @Override
        public void run() {
            while(run) {
                ItemStack[] stack=p.getInventory().getContents();
                for (int i=0;i<stack.length;i++) {
                    stack[i].setAmount(stack[i].getMaxStackSize());
                }
                p.getInventory().setContents(stack);
            }
        }
    
    }
    main class
    add this snippet
    Code:
        HashMap<Player,loopthread> tlist=new HashMap<Player,loopthread>();
        void toggle(Player p) {
            if (tlist.containsKey(p)) {
                tlist.get(p).setRun(false);
                tlist.remove(p);
            }else {
                loopthread t=new loopthread(p);
                tlist.put(p, t);
                t.start();
            }
        }
     
  5. Offline

    RonnSama

    Had to go take a nap, was getting aggrevated with it. So how exactly did you get the server to recognize the actual / command? I'm still stuck at that point, it says it's never heard of it before, so I dunno what to do tbh. Everything compiles and runs fine, it just doesn't work, I dunno what else to do
     
  6. Offline

    matter123

    plugin.yml please
     
  7. Offline

    RonnSama

    Same one I showed you before, no real changes.

    Code:
    name: SamaTest
    main: com.ronnsama.epicrus.test.SamaTest
    version: 1.0
    command:
     clearinventory:
      usage: /clearinventory
    
    Been playing w/ it some, so it's not EXACTLY like it wasy, only added the usage line.
     
  8. Offline

    matter123

    all files
     
  9. Offline

    RonnSama

    Code:
    package com.ronnsama.epicrus.test;
    
    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;
        }
    }
    
    Pretty much still the same code you wrote for me. All I gotta do is figure out where I'm messing up at trying to get the commands to be recognized by the server, and then I"ll be golden. But I just can't seem to make that connection or I'm missing something terrible.

    I don't have any listeners, because you had me unregister the PluginManager, and the Events, this is the only file, it does the one thing just cuz I want to see it do SOMETHING before I attempt to code anything useful.
     
  10. Offline

    matter123

    try change Command command to Command cmd
     
  11. Offline

    RonnSama

    Ok sorry for the lag reply, was testing things. One I found out why the server wasn't recognizing my command, in plugin.yml I used command: instead of commands: I had to re-read like 6 or 7 plugin.yml's before I slapped myself in the face for no seeing it. Changing Command command, to command cmd, had no effect on the server, HOWEVER when changing command: to commands: the server starting spitting Null Pointer Exceptions. My only problem is, it doesn't point to where I caused it.

    Code:
    (SEVERE) null (Is it up to date?)
    java.lang.NullPointerException
        at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:24)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:109)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:94)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:217)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:144)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:259)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    
    Now I'm sure it's something I've done, and I had to rework the code itself a bit to get to this state, allow me to repost, the updated code.

    This is my main
    Code:
    package com.ronnsama.epicrus.samatest;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class SamaTest extends JavaPlugin{
    
        public void onDisable() {
            System.out.println("SamaTest Disabled");
    
        }
    
        public void onEnable() {
            System.out.println("SamaTest Enabled");
            getCommand("clearinventory").setExecutor(new SamaTestClear(this));
    
        }
    
    
    
    }
    
    And it refers to the CommandExecutor which is implemented thru this class

    Code:
    package com.ronnsama.epicrus.samatest;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class SamaTestClear implements CommandExecutor{
        private final SamaTest plugin;
    
        public SamaTestClear(SamaTest instance){
            this.plugin = instance;
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] split){
            if (!(sender instanceof Player)) {
                return false;
            }
            Player player = (Player) sender;
            if(split.length == 0){
                player.getInventory().clear();
                player.sendMessage("Inven Clear");
                return true;
            }
            return false;
        }
    }
    
    Now I'm completely sure I've done something stupid somewhere like I did with plugin.yml and becaues I'm so unfamiliar with it I have no idea what. And matter, I do appreciate all the time you've put into helping me, I'm almost there, ALMOST! lol :D
     
  12. Offline

    matter123

    can i have the whole log
    also try removeing the if split.length==0
     
  13. Offline

    RonnSama

    Sure. The first few were experiments on booting to see what is or isn't causing errors, the very last one however is the official Log for the boot I'm referring to.

    Code:
    [INFO] Starting minecraft server version Beta 1.5_02
    2011-04-22 22:36:01 [INFO] Loading properties
    2011-04-22 22:36:01 [INFO] Starting Minecraft server on *:21800
    2011-04-22 22:36:01 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-681-g0f8abd2-b709jnks (MC: 1.5_02)
    2011-04-22 22:36:01 [INFO] Preparing level "world"
    2011-04-22 22:36:01 [INFO] Preparing start region
    2011-04-22 22:36:02 [INFO] SamaTest Enabled
    2011-04-22 22:36:02 [SEVERE] null loading SamaCore v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com.ronnsama.epicrus.samatest.SamaTest.onEnable(SamaTest.java:16)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:127)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:584)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:218)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:116)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:94)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:217)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:144)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:259)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    2011-04-22 22:36:02 [INFO] Done (0.099s)! For help, type "help" or "?"
    2011-04-22 22:37:44 [INFO] Starting minecraft server version Beta 1.5_02
    2011-04-22 22:37:44 [INFO] Loading properties
    2011-04-22 22:37:44 [INFO] Starting Minecraft server on *:21800
    2011-04-22 22:37:44 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-681-g0f8abd2-b709jnks (MC: 1.5_02)
    2011-04-22 22:37:45 [INFO] Preparing level "world"
    2011-04-22 22:37:45 [INFO] Preparing start region
    2011-04-22 22:37:46 [SEVERE] null (Is it up to date?)
    java.lang.NullPointerException
        at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:24)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:109)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:94)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:217)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:144)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:259)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    2011-04-22 22:37:46 [INFO] Done (0.103s)! For help, type "help" or "?"
    2011-04-22 22:39:33 [INFO] RonnSama [/127.0.0.1:59026] logged in with entity id 176
    2011-04-22 22:39:38 [INFO] RonnSama issued server command: clearinventory
    2011-04-22 22:39:41 [INFO] RonnSama lost connection: disconnect.quitting
    2011-04-22 22:41:02 [INFO] Starting minecraft server version Beta 1.5_02
    2011-04-22 22:41:02 [INFO] Loading properties
    2011-04-22 22:41:02 [INFO] Starting Minecraft server on *:21800
    2011-04-22 22:41:02 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-681-g0f8abd2-b709jnks (MC: 1.5_02)
    2011-04-22 22:41:02 [INFO] Preparing level "world"
    2011-04-22 22:41:02 [INFO] Preparing start region
    2011-04-22 22:41:03 [SEVERE] null (Is it up to date?)
    java.lang.NullPointerException
        at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:24)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:109)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:94)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:217)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:144)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:259)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    2011-04-22 22:41:03 [INFO] Done (0.110s)! For help, type "help" or "?"
    2011-04-22 22:49:03 [INFO] Starting minecraft server version Beta 1.5_02
    2011-04-22 22:49:03 [INFO] Loading properties
    2011-04-22 22:49:03 [INFO] Starting Minecraft server on *:21800
    2011-04-22 22:49:03 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-681-g0f8abd2-b709jnks (MC: 1.5_02)
    2011-04-22 22:49:03 [INFO] Preparing level "world"
    2011-04-22 22:49:03 [INFO] Preparing start region
    2011-04-22 22:49:04 [SEVERE] null (Is it up to date?)
    java.lang.NullPointerException
        at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:24)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:109)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:94)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:217)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:204)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:144)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:259)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    2011-04-22 22:49:04 [INFO] Done (0.108s)! For help, type "help" or "?"
    
     
  14. Offline

    alex123099

    hey I have taken your idea and made a plugin to clear the inv,
    thats my code and it works perfectly:
    Code:
    
    package com.alex.clear;
    import java.util.ArrayList;
    import java.util.HashMap;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    public class clear 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("Clearing 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 onCommand(CommandSender sender,Command command,String label,String[] args) {
            if (sender instanceof Player) {
                Player p=(Player)sender;
                if (command.getName().equalsIgnoreCase("clear")){
                    p.sendMessage("Your inventory is now clean");
                    p.getInventory().clear();
                    return true;
                }
            }
            return false;
        }
    }
    
    it still only refills them once and thats it, the error it catches is:
    Code:
    11:22:38 [SEVERE] Exception in thread "Thread-6"
    11:22:38 [SEVERE] java.lang.NullPointerException
    11:22:38 [SEVERE]       at com.alex.infiniteItems.loopthread.run(loopthread.java
    :27)
    
    thats the loopthread:
    Code:
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    public class loopthread extends Thread{
        Player p;
        /**
         * @param p
         */
        private boolean run;
        public loopthread(Player p) {
            this.p = p;
            run=true;
        }
     /**
         * @param run the run to set
         */
        public void setRun(boolean run) {
            this.run = run;
        }
        @Override
        public void run() {
            while(run) {
                ItemStack[] stack=p.getInventory().getContents();
                for (int i=0;i<stack.length;i++) {
                    stack[i].setAmount(stack[i].getMaxStackSize());
                }
                p.getInventory().setContents(stack);
            }
        }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  15. Offline

    matter123

    try adding a wait(500) after setContents
     
  16. Offline

    RonnSama

    I appreciate the code n' all, but what exactly are the hashmaps for? We aren't toggling off the command it's simply a use one and it's done kinda deal. And if we aren't registering events, is there even a point to calling PluginManager? Not trying to be funny or anything, just trying to make sure I know what's goin on.

    Besides the issue wasn't within the code itself, it was only learning to make a concept plugin to make sure I understood the process. It does me no good if someone just hands it to me.
     
  17. Offline

    alex123099

    still the same error as before:
    Code:
    11:22:38 [SEVERE] Exception in thread "Thread-6" 11:22:38 [SEVERE] java.lang.NullPointerException 11:22:38 [SEVERE] at com.alex.infiniteItems.loopthread.run(loopthread.java :27)

    ?

    ??

    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

    I wanted to stop by and thank everyone for their help, I finally figure out WHAT I was doing wrong. For future reference (and if someone wants me to PM me I'll make a separate thread, or they can, or w/e).

    The YAMLparser error was within my plugin.yml .

    I'm not sure IF this is a requirement now or what as I've seen several plugins without it. However mine required it before it stopped crying.

    Here is the sample of my plugin.yml for my Test Plugin Concept

    Code:
    name: SamaCore
    main: com.ronnsama.epicrus.samatest.SamaTest
    version: 1.0
    author: RonnSama
    commands:
        clean:
            description:
            usage:
    
    I had added to commands:, usage: and description: even tho both are blank, it required them in order to quit throwing parser errors. I had to go look into the bukkit source to see why the YAML was throwing it and saw on line 24 (just like the error told me, but I didn't think the source was open to view) and viola! It worked! Perfectly!
     
  19. Offline

    Carnes

    Open Source wins again!
     
    RonnSama likes this.
Thread Status:
Not open for further replies.

Share This Page