What's wrong with this?

Discussion in 'Plugin Development' started by BadSong, Apr 23, 2016.

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

    BadSong

    Just started making Minecraft plugins and I have a problem, this code doesn't work for me.. Version: 1.9.2
    Code:
    package pw.BadSong.MyPlugin;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Commands extends JavaPlugin implements Listener{
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            System.out.println("Ready to go!");
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (cmd.getName().equalsIgnoreCase("glow")){
                if (sender instanceof Player){
                    Player player = (Player) sender;
                    player.sendMessage("Ooo, it shines :)");
                    player.setGlowing(true);
                    }
                else{
                    sender.sendMessage("Only player can glow!");
                }
                }
            else if (cmd.getName().equalsIgnoreCase("unglow")){
                if (sender instanceof Player){
                    Player player = (Player) sender;
                    if (!player.isGlowing()){
                        player.setGlowing(false);
                    }
                    else
                    {
                        player.sendMessage("You're already glowing, aren't you?");
                    }
                }
                else {
                    sender.sendMessage("Only players can glow!");
                }
            }
           
            return false;
        }
    
    }
    
    Thanks in advance!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @BadSong 1. I hope that you remove the message in the onEnable before releasing.
    2. You are implementing Listener and registering while you have no events.
    3. Define "does not work", are you not getting messages? Is the glow not set?
     
  3. Offline

    mcdorli

    Currently in the unglow command, you check if the player is not glowing, amd just to be safe (I guess/hope) you make him not glow.

    You also never return true, you will get a usage message in the chat jf you do this.
     
  4. Offline

    SP3NC3RXD

    I think you meant never return false.
     
  5. Offline

    mcdorli

    No, I meant he never returns true.
     
  6. Offline

    BadSong

    Current code: (Still doesn't work, the plugin doesn't show up in the Plugins list.. [/pl])
    Code:
    package pw.BadSong.MyPlugin;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Commands extends JavaPlugin {
        public void onEnable() {
            System.out.println("Plugin is ready to go.");
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (cmd.getName().equalsIgnoreCase("glow")){
                if (sender instanceof Player){
                    Player player = (Player) sender;
                    if (player.isGlowing()){
                        player.sendMessage("You're already glowing :c");
                    }
                    }
                else{
                    sender.sendMessage("Only player can glow!");
                }
                }
            else if (cmd.getName().equalsIgnoreCase("unglow")){
                if (sender instanceof Player){
                    Player player = (Player) sender;
                    if (!player.isGlowing()){
                        player.sendMessage("You're not glowing.");
                    }
                    else
                    {
                        player.setGlowing(false);
                    }
                }
                else {
                    sender.sendMessage("Only players can glow!");
                }
            }
           
            return true;
        }
    
    }
    
     
  7. Offline

    mcdorli

    Can you paste the full startup log in a code tag, and also your plugin.yml?
     
Thread Status:
Not open for further replies.

Share This Page