EntityDamageByEntityEvent Bug

Discussion in 'Spigot Plugin Development' started by suitinacow, Jul 14, 2015.

  1. Code (Text):
    @EventHandler(priority = EventPriority.HIGHEST)
        public void pvping(final EntityDamageByEntityEvent event){
            if(event.getEntity() instanceof Player && event.getDamager() instanceof Player){
                final Player player = (Player) event.getEntity();
                final Player damager = (Player) event.getDamager();
                pvping.add(player);
                pvping.add(damager);
                player.sendMessage(ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "V" + ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "//" + " You are currently in battle!");
                damager.sendMessage(ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "V" + ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "//" + " You are currently in battle!");
                Bukkit.getServer().getScheduler().runTaskLater(plugin, new Runnable(){
                    public void run() {
                        pvping.remove(player);
                        pvping.remove(damager);
                        player.sendMessage(ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "V" + ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "//" + " You are no longer in battle!");
                        damager.sendMessage(ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "V" + ChatColor.DARK_PURPLE + "P" + ChatColor.DARK_GRAY + "//" + " You are currently in battle!");
                    }
                }, 8000L);
            }
        }
    Unlike my recent post where the event listeners didnt work at all, this one does but it doesn't do what i want it to do.. when a player hits a player their supposed to be tagged with pvp once, with this it tags them every time they hit eachother.. any idea how to fix this up?
     
  2. You haven't checked if the player has been tagged... So whenever the event is fired the player will be tagged...
     
  3. You mean I should check if it was tagged in another class?
     
  4. You have a method for tagging and removing the tag from a player, so make a method that checks if the player is tagged ;)
     

  5. i already have in my afk class
    Code (Text):
        public HashSet<Player> playerAFK = new HashSet<Player>();

        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(!(sender instanceof Player))
            {
                return true;
            }
            Player player = (Player) sender;
         
            if(!(pvp.pvping.contains(player))){
                Bukkit.getServer().broadcastMessage(ChatColor.BLUE + player.getName()+ ChatColor.DARK_PURPLE + " is now AFK");
                player.sendMessage("Hi");
                playerAFK.add(player);
            }else{
                player.sendMessage(ChatColor.RED + "You can't afk when you're in battle!");
            }
            return false;
        }

    }
     
  6. So why are you. Not checking if the player is PVPing in the event...
     
  7. well what im tyring to to is to disallow the player to /afk if they're in battle.. the class afk checks if the player is tagged or not with
    Code (Text):
    if(!(pvp.pvping.contains(player))){
    and theoretically is supposed to announce to the server that the player is not afk if it's coded properly.. and says
    Code (Text):
    player.sendMessage(ChatColor.RED + "You can't afk when you're in battle!");
    if the player is in battle.. are you saying i need this code in the event?