Skip to content

Commit

Permalink
Fixed new islands not detected as active, causing redstone to not fun…
Browse files Browse the repository at this point in the history
…ction (#1579)
  • Loading branch information
OmerBenGera committed Feb 10, 2023
1 parent d041245 commit 40488c4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 8 deletions.
Expand Up @@ -684,6 +684,16 @@ public void setCurrentlyActive() {
this.handle.setCurrentlyActive();
}

@Override
public void setCurrentlyActive(boolean active) {
this.handle.setCurrentlyActive(active);
}

@Override
public boolean isCurrentlyActive() {
return this.handle.isCurrentlyActive();
}

@Override
public long getLastTimeUpdate() {
return this.handle.getLastTimeUpdate();
Expand Down
Expand Up @@ -896,8 +896,23 @@ public interface Island extends Comparable<Island>, IMissionsHolder, IPersistent
*/
void setCurrentlyActive();

/**
* Set whether the island is currently active.
* Active islands are islands that have at least one island member online.
*
* @param active Whether the island is active.
*/
void setCurrentlyActive(boolean active);

/**
* Check whether the island is currently active.
* Active islands are islands that have at least one island member online.
*/
boolean isCurrentlyActive();

/**
* Get the last time the island was updated.
* In case the island is active, -1 will be returned.
*/
long getLastTimeUpdate();

Expand Down
Expand Up @@ -305,7 +305,7 @@ public void onEnable() {
}

if (playerIsland != null)
playerIsland.setCurrentlyActive();
playerIsland.setCurrentlyActive(true);

if (island != null)
island.setPlayerInside(superiorPlayer, true);
Expand Down
Expand Up @@ -232,6 +232,7 @@ private void createIslandInternalAsync(IslandBuilderImpl builder, Biome biome, b

island.setBiome(biome);
island.setSchematicGenerate(plugin.getSettings().getWorlds().getDefaultWorld());
island.setCurrentlyActive(true);

if (offset) {
island.setBonusWorth(island.getRawWorth().negate());
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -204,6 +204,7 @@ public class SIsland implements Island {
* Island Time-Trackers
*/
private volatile long lastTimeUpdate;
private volatile boolean currentlyActive = false;
private volatile long lastInterest;
private volatile long lastUpgradeTime = -1L;
private volatile boolean giveInterestFailed = false;
Expand Down Expand Up @@ -1795,18 +1796,27 @@ public boolean isBeingRecalculated() {

@Override
public void updateLastTime() {
if (this.lastTimeUpdate != -1)
setLastTimeUpdate(System.currentTimeMillis() / 1000);
setLastTimeUpdate(System.currentTimeMillis() / 1000);
}

@Override
public void setCurrentlyActive() {
this.lastTimeUpdate = -1L;
setCurrentlyActive(true);
}

@Override
public void setCurrentlyActive(boolean active) {
this.currentlyActive = active;
}

@Override
public boolean isCurrentlyActive() {
return this.currentlyActive;
}

@Override
public long getLastTimeUpdate() {
return lastTimeUpdate;
return this.currentlyActive ? -1 : lastTimeUpdate;
}

public void setLastTimeUpdate(long lastTimeUpdate) {
Expand Down
Expand Up @@ -810,6 +810,16 @@ public void setCurrentlyActive() {
// Do nothing.
}

@Override
public boolean isCurrentlyActive() {
return true;
}

@Override
public void setCurrentlyActive(boolean active) {
// Do nothing.
}

@Override
public long getLastTimeUpdate() {
return -1;
Expand Down
Expand Up @@ -27,7 +27,7 @@ private void onBlockRedstone(BlockRedstoneEvent e) {
if (island == null || island.isSpawn())
return;

if ((plugin.getSettings().isDisableRedstoneOffline() && island.getLastTimeUpdate() != -1) ||
if ((plugin.getSettings().isDisableRedstoneOffline() && !island.isCurrentlyActive()) ||
(plugin.getSettings().getAFKIntegrations().isDisableRedstone() &&
island.getAllPlayersInside().stream().allMatch(SuperiorPlayer::isAFK))) {
e.setNewCurrent(0);
Expand Down
Expand Up @@ -183,7 +183,7 @@ public void notifyPlayerJoin(SuperiorPlayer superiorPlayer) {
if (island != null) {
IslandUtils.sendMessage(island, Message.PLAYER_JOIN_ANNOUNCEMENT, Collections.singletonList(superiorPlayer.getUniqueId()), superiorPlayer.getName());
island.updateLastTime();
island.setCurrentlyActive();
island.setCurrentlyActive(true);
}
}

Expand Down Expand Up @@ -256,8 +256,10 @@ public void notifyPlayerQuit(SuperiorPlayer superiorPlayer) {
boolean anyOnline = island.getIslandMembers(true).stream().anyMatch(islandMember ->
islandMember != superiorPlayer && islandMember.isOnline());

if (!anyOnline)
if (!anyOnline) {
island.setLastTimeUpdate(System.currentTimeMillis() / 1000);
island.setCurrentlyActive(false);
}
}

/* PLAYER MOVES */
Expand Down

0 comments on commit 40488c4

Please sign in to comment.