API stuff

This commit is contained in:
YouHaveTrouble
2021-03-08 11:46:06 +01:00
parent e895cab31d
commit 74835aa283
2 changed files with 36 additions and 17 deletions
@@ -1,6 +1,7 @@
package eu.endermite.togglepvp.api; package eu.endermite.togglepvp.api;
import eu.endermite.togglepvp.TogglePvp; import eu.endermite.togglepvp.TogglePvp;
import eu.endermite.togglepvp.util.CombatTimer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID; import java.util.UUID;
@@ -8,7 +9,7 @@ public class TogglePvpAPI {
/** /**
* Sets players PvP state. This will always save to database. * Sets players PvP state. This will always save to database.
* @param player player to set pvp state to * @param player Player to set pvp state to
* @param newState State to set * @param newState State to set
*/ */
public static void setPvpEnabled(Player player, boolean newState) { public static void setPvpEnabled(Player player, boolean newState) {
@@ -17,7 +18,7 @@ public class TogglePvpAPI {
/** /**
* Sets players PvP state. This will always save to database. * Sets players PvP state. This will always save to database.
* @param uuid uuid of player to set pvp state to * @param uuid UUID of player to set pvp state to
* @param newState State to set * @param newState State to set
*/ */
public static void setPvpEnabled(UUID uuid, boolean newState) { public static void setPvpEnabled(UUID uuid, boolean newState) {
@@ -27,7 +28,7 @@ public class TogglePvpAPI {
/** /**
* Gets player's PvP state. If player is not cached this will query the database. * Gets player's PvP state. If player is not cached this will query the database.
* @param uuid UUID of the player to get data from. * @param uuid UUID of the player to get data from.
* @return true if enabled, false if disabled * @return True if enabled, false if disabled
*/ */
public static boolean getPvpEnabled(UUID uuid) { public static boolean getPvpEnabled(UUID uuid) {
return TogglePvp.getPlugin().getSmartCache().getPlayerData(uuid).isPvpEnabled(); return TogglePvp.getPlugin().getSmartCache().getPlayerData(uuid).isPvpEnabled();
@@ -36,7 +37,7 @@ public class TogglePvpAPI {
/** /**
* Gets player's PvP state. If player is not cached this will query the database. * Gets player's PvP state. If player is not cached this will query the database.
* @param player Player to get data from. * @param player Player to get data from.
* @return true if enabled, false if disabled * @return True if enabled, false if disabled
*/ */
public static boolean getPvpEnabled(Player player) { public static boolean getPvpEnabled(Player player) {
return TogglePvp.getPlugin().getSmartCache().getPlayerData(player.getUniqueId()).isPvpEnabled(); return TogglePvp.getPlugin().getSmartCache().getPlayerData(player.getUniqueId()).isPvpEnabled();
@@ -44,10 +45,10 @@ public class TogglePvpAPI {
/** /**
* Checks if player can be damaged by another. Providing UUID of entity other than player may result in exceptions * Checks if player can be damaged by another. Providing UUID of entity other than player may result in exceptions
* @param attackerUuid attacker's UUID * @param attackerUuid Attacker's UUID
* @param victimUuid victim's UUID * @param victimUuid Victim's UUID
* @param sendDenyMessage true if check should send deny message to attacker * @param sendDenyMessage True if check should send deny message to attacker
* @return true if victim can be attacked by attacker, false if not * @return True if victim can be attacked by attacker, false if not
*/ */
public static boolean canDamage(UUID attackerUuid, UUID victimUuid, boolean sendDenyMessage) { public static boolean canDamage(UUID attackerUuid, UUID victimUuid, boolean sendDenyMessage) {
return TogglePvp.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, sendDenyMessage); return TogglePvp.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, sendDenyMessage);
@@ -55,10 +56,10 @@ public class TogglePvpAPI {
/** /**
* Checks if player can be damaged by another. * Checks if player can be damaged by another.
* @param attacker attacker * @param attacker Attacker
* @param victim victim * @param victim Victim
* @param sendDenyMessage true if check should send deny message to attacker * @param sendDenyMessage True if check should send deny message to attacker
* @return true if victim can be attacked by attacker, false if not * @return True if victim can be attacked by attacker, false if not
*/ */
public static boolean canDamage(Player attacker, Player victim, boolean sendDenyMessage) { public static boolean canDamage(Player attacker, Player victim, boolean sendDenyMessage) {
return TogglePvp.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), sendDenyMessage); return TogglePvp.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), sendDenyMessage);
@@ -66,8 +67,8 @@ public class TogglePvpAPI {
/** /**
* Checks if player has login protection. * Checks if player has login protection.
* @param uuid uuid of player to check * @param uuid UUID of player to check
* @return true if player has login protection, false if not * @return True if player has login protection, false if not
*/ */
public static boolean hasLoginProtection(UUID uuid) { public static boolean hasLoginProtection(UUID uuid) {
return TogglePvp.getPlugin().getPlayerManager().hasLoginProtection(uuid); return TogglePvp.getPlugin().getPlayerManager().hasLoginProtection(uuid);
@@ -75,12 +76,30 @@ public class TogglePvpAPI {
/** /**
* Checks if player has login protection. * Checks if player has login protection.
* @param player player to check * @param player Player to check
* @return true if player has login protection, false if not * @return True if player has login protection, false if not
*/ */
public static boolean hasLoginProtection(Player player) { public static boolean hasLoginProtection(Player player) {
return TogglePvp.getPlugin().getPlayerManager().hasLoginProtection(player.getUniqueId()); return TogglePvp.getPlugin().getPlayerManager().hasLoginProtection(player.getUniqueId());
} }
/**
* Checks if player is in combat.
* @param uuid UUID of player to check
* @return True if player is in combat, false if they are not or if they are offline
*/
public static boolean isInCombat(UUID uuid) {
return CombatTimer.isInCombat(uuid);
}
/**
* Checks if player is in combat.
* @param player Player to check
* @return True if player is in combat, false if they are not or if they are offline
*/
public static boolean isInCombat(Player player) {
return CombatTimer.isInCombat(player.getUniqueId());
}
} }
@@ -24,7 +24,7 @@ public class CombatTimer {
public static boolean isInCombat(UUID uuid) { public static boolean isInCombat(UUID uuid) {
try { try {
long combattimer = TogglePvp.getPlugin().getSmartCache().getPlayerData(uuid).getCombattime(); long combattimer = TogglePvp.getPlugin().getPlayerManager().getPlayer(uuid).getCombattime();
long now = Instant.now().getEpochSecond(); long now = Instant.now().getEpochSecond();
return combattimer > now; return combattimer > now;
} catch (Exception e) { } catch (Exception e) {