diff --git a/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java b/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java index f3898a3..f27a037 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java +++ b/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java @@ -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) { diff --git a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerData.java b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerData.java index 255ccc4..c4c289d 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerData.java +++ b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerData.java @@ -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; } diff --git a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerManager.java b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerManager.java index da0357f..234ba94 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/data/PlayerManager.java +++ b/src/main/java/me/youhavetrouble/preventstabby/data/PlayerManager.java @@ -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); }; } diff --git a/src/main/java/me/youhavetrouble/preventstabby/listeners/PlayerDamageListener.java b/src/main/java/me/youhavetrouble/preventstabby/listeners/PlayerDamageListener.java index 725468e..1329f42 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/listeners/PlayerDamageListener.java +++ b/src/main/java/me/youhavetrouble/preventstabby/listeners/PlayerDamageListener.java @@ -12,7 +12,7 @@ public class PlayerDamageListener implements Listener { private final PreventStabby plugin; - PlayerDamageListener(PreventStabby plugin) { + public PlayerDamageListener(PreventStabby plugin) { this.plugin = plugin; }