mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
combat tracking is working again!
This commit is contained in:
@@ -6,6 +6,7 @@ import me.youhavetrouble.preventstabby.hooks.PlaceholderApiHook;
|
|||||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||||
import me.youhavetrouble.preventstabby.data.PlayerListener;
|
import me.youhavetrouble.preventstabby.data.PlayerListener;
|
||||||
import me.youhavetrouble.preventstabby.data.PlayerManager;
|
import me.youhavetrouble.preventstabby.data.PlayerManager;
|
||||||
|
import me.youhavetrouble.preventstabby.listeners.PlayerDamageListener;
|
||||||
import me.youhavetrouble.preventstabby.util.*;
|
import me.youhavetrouble.preventstabby.util.*;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -33,6 +34,8 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
// Register listeners TODO
|
// Register listeners TODO
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerDamageListener(this), this);
|
||||||
|
|
||||||
// Register command
|
// Register command
|
||||||
PluginCommand pvpCommand = getCommand("pvp");
|
PluginCommand pvpCommand = getCommand("pvp");
|
||||||
if (pvpCommand == null) {
|
if (pvpCommand == null) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import java.util.UUID;
|
|||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
|
|
||||||
private final UUID playerUuid;
|
private final UUID playerUuid;
|
||||||
private long lastAccessTimestamp, loginTimestamp;
|
private long lastAccessTimestamp;
|
||||||
private Long combatStartTimestamp, teleportTimestamp;
|
private Long combatStartTimestamp, teleportTimestamp, loginTimestamp;
|
||||||
private boolean pvpEnabled, lastCombatCheck;
|
private boolean pvpEnabled, lastCombatCheck;
|
||||||
|
|
||||||
public PlayerData(UUID playerUuid, boolean pvpEnabled) {
|
public PlayerData(UUID playerUuid, boolean pvpEnabled) {
|
||||||
@@ -19,7 +19,7 @@ public class PlayerData {
|
|||||||
this.pvpEnabled = pvpEnabled;
|
this.pvpEnabled = pvpEnabled;
|
||||||
this.lastCombatCheck = false;
|
this.lastCombatCheck = false;
|
||||||
this.combatStartTimestamp = null;
|
this.combatStartTimestamp = null;
|
||||||
this.loginTimestamp = System.currentTimeMillis();
|
this.loginTimestamp = null;
|
||||||
this.teleportTimestamp = null;
|
this.teleportTimestamp = null;
|
||||||
refreshCacheTime();
|
refreshCacheTime();
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ public class PlayerData {
|
|||||||
* Retrieves the login timestamp for the player.
|
* Retrieves the login timestamp for the player.
|
||||||
* @return The login timestamp for the player.
|
* @return The login timestamp for the player.
|
||||||
*/
|
*/
|
||||||
public long getLoginTimestamp() {
|
public Long getLoginTimestamp() {
|
||||||
return loginTimestamp;
|
return loginTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +123,7 @@ public class PlayerData {
|
|||||||
* @return true if the player is in combat, false otherwise.
|
* @return true if the player is in combat, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isInCombat() {
|
public boolean isInCombat() {
|
||||||
|
if (combatStartTimestamp == null) return false;
|
||||||
return System.currentTimeMillis() - (combatStartTimestamp + (PreventStabby.getPlugin().getConfigCache().combat_time * 1000)) < 0;
|
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.
|
* @return true if the player has login protection, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasLoginProtection() {
|
public boolean hasLoginProtection() {
|
||||||
|
if (loginTimestamp == null) return false;
|
||||||
return System.currentTimeMillis() - (loginTimestamp + (PreventStabby.getPlugin().getConfigCache().login_protection_time * 1000)) < 0;
|
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) {
|
public void handleDamageCheck(@NotNull DamageCheckResult damageCheckResult) {
|
||||||
|
if (damageCheckResult.attackerId() == null) return;
|
||||||
|
if (damageCheckResult.victimId() == null) return;
|
||||||
PluginMessages.sendOutMessages(damageCheckResult);
|
PluginMessages.sendOutMessages(damageCheckResult);
|
||||||
PlayerData attacker = getPlayer(damageCheckResult.attackerId());
|
PlayerData attacker = getPlayer(damageCheckResult.attackerId());
|
||||||
PlayerData victim = getPlayer(damageCheckResult.victimId());
|
PlayerData victim = getPlayer(damageCheckResult.victimId());
|
||||||
@@ -154,8 +156,8 @@ public class PlayerManager {
|
|||||||
|
|
||||||
return switch (getForcedPvpState()) {
|
return switch (getForcedPvpState()) {
|
||||||
case DISABLED -> new DamageCheckResult(false, attackerId, victimId, plugin.getConfigCache().cannotAttackForcedPvpOff, null);
|
case DISABLED -> new DamageCheckResult(false, attackerId, victimId, plugin.getConfigCache().cannotAttackForcedPvpOff, null);
|
||||||
case ENABLED -> DamageCheckResult.positive();
|
case ENABLED -> DamageCheckResult.positive(attackerId, victimId);
|
||||||
default -> DamageCheckResult.positive();
|
default -> DamageCheckResult.positive(attackerId, victimId);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class PlayerDamageListener implements Listener {
|
|||||||
|
|
||||||
private final PreventStabby plugin;
|
private final PreventStabby plugin;
|
||||||
|
|
||||||
PlayerDamageListener(PreventStabby plugin) {
|
public PlayerDamageListener(PreventStabby plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user