Developers

Currently PvPManager doesn't have javadocs but you can easily access several methods which will allow to do what you need.

When in doubt you can also take a look at the Source Code and see what a method does.

First, you want to have access to a PvPManager instance:

PvPManager pvp = (PvPManager) Bukkit.getPluginManager().getPlugin("PvPManager");

Then make the proper checks like if "pvp" isn't null. Once this is done you can get the PlayerHandler class

PlayerHandler playerHandler = pvp.getPlayerHandler();

Which allows you to get PvPlayer instances for specific players and check for what you need. Example:

Player p = Bukkit.getPlayerExact("NoChanceSD"); //just for the example
PvPlayer pvplayer = playerHandler.get(p);

Let's say we want to know if he has Newbie Protection

if (pvplayer.isNewbie())
    pvplayer.message("You are a Newbie!");

As you can see, it's very simple to use. Additionally, there are a few useful utilities you might want in the CombatUtils class

The first one is the method isPvP(EntityDamageByEntityEvent event), you can easily check if the event is a fight between two players or something else. Here is a regular listener

@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {

With this method everything not considered PvP will be ignored and you can assume that the damager is either a Player or a Projectile and the attacked entity is a Player.

    if (!CombatUtils.isPvP(event))
        return;
}

The second method provides PvPManager compatibility, you give the method 2 Players(or PvPlayers) and it will tell you if PvPManager would block this attack or let it pass. It returns a CancelResult. Example:

Player attacker;
Player defender;

This result can be several things, you can take a look at the Enum in CombatUtils class

CancelResult result = CombatUtils.tryCancel(attacker, defender);

Basically if the result is CancelResult.FAIL or CancelResult.FAIL_OVERRIDE it means PvPManager would not block this attack. If it's not one of those two, then it would get blocked. You could use this information to respect PvPManager settings if you wish.

if (result != CancelResult.FAIL && result != CancelResult.FAIL_OVERRIDE)
    attacker.sendMessage("PvPManager blocked this attack!");


That's pretty much all you need to do if you want to hook into PvPManager. In the future there might be some custom events but for now that's all.

Pull Requests are always welcome if you have anything you would like added.
If you have questions, feel free to ask in the comments or by private message.


Comments

Posts Quoted:
Reply
Clear All Quotes