Skip to content

Developer API

YouHaveTrouble edited this page Nov 20, 2023 · 5 revisions

Setting up dependencies

Replace VERSION with latest version visible here:

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
	<url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.YouHaveTrouble</groupId>
    <artifactId>PreventStabby</artifactId>
    <version>VERSION</version>
</dependency>

Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.YouHaveTrouble:PreventStabby:VERSION'
}

API Usage

For all API methods here you can provide a Player object or player UUID object.

API will be improved in the future, consistency not guaranteed between major versions!

Set player's PvP toggle state

PreventStabbyAPI.setPvpEnabled(player, true);

Get player's PvP toggle state

boolean state = PreventStabbyAPI.getPvpEnabled(player);

Check if player can damage another player

The boolean at the end decides if the deny message should be sent to attacker in case they can't damage the victim.

boolean canDamage = PreventStabbyAPI.canDamage(playerAttacker, playerVictim, false);

Check if player has login protection

This check is included in PreventStabbyAPI#canDamage(), but in case you need to check for that specifically here's the method for that

boolean hasloginProtection = PreventStabbyAPI.hasLoginProtection(player);

Check if player is in combat with other player

boolean isInCombat = PreventStabbyAPI.isInCombat(player);

Check if pvp is currently forced. Enum value NONE means the PvP is not forced.

Pvpstate pvpState = PreventStabbyAPI.getForcedPvpState();

Sets forced PvP state until server restart or changed with override command or this method.

PreventStabbyAPI.setForcedPvpState(PvpState newForcedPvpState);

Events

PlayerEnterCombatEvent

Called when player enters pvp combat. If cancelled, player will not be put in combat. Example use:

@EventHandler(ignoreCancelled = true)
public void onPlayerJoin(PlayerEnterCombatEvent event) {
    // do stuff
}

PlayerLeaveCombatEvent

Called when player leaves pvp combat. If cancelled, combat time will be refreshed for the combat time set in plugin config. Example use:

@EventHandler(ignoreCancelled = true)
public void onPlayerJoin(PlayerLeaveCombatEvent event) {
    // do stuff
}