From 2a6ba247bb981d11e43048a1e76349ebc8e96886 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 24 Dec 2018 20:50:16 -0800 Subject: [PATCH] Implements new GameModeAddon API. See https://github.com/BentoBoxWorld/BentoBox/pull/415 --- pom.xml | 2 +- .../world/bentobox/acidisland/AcidIsland.java | 72 ++++++++++----- .../acidisland/commands/AcidCommand.java | 2 - .../acidisland/commands/AiCommand.java | 3 - .../acidisland/listeners/AcidEffect.java | 6 +- .../acidisland/listeners/LavaCheck.java | 2 +- .../acidisland/world/AcidIslandWorld.java | 90 ------------------- .../bentobox/acidisland/world/AcidTask.java | 6 +- .../acidisland/world/ChunkGeneratorWorld.java | 2 +- 9 files changed, 60 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/world/bentobox/acidisland/world/AcidIslandWorld.java diff --git a/pom.xml b/pom.xml index cf9c9a7..8aa8258 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,7 @@ world.bentobox bentobox - 0.12.0-SNAPSHOT + 1.0-SNAPSHOT provided diff --git a/src/main/java/world/bentobox/acidisland/AcidIsland.java b/src/main/java/world/bentobox/acidisland/AcidIsland.java index 3a565b1..e7a5535 100644 --- a/src/main/java/world/bentobox/acidisland/AcidIsland.java +++ b/src/main/java/world/bentobox/acidisland/AcidIsland.java @@ -1,37 +1,41 @@ package world.bentobox.acidisland; import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.WorldType; import org.bukkit.plugin.PluginManager; import world.bentobox.acidisland.commands.AcidCommand; import world.bentobox.acidisland.commands.AiCommand; import world.bentobox.acidisland.listeners.AcidEffect; import world.bentobox.acidisland.listeners.LavaCheck; -import world.bentobox.acidisland.world.AcidIslandWorld; import world.bentobox.acidisland.world.AcidTask; -import world.bentobox.bentobox.api.addons.Addon; +import world.bentobox.acidisland.world.ChunkGeneratorWorld; +import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.configuration.Config; +import world.bentobox.bentobox.api.configuration.WorldSettings; /** * Add-on to BentoBox that enables AcidIsland * @author tastybento * */ -public class AcidIsland extends Addon { +public class AcidIsland extends GameModeAddon { private static AcidIsland addon; private AISettings settings; - private AcidIslandWorld aiw; private AcidTask acidTask; + private static final String NETHER = "_nether"; + private static final String THE_END = "_the_end"; + + @Override public void onLoad() { addon = this; saveDefaultConfig(); // Load settings settings = new Config<>(this, AISettings.class).loadConfigObject(); - // Create worlds - aiw = new AcidIslandWorld(this); } @Override @@ -61,21 +65,6 @@ public class AcidIsland extends Addon { return settings; } - /** - * @return the aiw - */ - public AcidIslandWorld getAiw() { - return aiw; - } - - /** - * Convenience method to obtain the AcidIsland overworld - * @return Island World - */ - public World getIslandWorld() { - return aiw.getOverWorld(); - } - @Override public void log(String string) { getPlugin().log(string); @@ -85,4 +74,45 @@ public class AcidIsland extends Addon { return addon; } + @Override + public void createWorlds() { + String worldName = settings.getWorldName(); + if (getServer().getWorld(worldName) == null) { + getLogger().info("Creating AcidIsland..."); + } + // Create the world if it does not exist + islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(addon)) + .createWorld(); + + // Make the nether if it does not exist + if (settings.isNetherGenerate()) { + if (getServer().getWorld(worldName + NETHER) == null) { + log("Creating AcidIsland's Nether..."); + } + if (!settings.isNetherIslands()) { + netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld(); + } else { + netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon)) + .environment(World.Environment.NETHER).createWorld(); + } + } + // Make the end if it does not exist + if (settings.isEndGenerate()) { + if (getServer().getWorld(worldName + THE_END) == null) { + log("Creating AcidIsland's End World..."); + } + if (!settings.isEndIslands()) { + endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld(); + } else { + endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon)) + .environment(World.Environment.THE_END).createWorld(); + } + } + } + + @Override + public WorldSettings getWorldSettings() { + return settings; + } + } diff --git a/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java b/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java index 3a50db0..3cea3e1 100644 --- a/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java +++ b/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java @@ -2,7 +2,6 @@ package world.bentobox.acidisland.commands; import java.util.List; -import world.bentobox.acidisland.AcidIsland; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.admin.AdminClearresetsCommand; @@ -36,7 +35,6 @@ public class AcidCommand extends CompositeCommand { setOnlyPlayer(false); setParametersHelp("commands.admin.help.parameters"); setDescription("commands.admin.help.description"); - setWorld(((AcidIsland)getAddon()).getIslandWorld()); new AdminVersionCommand(this); new AdminTeleportCommand(this, "tp"); new AdminTeleportCommand(this, "tpnether"); diff --git a/src/main/java/world/bentobox/acidisland/commands/AiCommand.java b/src/main/java/world/bentobox/acidisland/commands/AiCommand.java index de925f3..105751e 100644 --- a/src/main/java/world/bentobox/acidisland/commands/AiCommand.java +++ b/src/main/java/world/bentobox/acidisland/commands/AiCommand.java @@ -3,7 +3,6 @@ package world.bentobox.acidisland.commands; import java.util.ArrayList; import java.util.List; -import world.bentobox.acidisland.AcidIsland; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.island.IslandBanCommand; @@ -39,8 +38,6 @@ public class AiCommand extends CompositeCommand { setOnlyPlayer(true); // Permission setPermission("island"); - // Set up world - setWorld(((AcidIsland)getAddon()).getIslandWorld()); // Set up subcommands new IslandAboutCommand(this); new IslandCreateCommand(this); diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index 6f5f3f4..2294a0a 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -67,7 +67,7 @@ public class AcidEffect implements Listener { public void onSeaBounce(PlayerMoveEvent e) { Player player = e.getPlayer(); if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR) - && player.getWorld().equals(addon.getIslandWorld()) && player.getLocation().getBlockY() < 1) { + && player.getWorld().equals(addon.getOverWorld()) && player.getLocation().getBlockY() < 1) { player.setVelocity(new Vector(player.getVelocity().getX(), 1D, player.getVelocity().getZ())); } } @@ -81,7 +81,7 @@ public class AcidEffect implements Listener { || player.getGameMode().equals(GameMode.CREATIVE) || player.getGameMode().equals(GameMode.SPECTATOR) || addon.getPlayers().isInTeleport(player.getUniqueId()) - || !Util.sameWorld(addon.getIslandWorld(), player.getWorld()) + || !Util.sameWorld(addon.getOverWorld(), player.getWorld()) || (!player.isOp() && player.hasPermission("acidisland.mod.noburn")) || (!player.isOp() && player.hasPermission("admin.noburn")) || (player.isOp() && !addon.getSettings().isAcidDamageOp())) { @@ -349,7 +349,7 @@ public class AcidEffect implements Listener { */ @EventHandler(priority = EventPriority.NORMAL) public void onWeatherChange(final WeatherChangeEvent e) { - if (e.getWorld().equals(addon.getIslandWorld())) { + if (e.getWorld().equals(addon.getOverWorld())) { this.isRaining = e.toWeatherState(); } } diff --git a/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java b/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java index d294778..a0669a0 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java +++ b/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java @@ -27,7 +27,7 @@ public class LavaCheck implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onCleanstoneGen(BlockFromToEvent e) { // Only do this in AcidIsland over world - if (!e.getBlock().getWorld().equals(addon.getIslandWorld()) || addon.getSettings().getAcidDamage() <= 0 + if (!e.getBlock().getWorld().equals(addon.getOverWorld()) || addon.getSettings().getAcidDamage() <= 0 // TODO: backward compatibility hack || !(e.getToBlock().getType().name().equals("WATER"))) { return; diff --git a/src/main/java/world/bentobox/acidisland/world/AcidIslandWorld.java b/src/main/java/world/bentobox/acidisland/world/AcidIslandWorld.java deleted file mode 100644 index 6f3b801..0000000 --- a/src/main/java/world/bentobox/acidisland/world/AcidIslandWorld.java +++ /dev/null @@ -1,90 +0,0 @@ -package world.bentobox.acidisland.world; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; - -import world.bentobox.acidisland.AcidIsland; -import world.bentobox.bentobox.util.Util; - -/** - * Creates the AI worlds and registers them with BSkyBlock - * @author tastybento - * - */ -public class AcidIslandWorld { - - private static final String NETHER = "_nether"; - private static final String THE_END = "_the_end"; - private World islandWorld; - private World netherWorld; - private World endWorld; - - /** - * Create a register worlds with BSkyBlock - * @param addon - addon - */ - public AcidIslandWorld(AcidIsland addon) { - String worldName = addon.getSettings().getWorldName(); - if (addon.getServer().getWorld(worldName) == null) { - addon.getLogger().info("Creating AcidIsland..."); - } - // Create the world if it does not exist - islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(addon)) - .createWorld(); - addon.getPlugin().registerWorld(islandWorld, addon.getSettings()); - - // Make the nether if it does not exist - if (addon.getSettings().isNetherGenerate()) { - if (addon.getServer().getWorld(worldName + NETHER) == null) { - addon.log("Creating AcidIsland's Nether..."); - } - if (!addon.getSettings().isNetherIslands()) { - netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld(); - } else { - netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon)) - .environment(World.Environment.NETHER).createWorld(); - } - } - // Make the end if it does not exist - if (addon.getSettings().isEndGenerate()) { - if (addon.getServer().getWorld(worldName + THE_END) == null) { - addon.log("Creating AcidIsland's End World..."); - } - if (!addon.getSettings().isEndIslands()) { - endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld(); - } else { - endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(addon)) - .environment(World.Environment.THE_END).createWorld(); - } - } - - // Load schematics - addon.getPlugin().getSchemsManager().loadIslands(islandWorld); - - } - - - /** - * Checks if a player is in any of the island worlds - * @param loc - player to check - * @return true if in a world or false if not - */ - public boolean inWorld(Location loc) { - return Util.sameWorld(loc.getWorld(), islandWorld); - } - - public World getOverWorld() { - return islandWorld; - } - - public World getNetherWorld() { - return netherWorld; - } - - public World getEndWorld() { - return endWorld; - } - -} diff --git a/src/main/java/world/bentobox/acidisland/world/AcidTask.java b/src/main/java/world/bentobox/acidisland/world/AcidTask.java index 7450204..96faf89 100644 --- a/src/main/java/world/bentobox/acidisland/world/AcidTask.java +++ b/src/main/java/world/bentobox/acidisland/world/AcidTask.java @@ -55,13 +55,13 @@ public class AcidTask { } private Stream getEntityStream() { - Stream entityStream = addon.getIslandWorld().getEntities().stream(); + Stream entityStream = addon.getOverWorld().getEntities().stream(); // Nether and end if (addon.getSettings().isNetherGenerate() && addon.getSettings().isNetherIslands()) { - entityStream = Stream.concat(entityStream, addon.getAiw().getNetherWorld().getEntities().stream()); + entityStream = Stream.concat(entityStream, addon.getNetherWorld().getEntities().stream()); } if (addon.getSettings().isEndGenerate() && addon.getSettings().isEndIslands()) { - entityStream = Stream.concat(entityStream, addon.getAiw().getEndWorld().getEntities().stream()); + entityStream = Stream.concat(entityStream, addon.getEndWorld().getEntities().stream()); } return entityStream; } diff --git a/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java b/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java index 3f50eef..feaae8a 100644 --- a/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java +++ b/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java @@ -18,7 +18,7 @@ import world.bentobox.acidisland.AcidIsland; * @author tastybento * */ -class ChunkGeneratorWorld extends ChunkGenerator { +public class ChunkGeneratorWorld extends ChunkGenerator { private final AcidIsland addon; private final Random rand = new Random();