Changing PvP Status of Players

Discussion in 'Plugin Development' started by DarkFuzzyCookie, Jul 13, 2013.

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

    DarkFuzzyCookie

    Hi there, I was wondering if there is a way to change the PvP status of individual players. I know that there is world.setPvp(boolean) but that sets the PvP of the entire world(or server, not exactly sure). Then I tried to do EntityDamageEntityEvent and grab the damage and directly injure the player, but that didn't work either. Any help would be greatly appreciated.
     
  2. Offline

    turqmelon

    Use EntityDamageByEntityEvent and save the status of each player. (Hashmap, file, etc.) Within the event, just check the status of the entity and the damager, and cancel the event accordingly.
     
  3. Offline

    DarkFuzzyCookie

    turqmelon
    What if I want the server PvP to be false but when in a certain area to be true? (The opposite of what you said) How would I make it so that the damager CAN damage the player?
     
  4. Offline

    turqmelon

    If you disable PVP in your server.properties, PVP is disabled globally. You can't allow PVP between players if it's off in your properties file.
     
  5. Offline

    Loogeh

    DarkFuzzyCookie
    Make a method somewhere like this:

    Code:
    public static boolean isInArea(Player player, int smallX, int bigX, int smallZ, int bigZ) {
            return (player.getLocation().getX() >= smallX && player.getLocation().getX() <= bigX && player.getLocation().getZ() >= smallZ && player.getLocation().getZ() <= bigZ);
            }
    Then in the EntityDamageByEntityEvent check if the damager was an instanceof player and check if the event.getEntity (damaged entity) was an instanceof player. If both of those are true, check if the damager or the damaged player are not in the area you want to be pvp enable and if that returns false then use event.setCancelled(true) and then do an else statement and put event.setCancelled(false);
     
Thread Status:
Not open for further replies.

Share This Page