Skip to content

Commit

Permalink
fix: Teleport Invulnerability oversight & incorrect values on Sponge (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ProdPreva1l authored Aug 9, 2024
1 parent 0eeab97 commit afae073
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,11 @@ public void handleInvulnerability() {
plugin.runSyncDelayed(() -> player.setInvulnerable(false), this, invulnerabilityTimeInTicks);
}

@Override
public void removeInvulnerabilityIfPermitted() {
if (plugin.isInvulnerable(this.getUuid())) {
player.setInvulnerable(false);
}
}

}
13 changes: 13 additions & 0 deletions common/src/main/java/net/william278/huskhomes/HuskHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ default boolean isWarmingUp(@NotNull UUID userUuid) {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected final void handlePlayerJoin(@NotNull OnlineUser onlineUser) {
* @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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public Audience getAudience() {
*/
public abstract void handleInvulnerability();

public abstract void removeInvulnerabilityIfPermitted();

/**
* Get the maximum number of homes this user may set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ public void handleInvulnerability() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,15 @@ public void handleInvulnerability() {
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);
}
}
}

0 comments on commit afae073

Please sign in to comment.