Fixes flag saving issue exposed by Flag API on Bentobox.

https://github.com/BentoBoxWorld/AcidIsland/issues/53

AcidIsland was creating a new config object every time which caused
async race conditions when saving. The same config object should be used
continuously.

Also fixed test issue with DelayedCommand.
This commit is contained in:
tastybento 2019-07-18 18:44:10 -07:00
parent dd47f6191b
commit 933ed94dee
2 changed files with 24 additions and 6 deletions

View File

@ -27,6 +27,7 @@ public class AcidIsland extends GameModeAddon {
private AISettings settings;
private AcidTask acidTask;
private @NonNull ChunkGenerator chunkGenerator;
private Config<AISettings> config = new Config<>(this, AISettings.class);
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
@ -45,7 +46,7 @@ public class AcidIsland extends GameModeAddon {
}
private boolean loadSettings() {
settings = new Config<>(this, AISettings.class).loadConfigObject();
settings = config.loadConfigObject();
if (settings == null) {
// Woops
this.logError("AcidIsland settings could not load! Addon disabled.");
@ -65,6 +66,11 @@ public class AcidIsland extends GameModeAddon {
if (settings == null) {
return;
}
// Set default access to boats
Flags.BOAT.setDefaultSetting(islandWorld, true);
if (netherWorld != null) Flags.BOAT.setDefaultSetting(netherWorld, true);
if (endWorld != null) Flags.BOAT.setDefaultSetting(endWorld, true);
// Register listeners
// Acid Effects
registerListener(new AcidEffect(this));
@ -92,6 +98,9 @@ public class AcidIsland extends GameModeAddon {
getPlugin().log(string);
}
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.GameModeAddon#createWorlds()
*/
@Override
public void createWorlds() {
String worldName = settings.getWorldName().toLowerCase();
@ -102,8 +111,6 @@ public class AcidIsland extends GameModeAddon {
chunkGenerator = new ChunkGeneratorWorld(this);
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator)
.createWorld();
// Set default access to boats
Flags.BOAT.setDefaultSetting(islandWorld, true);
// Make the nether if it does not exist
if (settings.isNetherGenerate()) {
if (getServer().getWorld(worldName + NETHER) == null) {
@ -111,7 +118,7 @@ public class AcidIsland extends GameModeAddon {
}
if (!settings.isNetherIslands()) {
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
Flags.BOAT.setDefaultSetting(netherWorld, true);
} else {
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(chunkGenerator)
.environment(World.Environment.NETHER).createWorld();
@ -124,7 +131,6 @@ public class AcidIsland extends GameModeAddon {
}
if (!settings.isEndIslands()) {
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
Flags.BOAT.setDefaultSetting(endWorld, true);
} else {
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(chunkGenerator)
.environment(World.Environment.THE_END).createWorld();
@ -152,7 +158,7 @@ public class AcidIsland extends GameModeAddon {
@Override
public void saveWorldSettings() {
if (settings != null) {
new Config<>(this, AISettings.class).saveConfigObject(settings);
config.saveConfigObject(settings);
}
}

View File

@ -16,6 +16,8 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -29,6 +31,7 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
@ -81,6 +84,9 @@ public class AiCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
// Player has island to begin with
im = mock(IslandsManager.class);
@ -108,7 +114,13 @@ public class AiCommandTest {
when(bun.isRequirePermission()).thenReturn(true);
when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map);
when(plugin.getBlueprintsManager()).thenReturn(bpm);
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
PluginManager pim = mock(PluginManager.class);
when(Bukkit.getPluginManager()).thenReturn(pim);
BukkitScheduler sch = mock(BukkitScheduler.class);
when(Bukkit.getScheduler()).thenReturn(sch);
}