Skip to content

Commit

Permalink
Fixed changing upgrades using does not update crop growth multipliers (
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Apr 12, 2023
1 parent d2d845a commit 1734de4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
Expand Up @@ -85,8 +85,6 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, Superio
if (!anyIslandChanged)
return;

islands.forEach(Island::updateBorder);

if (islands.size() > 1)
Message.CHANGED_ISLAND_SIZE_ALL.send(sender);
else if (targetPlayer == null)
Expand Down
Expand Up @@ -85,8 +85,6 @@ public void execute(SuperiorSkyblockPlugin plugin, CommandSender sender, Superio
if (!anyIslandChanged)
return;

islands.forEach(Island::updateBorder);

if (islands.size() > 1)
Message.CHANGED_ISLAND_SIZE_ALL.send(sender);
else if (targetPlayer == null)
Expand Down
65 changes: 36 additions & 29 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -1554,6 +1554,12 @@ public void setIslandSize(int islandSize) {
if (islandSize == getIslandSizeRaw())
return;

setIslandSizeInternal(Value.fixed(islandSize));

IslandsDatabaseBridge.saveSize(this);
}

private void setIslandSizeInternal(Value<Integer> islandSize) {
boolean cropGrowthEnabled = BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeCropGrowth.class);

if (cropGrowthEnabled) {
Expand All @@ -1562,15 +1568,15 @@ public void setIslandSize(int islandSize) {
plugin.getNMSChunks().startTickingChunk(this, chunk, true));
}

this.islandSize.set(Value.fixed(islandSize));
this.islandSize.set(islandSize);

if (cropGrowthEnabled) {
// Now, we want to update the tile entities again
getLoadedChunks(true, false).forEach(chunk ->
plugin.getNMSChunks().startTickingChunk(this, chunk, false));
}

IslandsDatabaseBridge.saveSize(this);
updateBorder();
}

@Override
Expand Down Expand Up @@ -2285,9 +2291,6 @@ public void setUpgradeLevel(Upgrade upgrade, int level) {
syncUpgrade((SUpgradeLevel) upgradeLevel, false);
}

if (upgradeLevel.getBorderSize() != -1)
updateBorder();

plugin.getMenus().refreshUpgrades(this);
}

Expand Down Expand Up @@ -2348,12 +2351,7 @@ public void setCropGrowthMultiplier(double cropGrowth) {

IslandsDatabaseBridge.saveCropGrowth(this);

// Update the crop growth ticking
if (BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeCropGrowth.class)) {
double newCropGrowthMultiplier = cropGrowth - 1;
IslandUtils.getChunkCoords(this, true, true).values()
.forEach(chunkPositions -> plugin.getNMSChunks().updateCropsTicker(chunkPositions, newCropGrowthMultiplier));
}
notifyCropGrowthChange(cropGrowth);
}

@Override
Expand Down Expand Up @@ -2666,7 +2664,6 @@ public void setPotionEffect(PotionEffectType type, int level) {

Log.debug(Debug.SET_ISLAND_EFFECT, owner.getName(), type.getName(), level);

PotionEffect potionEffect = new PotionEffect(type, Integer.MAX_VALUE, level - 1);
Value<Integer> oldPotionLevel = islandEffects.put(type, Value.fixed(level));

if (level == Value.getRaw(oldPotionLevel, -1))
Expand All @@ -2677,6 +2674,8 @@ public void setPotionEffect(PotionEffectType type, int level) {
assert player != null;
if (oldPotionLevel != null && oldPotionLevel.get() > level)
player.removePotionEffect(type);

PotionEffect potionEffect = new PotionEffect(type, Integer.MAX_VALUE, level - 1);
player.addPotionEffect(potionEffect, true);
}));

Expand Down Expand Up @@ -3832,9 +3831,6 @@ public void syncUpgrades(boolean overrideCustom) {

// Syncing all real upgrades
plugin.getUpgrades().getUpgrades().forEach(upgrade -> syncUpgrade((SUpgradeLevel) getUpgradeLevel(upgrade), overrideCustom));

if (getIslandSize() != -1)
updateBorder();
}

/*
Expand Down Expand Up @@ -4082,15 +4078,12 @@ private void updateOldUpgradeValues() {
}

private void clearUpgrades(boolean overrideCustom) {
islandSize.set(islandSize -> {
if (overrideCustom || islandSize instanceof SyncedValue) {
if (overrideCustom)
IslandsDatabaseBridge.saveSize(this);
return Value.syncedFixed(-1);
}
if (overrideCustom || this.islandSize.get() instanceof SyncedValue) {
if (overrideCustom)
IslandsDatabaseBridge.saveSize(this);

return islandSize;
});
setIslandSizeInternal(Value.syncedFixed(-1));
}

warpsLimit.set(warpsLimit -> {
if (overrideCustom || warpsLimit instanceof SyncedValue) {
Expand Down Expand Up @@ -4123,8 +4116,12 @@ private void clearUpgrades(boolean overrideCustom) {
if (overrideCustom || cropGrowth instanceof SyncedValue) {
if (overrideCustom)
IslandsDatabaseBridge.saveCropGrowth(this);

notifyCropGrowthChange(-1D);

return Value.syncedFixed(-1D);
}

return cropGrowth;
});

Expand Down Expand Up @@ -4182,8 +4179,11 @@ private void clearUpgrades(boolean overrideCustom) {

private void syncUpgrade(SUpgradeLevel upgradeLevel, boolean overrideCustom) {
cropGrowth.set(cropGrowth -> {
if ((overrideCustom || cropGrowth instanceof SyncedValue) && cropGrowth.get() < upgradeLevel.getCropGrowth())
if ((overrideCustom || cropGrowth instanceof SyncedValue) && cropGrowth.get() < upgradeLevel.getCropGrowth()) {
notifyCropGrowthChange(upgradeLevel.getCropGrowth());
return upgradeLevel.getCropGrowthUpgradeValue();
}

return cropGrowth;
});

Expand Down Expand Up @@ -4217,11 +4217,9 @@ private void syncUpgrade(SUpgradeLevel upgradeLevel, boolean overrideCustom) {
return coopLimit;
});

islandSize.set(islandSize -> {
if ((overrideCustom || islandSize instanceof SyncedValue) && islandSize.get() < upgradeLevel.getBorderSize())
return upgradeLevel.getBorderSizeUpgradeValue();
return islandSize;
});
Value<Integer> islandSize = this.islandSize.get();
if ((overrideCustom || islandSize instanceof SyncedValue) && islandSize.get() < upgradeLevel.getBorderSize())
setIslandSizeInternal(upgradeLevel.getBorderSizeUpgradeValue());

bankLimit.set(bankLimit -> {
if ((overrideCustom || bankLimit instanceof SyncedValue) && bankLimit.get().compareTo(upgradeLevel.getBankLimit()) < 0)
Expand Down Expand Up @@ -4329,6 +4327,15 @@ private void forEachIslandMember(List<UUID> ignoredMembers, boolean onlyOnline,
}
}

private void notifyCropGrowthChange(double newCropGrowth) {
if (!BuiltinModules.UPGRADES.isUpgradeTypeEnabled(UpgradeTypeCropGrowth.class))
return;

double newCropGrowthMultiplier = newCropGrowth - 1;
IslandUtils.getChunkCoords(this, true, true).values().forEach(chunkPositions ->
plugin.getNMSChunks().updateCropsTicker(chunkPositions, newCropGrowthMultiplier));
}

public static class UniqueVisitor {

private final Pair<SuperiorPlayer, Long> pair;
Expand Down

0 comments on commit 1734de4

Please sign in to comment.