ColouredConsoleSender cannot be cast?

Discussion in 'Plugin Development' started by Adrenaline, Mar 10, 2012.

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

    Adrenaline

    Hi,

    My problem is strange for me.

    I dont understand this error when i try execute command from console

    Code:java
    1. Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player


    Someone can say me how to repair it ? :eek:

    Line Plugin.java:80:
    Player player = (Player)sender;

    This is full error:
    Code:java
    1. [WARNING] Unexpected exception while parsing console command
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'rb' in plugin Plugin v1.0
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    5. at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:461)
    6. at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:457)
    7. at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:599)
    8. at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:568)
    9. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:452)
    10. at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)
    11. Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
    12. at samoht2401.RebuildPlugin.RebuildPlugin.onCommand(Plugin.java:80)
    13. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    14. ... 7 more
     
  2. Offline

    Superkabii

    You don't know if the sender is actually a player yet. Check if the sender is an instance of a Player, otherwise send some message to the sender or execute some alternate code. For example, a way to check this:

    Code:java
    1. if(sender instanceof Player)
     
Thread Status:
Not open for further replies.

Share This Page