What am i doing wrong?

Discussion in 'Plugin Development' started by 1337, Mar 6, 2011.

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

    1337

    when i hit someone with a snowball using my plugin i get this :
    Code:
    10:21:59 [SEVERE] Could not pass event ENTITY_DAMAGED to Snowball fight
    java.lang.ClassCastException: plugin.x1337x.Snowball.SnowballPlayerListener cann
    ot be cast to org.bukkit.event.entity.EntityListener
            at org.bukkit.plugin.java.JavaPluginLoader$38.execute(JavaPluginLoader.j
    ava:319)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:59)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:225)
            at net.minecraft.server.EntityHuman.a(EntityHuman.java:368)
            at net.minecraft.server.EntityPlayer.a(EntityPlayer.java:137)
            at net.minecraft.server.EntityHuman.d(EntityHuman.java:451)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:722)
            at net.minecraft.server.Packet7UseEntity.a(SourceFile:33)
            at net.minecraft.server.NetworkManager.a(SourceFile:230)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:75)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:357)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:272)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    
    how im handling the enity_damaged event:

    Code:
    public void snowballhit(EntityDamageByProjectileEvent event)
      {
        if ((event instanceof EntityDamageByProjectileEvent)) {
          EntityDamageByEntityEvent sub = event;
          Entity entity = sub.getEntity();
          Player attacker = null;
          Player defender = null;
          String attackername = null;
          String defendername = null;
          if ((entity instanceof Player)) {
            defender = (Player)sub.getEntity();
            attacker = (Player)sub.getDamager();
            attackername = attacker.getDisplayName().toString();
            defendername = defender.getDisplayName().toString();
          }
    
          if (((entity instanceof Player)) &&
            ((event.getProjectile() instanceof Snowball)) &&
            (defender != null) && (attacker != null)) {
            defender.sendMessage("you were hit by " + attackername + " and you now have " + getLives(defendername) + " lives remaining");
            getLives(defendername);
            attacker.sendMessage("you hit" + defendername + " and he now has " + getLives(defendername) + " lives left");
            int lives = getLives(defendername);
            if (lives == 3) {
              threelives.remove(defendername);
              twolives.add(defendername);
            }
            if (lives == 2) {
              twolives.remove(defendername);
              onelive.add(defendername);
            }
            if (lives == 1) {
              onelive.remove(defendername);
              warp(this.l.dloc, defender);
            }
          }
        }
      }
    also i cant get my command to work
    the oncommand method:
    Code:
      public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args, Server server)
      {
        String[] trimmedArgs = args;
        Player csender = (Player)sender;
        String sendername = csender.getDisplayName();
        String commandname = command.toString();
        String[] split = commandname.split(" ");
        String commandName = split[0];
        if (commandName.equalsIgnoreCase("s"))
        {
          System.out.println("hello");
          sender.sendMessage("The Snowball commands are (RED lines are ops only green are not added yet):");
          sender.sendMessage(ChatColor.RED + "/sstart to start a fight");
          sender.sendMessage(ChatColor.RED + "/sstop to stop a fight");
          sender.sendMessage(ChatColor.GREEN + "/sdeadwarp to set the warp when out of the fight");
          sender.sendMessage(ChatColor.GREEN + "/sarenawarp to set the warp when using /snowball arena");
          sender.sendMessage("/sout  to pull out of a fight");
          sender.sendMessage("/sarena to warp to the snowball arena");
        }
    
        if (commandName.equalsIgnoreCase("sstart")) {
          if (sender.isOp()) {
            getServer().broadcastMessage(sender + "has started a snowball fight! use /snowball arena to go to the arena");
            this.pl.startfight();
          }if (!sender.isOp()) {
            sender.sendMessage("you need to be an op to start a snowball fight!");
          }
        }
    
        if (commandName.equalsIgnoreCase("sdisable")) {
          if (sender.isOp()) {
            disable();
            getServer().broadcastMessage(getDescription().getName() + "has been disabled by " + sendername);
          }
          if (!sender.isOp()) {
            sender.sendMessage("you need to be an op to disable snowball fight");
          }
    
        }
    
        if (commandName.equalsIgnoreCase("sarena")) {
          this.pl.warp(this.l.aloc, csender);
        }
    
        if (commandName.equalsIgnoreCase("sout")) {
          this.pl.out(csender);
          sender.sendMessage("you have pulled out of the fight and cant be warp away by snowballs");
          sender.sendMessage("you also can not throw snowballs until the fight is over");
        }
    
        if (commandName.equalsIgnoreCase("sstop")) {
          if ((sender.isOp()) && (this.pl.fightinprogress)) {
            getServer().broadcastMessage(sender + "has just ended the snowball fight");
            this.pl.endfight();
          }
          if (!sender.isOp()) {
            sender.sendMessage("you need to be an op to stop a snowball fight! ");
          }
    
        }
    
        return false;
      }
    the plugin.yml
    Code:
    name: Snowball fight
    main: plugin.x1337x.Snowball.Snowball
    version: 0.1
    author: (1337)
    description: Snowball fight!!!!
    
    sarena :
        description: warps you to the Snowball Arena
        usage: /<command>
    s :
     description : shows you the snowball commands
    usage : /<command>
    sout :
     description : opt you out of the snowball fight
    usage : /<command>
    sstop :
     description : Stops a snowball fight
    usage : /<command>
    sdisable :
     description : Disables snowball fight
    usage : /<command>
    
    --- merged: Mar 6, 2011 12:36 PM ---
    ?
     
  2. Offline

    Plague

    The handling function has to be onEntityDamage(EntityDamageEvent)
     
  3. Offline

    1337

    Yep just found that out for myself but what about the commands?
     
  4. Offline

    Plague

    There needs to be asection commands: and only under that you can write the commands themselves
     
  5. Offline

    1337

    i thought i had that but ok thanks. with the fix for the damaged event you said still get the same error
    Code:
    public void onEntityDamaged(EntityDamageEvent event ){
    
             if (event instanceof EntityDamageByProjectileEvent){
                 EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event;
                 Entity entity = sub.getEntity();
        Player attacker = null;
        Player defender = null;
        String attackername = null;
        String defendername = null;
        if (entity instanceof Player){
            defender = (Player)sub.getEntity();
            attacker = (Player)sub.getDamager();
            attackername = attacker.getDisplayName().toString();
            defendername = defender.getDisplayName().toString();
     
        }
    
        if (entity instanceof Player){
            if (sub.getProjectile() instanceof Snowball){
                if (defender != null && attacker != null){
                defender.sendMessage("you were hit by " + attackername +  " and you now have " + getLives(defendername) + " lives remaining");
                getLives(defendername);
                attacker.sendMessage("you hit" + defendername + " and he now has " +     getLives(defendername) + " lives left");
            int lives = getLives(defendername);
            if (lives == 3){
                threelives.remove(defendername);
                twolives.add(defendername);
            }
            if (lives == 2){
                twolives.remove(defendername);
                onelive.add(defendername);
            }
            if (lives == 1){
                onelive.remove(defendername);
                warp(l.dloc, defender);
            }
    
                }
            }
        }
    }
    }
    is the new method
     
  6. Offline

    Plague

    how do you register the event?
     
  7. Offline

    1337

    pm.registerEvent(Event.Type.ENTITY_DAMAGED, playerListener, Priority.Normal, this);
    --- merged: Mar 6, 2011 6:47 PM ---
    Also the commands still dont work
     
  8. Offline

    Plague

     
  9. Offline

    1337

    just the d?
    oh sorry
    But what about the commands?
    [MERGETIME="1299440499"][/MERGETIME]
    stll does it even ithout the d
    [MERGETIME="1299516825"][/MERGETIME]
    bump
    [MERGETIME="1299613766"][/MERGETIME]
    bump
     
Thread Status:
Not open for further replies.

Share This Page