mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Remove redundant SmartCache and refactor related classes
The SmartCache class has been removed, and logic within it has been moved to relevant classes to reduce redundancy. This involved utilizing the PlayerManager for player data, instead of invalidating a separate cache in the now-removed SmartCache. Other classes that interacted with SmartCache, such as API, listeners and PreventStabby, have been updated to use the newly refactored system.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package me.youhavetrouble.preventstabby.api;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,138 +11,6 @@ import java.util.UUID;
|
||||
|
||||
public class PreventStabbyAPI {
|
||||
|
||||
/**
|
||||
* Sets players PvP state. This will always save to database.
|
||||
* @param player Player to set pvp state to
|
||||
* @param newState State to set
|
||||
*/
|
||||
public static void setPvpEnabled(Player player, boolean newState) {
|
||||
PreventStabby.getPlugin().getSmartCache().setPlayerPvpState(player.getUniqueId(), newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets players PvP state. This will always save to database.
|
||||
* @param uuid UUID of player to set pvp state to
|
||||
* @param newState State to set
|
||||
*/
|
||||
public static void setPvpEnabled(UUID uuid, boolean newState) {
|
||||
PreventStabby.getPlugin().getSmartCache().setPlayerPvpState(uuid, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return True if enabled, false if disabled
|
||||
*/
|
||||
public static boolean getPvpEnabled(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getSmartCache().getPlayerData(uuid).isPvpEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets player's PvP state. If player is not cached this will query the database.
|
||||
* @param player Player to get data from.
|
||||
* @return True if enabled, false if disabled
|
||||
*/
|
||||
public static boolean getPvpEnabled(Player player) {
|
||||
return PreventStabby.getPlugin().getSmartCache().getPlayerData(player.getUniqueId()).isPvpEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 victimUuid Victim's UUID
|
||||
* @param sendDenyMessage True if check should send deny message to attacker
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(UUID attackerUuid, UUID victimUuid, boolean sendDenyMessage) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, sendDenyMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another.
|
||||
* @param attacker Attacker
|
||||
* @param victim Victim
|
||||
* @param sendDenyMessage True if check should send deny message to attacker
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(Player attacker, Player victim, boolean sendDenyMessage) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), sendDenyMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 victimUuid Victim's UUID
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(UUID attackerUuid, UUID victimUuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another.
|
||||
* @param attacker Attacker
|
||||
* @param victim Victim
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(Player attacker, Player victim) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has login protection.
|
||||
* @param uuid UUID of player to check
|
||||
* @return True if player has login protection, false if not
|
||||
*/
|
||||
public static boolean hasLoginProtection(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has teleport protection.
|
||||
* @param player Player to check
|
||||
* @return True if player has teleport protection, false if not
|
||||
*/
|
||||
public static boolean hasTeleportProtection(Player player) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has teleport protection.
|
||||
* @param uuid UUID of player to check
|
||||
* @return True if player has teleport protection, false if not
|
||||
*/
|
||||
public static boolean hasTeleportProtection(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has login protection.
|
||||
* @param player Player to check
|
||||
* @return True if player has login protection, false if not
|
||||
*/
|
||||
public static boolean hasLoginProtection(Player player) {
|
||||
return PreventStabby.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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current state of forced PvP
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user