Solved How to check if PvP is enabled

Discussion in 'Plugin Development' started by DeadlyScone, Jun 14, 2015.

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


    I have been trying to figure out ways to test if pvp is enabled without hooking into WorldGuard, Factions, Towny, ect just to test if pvp is enabled.
    Here are my possible solutions.
    1. damage a player with 0.0 damage(essential not hurting them) and see if the event was canceled
    2. spawn an invisible NPC, damage it, then check to see if the event was canceled.

    The problem with 1 is that i don't know how to disable the screen effect to indiscreetly damage the other player.
    The problem with 2 is i can't seem to find a good source code for spanwing NPC's and iam not familiar with NMS and am not open to hooking into another API just to spawn one either.

    Thanks for any help or suggestions!
  2. Offline

    I Al Istannen

    @DeadlyScone The Entity damage event shouldn't be triggered by a fake NPC. And you can't spawn a right one, as this would be a player.
    You could however damage the player and listen on highest priority: "@EventHandler(priority=HIGHEST)". If the event wasn't cancelled until then, it probably won't be canceled at all as this will run last. It could only be wrong if another Listener is cancelling at Highest priority which it shouldn't.
    Then simply cancel the even't yourself, preventing the damage.
  3. Offline


    Thanks for your input, ill try that out and let you know.
  4. Offline


    @DeadlyScone Another option would be to manually create an EntityDamageEvent with the player in question, call it with the plugin manager and check if it's cancelled or not, this will prevent the issue with the possible listener cancelling at highest priority.
  5. Offline


    @Konato_K , @I Al Istannen

    Thank you for all your suggestions. I was able to successfully detect if PvP was enabled by implementing a hashmap containing the entity(player) ID and specific data for my plugin, then damaging the aforementioned entity(player) then observing the entitydamage event(priority is at Monitor) and checking if the entity id involved matched the entityID in the map and if the event had not been canceled(essentially meaning PvP is enabled) if so my plugin continues its business
Thread Status:
Not open for further replies.

Share This Page