mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-26 20:55:50 +01:00
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:
parent
dd47f6191b
commit
933ed94dee
@ -27,6 +27,7 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
private AISettings settings;
|
private AISettings settings;
|
||||||
private AcidTask acidTask;
|
private AcidTask acidTask;
|
||||||
private @NonNull ChunkGenerator chunkGenerator;
|
private @NonNull ChunkGenerator chunkGenerator;
|
||||||
|
private Config<AISettings> config = new Config<>(this, AISettings.class);
|
||||||
|
|
||||||
private static final String NETHER = "_nether";
|
private static final String NETHER = "_nether";
|
||||||
private static final String THE_END = "_the_end";
|
private static final String THE_END = "_the_end";
|
||||||
@ -45,7 +46,7 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadSettings() {
|
private boolean loadSettings() {
|
||||||
settings = new Config<>(this, AISettings.class).loadConfigObject();
|
settings = config.loadConfigObject();
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
// Woops
|
// Woops
|
||||||
this.logError("AcidIsland settings could not load! Addon disabled.");
|
this.logError("AcidIsland settings could not load! Addon disabled.");
|
||||||
@ -65,6 +66,11 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
return;
|
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
|
// Register listeners
|
||||||
// Acid Effects
|
// Acid Effects
|
||||||
registerListener(new AcidEffect(this));
|
registerListener(new AcidEffect(this));
|
||||||
@ -92,6 +98,9 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
getPlugin().log(string);
|
getPlugin().log(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.api.addons.GameModeAddon#createWorlds()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void createWorlds() {
|
public void createWorlds() {
|
||||||
String worldName = settings.getWorldName().toLowerCase();
|
String worldName = settings.getWorldName().toLowerCase();
|
||||||
@ -102,8 +111,6 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
chunkGenerator = new ChunkGeneratorWorld(this);
|
chunkGenerator = new ChunkGeneratorWorld(this);
|
||||||
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator)
|
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator)
|
||||||
.createWorld();
|
.createWorld();
|
||||||
// Set default access to boats
|
|
||||||
Flags.BOAT.setDefaultSetting(islandWorld, true);
|
|
||||||
// Make the nether if it does not exist
|
// Make the nether if it does not exist
|
||||||
if (settings.isNetherGenerate()) {
|
if (settings.isNetherGenerate()) {
|
||||||
if (getServer().getWorld(worldName + NETHER) == null) {
|
if (getServer().getWorld(worldName + NETHER) == null) {
|
||||||
@ -111,7 +118,7 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
}
|
}
|
||||||
if (!settings.isNetherIslands()) {
|
if (!settings.isNetherIslands()) {
|
||||||
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
|
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
|
||||||
Flags.BOAT.setDefaultSetting(netherWorld, true);
|
|
||||||
} else {
|
} else {
|
||||||
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(chunkGenerator)
|
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(chunkGenerator)
|
||||||
.environment(World.Environment.NETHER).createWorld();
|
.environment(World.Environment.NETHER).createWorld();
|
||||||
@ -124,7 +131,6 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
}
|
}
|
||||||
if (!settings.isEndIslands()) {
|
if (!settings.isEndIslands()) {
|
||||||
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
|
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
|
||||||
Flags.BOAT.setDefaultSetting(endWorld, true);
|
|
||||||
} else {
|
} else {
|
||||||
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(chunkGenerator)
|
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(chunkGenerator)
|
||||||
.environment(World.Environment.THE_END).createWorld();
|
.environment(World.Environment.THE_END).createWorld();
|
||||||
@ -152,7 +158,7 @@ public class AcidIsland extends GameModeAddon {
|
|||||||
@Override
|
@Override
|
||||||
public void saveWorldSettings() {
|
public void saveWorldSettings() {
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
new Config<>(this, AISettings.class).saveConfigObject(settings);
|
config.saveConfigObject(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -29,6 +31,7 @@ import org.powermock.reflect.Whitebox;
|
|||||||
import world.bentobox.acidisland.AISettings;
|
import world.bentobox.acidisland.AISettings;
|
||||||
import world.bentobox.acidisland.AcidIsland;
|
import world.bentobox.acidisland.AcidIsland;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||||
@ -81,6 +84,9 @@ public class AiCommandTest {
|
|||||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings s = mock(Settings.class);
|
||||||
|
when(plugin.getSettings()).thenReturn(s);
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
im = mock(IslandsManager.class);
|
||||||
@ -108,7 +114,13 @@ public class AiCommandTest {
|
|||||||
when(bun.isRequirePermission()).thenReturn(true);
|
when(bun.isRequirePermission()).thenReturn(true);
|
||||||
when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map);
|
when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map);
|
||||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||||
|
|
||||||
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||||
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user