Can You Spot The error?

Discussion in 'Plugin Development' started by nanhyh, Jul 12, 2012.

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

    nanhyh

    Im trying to give players kits through consle and am getting this error
    Code:
    21:52:47 [WARNING] Unexpected exception while parsing console command
    org.bukkit.command.CommandException: Unhandled exception executing command 'donate' in plugin kits v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479)
        at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:475)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:612)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:581)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
        at me.nanhyh.kits.fdsa.onCommand(fdsa.java:56)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 7 more
    
    Im useing this as my code
    Code:
            }else if(commandLabel.equalsIgnoreCase("donate")){
                if(sender instanceof Player){
            } else {
                if(args.length == 1){
                Player player2 = player1.getServer().getPlayer(args[0]);
                Bukkit.broadcastMessage(player2.getDisplayName() + " Has donated for a OverPowered Kit!");
                player2.removePotionEffect(PotionEffectType.JUMP);
                player2.removePotionEffect(PotionEffectType.SPEED);
                player2.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
                player2.removePotionEffect(PotionEffectType.SLOW);
                player2.getInventory().clear();
                ItemStack h = new ItemStack(Material.DIAMOND_HELMET, 1);
                    h.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4);
                ItemStack c = new ItemStack(Material.DIAMOND_CHESTPLATE, 1);
                    c.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4);
                ItemStack l = new ItemStack(Material.DIAMOND_LEGGINGS, 1);
                    l.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4);
                ItemStack b = new ItemStack(Material.DIAMOND_BOOTS, 1);
                    b.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4);
                ItemStack d = new ItemStack(Material.DIAMOND_SWORD, 1);
                    d.addEnchantment(Enchantment.DAMAGE_ALL, 4);    d.addEnchantment(Enchantment.FIRE_ASPECT, 2);
                ItemStack s = new ItemStack(Material.MUSHROOM_SOUP, 1);
                PlayerInventory pi = player1.getInventory();
                pi.setBoots(b);
                pi.setHelmet(h);
                pi.setChestplate(c);
                pi.setLeggings(l);
                pi.addItem(d);
                for (int i = 0; i < 35; i++) {
                    pi.addItem(s);
                }
            }
     
  2. Offline

    ZeusAllMighty11

    You didn't check to see if the console could be a sender. (No if player == null || !instanceof Player )
     
  3. Offline

    nanhyh

    Shouldnt the else statement do that? (i kind of dont understand what you are saying)
     
  4. Offline

    LucasEmanuel

    Well one problem is that you never close the body of this if-statement.

    Code:
    }else if(commandLabel.equalsIgnoreCase("donate")){
        if(sender instanceof Player){
    } else {
    And as zeus stated you never check to see in the sender is a player, unless the code above is indented incorrectly then you are checking if the sender is not a player.

    Then change your code like this:
    Code:
        }else if(commandLabel.equalsIgnoreCase("donate")){
            if(sender instanceof Player){
                // Move your code into here
            } else {
                // Move this code
            }
        }
     
  5. Offline

    SchmidtMathias

    Could you give us the whole class? Or could you give us line 56 of the class? Somewhere there is a Cast that is not allowed.
     
Thread Status:
Not open for further replies.

Share This Page