combat tracking is working again!

This commit is contained in:
2024-02-28 20:09:56 +01:00
parent 3c7904786e
commit 58a4a9f25d
4 changed files with 14 additions and 7 deletions
@@ -6,6 +6,7 @@ import me.youhavetrouble.preventstabby.hooks.PlaceholderApiHook;
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
import me.youhavetrouble.preventstabby.data.PlayerListener;
import me.youhavetrouble.preventstabby.data.PlayerManager;
import me.youhavetrouble.preventstabby.listeners.PlayerDamageListener;
import me.youhavetrouble.preventstabby.util.*;
import org.bstats.bukkit.Metrics;
import org.bukkit.command.CommandSender;
@@ -33,6 +34,8 @@ public final class PreventStabby extends JavaPlugin {
// Register listeners TODO
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
getServer().getPluginManager().registerEvents(new PlayerDamageListener(this), this);
// Register command
PluginCommand pvpCommand = getCommand("pvp");
if (pvpCommand == null) {
@@ -10,8 +10,8 @@ import java.util.UUID;
public class PlayerData {
private final UUID playerUuid;
private long lastAccessTimestamp, loginTimestamp;
private Long combatStartTimestamp, teleportTimestamp;
private long lastAccessTimestamp;
private Long combatStartTimestamp, teleportTimestamp, loginTimestamp;
private boolean pvpEnabled, lastCombatCheck;
public PlayerData(UUID playerUuid, boolean pvpEnabled) {
@@ -19,7 +19,7 @@ public class PlayerData {
this.pvpEnabled = pvpEnabled;
this.lastCombatCheck = false;
this.combatStartTimestamp = null;
this.loginTimestamp = System.currentTimeMillis();
this.loginTimestamp = null;
this.teleportTimestamp = null;
refreshCacheTime();
}
@@ -105,7 +105,7 @@ public class PlayerData {
* Retrieves the login timestamp for the player.
* @return The login timestamp for the player.
*/
public long getLoginTimestamp() {
public Long getLoginTimestamp() {
return loginTimestamp;
}
@@ -123,6 +123,7 @@ public class PlayerData {
* @return true if the player is in combat, false otherwise.
*/
public boolean isInCombat() {
if (combatStartTimestamp == null) return false;
return System.currentTimeMillis() - (combatStartTimestamp + (PreventStabby.getPlugin().getConfigCache().combat_time * 1000)) < 0;
}
@@ -143,6 +144,7 @@ public class PlayerData {
* @return true if the player has login protection, false otherwise.
*/
public boolean hasLoginProtection() {
if (loginTimestamp == null) return false;
return System.currentTimeMillis() - (loginTimestamp + (PreventStabby.getPlugin().getConfigCache().login_protection_time * 1000)) < 0;
}
@@ -100,6 +100,8 @@ public class PlayerManager {
}
public void handleDamageCheck(@NotNull DamageCheckResult damageCheckResult) {
if (damageCheckResult.attackerId() == null) return;
if (damageCheckResult.victimId() == null) return;
PluginMessages.sendOutMessages(damageCheckResult);
PlayerData attacker = getPlayer(damageCheckResult.attackerId());
PlayerData victim = getPlayer(damageCheckResult.victimId());
@@ -154,8 +156,8 @@ public class PlayerManager {
return switch (getForcedPvpState()) {
case DISABLED -> new DamageCheckResult(false, attackerId, victimId, plugin.getConfigCache().cannotAttackForcedPvpOff, null);
case ENABLED -> DamageCheckResult.positive();
default -> DamageCheckResult.positive();
case ENABLED -> DamageCheckResult.positive(attackerId, victimId);
default -> DamageCheckResult.positive(attackerId, victimId);
};
}
@@ -12,7 +12,7 @@ public class PlayerDamageListener implements Listener {
private final PreventStabby plugin;
PlayerDamageListener(PreventStabby plugin) {
public PlayerDamageListener(PreventStabby plugin) {
this.plugin = plugin;
}