fix: Teleport Invulnerability oversight & incorrect values on Sponge (#671)

This commit is contained in:
Preva1l authored and GitHub committed 2024-08-09 10:25:14 +01:00
1 parent 0eeab972e4
commit afae073ab7
9 files changed
+41 -2

No files matched your search

@@ -98,6 +98,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
private final Set<SavedUser> savedUsers = Sets.newHashSet();
private final Map<String, List<String>> globalPlayerList = Maps.newConcurrentMap();
private final Set<UUID> currentlyOnWarmup = Sets.newConcurrentHashSet();
private final Set<UUID> currentlyInvulnerable = Sets.newConcurrentHashSet();
private Settings settings;
private Locales locales;
@@ -154,4 +154,11 @@ public class BukkitUser extends OnlineUser {
plugin.runSyncDelayed(() -> player.setInvulnerable(false), this, invulnerabilityTimeInTicks);
}
@Override
public void removeInvulnerabilityIfPermitted() {
if (plugin.isInvulnerable(this.getUuid())) {
player.setInvulnerable(false);
}
}
}
@@ -370,6 +370,19 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
return this.getCurrentlyOnWarmup().contains(userUuid);
}
@NotNull
Set<UUID> getCurrentlyInvulnerable();
/**
* Returns if the given user is currently invulnerable and if it should be removed.
*
* @param uuid the user to check.
* @return if the user is currently invulnerable.
*/
default boolean isInvulnerable(@NotNull UUID uuid) {
return this.getCurrentlyInvulnerable().contains(uuid);
}
@NotNull
default UpdateChecker getUpdateChecker() {
return UpdateChecker.builder()
@@ -101,6 +101,7 @@ public class EventListener {
* @param onlineUser the leaving {@link OnlineUser}
*/
protected final void handlePlayerLeave(@NotNull OnlineUser onlineUser) {
onlineUser.removeInvulnerabilityIfPermitted();
plugin.runAsync(() -> {
// Set offline position
plugin.getDatabase().setOfflinePosition(onlineUser, onlineUser.getPosition());
@@ -220,6 +220,8 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
*/
public abstract void handleInvulnerability();
public abstract void removeInvulnerabilityIfPermitted();
/**
* Get the maximum number of homes this user may set.
*
@@ -106,6 +106,7 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
private final Set<SavedUser> savedUsers = Sets.newHashSet();
private final ConcurrentMap<String, List<String>> globalPlayerList = Maps.newConcurrentMap();
private final Set<UUID> currentlyOnWarmup = Sets.newHashSet();
private final Set<UUID> currentlyInvulnerable = Sets.newHashSet();
private MinecraftServer minecraftServer;
private Settings settings;
@@ -177,6 +177,13 @@ public class FabricUser extends OnlineUser {
plugin.runSyncDelayed(() -> player.setInvulnerable(false), this, invulnerabilityTimeInTicks);
}
@Override
public void removeInvulnerabilityIfPermitted() {
if (plugin.isInvulnerable(this.getUuid())) {
player.setInvulnerable(false);
}
}
@NotNull
public ServerPlayerEntity getPlayer() {
return player;
@@ -103,6 +103,7 @@ public class SpongeHuskHomes implements HuskHomes, SpongeTask.Supplier, SpongeSa
private final Set<SavedUser> savedUsers = Sets.newHashSet();
private final Map<String, List<String>> globalPlayerList = Maps.newConcurrentMap();
private final Set<UUID> currentlyOnWarmup = Sets.newHashSet();
private final Set<UUID> currentlyInvulnerable = Sets.newHashSet();
@Inject
@ConfigDir(sharedRoot = false)
@@ -147,9 +147,15 @@ public class SpongeUser extends OnlineUser {
return;
}
long invulnerabilityTimeInTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
player.invulnerable().set(false);
player.invulnerable().set(true);
// Remove the invulnerability
plugin.runSyncDelayed(() -> player.invulnerable().set(true), this, invulnerabilityTimeInTicks);
plugin.runSyncDelayed(() -> player.invulnerable().set(false), this, invulnerabilityTimeInTicks);
}
@Override
public void removeInvulnerabilityIfPermitted() {
if (plugin.isInvulnerable(this.getUuid())) {
player.invulnerable().set(false);
}
}
}