Skip to content
ChanceSD edited this page Aug 8, 2024 · 7 revisions

Maven details

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.18.5</version>
    <scope>provided</scope>
</dependency>

Get a PvPlayer

In most cases you will need a PvPlayer instance. The static PvPlayer.get() method should be preferred for compatibility with the premium version.

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

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

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

// 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);
// You can check each individual protection like this
if (combatPlayer.hasRespawnProtection())
    pvplayer.message("You can't be attacked");

// Or ideally, what you probably want is to check if there's any protections 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 the attack was blocked or CancelResult.FAIL if is wasn't
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 events you can listen to, 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:

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.