Implements new GameModeAddon API.

See https://github.com/BentoBoxWorld/BentoBox/pull/415
This commit is contained in:
tastybento 2018-12-24 20:50:16 -08:00
parent 1cc0552450
commit 2a6ba247bb
9 changed files with 60 additions and 125 deletions

View File

@ -91,7 +91,7 @@
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>0.12.0-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -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;
}
}

View File

@ -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");

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -55,13 +55,13 @@ public class AcidTask {
}
private Stream<Entity> getEntityStream() {
Stream<Entity> entityStream = addon.getIslandWorld().getEntities().stream();
Stream<Entity> 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;
}

View File

@ -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();