Helpppp ERROR on console

Discussion in 'Plugin Development' started by Whomp54, Jul 10, 2013.

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

    Whomp54

    Main Class:

    Code:
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MobSigns extends JavaPlugin{
     
    public void onEnable(){
    getServer().getPluginManager().registerEvents(new SignListener(), this);
    }
    public void onDisable(){
    }
    }
    Listener:

    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Spider;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    public class SignListener implements Listener{
     
    @EventHandler
    public void MobSigns(PlayerInteractEvent e){
        Sign sign = (Sign) e.getClickedBlock().getState();
        Player player = e.getPlayer();
        Location location = sign.getLocation();
        World w = player.getWorld();
        if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.SIGN || e.getClickedBlock().getType() == Material.SIGN_POST || e.getClickedBlock().getType() == Material.WALL_SIGN){
                  if(sign.getLine(0).equalsIgnoreCase("[MobSigns]") && sign.getLine(1).equalsIgnoreCase("Creeper")){
                        w.spawn(location, Creeper.class);
                        player.sendMessage(ChatColor.GREEN+"Creeper spawned");
                        }else{
                        }
                  if(sign.getLine(0).equalsIgnoreCase("[MobSigns]") && sign.getLine(1).equalsIgnoreCase("Skeleton")){
                      w.spawn(location, Skeleton.class);
                      player.sendMessage(ChatColor.GREEN+"Skeleton spawned");
                      }else{
                      }
                  if(sign.getLine(0).equalsIgnoreCase("[MobSigns]") && sign.getLine(1).equalsIgnoreCase("Spider")){
                      w.spawn(location, Spider.class);
                      player.sendMessage(ChatColor.GREEN+"Spider spawned");
                      }else{
                      }
                  if(sign.getLine(0).equalsIgnoreCase("[MobSigns]") && sign.getLine(1).equalsIgnoreCase("Zombie")){
                      w.spawn(location, Zombie.class);
                      player.sendMessage(ChatColor.GREEN+"Zombie spawned");
                      }else{
                      }
              }else{
                  }
            }
    }
    Error:

    [SEVERE] Could not pass event PlayerInteractEvent to MobSigns v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191)
    at net.minecraft.server.v1_6_R2.PlayerInteractManager.dig(PlayerInteractManager.java:108)
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:540)
    at net.minecraft.server.v1_6_R2.Packet14BlockDig.handle(SourceFile:46)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
    at com.gmail.thetechwiz123.msigns.SignListener.MobSigns(SignListener.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 16 more


    HEEELPPPP :(

    Sorry forgot to put this in but its whenever i break or place a block it does this, even when the block is air.

    does anyone know how? I know its probably pretty easy.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    Rocoty

  3. Offline

    Whomp54

  4. Offline

    Dpasi314

    Whomp54
    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
    To explain on what Rocoty said. You're not properly casting CraftBlockState to the sign. Hence the "CraftBlockState cannot be cast to org.bukkit.block.sign"
     
  5. Offline

    SnipsRevival

    Whomp54 check if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) before casting.
     
    zack6849 likes this.
  6. Offline

    Whomp54

    ok ill try that

    Sorry im kind of new to all of this… Im not really sure how to cast to that. Mind giving me an example @Dpasi314 or SnipsRevival ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    SnipsRevival

  8. Offline

    Whomp54

    I know how to cast, i just dont know how to cast it the RIGHT way SnipsRevival
     
Thread Status:
Not open for further replies.

Share This Page