fixed missing countdown for JoinProtection
This commit is contained in:
parent
859733e3dd
commit
ef7232e687
@ -3,6 +3,7 @@ package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection;
|
|||||||
import eu.mhsl.craftattack.core.Main;
|
import eu.mhsl.craftattack.core.Main;
|
||||||
import eu.mhsl.craftattack.core.appliance.Appliance;
|
import eu.mhsl.craftattack.core.appliance.Appliance;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.util.Ticks;
|
import net.kyori.adventure.util.Ticks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -20,6 +21,7 @@ public class JoinProtection extends Appliance {
|
|||||||
|
|
||||||
static final class Options {
|
static final class Options {
|
||||||
public boolean wasOnGround = false;
|
public boolean wasOnGround = false;
|
||||||
|
public Long joinTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
private final Map<UUID, Options> protectedPlayers = new HashMap<>();
|
private final Map<UUID, Options> protectedPlayers = new HashMap<>();
|
||||||
|
|
||||||
@ -36,15 +38,21 @@ public class JoinProtection extends Appliance {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable Options getOptions(Player player) {
|
@Nullable JoinProtection.Options getOptions(Player player) {
|
||||||
return this.protectedPlayers.get(player.getUniqueId());
|
return this.protectedPlayers.get(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelEvent(Player player, Cancellable event) {
|
public void cancelEvent(Player player, Cancellable event) {
|
||||||
if(!this.protectedPlayers.containsKey(player.getUniqueId())) return;
|
if(!this.protectedPlayers.containsKey(player.getUniqueId())) return;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
Options option = this.protectedPlayers.get(player.getUniqueId());
|
||||||
|
int secondsLeft = Math.abs((int) ((System.currentTimeMillis() - option.joinTime) / 1000) - resistanceDuration);
|
||||||
player.sendActionBar(
|
player.sendActionBar(
|
||||||
Component.text("Du befindest dich in der %s Sekündigen")
|
Component.text(
|
||||||
|
String.format("Du bist in %d Sekunden angreifbar", secondsLeft),
|
||||||
|
NamedTextColor.RED
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user