Fixed combat placeholders

This commit is contained in:
Jules 2023-03-18 21:56:14 +01:00
parent e1011d449f
commit a3166b1049
2 changed files with 7 additions and 9 deletions

View File

@ -99,14 +99,13 @@ public class RPGPlaceholders extends PlaceholderExpansion {
return String.valueOf(playerData.getCombat().isInPvpMode());
else if (identifier.startsWith("since_enter_combat"))
return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getFirstHit()) / 1000) : "-1";
return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastEntry()) / 1000.) : "-1";
else if (identifier.startsWith("invulnerability_left"))
return MythicLib.plugin.getMMOConfig().decimal.format(Math.max(0, (double) (playerData.getCombat().getInvulnerableTill() - System.currentTimeMillis()) / 1000));
return MythicLib.plugin.getMMOConfig().decimal.format(Math.max(0, (playerData.getCombat().getInvulnerableTill() - System.currentTimeMillis()) / 1000.));
else if (identifier.startsWith("since_last_hit"))
return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastHit()) / 1000) : "-1";
return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastHit()) / 1000.) : "-1";
else if (identifier.startsWith("bound_")) {
int slot = Math.max(0, Integer.parseInt(identifier.substring(6)) - 1);

View File

@ -12,9 +12,7 @@ import org.jetbrains.annotations.Nullable;
public class CombatHandler implements Closable {
private final PlayerData player;
private final long firstHit = System.currentTimeMillis();
private long lastHit = System.currentTimeMillis(), invulnerableTill;
private long lastEntry = System.currentTimeMillis(), lastHit = System.currentTimeMillis(), invulnerableTill;
private boolean pvpMode;
@ -37,6 +35,7 @@ public class CombatHandler implements Closable {
// Entering combat
} else {
lastEntry = System.currentTimeMillis();
MMOCore.plugin.configManager.getSimpleMessage("now-in-combat").send(player.getPlayer());
Bukkit.getPluginManager().callEvent(new PlayerCombatEvent(player, true));
task = newTask();
@ -59,8 +58,8 @@ public class CombatHandler implements Closable {
return lastHit;
}
public long getFirstHit() {
return firstHit;
public long getLastEntry() {
return lastEntry;
}
public long getInvulnerableTill() {