Solved Unhandled Command Exception

Discussion in 'Plugin Help/Development/Requests' started by waylock, Apr 6, 2015.

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


    Hi guys,

    Im working on a trading plugin, but I keep getting this annoying error:
    [15:21:59 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'trad
    er' in plugin BukkitPlugin2 v1.5
            at org.bukkit.command.PluginCommand.execute( ~[cra
            at org.bukkit.command.SimpleCommandMap.dispatch(
    0) ~[craftbukkit.jar:git-Bukkit-63e28b1]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServe ~[craftbukkit.jar:git-Bukkit-63e28b1]
            at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerCon [craftbukkit.jar:git-Bukkit-63e28b1]
            at net.minecraft.server.v1_8_R2.PlayerConnection.a(
    :937) [craftbukkit.jar:git-Bukkit-63e28b1]
            at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(SourceFile:37) [craft
            at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(SourceFile:9) [craftb
            at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$
    3) [craftbukkit.jar:git-Bukkit-63e28b1]
            at java.util.concurrent.Executors$ Source) [
            at Source) [?:1.7.0_75]
            at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [craftbukki
            at net.minecraft.server.v1_8_R2.MinecraftServer.A(
    70) [craftbukkit.jar:git-Bukkit-63e28b1]
            at net.minecraft.server.v1_8_R2.DedicatedServer.A(
    36) [craftbukkit.jar:git-Bukkit-63e28b1]
            at net.minecraft.server.v1_8_R2.MinecraftServer.z(
    26) [craftbukkit.jar:git-Bukkit-63e28b1]
    :534) [craftbukkit.jar:git-Bukkit-63e28b1]
            at Source) [?:1.7.0_75]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.entity.C
    raftPlayer cannot be cast to mc.waylock.main.Tradable
            at mc.waylock.main.PluginClass.onCommand( ~[?:?]
            at org.bukkit.command.PluginCommand.execute( ~[cra
            ... 15 more
    My java Code:
    package mc.waylock.main;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class PluginClass extends JavaPlugin {
        public MenuInv tradeHost;
        public InviteHandler invHandler;
        public Player target;
        public Tradable tradableTarget;
        public void onEnable() {
            Bukkit.getServer().getLogger().info("Plugin Enabled");
            tradeHost = new MenuInv(this);
            invHandler = new InviteHandler(null, null);
        public void onDisable() {
            Bukkit.getServer().getLogger().info("Plugin Disabled");
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                if (cmd.getLabel().equalsIgnoreCase("gm")) {
                    if (args.length == 0) {
                        p.sendMessage("Please specify a gamemode");
                    if (args.length == 1) {
                        if (args[0].equalsIgnoreCase("0")) {
                            p.sendMessage("Gamemode set to " + ChatColor.RED
                                    + "Survival");
                        if (args[0].equalsIgnoreCase("1")) {
                            p.sendMessage("Gamemode set to " + ChatColor.GREEN
                                    + "Creative");
                        if (args[0].equalsIgnoreCase("2")) {
                            p.sendMessage("Gamemode set to " + ChatColor.DARK_GRAY
                                    + "Adventure");
                if (cmd.getLabel().equalsIgnoreCase("trader")) {
                    if (args.length == 0) {
                        p.sendMessage("For Help use: /trader help");
                    if (args.length > 0) {
                        if (args[0].equalsIgnoreCase("invite")) {
                            if(args[1] != null){
                                Tradable tradableTarget = (Tradable) Bukkit.getServer().getPlayer(args[1]);
                            }else {
                                p.sendMessage("Please specify a player");
                            if (tradableTarget == null) {
                                p.sendMessage("That player is not online");
                                return true;
                            if (tradableTarget.getTrading()) {
                                p.sendMessage("That Player is already trading!");
                                return true;
                            } else {
                                invHandler = new InviteHandler(p, target);
                        if (args[0].equalsIgnoreCase("accept")) {
                            invHandler.reactionHandler(p, args[0].toString());
                        if (args[0].equalsIgnoreCase("deny")) {
                            invHandler.reactionHandler(p, args[0].toString());
                        if (args[0].equalsIgnoreCase("help")) {
                                    + "**************************************");
                                    + "Trader Commands and its function");
                            p.sendMessage(ChatColor.RED + "/trader invite "
                                    + ChatColor.WHITE + "Invite someone to a trade");
                            p.sendMessage(ChatColor.RED + "/trader accept "
                                    + ChatColor.WHITE + "Accept an invitation");
                            p.sendMessage(ChatColor.RED + "/trader deny "
                                    + ChatColor.WHITE + "Deny an invitation");
                            p.sendMessage(ChatColor.RED + "/trader help "
                                    + ChatColor.WHITE
                                    + "Get help about this plugin");
                                    + "**************************************");
            } else {
                sender.sendMessage("This command is for players only");
            return true;
    I know it has something to do with passing a null value, but i cant see why.
    Does someone knows what to do?

  2. Offline

    bwfcwalshy Retired Staff

    Moved to Bukkit Alternates.
  3. Offline


    1. No need to log enable/disable messages; Bukkit already does this for you.
    2. Why are all of your fields public? Make them private. If you need to access them from other classes, use getters.
    3. Use cmd.getName() instead of cmd.getLabel()
    Now to the actual problem:
    Which is happening on this line:
    So. What on Earth could this problem be?!?!
  4. Offline


    Wow, thank you so much. Im new at this so yeah.
  5. Offline


    @waylock No problem! And make sure you tag or quote me if you want to be sure I see your post!
Thread Status:
Not open for further replies.

Share This Page