[Help] Counting zombie deaths in a certain area

Discussion in 'Plugin Development' started by dajako, Aug 16, 2013.

Thread Status:
Not open for further replies.
  1. So I am making an arena plugin which looks like this atm:
    Code:
    package me.dajakos.plugin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class plugin extends JavaPlugin implements Listener {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static plugin plugin;
        public final playereventlistener pl = new playereventlistener();
        public final blocklistener bl = new blocklistener();
       
        int zombieskilled = 0;
        int round = 0;
        int endround = 5;
        int actualendround = endround;
        int zombiesinround = endround*4;
        int actualround = 1;
       
       
     
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled!");
            getServer().getPluginManager().registerEvents(this, this);
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.pl, this);
            pm.registerEvents(this.bl, this);
            // TODO Insert logic to be performed when the plugin is enabled
        }
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been disabled!");
            // TODO Insert logic to be performed when the plugin is disabled
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args){
            Player player = (Player) sender;
            World world = player.getWorld();
            Location spawn1 = new Location(world, -275, 51, -425);
            Location spawn2 = new Location(world, -330, 51, -416);
            Location spawn3 = new Location(world, -343, 51, -478);
            Location spawn4 = new Location(world, -271, 53, -484);
           
            if(lbl.equalsIgnoreCase("deadoralive")){
            player.sendMessage("Welcome! You must kill all of the zombies in the area to proceed to the next round!");
            player.sendMessage("Round " + actualround);
            player.teleport(new Location(world, -308, 51, -444));
            do{
              world.spawnEntity(spawn1, EntityType.ZOMBIE);
              world.spawnEntity(spawn2, EntityType.ZOMBIE);
              world.spawnEntity(spawn3, EntityType.ZOMBIE);
              world.spawnEntity(spawn4, EntityType.ZOMBIE);
              round++;
            }while(actualendround != round);
            }
            return false;
            }
        @EventHandler
        public void EDE(EntityDeathEvent event){
            Player player = event.getEntity().getKiller();
            double x = event.getEntity().getLocation().getX();
            double z = event.getEntity().getLocation().getY();
            if(x>-349 && x<-268 && z>-488 && z<-407 &&event.getEntity().getLocation().getWorld().equals(getServer().getWorld("map"))){
                zombieskilled++;
                player.sendMessage("You have killed " + zombieskilled);
            if(event.getEntity().getKiller()!=null){
              player.sendMessage("You have killed " + zombieskilled);
              if(zombieskilled == zombiesinround){
                actualround++;
                actualendround = endround+5;
                player.sendMessage("Round " + actualround);
              }
            }
            }
          }
        @EventHandler
        public void nodespawn(CreatureSpawnEvent event){
           
            double x = event.getEntity().getLocation().getX();
            double z = event.getEntity().getLocation().getZ();
            if(event.getEntity().getLocation().getWorld() == getServer().getWorld("map")){
            if(x > -349 && x < -268 && z > -488 && z < -407){
                event.getEntity().setCustomName("UpButtCoconut");
                event.getEntity().setRemoveWhenFarAway(false);
                }
            }
        }
    }
    But, I am having issues with this:
    Code:
        @EventHandler
        public void EDE(EntityDeathEvent event){
            Player player = event.getEntity().getKiller();
            double x = event.getEntity().getLocation().getX();
            double z = event.getEntity().getLocation().getY();
            if(x>-349 && x<-268 && z>-488 && z<-407 &&event.getEntity().getLocation().getWorld().equals(getServer().getWorld("map"))){
                zombieskilled++;
                player.sendMessage("You have killed " + zombieskilled);
            if(event.getEntity().getKiller()!=null){
              player.sendMessage("You have killed " + zombieskilled);
              if(zombieskilled == zombiesinround){
                actualround++;
                actualendround = endround+5;
                player.sendMessage("Round " + actualround);
              }
            }
            }
          }
    I believe that this is not working.
    None of the player.sendMessages actually send so I am unable to tell if the rest is working.

    Code:
                actualendround = endround+5;
                player.sendMessage("Round " + actualround);
    Also doesn't work as more zombies don't spawn after zombieskilled is equal to zombiesinround.

    I'm pretty sure that I've tried everything but no changes! :(

    If you are confused please tell me why!

    Please do not discard this thread!

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

    Whomp54

    i think the problem is that you are trying to get the killer, not the player. So you're trying to send the killer a message… lol

    getKiller is trying to get the player's name of who killed them.

    try:
    Code:java
    1. @EventHandler
    2. public void EDE(EntityDeathEvent event){
    3. Player player = event.getPlayer();
    4. double x = player.getLocation().getX();
    5. double z = player.getLocation().getY();
    6. if(x>-349 && x<-268 && z>-488 && z<-407 && player.getLocation().getWorld().equals(getServer().getWorld("map"))){
    7. zombieskilled++;
    8. player.sendMessage("You have killed " + zombieskilled);
    9. if(player !=null){
    10. player.sendMessage("You have killed " + zombieskilled);
    11. if(zombieskilled == zombiesinround){
    12. actualround++;
    13. actualendround = endround+5;
    14. player.sendMessage("Round " + actualround);
    15. }
    16. }
    17. }
    18. }
    19.  
     
  3. Well, get.Player isn't defined in the EntityDeathEvent so yea. But I'll try casting it and see how that works out.

    Whomp54 Yea doesn't work

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

    Whomp54

    dajako
    Hmmmm give me some thinking time and ill come back to you…. lol
    I'll play around with it a little

    dajako
    Is there an error on the console?

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

    Whomp54

    dajako
    Lol. Totally spaced on this, but you used the wrong event :p

    The event you SHOULD use is:
    PlayerDeathEvent


    If you copied my changes, thats all you need to change :)
     
  7. Eh... It's used to count how many zombies have been killed. lol
     
  8. Anyone know what the issue is?

    Changed title, hope it makes more sense now! :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page