code does not work, but there is no error

Discussion in 'Spigot Plugin Development' started by dc5941x, May 10, 2015.

  1. I just did an test code. But, it does not work. Eclipse and the console don't throw an error.

    I hope u can help me

    Here is my code:
    PHP:
    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;


    @SuppressWarnings("unused")
    public class test implements CommandExecutor {
     
    private main plugin;
     
        public test(main instance) {
            this.plugin = instance;
        }
     
        @Override
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("test")) {
                Player p = (Player)s;
                plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                    public void run() {
                    Bukkit.broadcastMessage("This message should be sent after 3 seconds");
                    }
                    }, 20L);
             
            }
        return true;
        }

    }
     
  2. Have you created plugin.yml?
     
  3. This happens from time-to-time.

    Usually for me in eclipse, Removing the suppress warnings are good.
     
  4. Yes I have made an plugin.yml
     
  5. Can I see your main class?

    It'll require setExecutor for class test
     
  6. thx, im gonna test that
     
  7. PHP:
    package main;


    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin{
     
        public void onEnable() {
            new test(this);
        }
     
    }
     
  8. You need to add setExecutor on (onEnable)

    add this "getCommand("test").setExecutor(new test(this));"

    It should work

    Edit: And remove newtest(this); <-- You don't need this , replace this one with the method.
     
  9. Did you remove "new test(this)" ?
     
  10. Okay it worked finally, thx for the help :)
     
  11. No Problem ;)