Doing command returns command name?

Discussion in 'Plugin Development' started by Blingdaddy1, Dec 4, 2013.

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

    Blingdaddy1

    Why is this happening? Please help :p

    Main:
    Code:
    package me.Blingdaddy1.NexodusMain;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.BookMeta;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class NexodusMain extends JavaPlugin implements Listener {
       
        public void onEnable() {
            Bukkit.getServer().getLogger().info("NexodusMain is now starting!");
           
        }
       
        public void onDisable() {
            Bukkit.getServer().getLogger().info("NexodusMain is now stopping!");
           
        }
       
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (!(player.hasPlayedBefore())) {
                    player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 1, 0);
                }
            }
        }
       
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            if (player.getLocation().getWorld().getName().equalsIgnoreCase("randombuildings")) {
                event.setCancelled(true);
            }
        }
       
       
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            Player player = e.getPlayer();
           
            if (player.isOp()) {
               
                if ((e.getLine(0).contains("&1")) || (e.getLine(0).contains("&2")) || (e.getLine(0).contains("&3")) || (e.getLine(0).contains("&4")) || (e.getLine(0).contains("&5")) || (e.getLine(0).contains("&6")) || (e.getLine(0).contains("&7")) || (e.getLine(0).contains("&8")) || (e.getLine(0).contains("&9")) || (e.getLine(0).contains("&0")) || (e.getLine(0).contains("&a")) || (e.getLine(0).contains("&b")) || (e.getLine(0).contains("&c")) || (e.getLine(0).contains("&d")) || (e.getLine(0).contains("&e")) || (e.getLine(0).contains("&f")) || (e.getLine(0).contains("&o")) || (e.getLine(0).contains("&l")) || (e.getLine(0).contains("&k")) || (e.getLine(0).contains("&n")) || (e.getLine(0).contains("&m")) || (e.getLine(0).contains("&r"))) {
                    e.setLine(0, e.getLine(0).replace("&", "§"));
                }
                if ((e.getLine(1).contains("&1")) || (e.getLine(1).contains("&2")) || (e.getLine(1).contains("&3")) || (e.getLine(1).contains("&4")) || (e.getLine(1).contains("&5")) || (e.getLine(1).contains("&6")) || (e.getLine(1).contains("&7")) || (e.getLine(1).contains("&8")) || (e.getLine(1).contains("&9")) || (e.getLine(1).contains("&0")) || (e.getLine(1).contains("&a")) || (e.getLine(1).contains("&b")) || (e.getLine(1).contains("&c")) || (e.getLine(1).contains("&d")) || (e.getLine(1).contains("&e")) || (e.getLine(1).contains("&f")) || (e.getLine(1).contains("&o")) || (e.getLine(1).contains("&l")) || (e.getLine(1).contains("&k")) || (e.getLine(1).contains("&n")) || (e.getLine(1).contains("&m")) || (e.getLine(1).contains("&r"))) {
                    e.setLine(1, e.getLine(1).replace("&", "§"));
                }
                if ((e.getLine(2).contains("&1")) || (e.getLine(2).contains("&2")) || (e.getLine(2).contains("&3")) || (e.getLine(2).contains("&4")) || (e.getLine(2).contains("&5")) || (e.getLine(2).contains("&6")) || (e.getLine(2).contains("&7")) || (e.getLine(2).contains("&8")) || (e.getLine(2).contains("&9")) || (e.getLine(2).contains("&0")) || (e.getLine(2).contains("&a")) || (e.getLine(2).contains("&b")) || (e.getLine(2).contains("&c")) || (e.getLine(2).contains("&d")) || (e.getLine(2).contains("&e")) || (e.getLine(2).contains("&f")) || (e.getLine(2).contains("&o")) || (e.getLine(2).contains("&l")) || (e.getLine(2).contains("&k")) || (e.getLine(2).contains("&n")) || (e.getLine(2).contains("&m")) || (e.getLine(2).contains("&r"))) {
                    e.setLine(2, e.getLine(2).replace("&", "§"));
                }
                if ((e.getLine(3).contains("&1")) || (e.getLine(3).contains("&2")) || (e.getLine(3).contains("&3")) || (e.getLine(3).contains("&4")) || (e.getLine(3).contains("&5")) || (e.getLine(3).contains("&6")) || (e.getLine(3).contains("&7")) || (e.getLine(3).contains("&8")) || (e.getLine(3).contains("&9")) || (e.getLine(3).contains("&0")) || (e.getLine(3).contains("&a")) || (e.getLine(3).contains("&b")) || (e.getLine(3).contains("&c")) || (e.getLine(3).contains("&d")) || (e.getLine(3).contains("&e")) || (e.getLine(3).contains("&f")) || (e.getLine(3).contains("&o")) || (e.getLine(3).contains("&l")) || (e.getLine(3).contains("&k")) || (e.getLine(3).contains("&n")) || (e.getLine(3).contains("&m")) || (e.getLine(3).contains("&r"))) {
                    e.setLine(3, e.getLine(3).replace("&", "§"));
                }
            }
        }
       
        public enum MsgType{
            Prefix(ChatColor.RED + "<" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.RED + "> ");
           
            private String prefix;
           
            MsgType(String prefix){
                this.prefix = prefix;
            }
           
            @Override
            public String toString() {
                return this.prefix;
            }
           
        @EventHandler
        public void onPlayerFirstJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if (!(player.hasPlayedBefore())) {
                player.sendMessage(Prefix + "Welcome to NexodusMC.net! NexodusMC is a server with a ton of Minigames!");
            }
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            player.sendMessage(Prefix + "Welcome back, " + player + "  !");
        }
       
        @EventHandler
        public void onBlockedWord(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            if (event.getMessage().contains("hacks")) {
                event.setCancelled(true);
                player.sendMessage(Prefix + "You can't say one of those words!");
            }
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Block b = event.getClickedBlock();
                if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
                    Sign sign = (Sign) b.getState();
                    String[] lines = sign.getLines();
                    if (lines[0].equalsIgnoreCase(ChatColor.RED + "<" + ChatColor.DARK_PURPLE + "NexodusMC" + ChatColor.RED + "> ")) {
                        if (lines[1].equalsIgnoreCase(ChatColor.RED + "Help")) {
                            player.performCommand("help");
                        }
                    }
                       
                }
            }
        }
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            Player target = Bukkit.getServer().getPlayer(args[0]);
           
            if (cmd.getName().equalsIgnoreCase("gf")) {
                player.sendMessage(Prefix + "You have been de-ghosted!");
                player.teleport(player.getLocation());
            }
           
           
           
            if (cmd.getName().equalsIgnoreCase("spawnmob")) {
                if (!(sender.hasPermission("nexodus.spawnmob"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You must specify a mobtype to spawn!");
                }
                else if (args.length == 1) {
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("vanish")) {
                if (!(sender.hasPermission("nexodus.vanish"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.hidePlayer(player);
                    player.sendMessage(Prefix + "You have been hidden!");
                }
                else if (args.length == 1) {
                    player.hidePlayer(target);
                    player.sendMessage(Prefix + "Player " + target + " has been hidden!");   
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("ban")) {
                if (!(sender.hasPermission("nexodus.ban"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You need to specify a player to ban!");
                }
                else if (args.length == 1) {
                    player.sendMessage(Prefix + "Banned player!");
                    target.setBanned(true);
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("kick")) {
                if (!(sender.hasPermission("nexodus.kick"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You need to specify a player to kick!");
                }
                else if (args.length == 1) {
                    player.sendMessage(Prefix + "Kicked player!");
                    target.kickPlayer("You have been kicked my a moderator or Admin!");
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("top")) {
                if (!(sender.hasPermission("nexodus.top"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You have been teleported to the top");
                    player.teleport(player.getWorld().getHighestBlockAt(player.getLocation()).getLocation().add(0, 1, 0));
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("cb")) {
                if (!(sender.hasPermission("nexodus.cb"))) {
                    if (!(player.getLocation().getWorld().getName().equalsIgnoreCase("survival"))) {
                        player.sendMessage(Prefix + "You do not have permission to do this command, or not able to be preformed in this world");
                    }
                    else if (args.length == 0) {
                        player.openWorkbench(player.getLocation(), true);
                    }
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("ec")) {
                if (!(sender.hasPermission("nexodus.ec")))
                    if (!(player.getLocation().getWorld().getName().equalsIgnoreCase("survival"))) {
                        player.sendMessage(Prefix + "You do not have permission to do this command, or not able to be preformed in this world");
                    }
                    else if (args.length == 0) {
                        player.openInventory(player.getEnderChest());
                    }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("op")) {
                if (!(sender.hasPermission("nexodus.op"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You must specify a player to op!");
                }
                else if (args.length == 1) {
                    player.sendMessage(Prefix + "You opped" + target);
                    target.setOp(true);
                }
                else if (args[0].equalsIgnoreCase("me")) {
                    player.sendMessage(Prefix + "You opped yourself!");
                    player.setOp(true);
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("packet")) {
                if (!(sender.hasPermission("nexodus.packet"))) {
                    player.sendMessage(Prefix + "Packet");
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("nick")) {
                if (!(sender.hasPermission("nexodus.nick"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You need to specify a name to nick as!");
                }
                else if (args.length == 1) {
                    player.sendMessage(Prefix + "You have been nicked!");
                    player.setDisplayName(args[1]);
                }
                return true;
            }
           
           
            if (cmd.getName().equalsIgnoreCase("bcast")) {
                if (!(sender.hasPermission("nexodus.bcast"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You need to specify a message to broadcast!");
                }
                else if (args.length == 1) {
                    Bukkit.broadcastMessage(args[0]);
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("me")) {
                if (!(sender.hasPermission("nexodus.me"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "So full of yourself, eh? No one cares!");
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("hubreload")) {
                if (!(sender.hasPermission("nexodus.hubreload"))) {
                    player.sendMessage("");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You are now reloading the server");
                    Bukkit.reload();
                    player.sendMessage(Prefix + "You have reloaded the server!");
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("whereami")) {
                if (!(sender.hasPermission("nexodus.whereami"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You are on NexodusMC.net!");
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("goto")) {
                if (!(sender.hasPermission("nexodus.goto"))) {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (player.getLocation().getWorld().getName().equalsIgnoreCase("randombuildings")) {
                    player.sendMessage(Prefix + "You can not teleport in this world!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You need to specify a user to goto!");
                }
                else if (args.length == 1) {
                    player.teleport(target);
                    player.sendMessage(Prefix + "You have gone to " + target + "!");
                }
                return true;
            }
           
           
            if (cmd.getName().equalsIgnoreCase("fly"))  {
                if (!(player.hasPermission("nexodus.fly")))  {
                    player.sendMessage(Prefix + "You do not have permission to do that command!");
                }
                else if (args.length == 0) {
                    player.sendMessage(Prefix + "You have to specify on or off!");
                }
                else if (args.length == 1) {
                    if(args[0].equalsIgnoreCase("on")) {
                        player.setFlying(true);
                    }
                }
                else if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("off")) {
                        player.setFlying(false);
                    }
                }
                return true;
            }
           
            if (cmd.getName().equalsIgnoreCase("help")) {
                if (!(sender.hasPermission("nexodus.help"))) {
                    player.sendMessage(Prefix + "Help / Commands");
                    player.sendMessage(Prefix + "/plugins - Lists all plugins on the server");
                    player.sendMessage(Prefix + "/help - Shows this message");
                    player.sendMessage(Prefix + "/fly - Enables flight");
                    player.sendMessage(Prefix + "/about - Shows info about the server");
                    player.sendMessage(Prefix + "/lobby - Gives a list of all lobbies you can teleport to");
                    player.sendMessage(Prefix + "/hub - Gives a list of all lobbies you can teleport to");
                    player.sendMessage(Prefix + "/nexodite - Shows how many nexodites you have");
                    player.sendMessage(Prefix + "/buy - Shows donation info");
                    player.sendMessage(Prefix + "/thanks - Tells you who to thank :)");
                    player.sendMessage(Prefix + "/coder - Lists all the developers for the server");
                    player.sendMessage(Prefix + "Help / Commands");
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("plugins")) {
                if (!(sender.hasPermission("nexodus.plugins")))  {
                    player.sendMessage(ChatColor.WHITE + "Plugins (1):" + ChatColor.GREEN + "NexodusMain" );
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("about")) {
                if (sender.hasPermission("nexodus.about")) {
                    player.sendMessage(Prefix + "Owner: Blingdaddy1");
                    player.sendMessage(Prefix + "Admins: GabbageFilms, Skylord_Aaron, GetBuilt, Odman12");
                    player.sendMessage(Prefix + "Moderators: ThaCreator4Life, 31HPF07");
                    player.sendMessage(Prefix + "IP: NexodusMC.net");
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("lobby")) {
                if (sender.hasPermission("nexodus.lobby")) {
                    player.sendMessage(Prefix + "List of lobbies eligible to teleport to");
                    player.sendMessage(Prefix + "/lobby SG");
                    player.sendMessage(Prefix + "/lobby CG");
                    player.sendMessage(Prefix + "/lobby Creative");
                    player.sendMessage(Prefix + "/lobby Survival");
                    player.sendMessage(Prefix + "More to come!");
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("thanks")) {
                if (sender.hasPermission("nexodus.thanks")) {
                    player.sendMessage(Prefix + "Thank McProHosting for hosting the server");
                    player.sendMessage(Prefix + "Thank Blingdaddy1 for owning the server");
                    player.sendMessage(Prefix + "Thank the admins for keeping the server safe");
                    player.sendMessage(Prefix + "Thank Mojang for making this game");
                    player.sendMessage(Prefix + "Thank the Bukkit community for making this possible");
                }
            }
            return true;
        }
     
    }
    }
    
    and plugin.yml (I know i dont have perms registered)

    Code:
    name: NexodusHub
    version: 1.0
    description: NexodusHub plugin!
    author: Blingdaddy1
    main: me.Blingdaddy1.NexodusMain.NexodusMain
     
    commands:
        gf:
            usage: /<command>
            description: a
        me:
            usage: /<command>
            description: a
        vanish:
            usage: /<command>
            description: a
        ban:
            usage: /<command>
            description: a
        kick:
            usage: /<command>
            description: a
        top:
            usage: /<command>
            description: a
        cb:
            usage: /<command>
            description: a
        ec:
            usage: /<command>
            description: a
        op:
            usage: /<command>
            description: a
        packet:
            usage: /<command>
            description: a
        nick:
            usage: /<command>
            description: a
        bcast:
            usage: /<command>
            description: a
        hubreload:
            usage: /<command>
            description: a
        whereami:
            usage: /<command>
            description: a
        goto:
            usage: /<command>
            description: a
        fly:
            usage: /<command>
            description: a
        help:
            usage: /<command>
            description: a
        plugins:
            usage: /<command>
            description: a
        about:
            usage: /<command>
            description: a
        lobby:
            usage: /<command>
            description: a
        thanks:
            usage: /<command>
            description: a
     
  2. Offline

    The_Doctor_123

    I'm trying to comprehend this question.

    "Doing command returns command name?"
     
  3. Offline

    Blingdaddy1

    Sorry, say if I do /thanks, it says in chat /thanks.
     
  4. Offline

    The_Doctor_123

    That occurs when you return false in onCommand(). It sends the usage to the player.
     
  5. Offline

    Darq

    as in it's printing the usage of the command, which means it's registered but for some reason your onCommand() is not handling the commands. I think it's because your Enum MsgType's scope is surrounding your onCommand and many event handlers. Move its closing "}" to the right spot :p

    Edit: spelling
     
  6. Offline

    Blingdaddy1

    Darq would backspacing the last } work? I did that and it gave no errors, so I assumed thats what I was supposed to do?
     
  7. Offline

    The_Doctor_123

    Blingdaddy1
    Inspect what you did wrong.. it shouldn't be that hard.
     
  8. Offline

    Darq

  9. Offline

    Blingdaddy1

    Darq adding another } gives tons of errors
     
  10. Offline

    Darq

    I'll have to go with what@The_Doctor_123 said. I found that error by eye and didn't catch what else could be wrong.. the IDE should clearly layout which scope your code relies in if you just "formnat" the code. You don't want your main class code inside of an enum type.. generally.
     
  11. Offline

    Rocoty

    That might be because you are not adding it in an appropriate place. Press CTRL+SHIFT+F (if you are using Eclipse) to get proper indentation, then you should clearly be able to see where you need to put the brackets, just like Darq said.

    OT: The_Doctor_123 Oh! You've regenerated! About bloody time...
     
  12. Offline

    Blingdaddy1

    Rocoty tried, nothing seems to be working! D:
     
Thread Status:
Not open for further replies.

Share This Page