mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
refactor: store invulnerability as tag, fix #687
This commit is contained in:
6 files changed
+32
-34
No files matched your search
@@ -100,7 +100,6 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
|
||||
|
||||
private final Set<SavedUser> savedUsers = Sets.newHashSet();
|
||||
private final Set<UUID> currentlyOnWarmup = Sets.newConcurrentHashSet();
|
||||
private final Set<UUID> currentlyInvulnerable = Sets.newConcurrentHashSet();
|
||||
private final Map<UUID, OnlineUser> onlineUserMap = Maps.newHashMap();
|
||||
private final Map<String, List<User>> globalUserList = Maps.newConcurrentMap();
|
||||
private final List<Command> commands = Lists.newArrayList();
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class FabricUser extends OnlineUser {
|
||||
|
||||
private final String INVULNERABLE_TAG = plugin.getKey("invulnerable").asString();
|
||||
private final ServerPlayerEntity player;
|
||||
|
||||
private FabricUser(@NotNull ServerPlayerEntity player, @NotNull FabricHuskHomes plugin) {
|
||||
@@ -164,26 +165,28 @@ public class FabricUser extends OnlineUser {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles player invulnerability after teleporting.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasInvulnerability() {
|
||||
return player.getCommandTags().contains(INVULNERABLE_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInvulnerability() {
|
||||
if (plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime() <= 0) {
|
||||
final long invulnerableTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
|
||||
if (invulnerableTicks <= 0) {
|
||||
return;
|
||||
}
|
||||
long invulnerabilityTimeInTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
|
||||
player.setInvulnerable(true);
|
||||
|
||||
// Remove the invulnerability
|
||||
plugin.runSyncDelayed(() -> player.setInvulnerable(false), this, invulnerabilityTimeInTicks);
|
||||
player.getCommandTags().add(INVULNERABLE_TAG);
|
||||
plugin.runSyncDelayed(this::removeInvulnerabilityIfPermitted, this, invulnerableTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeInvulnerabilityIfPermitted() {
|
||||
if (plugin.isInvulnerable(this.getUuid())) {
|
||||
if (this.hasInvulnerability()) {
|
||||
player.setInvulnerable(false);
|
||||
}
|
||||
player.removeCommandTag(INVULNERABLE_TAG);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in new issue
Block a user