Solved Command spams the console

Discussion in 'Plugin Help/Development/Requests' started by Rowinvd, Mar 12, 2015.

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

    Rowinvd

    I created a kill plugin, but if i run the command in the console it gives a big error:
    Its hard to read, I know

    Code:
    [17:39:37] [Server thread/WARN]: Unexpected exception while parsing console command "kick"
    org.bukkit.command.CommandException: Unhandled exception executing command 'kick' in plugin Trivium v1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1558]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
        at me.rowinvd.CommandKick.onCommand(CommandKick.java:18) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot.jar:git-Spigot-1558]
        ... 8 more
    [17:39:41] [Server thread/WARN]: Unexpected exception while parsing console command "kill"
    org.bukkit.command.CommandException: Unhandled exception executing command 'kill' in plugin Trivium v1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[Spigot.jar:git-Spigot-1558]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1558]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1558]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
        at me.rowinvd.CommandKill.onCommand(CommandKill.java:18) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot.jar:git-Spigot-1558]
        ... 8 more
    
    My code is:
    Code:
    package me.rowinvd;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class CommandKill implements CommandExecutor {
    
        public CommandKill(Main plugin) {
        }
    
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("kill")) {
                Player p = (Player) sender;
                if (!(sender instanceof Player)) {
                    p.sendMessage(ChatColor.GOLD + "Trivium" + (ChatColor.DARK_GRAY + " ▏ " + (ChatColor.YELLOW + "This command can be only used in-game!")));
                    return true;
                }
                if (args.length == 0) {
                    p.setHealth(0);
                    p.sendMessage(ChatColor.GOLD + "Trivium" + (ChatColor.DARK_GRAY + " ▏ " + (ChatColor.YELLOW + "You committed suicide!")));
                    return true;
                }
                if (!p.hasPermission("kill.otherpeople")) {
                    p.sendMessage(ChatColor.GOLD + "Trivium" + (ChatColor.DARK_GRAY + " ▏ " + (ChatColor.YELLOW + "You're not allowed to do this!")));
                } else {
                    Player target = Bukkit.getServer().getPlayer(args[0]);
                    if (target == null) {
                        p.sendMessage(ChatColor.GOLD + "Trivium" + (ChatColor.DARK_GRAY + " ▏ " + (ChatColor.YELLOW + "Could not find player!")));
                        return true;
                    }
                    target.setHealth(0);
                    p.sendMessage(ChatColor.GOLD + "Trivium" + (ChatColor.DARK_GRAY + " ▏ " + (ChatColor.YELLOW + "You killed " + args[0])));
                }
            }
            return true;
        }
    }
     
  2. Offline

    adam753

  3. Offline

    Rowinvd

    @adam753 How can I make this that players and the console can kick players?
    if (sender instanceof Player) {
    ...
    } else {
    ....
     
  4. Offline

    MaTaMoR_

    Use sender instead of player .
     
  5. Offline

    uksspy

  6. Offline

    teej107

    No it's not.
    http://bukkit.org/threads/how-to-re...ubleshoot-your-own-plugins-by-yourself.32457/

    If you don't need access to any of the Player methods, then don't cast the CommandSender to one. If you do, then you should check to make sure that the CommandSender is an instance of Player first since not all CommandSenders are Players.
     
Thread Status:
Not open for further replies.

Share This Page