1.15.2 Can't cancel pvp attack

Discussion in 'Spigot Plugin Development' started by Joshuak52, Feb 12, 2020.

Thread Status:
Not open for further replies.
  1. I can't figure out why the attacks are still going through, I get the correct messages

    Code (Text):

    @EventHandler
        public void onHit(EntityDamageByEntityEvent e) {
            if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
                Player whoWasHit = (Player) e.getEntity();
                Player whoHit = (Player) e.getDamager();
                if(whoWasHit.hasPermission("Safe.PvP")) {
                    e.setCancelled(true);
                    whoWasHit.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + "You're being attacked! PvP is not available until rank F!");
                    whoWasHit.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + "Enable PvP now by attacking back!");
                    whoHit.sendMessage(ChatColor.GOLD + whoWasHit.getName() + ChatColor.DARK_RED + "" + ChatColor.ITALIC + " does not have pvp available until rank F!");
                    return;
                }
                if(whoHit.hasPermission("Safe.PvP")) {
                    whoHit.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + "You have enabled PvP by attacking " + ChatColor.GOLD + whoWasHit.getName());
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + whoHit.getName() + " -Safe.PvP");
                }
            }
        }
     
     
  2. another plugin is likely uncancelling the event. probably another plugin thats poorly coded. create another event handler for edbee with priority monitor and print the cancel state, see if your event gets uncancelled. if so, try a higher priority (that isnt monitor) for your original event handler
     
  3. If you don't have other plugins on your server that could be causing problems with the event being uncancelled, there may be another event in your plugin doing it. A band-aid solution would be to set the event damage to 0.
     
  4. Change
    Code (Text):
    @EventHandler
    to
    Code (Text):
    @EventHandler(ignoreCancelled = true)
    Or change EventPriority to
     
  5. thats not gonna change anything
     
Thread Status:
Not open for further replies.