Skip to content

Commit

Permalink
Fixed errors due to the new unlockedWorlds and generatedSchematics
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 4, 2022
1 parent 264e9b4 commit 23116ac
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -105,14 +105,6 @@
@SuppressWarnings("unused")
public final class SIsland implements Island {

private static final int NORMAL_GENERATED_SCHEMATIC_BIT_INDEX = 3;
private static final int NETHER_GENERATED_SCHEMATIC_BIT_INDEX = 2;
private static final int THE_END_GENERATED_SCHEMATIC_BIT_INDEX = 1;

private static final int NORMAL_UNLOCKED_WORLDS_BIT_INDEX = 3;
private static final int NETHER_UNLOCKED_WORLDS_BIT_INDEX = 0;
private static final int THE_END_UNLOCKED_WORLDS_BIT_INDEX = 1;

private static final UUID CONSOLE_UUID = new UUID(0, 0);
private static final BigInteger MAX_INT = BigInteger.valueOf(Integer.MAX_VALUE);
private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();
Expand Down Expand Up @@ -205,8 +197,8 @@ public final class SIsland implements Island {
private volatile String islandRawName;
private volatile String description = "";
private volatile Biome biome = null;
private final BitSet generatedSchematics = new BitSet(3);
private final BitSet unlockedWorlds = new BitSet(3);
private final AtomicInteger generatedSchematics = new AtomicInteger(0);
private final AtomicInteger unlockedWorlds = new AtomicInteger(0);

public SIsland(GridHandler grid, DatabaseResult resultSet) {
this.uuid = UUID.fromString(resultSet.getString("uuid"));
Expand Down Expand Up @@ -963,13 +955,12 @@ public boolean isInsideRange(Chunk chunk) {

@Override
public boolean isNormalEnabled() {
return plugin.getProviders().getWorldsProvider().isNormalUnlocked() ||
unlockedWorlds.get(NORMAL_UNLOCKED_WORLDS_BIT_INDEX);
return plugin.getProviders().getWorldsProvider().isNormalUnlocked() || (unlockedWorlds.get() & 4) == 4;
}

@Override
public void setNormalEnabled(boolean enabled) {
this.unlockedWorlds.set(NORMAL_UNLOCKED_WORLDS_BIT_INDEX, enabled);
this.unlockedWorlds.updateAndGet(unlockedWorlds -> enabled ? unlockedWorlds | 4 : unlockedWorlds & 3);

if (enabled) {
PluginDebugger.debug("Action: Enable Normal, Island: " + owner.getName());
Expand All @@ -982,13 +973,12 @@ public void setNormalEnabled(boolean enabled) {

@Override
public boolean isNetherEnabled() {
return plugin.getProviders().getWorldsProvider().isNetherUnlocked() ||
unlockedWorlds.get(NETHER_UNLOCKED_WORLDS_BIT_INDEX);
return plugin.getProviders().getWorldsProvider().isNetherUnlocked() || (unlockedWorlds.get() & 1) == 1;
}

@Override
public void setNetherEnabled(boolean enabled) {
this.unlockedWorlds.set(NETHER_UNLOCKED_WORLDS_BIT_INDEX, enabled);
this.unlockedWorlds.updateAndGet(unlockedWorlds -> enabled ? unlockedWorlds | 1 : unlockedWorlds & 6);

if (enabled) {
PluginDebugger.debug("Action: Enable Nether, Island: " + owner.getName());
Expand All @@ -1001,13 +991,12 @@ public void setNetherEnabled(boolean enabled) {

@Override
public boolean isEndEnabled() {
return plugin.getProviders().getWorldsProvider().isEndUnlocked() ||
unlockedWorlds.get(THE_END_UNLOCKED_WORLDS_BIT_INDEX);
return plugin.getProviders().getWorldsProvider().isEndUnlocked() || (unlockedWorlds.get() & 2) == 2;
}

@Override
public void setEndEnabled(boolean enabled) {
this.unlockedWorlds.set(THE_END_UNLOCKED_WORLDS_BIT_INDEX, enabled);
this.unlockedWorlds.updateAndGet(unlockedWorlds -> enabled ? unlockedWorlds | 2 : unlockedWorlds & 5);

if (enabled) {
PluginDebugger.debug("Action: Enable End, Island: " + owner.getName());
Expand All @@ -1020,7 +1009,7 @@ public void setEndEnabled(boolean enabled) {

@Override
public int getUnlockedWorldsFlag() {
return (int) this.unlockedWorlds.toLongArray()[0];
return this.unlockedWorlds.get();
}

/*
Expand Down Expand Up @@ -2919,11 +2908,11 @@ public boolean wasSchematicGenerated(World.Environment environment) {

switch (environment) {
case NORMAL:
return this.generatedSchematics.get(NORMAL_GENERATED_SCHEMATIC_BIT_INDEX);
return (generatedSchematics.get() & 8) == 8;
case NETHER:
return this.generatedSchematics.get(NETHER_GENERATED_SCHEMATIC_BIT_INDEX);
return (generatedSchematics.get() & 4) == 4;
case THE_END:
return this.generatedSchematics.get(THE_END_GENERATED_SCHEMATIC_BIT_INDEX);
return (generatedSchematics.get() & 3) == 3;
}

return false;
Expand All @@ -2942,13 +2931,13 @@ public void setSchematicGenerate(World.Environment environment, boolean generate

switch (environment) {
case NORMAL:
this.generatedSchematics.set(NORMAL_GENERATED_SCHEMATIC_BIT_INDEX);
this.generatedSchematics.updateAndGet(generatedSchematics -> generatedSchematics);
break;
case NETHER:
this.generatedSchematics.set(NETHER_GENERATED_SCHEMATIC_BIT_INDEX);
this.generatedSchematics.updateAndGet(generatedSchematics -> generatedSchematics);
break;
case THE_END:
this.generatedSchematics.set(THE_END_GENERATED_SCHEMATIC_BIT_INDEX);
this.generatedSchematics.updateAndGet(generatedSchematics -> generatedSchematics);
break;
}

Expand All @@ -2957,7 +2946,7 @@ public void setSchematicGenerate(World.Environment environment, boolean generate

@Override
public int getGeneratedSchematicsFlag() {
return (int) this.generatedSchematics.toLongArray()[0];
return this.generatedSchematics.get();
}

/*
Expand Down

0 comments on commit 23116ac

Please sign in to comment.