Skip to content
ChanceSD edited this page Apr 6, 2024 · 5 revisions

PvPManager doesn't have a Javadocs page but using the API should be fairly simple.
When in doubt you can also take a look at the source code and see what a method does.

Maven Repo:

<repository>
    <id>CodeMC</id>
    <url>https://repo.codemc.org/repository/maven-public/</url>
</repository>

Artifact Information:

<dependency>
    <groupId>me.NoChance.PvPManager</groupId>
    <artifactId>pvpmanager</artifactId>
    <version>3.17.8</version>
    <scope>provided</scope>
</dependency>

Get a PvPlayer

In most cases all you will need is a PvPlayer instance. The static PvPlayer.get() method should be preferred.

PvPManager pvpmanager;
// Check if PvPManager is enabled 
if (Bukkit.getPluginManager().isPluginEnabled("PvPManager"))
    pvpmanager = (PvPManager) Bukkit.getPluginManager().getPlugin("PvPManager");
if (pvpmanager == null)
    return;

// Once this is done you can get the PlayerHandler class
PlayerHandler playerHandler = pvpmanager.getPlayerHandler();

Player player = Bukkit.getPlayerExact("ChanceSD");

// You can get a PvPlayer either through the playerHandler or directly with the static get method
PvPlayer pvplayer = PvPlayer.get(player);
PvPlayer pvplayer = playerHandler.get(player);

// Let's say we want to know if the player has newbie protection or is tagged
if (pvplayer.isNewbie())
    pvplayer.message("You are a newbie!");

if (pvplayer.isInCombat())
    pvplayer.message("You are in combat!");

Check if two players can PvP

PvPlayer combatPlayer = PvPlayer.get(player);
// Obviously you can check each individual protection like
if (combatPlayer.hasRespawnProtection())
    pvplayer.message("You can't be attacked");

// Or ideally, what you probably want is to check if there's any protection at all
// This returns a boolean, true if the two players can attack each other, false otherwise
boolean canAttack = pvpmanager.getPlayerHandler().canAttack(Player attacker, Player defender);

// This returns a CancelResult enum with the reason why PvP was blocked or CancelResult.FAIL if not
CancelResult result = pvpmanager.getPlayerHandler().tryCancel(Player attacker, Player defender);
if (result == CancelResult.NEWBIE_PROTECTION)
    // The players can't PvP because one of them has newbie protection

Additionally, there are some events you can use, see below for a list.

PvPManager Events

There are some custom events you can listen to. You can find a list here
At the time of writing these are the existing events:

They should be self-explanatory, use them as you would any Bukkit event.
Feel free to suggest more events or improvements to them.

Pull Requests are always welcome if you have anything you would like added or fixed.
If you have questions, feel free to ask in discord or in the Spigot/Bukkit thread.