Merge pull request #480 from BentoBoxWorld/allworlds

Adds all worlds to map in IWM
This commit is contained in:
Florian CUNY 2019-01-19 22:11:39 +01:00 committed by GitHub
commit b7bc63249e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 90 deletions

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.hooks;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.hooks.Hook; import world.bentobox.bentobox.api.hooks.Hook;
@ -20,8 +21,10 @@ public class MultiverseCoreHook extends Hook {
} }
public void registerWorld(World world) { public void registerWorld(World world) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), MULTIVERSE_IMPORT + world.getName() + " normal -g " + BentoBox.getInstance().getName()); String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase() + " -g " + BentoBox.getInstance().getName();
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName()); String cmd2 = MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName();
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2);
} }
@Override @Override

View File

@ -24,7 +24,6 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.hooks.MultiverseCoreHook; import world.bentobox.bentobox.hooks.MultiverseCoreHook;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
/** /**
* Handles registration and management of worlds * Handles registration and management of worlds
@ -33,9 +32,6 @@ import world.bentobox.bentobox.util.Util;
*/ */
public class IslandWorldManager { public class IslandWorldManager {
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
private BentoBox plugin; private BentoBox plugin;
private Map<@NonNull World, @NonNull GameModeAddon> gameModes; private Map<@NonNull World, @NonNull GameModeAddon> gameModes;
@ -48,7 +44,15 @@ public class IslandWorldManager {
} }
public void registerWorldsToMultiverse() { public void registerWorldsToMultiverse() {
gameModes.forEach((world, s) -> registerToMultiverse(world)); gameModes.values().stream().distinct().forEach(gm -> {
registerToMultiverse(gm.getOverWorld());
if (gm.getWorldSettings().isNetherGenerate() && gm.getWorldSettings().isNetherIslands()) {
registerToMultiverse(gm.getNetherWorld());
}
if (gm.getWorldSettings().isEndGenerate() && gm.getWorldSettings().isEndIslands()) {
registerToMultiverse(gm.getEndWorld());
}
});
} }
/** /**
@ -58,7 +62,13 @@ public class IslandWorldManager {
*/ */
private void registerToMultiverse(World world) { private void registerToMultiverse(World world) {
if (!isUseOwnGenerator(world) && plugin.getHooks() != null) { if (!isUseOwnGenerator(world) && plugin.getHooks() != null) {
plugin.getHooks().getHook("Multiverse-Core").ifPresent(hook -> ((MultiverseCoreHook) hook).registerWorld(world)); plugin.getHooks().getHook("Multiverse-Core").ifPresent(hook -> {
if (Bukkit.isPrimaryThread()) {
((MultiverseCoreHook) hook).registerWorld(world);
} else {
Bukkit.getScheduler().runTask(plugin, () -> ((MultiverseCoreHook) hook).registerWorld(world));
}
});
} }
} }
@ -109,6 +119,7 @@ public class IslandWorldManager {
*/ */
public Map<String, String> getOverWorldNames() { public Map<String, String> getOverWorldNames() {
return gameModes.values().stream() return gameModes.values().stream()
.distinct()
.collect(Collectors.toMap(a -> a.getOverWorld().getName(), a -> a.getWorldSettings().getFriendlyName())); .collect(Collectors.toMap(a -> a.getOverWorld().getName(), a -> a.getWorldSettings().getFriendlyName()));
} }
@ -119,18 +130,35 @@ public class IslandWorldManager {
* @return true if name is a known world name * @return true if name is a known world name
*/ */
public boolean isKnownFriendlyWorldName(String name) { public boolean isKnownFriendlyWorldName(String name) {
return gameModes.entrySet().stream().filter(e -> e.getKey().getEnvironment().equals(Environment.NORMAL)) return gameModes.values().stream().distinct()
.anyMatch(w -> w.getValue().getWorldSettings().getFriendlyName().equalsIgnoreCase(name)); .anyMatch(gm -> gm.getWorldSettings().getFriendlyName().equalsIgnoreCase(name));
} }
/**
* Adds a GameMode to island world manager
* @param gameMode
*/
public void addGameMode(GameModeAddon gameMode) { public void addGameMode(GameModeAddon gameMode) {
WorldSettings settings = gameMode.getWorldSettings(); WorldSettings settings = gameMode.getWorldSettings();
World world = gameMode.getOverWorld(); World world = gameMode.getOverWorld();
String friendlyName = settings.getFriendlyName().isEmpty() ? world.getName() : settings.getFriendlyName(); String friendlyName = settings.getFriendlyName().isEmpty() ? world.getName() : settings.getFriendlyName();
// Add worlds to map
gameModes.put(world, gameMode); gameModes.put(world, gameMode);
// Call Multiverse // Call Multiverse
registerToMultiverse(world); registerToMultiverse(world);
if (settings.isNetherGenerate()) {
gameModes.put(gameMode.getNetherWorld(), gameMode);
if (settings.isNetherIslands()) {
registerToMultiverse(gameMode.getNetherWorld());
}
}
if (settings.isEndGenerate() && settings.isEndIslands()) {
gameModes.put(gameMode.getEndWorld(), gameMode);
if (settings.isEndGenerate()) {
registerToMultiverse(gameMode.getEndWorld());
}
}
// Set default island settings // Set default island settings
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.PROTECTION)) Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.PROTECTION))
.forEach(f -> settings.getDefaultIslandFlags().putIfAbsent(f, f.getDefaultRank())); .forEach(f -> settings.getDefaultIslandFlags().putIfAbsent(f, f.getDefaultRank()));
@ -165,166 +193,162 @@ public class IslandWorldManager {
* @return world settings, or null if world is unknown * @return world settings, or null if world is unknown
*/ */
public WorldSettings getWorldSettings(World world) { public WorldSettings getWorldSettings(World world) {
if (gameModes.containsKey(Util.getWorld(world))) { if (gameModes.containsKey(world)) {
return gameModes.get(Util.getWorld(world)).getWorldSettings(); return gameModes.get(world).getWorldSettings();
} else { } else {
return null; return null;
} }
} }
/** /**
* Get the world based on friendly name. * Get the overworld based on friendly name.
* *
* @param friendlyName * @param friendlyName
* - friendly name of world * - friendly name of world
* @return world, or null if it does not exist * @return overworld, or null if it does not exist
* @since 1.1
*/ */
@Nullable @Nullable
public World getWorld(@NonNull String friendlyName) { public World getOverWorld(@NonNull String friendlyName) {
return gameModes.entrySet().stream().filter(en -> en.getValue().getWorldSettings().getFriendlyName().equalsIgnoreCase(friendlyName)) return gameModes.values().stream().distinct()
.map(Map.Entry::getKey).findFirst().orElse(null); .filter(gm -> gm.getWorldSettings().getFriendlyName().equalsIgnoreCase(friendlyName))
.map(gm -> gm.getOverWorld()).findFirst().orElse(null);
} }
/** /**
* @return the islandDistance * @return the islandDistance
*/ */
public int getIslandDistance(World world) { public int getIslandDistance(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandDistance(); return gameModes.get(world).getWorldSettings().getIslandDistance();
} }
/** /**
* @return the islandHeight * @return the islandHeight
*/ */
public int getIslandHeight(World world) { public int getIslandHeight(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandHeight(); return gameModes.get(world).getWorldSettings().getIslandHeight();
} }
/** /**
* @return the islandProtectionRange * @return the islandProtectionRange
*/ */
public int getIslandProtectionRange(World world) { public int getIslandProtectionRange(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandProtectionRange(); return gameModes.get(world).getWorldSettings().getIslandProtectionRange();
} }
/** /**
* @return the islandStartX * @return the islandStartX
*/ */
public int getIslandStartX(World world) { public int getIslandStartX(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandStartX(); return gameModes.get(world).getWorldSettings().getIslandStartX();
} }
/** /**
* @return the islandStartZ * @return the islandStartZ
*/ */
public int getIslandStartZ(World world) { public int getIslandStartZ(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandStartZ(); return gameModes.get(world).getWorldSettings().getIslandStartZ();
} }
/** /**
* @return the islandXOffset * @return the islandXOffset
*/ */
public int getIslandXOffset(World world) { public int getIslandXOffset(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandXOffset(); return gameModes.get(world).getWorldSettings().getIslandXOffset();
} }
/** /**
* @return the islandZOffset * @return the islandZOffset
*/ */
public int getIslandZOffset(World world) { public int getIslandZOffset(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIslandZOffset(); return gameModes.get(world).getWorldSettings().getIslandZOffset();
} }
/** /**
* @return the maxIslands * @return the maxIslands
*/ */
public int getMaxIslands(World world) { public int getMaxIslands(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getMaxIslands(); return gameModes.get(world).getWorldSettings().getMaxIslands();
} }
/** /**
* @return the netherSpawnRadius * @return the netherSpawnRadius
*/ */
public int getNetherSpawnRadius(World world) { public int getNetherSpawnRadius(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getNetherSpawnRadius(); return gameModes.get(world).getWorldSettings().getNetherSpawnRadius();
} }
/** /**
* @return the seaHeight * @return the seaHeight
*/ */
public int getSeaHeight(World world) { public int getSeaHeight(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getSeaHeight(); return gameModes.get(world).getWorldSettings().getSeaHeight();
} }
/** /**
* @return the worldName * @return the worldName
*/ */
public String getWorldName(World world) { public String getWorldName(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getWorldName(); return gameModes.get(world).getWorldSettings().getWorldName();
} }
/** /**
* @return the endGenerate * @return the endGenerate
*/ */
public boolean isEndGenerate(World world) { public boolean isEndGenerate(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isEndGenerate(); return gameModes.get(world).getWorldSettings().isEndGenerate();
} }
/** /**
* @return the endIslands * @return the endIslands
*/ */
public boolean isEndIslands(World world) { public boolean isEndIslands(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isEndIslands(); return gameModes.get(world).getWorldSettings().isEndIslands();
} }
/** /**
* @return the netherGenerate * @return the netherGenerate
*/ */
public boolean isNetherGenerate(World world) { public boolean isNetherGenerate(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isNetherGenerate(); return gameModes.get(world).getWorldSettings().isNetherGenerate();
} }
/** /**
* @return the netherIslands * @return the netherIslands
*/ */
public boolean isNetherIslands(World world) { public boolean isNetherIslands(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isNetherIslands(); return gameModes.get(world).getWorldSettings().isNetherIslands();
} }
/** /**
* Checks if a world is a known nether world * Checks if a world is a known nether world
* *
* @param world * @param world - world
* - world
* @return true if world is a known and valid nether world * @return true if world is a known and valid nether world
*/ */
public boolean isNether(World world) { public boolean isNether(World world) {
World w = Util.getWorld(world); return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherGenerate();
return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(w) && gameModes.get(w).getWorldSettings().isNetherGenerate();
} }
/** /**
* Checks if a world is a known island nether world * Checks if a world is a known island nether world
* *
* @param world * @param world - world
* - world
* @return true if world is a known and valid nether world * @return true if world is a known and valid nether world
*/ */
public boolean isIslandNether(World world) { public boolean isIslandNether(World world) {
World w = Util.getWorld(world); return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherGenerate()
return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(w) && gameModes.get(w).getWorldSettings().isNetherGenerate() && gameModes.get(world).getWorldSettings().isNetherIslands();
&& gameModes.get(w).getWorldSettings().isNetherIslands();
} }
/** /**
* Checks if a world is a known end world * Checks if a world is a known end world
* *
* @param world * @param world - world
* - world
* @return true if world is a known and valid end world * @return true if world is a known and valid end world
*/ */
public boolean isEnd(World world) { public boolean isEnd(World world) {
World w = Util.getWorld(world); return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndGenerate();
return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(w) && gameModes.get(w).getWorldSettings().isEndGenerate();
} }
/** /**
@ -335,43 +359,44 @@ public class IslandWorldManager {
* @return true if world is a known and valid nether world * @return true if world is a known and valid nether world
*/ */
public boolean isIslandEnd(World world) { public boolean isIslandEnd(World world) {
World w = Util.getWorld(world); return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndGenerate()
return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(w) && gameModes.get(w).getWorldSettings().isEndGenerate() && gameModes.get(world).getWorldSettings().isEndIslands();
&& gameModes.get(w).getWorldSettings().isEndIslands();
} }
/** /**
* Get the nether world of this overWorld * Get the nether world of this overWorld
* *
* @param overWorld * @param overWorld - overworld
* - overworld
* @return nether world, or null if it does not exist * @return nether world, or null if it does not exist
*/ */
public World getNetherWorld(World overWorld) { public World getNetherWorld(World overWorld) {
return Bukkit.getWorld(overWorld.getName() + NETHER); if (gameModes.containsKey(overWorld)) {
return gameModes.get(overWorld).getNetherWorld();
}
return null;
} }
/** /**
* Get the end world of this overWorld * Get the end world of this overWorld
* *
* @param overWorld * @param overWorld - overworld
* - overworld
* @return end world, or null if it does not exist * @return end world, or null if it does not exist
*/ */
public World getEndWorld(World overWorld) { public World getEndWorld(World overWorld) {
return Bukkit.getWorld(overWorld.getName() + THE_END); if (gameModes.containsKey(overWorld)) {
return gameModes.get(overWorld).getEndWorld();
}
return null;
} }
/** /**
* Check if nether trees should be created in the nether or not * Check if nether trees should be created in the nether or not
* *
* @param world * @param world - world
* - world
* @return true or false * @return true or false
*/ */
public boolean isNetherTrees(World world) { public boolean isNetherTrees(World world) {
World w = Util.getWorld(world); return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherTrees();
return gameModes.containsKey(w) && gameModes.get(w).getWorldSettings().isNetherTrees();
} }
/** /**
@ -382,8 +407,7 @@ public class IslandWorldManager {
* @return true (default) if it can spawn or not * @return true (default) if it can spawn or not
*/ */
public boolean isDragonSpawn(World world) { public boolean isDragonSpawn(World world) {
World w = Util.getWorld(world); return !gameModes.containsKey(world) || gameModes.get(world).getWorldSettings().isDragonSpawn();
return !gameModes.containsKey(w) || gameModes.get(w).getWorldSettings().isDragonSpawn();
} }
/** /**
@ -391,7 +415,7 @@ public class IslandWorldManager {
*/ */
public String getFriendlyNames() { public String getFriendlyNames() {
StringBuilder r = new StringBuilder(); StringBuilder r = new StringBuilder();
gameModes.values().forEach(n -> r.append(n).append(", ")); gameModes.values().stream().distinct().forEach(n -> r.append(n).append(", "));
if (r.length() > 0) { if (r.length() > 0) {
r.setLength(r.length() - 2); r.setLength(r.length() - 2);
} }
@ -418,7 +442,7 @@ public class IslandWorldManager {
* @return max team size * @return max team size
*/ */
public int getMaxTeamSize(World world) { public int getMaxTeamSize(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getMaxTeamSize(); return gameModes.get(world).getWorldSettings().getMaxTeamSize();
} }
/** /**
@ -429,7 +453,7 @@ public class IslandWorldManager {
* @return max homes * @return max homes
*/ */
public int getMaxHomes(World world) { public int getMaxHomes(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getMaxHomes(); return gameModes.get(world).getWorldSettings().getMaxHomes();
} }
/** /**
@ -440,7 +464,7 @@ public class IslandWorldManager {
* @return Friendly name * @return Friendly name
*/ */
public String getFriendlyName(World world) { public String getFriendlyName(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getFriendlyName(); return gameModes.get(world).getWorldSettings().getFriendlyName();
} }
/** /**
@ -451,7 +475,7 @@ public class IslandWorldManager {
* @return permission prefix for this world * @return permission prefix for this world
*/ */
public String getPermissionPrefix(World world) { public String getPermissionPrefix(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getPermissionPrefix(); return gameModes.get(world).getWorldSettings().getPermissionPrefix();
} }
@ -463,7 +487,7 @@ public class IslandWorldManager {
* @return invincible visitor settings * @return invincible visitor settings
*/ */
public List<String> getIvSettings(World world) { public List<String> getIvSettings(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getIvSettings(); return gameModes.get(world).getWorldSettings().getIvSettings();
} }
/** /**
@ -488,7 +512,7 @@ public class IslandWorldManager {
* @return GameMode: SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR * @return GameMode: SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR
*/ */
public GameMode getDefaultGameMode(World world) { public GameMode getDefaultGameMode(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDefaultGameMode(); return gameModes.get(world).getWorldSettings().getDefaultGameMode();
} }
/** /**
@ -499,49 +523,49 @@ public class IslandWorldManager {
* @return - set of entity types * @return - set of entity types
*/ */
public Set<EntityType> getRemoveMobsWhitelist(World world) { public Set<EntityType> getRemoveMobsWhitelist(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getRemoveMobsWhitelist(); return gameModes.get(world).getWorldSettings().getRemoveMobsWhitelist();
} }
/** /**
* @return the onJoinResetMoney * @return the onJoinResetMoney
*/ */
public boolean isOnJoinResetMoney(World world) { public boolean isOnJoinResetMoney(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnJoinResetMoney(); return gameModes.get(world).getWorldSettings().isOnJoinResetMoney();
} }
/** /**
* @return the onJoinResetInventory * @return the onJoinResetInventory
*/ */
public boolean isOnJoinResetInventory(World world) { public boolean isOnJoinResetInventory(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnJoinResetInventory(); return gameModes.get(world).getWorldSettings().isOnJoinResetInventory();
} }
/** /**
* @return the onJoinResetEnderChest * @return the onJoinResetEnderChest
*/ */
public boolean isOnJoinResetEnderChest(World world) { public boolean isOnJoinResetEnderChest(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnJoinResetEnderChest(); return gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
} }
/** /**
* @return the onLeaveResetMoney * @return the onLeaveResetMoney
*/ */
public boolean isOnLeaveResetMoney(World world) { public boolean isOnLeaveResetMoney(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnLeaveResetMoney(); return gameModes.get(world).getWorldSettings().isOnLeaveResetMoney();
} }
/** /**
* @return the onLeaveResetInventory * @return the onLeaveResetInventory
*/ */
public boolean isOnLeaveResetInventory(World world) { public boolean isOnLeaveResetInventory(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnLeaveResetInventory(); return gameModes.get(world).getWorldSettings().isOnLeaveResetInventory();
} }
/** /**
* @return the onLeaveResetEnderChest * @return the onLeaveResetEnderChest
*/ */
public boolean isOnLeaveResetEnderChest(World world) { public boolean isOnLeaveResetEnderChest(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isOnLeaveResetEnderChest(); return gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
} }
/** /**
@ -561,7 +585,7 @@ public class IslandWorldManager {
* @return GameModeAddon, or empty * @return GameModeAddon, or empty
*/ */
public Optional<GameModeAddon> getAddon(@Nullable World world) { public Optional<GameModeAddon> getAddon(@Nullable World world) {
return world == null ? Optional.empty() : Optional.ofNullable(gameModes.get(Util.getWorld(world))); return world == null ? Optional.empty() : Optional.ofNullable(gameModes.get(world));
} }
/** /**
@ -572,11 +596,11 @@ public class IslandWorldManager {
* @return default rank settings for new islands. * @return default rank settings for new islands.
*/ */
public Map<Flag, Integer> getDefaultIslandFlags(World world) { public Map<Flag, Integer> getDefaultIslandFlags(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDefaultIslandFlags(); return gameModes.get(world).getWorldSettings().getDefaultIslandFlags();
} }
public List<String> getVisibleSettings(World world) { public List<String> getVisibleSettings(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getVisibleSettings(); return gameModes.get(world).getWorldSettings().getVisibleSettings();
} }
/** /**
@ -587,11 +611,11 @@ public class IslandWorldManager {
* @return default settings for new islands * @return default settings for new islands
*/ */
public Map<Flag, Integer> getDefaultIslandSettings(World world) { public Map<Flag, Integer> getDefaultIslandSettings(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDefaultIslandSettings(); return gameModes.get(world).getWorldSettings().getDefaultIslandSettings();
} }
public boolean isUseOwnGenerator(World world) { public boolean isUseOwnGenerator(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isUseOwnGenerator(); return gameModes.get(world).getWorldSettings().isUseOwnGenerator();
} }
/** /**
@ -599,7 +623,7 @@ public class IslandWorldManager {
* @return the visitorbannedcommands * @return the visitorbannedcommands
*/ */
public List<String> getVisitorBannedCommands(World world) { public List<String> getVisitorBannedCommands(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getVisitorBannedCommands(); return gameModes.get(world).getWorldSettings().getVisitorBannedCommands();
} }
/** /**
@ -608,7 +632,7 @@ public class IslandWorldManager {
* @return true if water is not safe, e.g.for home locations * @return true if water is not safe, e.g.for home locations
*/ */
public boolean isWaterNotSafe(World world) { public boolean isWaterNotSafe(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isWaterUnsafe(); return gameModes.get(world).getWorldSettings().isWaterUnsafe();
} }
/** /**
@ -617,7 +641,7 @@ public class IslandWorldManager {
* @return list * @return list
*/ */
public List<String> getGeoLimitSettings(World world) { public List<String> getGeoLimitSettings(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getGeoLimitSettings(); return gameModes.get(world).getWorldSettings().getGeoLimitSettings();
} }
/** /**
@ -626,7 +650,7 @@ public class IslandWorldManager {
* @return number of resets allowed. -1 = unlimited * @return number of resets allowed. -1 = unlimited
*/ */
public int getResetLimit(World world) { public int getResetLimit(World world) {
return gameModes.containsKey(Util.getWorld(world)) ? gameModes.get(Util.getWorld(world)).getWorldSettings().getResetLimit() : -1; return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getResetLimit() : -1;
} }
@ -635,7 +659,7 @@ public class IslandWorldManager {
* @param world - world * @param world - world
*/ */
public long getResetEpoch(World world) { public long getResetEpoch(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getResetEpoch(); return gameModes.get(world).getWorldSettings().getResetEpoch();
} }
/** /**
@ -643,11 +667,11 @@ public class IslandWorldManager {
* @param world - world * @param world - world
*/ */
public void setResetEpoch(World world) { public void setResetEpoch(World world) {
gameModes.get(Util.getWorld(world)).getWorldSettings().setResetEpoch(System.currentTimeMillis()); gameModes.get(world).getWorldSettings().setResetEpoch(System.currentTimeMillis());
} }
public boolean isTeamJoinDeathReset(World world) { public boolean isTeamJoinDeathReset(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isTeamJoinDeathReset(); return gameModes.get(world).getWorldSettings().isTeamJoinDeathReset();
} }
/** /**
@ -656,10 +680,10 @@ public class IslandWorldManager {
* @return max deaths * @return max deaths
*/ */
public int getDeathsMax(World world) { public int getDeathsMax(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getDeathsMax(); return gameModes.get(world).getWorldSettings().getDeathsMax();
} }
public int getBanLimit(World world) { public int getBanLimit(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getBanLimit(); return gameModes.get(world).getWorldSettings().getBanLimit();
} }
} }

View File

@ -144,8 +144,6 @@ public class NewIsland {
plugin.logError("Failed to make island! Island could not be added to the grid."); plugin.logError("Failed to make island! Island could not be added to the grid.");
return; return;
} }
// Save the player so that if the server crashes weird things won't happen
plugin.getPlayers().save(user.getUniqueId());
// Clear any old home locations (they should be clear, but just in case) // Clear any old home locations (they should be clear, but just in case)
plugin.getPlayers().clearHomeLocations(world, user.getUniqueId()); plugin.getPlayers().clearHomeLocations(world, user.getUniqueId());
@ -153,6 +151,9 @@ public class NewIsland {
// Set home location // Set home location
plugin.getPlayers().setHomeLocation(user, next, 1); plugin.getPlayers().setHomeLocation(user, next, 1);
// Save the player so that if the server crashes weird things won't happen
plugin.getPlayers().save(user.getUniqueId());
// Fire event // Fire event
IslandBaseEvent event = IslandEvent.builder() IslandBaseEvent event = IslandEvent.builder()
.involvedPlayer(user.getUniqueId()) .involvedPlayer(user.getUniqueId())
@ -223,6 +224,8 @@ public class NewIsland {
// Set default settings // Set default settings
island.setFlagsDefaults(); island.setFlagsDefaults();
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount); plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
// Save island
plugin.getIslands().save(island);
} }
/** /**