mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
massive changes
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package me.youhavetrouble.preventstabby.api;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TogglePvpAPI {
|
||||
|
||||
/**
|
||||
* 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 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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Fired when player enters combat.
|
||||
*/
|
||||
public class PlayerEnterCombatEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final Player player;
|
||||
private boolean cancelled;
|
||||
|
||||
public PlayerEnterCombatEvent(Player player) {
|
||||
this.player = player;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData() {
|
||||
return PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Fired when player leaves combat. If cancelled, it will refresh combat timer to the value set in the config.
|
||||
*/
|
||||
public class PlayerLeaveCombatEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final Player player;
|
||||
private boolean cancelled;
|
||||
|
||||
public PlayerLeaveCombatEvent(Player player) {
|
||||
this.player = player;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData() {
|
||||
return PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* NOT IMPLEMENTED YET
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlayerTogglePvpEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final Player player;
|
||||
private boolean newState, sendMessage;
|
||||
|
||||
public PlayerTogglePvpEvent(Player player, boolean newState, boolean sendMessage) {
|
||||
this.player = player;
|
||||
this.newState = newState;
|
||||
this.sendMessage = sendMessage;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public boolean newState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
public void setNewState(boolean newState) {
|
||||
this.newState = newState;
|
||||
}
|
||||
|
||||
public boolean isSendMessage() {
|
||||
return sendMessage;
|
||||
}
|
||||
|
||||
public void setSendMessage(boolean sendMessage) {
|
||||
this.sendMessage = sendMessage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user