More multi-world work.

This handles multiworld operation. Test with AcidIsland addon.
This commit is contained in:
tastybento 2018-05-25 12:19:46 -07:00
parent 82ee6d746e
commit 6a18cc4ccc
51 changed files with 762 additions and 210 deletions

View File

@ -4,11 +4,13 @@ import org.bukkit.World;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.placeholders.PlaceholderHandler; import us.tastybento.bskyblock.api.placeholders.PlaceholderHandler;
import us.tastybento.bskyblock.api.user.Notifier; import us.tastybento.bskyblock.api.user.Notifier;
import us.tastybento.bskyblock.commands.AdminCommand; import us.tastybento.bskyblock.commands.AdminCommand;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.database.BSBDbSetup; import us.tastybento.bskyblock.database.BSBDbSetup;
import us.tastybento.bskyblock.listeners.BlockEndDragon;
import us.tastybento.bskyblock.listeners.JoinLeaveListener; import us.tastybento.bskyblock.listeners.JoinLeaveListener;
import us.tastybento.bskyblock.listeners.NetherPortals; import us.tastybento.bskyblock.listeners.NetherPortals;
import us.tastybento.bskyblock.listeners.ObsidianToLava; import us.tastybento.bskyblock.listeners.ObsidianToLava;
@ -155,6 +157,8 @@ public class BSkyBlock extends JavaPlugin {
manager.registerEvents(new ObsidianToLava(this), this); manager.registerEvents(new ObsidianToLava(this), this);
// Flying mobs protection // Flying mobs protection
manager.registerEvents(new FlyingMobEvents(this), this); manager.registerEvents(new FlyingMobEvents(this), this);
// End dragon blocking
manager.registerEvents(new BlockEndDragon(this), this);
} }
@Override @Override
@ -269,7 +273,7 @@ public class BSkyBlock extends JavaPlugin {
/** /**
* @return the Island World Manager * @return the Island World Manager
*/ */
public IslandWorldManager getIslandWorldManager() { public IslandWorldManager getIWM() {
return islandWorldManager; return islandWorldManager;
} }
@ -310,10 +314,11 @@ public class BSkyBlock extends JavaPlugin {
/** /**
* Registers a world as a world to be covered by this plugin * Registers a world as a world to be covered by this plugin
* @param world - world * @param world - Bukkit over world
* @param worldSettings - settings for this world
*/ */
public void registerWorld(String name, World world) { public void registerWorld(World world, WorldSettings worldSettings) {
islandWorldManager.addWorld(name, world); islandWorldManager.addWorld(world, worldSettings);
} }
} }

View File

@ -18,6 +18,7 @@ import us.tastybento.bskyblock.api.configuration.ConfigComment;
import us.tastybento.bskyblock.api.configuration.ConfigEntry; import us.tastybento.bskyblock.api.configuration.ConfigEntry;
import us.tastybento.bskyblock.api.configuration.ISettings; import us.tastybento.bskyblock.api.configuration.ISettings;
import us.tastybento.bskyblock.api.configuration.StoreAt; import us.tastybento.bskyblock.api.configuration.StoreAt;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.database.BSBDbSetup.DatabaseType; import us.tastybento.bskyblock.database.BSBDbSetup.DatabaseType;
import us.tastybento.bskyblock.database.objects.adapters.Adapter; import us.tastybento.bskyblock.database.objects.adapters.Adapter;
@ -28,7 +29,7 @@ import us.tastybento.bskyblock.database.objects.adapters.PotionEffectListAdapter
* @author Tastybento * @author Tastybento
*/ */
@StoreAt(filename="config.yml") // Explicitly call out what name this should have. @StoreAt(filename="config.yml") // Explicitly call out what name this should have.
public class Settings implements ISettings<Settings> { public class Settings implements ISettings<Settings>, WorldSettings {
private String uniqueId = "config"; private String uniqueId = "config";
@ -87,8 +88,11 @@ public class Settings implements ISettings<Settings> {
// --------------------------------------------- // ---------------------------------------------
/* WORLD */ /* WORLD */
@ConfigEntry(path = "world.friendly-name", needsReset = true)
private String friendlyName = "BSkyBlock";
@ConfigEntry(path = "world.world-name", needsReset = true) @ConfigEntry(path = "world.world-name", needsReset = true)
private String worldName = "BSkyBlock"; private String worldName = "BSkyBlock-world";
@ConfigEntry(path = "world.distance-between-islands", needsReset = true) @ConfigEntry(path = "world.distance-between-islands", needsReset = true)
private int islandDistance = 200; private int islandDistance = 200;
@ -136,16 +140,21 @@ public class Settings implements ISettings<Settings> {
@ConfigEntry(path = "world.end.islands", needsReset = true) @ConfigEntry(path = "world.end.islands", needsReset = true)
private boolean endIslands = true; private boolean endIslands = true;
@ConfigEntry(path = "world.end.dragon-spawn")
private boolean dragonSpawn = false;
// ---------------------------------------------
/* ISLAND */
// Entities // Entities
@ConfigEntry(path = "island.limits.entities") @ConfigEntry(path = "island.limits.entities")
private Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class); private Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
@ConfigEntry(path = "island.limits.tile-entities") @ConfigEntry(path = "island.limits.tile-entities")
private Map<String, Integer> tileEntityLimits = new HashMap<>(); private Map<String, Integer> tileEntityLimits = new HashMap<>();
// ---------------------------------------------
/* ISLAND */
@ConfigEntry(path = "island.max-team-size") @ConfigEntry(path = "island.max-team-size")
private int maxTeamSize = 4; private int maxTeamSize = 4;
@ConfigEntry(path = "island.max-homes") @ConfigEntry(path = "island.max-homes")
@ -685,12 +694,14 @@ public class Settings implements ISettings<Settings> {
/** /**
* @return the netherGenerate * @return the netherGenerate
*/ */
@Override
public boolean isNetherGenerate() { public boolean isNetherGenerate() {
return netherGenerate; return netherGenerate;
} }
/** /**
* @return the netherIslands * @return the netherIslands
*/ */
@Override
public boolean isNetherIslands() { public boolean isNetherIslands() {
return netherIslands; return netherIslands;
} }
@ -703,6 +714,7 @@ public class Settings implements ISettings<Settings> {
/** /**
* @return the netherTrees * @return the netherTrees
*/ */
@Override
public boolean isNetherTrees() { public boolean isNetherTrees() {
return netherTrees; return netherTrees;
} }
@ -1260,6 +1272,33 @@ public class Settings implements ISettings<Settings> {
public void setConfirmationTime(int confirmationTime) { public void setConfirmationTime(int confirmationTime) {
this.confirmationTime = confirmationTime; this.confirmationTime = confirmationTime;
} }
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.configuration.WorldSettings#getFriendlyName()
*/
@Override
public String getFriendlyName() {
return friendlyName;
}
/**
* @param friendlyName the friendlyName to set
*/
public void setFriendlyName(String friendlyName) {
this.friendlyName = friendlyName;
}
/**
* @return the dragonSpawn
*/
public boolean isDragonSpawn() {
return dragonSpawn;
}
/**
* @param dragonSpawn the dragonSpawn to set
*/
public void setDragonSpawn(boolean dragonSpawn) {
this.dragonSpawn = dragonSpawn;
}
} }

View File

@ -0,0 +1,114 @@
package us.tastybento.bskyblock.api.configuration;
import java.util.Map;
import org.bukkit.entity.EntityType;
/**
* Contains world-specific settings. Only getters are required, but you may need setters for your own class.
* @author tastybento
*
*/
public interface WorldSettings {
/**
* @return the friendly name of the world. Used in player commands
*/
public String getFriendlyName();
/**
* @return the entityLimits
*/
public Map<EntityType, Integer> getEntityLimits();
/**
* @return the islandDistance
*/
public int getIslandDistance();
/**
* @return the islandHeight
*/
public int getIslandHeight();
/**
* @return the islandProtectionRange
*/
public int getIslandProtectionRange();
/**
* @return the islandStartX
*/
public int getIslandStartX();
/**
* @return the islandStartZ
*/
public int getIslandStartZ();
/**
* @return the islandXOffset
*/
public int getIslandXOffset();
/**
* @return the islandZOffset
*/
public int getIslandZOffset();
/**
* @return the maxIslands
*/
public int getMaxIslands();
/**
* @return the netherSpawnRadius
*/
public int getNetherSpawnRadius();
/**
* @return the seaHeight
*/
public int getSeaHeight();
/**
* @return the tileEntityLimits
*/
public Map<String, Integer> getTileEntityLimits();
/**
* @return the worldName
*/
public String getWorldName();
/**
* @return the endGenerate
*/
public boolean isEndGenerate();
/**
* @return the endIslands
*/
public boolean isEndIslands();
/**
* @return the netherGenerate
*/
public boolean isNetherGenerate();
/**
* @return the netherIslands
*/
public boolean isNetherIslands();
/**
* @return the netherTrees
*/
public boolean isNetherTrees();
/**
* @return the dragonSpawn
*/
public boolean isDragonSpawn();
}

View File

@ -68,6 +68,9 @@ public class User {
* @return user * @return user
*/ */
public static User getInstance(UUID uuid) { public static User getInstance(UUID uuid) {
if (uuid == null) {
return null;
}
if (users.containsKey(uuid)) { if (users.containsKey(uuid)) {
return users.get(uuid); return users.get(uuid);
} }

View File

@ -2,6 +2,8 @@ package us.tastybento.bskyblock.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bukkit.World; import org.bukkit.World;
@ -22,6 +24,7 @@ import us.tastybento.bskyblock.commands.island.IslandSettingsCommand;
import us.tastybento.bskyblock.commands.island.IslandUnbanCommand; import us.tastybento.bskyblock.commands.island.IslandUnbanCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand; import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand; import us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand;
import us.tastybento.bskyblock.util.Util;
public class IslandCommand extends CompositeCommand { public class IslandCommand extends CompositeCommand {
@ -74,8 +77,8 @@ public class IslandCommand extends CompositeCommand {
return getSubCommand("create").map(createCmd -> createCmd.execute(user, new ArrayList<>())).orElse(false); return getSubCommand("create").map(createCmd -> createCmd.execute(user, new ArrayList<>())).orElse(false);
} else if (args.size() == 1) { } else if (args.size() == 1) {
// Argument should be a world // Argument should be a world
if (getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) { if (getPlugin().getIWM().isOverWorld(args.get(0))) {
World world = getPlugin().getIslandWorldManager().getWorld(args.get(0)); World world = getPlugin().getIWM().getWorld(args.get(0));
if (getPlugin().getIslands().hasIsland(world, user.getUniqueId())) { if (getPlugin().getIslands().hasIsland(world, user.getUniqueId())) {
return getSubCommand("go").map(goCmd -> goCmd.execute(user, args)).orElse(false); return getSubCommand("go").map(goCmd -> goCmd.execute(user, args)).orElse(false);
} }
@ -88,5 +91,11 @@ public class IslandCommand extends CompositeCommand {
} }
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
List<String> options = getPlugin().getIWM().getOverWorldNames().stream().collect(Collectors.toList());
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
return Optional.of(Util.tabLimit(options, lastArg));
}
} }

View File

@ -45,7 +45,7 @@ public class AdminGetRankCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
if (args.size() != 1) { if (args.size() != 1) {
// Show help // Show help

View File

@ -26,7 +26,7 @@ public class AdminInfoCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
if (args.size() > 1 || (args.isEmpty() && !user.isPlayer())) { if (args.size() > 1 || (args.isEmpty() && !user.isPlayer())) {
// Show help // Show help

View File

@ -29,7 +29,7 @@ public class AdminRegisterCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 1) { if (args.size() != 1) {

View File

@ -43,7 +43,7 @@ public class AdminSetRankCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
if (args.size() != 2) { if (args.size() != 2) {
// Show help // Show help

View File

@ -31,7 +31,7 @@ public class AdminTeleportCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
if (args.isEmpty()) { if (args.isEmpty()) {
this.showHelp(this, user); this.showHelp(this, user);
@ -45,11 +45,11 @@ public class AdminTeleportCommand extends CompositeCommand {
return false; return false;
} else { } else {
if (getIslands().hasIsland(world, targetUUID) || getIslands().inTeam(world, targetUUID)) { if (getIslands().hasIsland(world, targetUUID) || getIslands().inTeam(world, targetUUID)) {
Location warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getIslandWorld()); Location warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIWM().getIslandWorld());
if (getLabel().equals("tpnether")) { if (getLabel().equals("tpnether")) {
warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld()); warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIWM().getNetherWorld());
} else if (getLabel().equals("tpend")) { } else if (getLabel().equals("tpend")) {
warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getEndWorld()); warpSpot = getIslands().getIslandLocation(world, targetUUID).toVector().toLocation(getPlugin().getIWM().getEndWorld());
} }
// Other wise, go to a safe spot // Other wise, go to a safe spot
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "

View File

@ -26,7 +26,7 @@ public class AdminUnregisterCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 1) { if (args.size() != 1) {

View File

@ -26,7 +26,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 2) { if (args.size() != 2) {
showHelp(this, user); showHelp(this, user);

View File

@ -25,7 +25,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 1) { if (args.size() != 1) {

View File

@ -26,7 +26,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 1) { if (args.size() != 1) {

View File

@ -25,7 +25,7 @@ public class AdminTeamMakeLeaderCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
// TODO: fix world // TODO: fix world
World world = getPlugin().getIslandWorldManager().getIslandWorld(); World world = getPlugin().getIWM().getIslandWorld();
// If args are not right, show help // If args are not right, show help
if (args.size() != 1) { if (args.size() != 1) {

View File

@ -40,12 +40,12 @@ public class IslandCreateCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
World world = null; World world = null;
if (args.size() == 1 && getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) { if (args.size() == 1 && getPlugin().getIWM().isOverWorld(args.get(0))) {
world = getPlugin().getIslandWorldManager().getWorld(args.get(0)); world = getPlugin().getIWM().getWorld(args.get(0));
} }
if (world == null) { if (world == null) {
// See which worlds are available // See which worlds are available
Set<String> worldNames = getPlugin().getIslandWorldManager().getFreeOverWorldNames(user); Set<String> worldNames = getPlugin().getIWM().getFreeOverWorldNames(user);
if (!worldNames.isEmpty()) { if (!worldNames.isEmpty()) {
// Make a list of worlds // Make a list of worlds
StringBuilder worlds = new StringBuilder(); StringBuilder worlds = new StringBuilder();
@ -60,7 +60,7 @@ public class IslandCreateCommand extends CompositeCommand {
user.sendMessage("commands.island.create.pick-world", "[worlds]", worlds.toString()); user.sendMessage("commands.island.create.pick-world", "[worlds]", worlds.toString());
return false; return false;
} else { } else {
world = getPlugin().getIslandWorldManager().getIslandWorld(); world = getPlugin().getIWM().getIslandWorld();
} }
} }
if (getIslands().hasIsland(world, user.getUniqueId())) { if (getIslands().hasIsland(world, user.getUniqueId())) {

View File

@ -43,12 +43,12 @@ public class IslandGoCommand extends CompositeCommand {
World world = user.getWorld(); World world = user.getWorld();
if (!args.isEmpty() && !NumberUtils.isDigits(args.get(0))) { if (!args.isEmpty() && !NumberUtils.isDigits(args.get(0))) {
// World? // World?
if (getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) { if (getPlugin().getIWM().isOverWorld(args.get(0))) {
world = getPlugin().getIslandWorldManager().getWorld(args.get(0)); world = getPlugin().getIWM().getWorld(args.get(0));
} else { } else {
// Make a list of worlds // Make a list of worlds
StringBuilder worlds = new StringBuilder(); StringBuilder worlds = new StringBuilder();
getPlugin().getIslandWorldManager().getOverWorldNames().forEach(w -> { getPlugin().getIWM().getOverWorldNames().forEach(w -> {
worlds.append(w); worlds.append(w);
worlds.append(", "); worlds.append(", ");
}); });

View File

@ -110,7 +110,7 @@ public class Island implements DataObject {
updatedDate = System.currentTimeMillis(); updatedDate = System.currentTimeMillis();
world = location.getWorld(); world = location.getWorld();
center = location; center = location;
range = BSkyBlock.getInstance().getSettings().getIslandDistance(); range = BSkyBlock.getInstance().getIWM().getIslandDistance(world);
minX = center.getBlockX() - range; minX = center.getBlockX() - range;
minZ = center.getBlockZ() - range; minZ = center.getBlockZ() - range;
this.protectionRange = protectionRange; this.protectionRange = protectionRange;

View File

@ -0,0 +1,36 @@
package us.tastybento.bskyblock.listeners;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import us.tastybento.bskyblock.BSkyBlock;
public class BlockEndDragon implements Listener {
private BSkyBlock plugin;
public BlockEndDragon(BSkyBlock plugin) {
this.plugin = plugin;
}
/**
* This handles end dragon spawning prevention
*
* @param event
* @return true if dragon can spawn, false if not
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public boolean onDragonSpawn(CreatureSpawnEvent event) {
if (!event.getEntityType().equals(EntityType.ENDER_DRAGON) || plugin.getIWM().isDragonSpawn(event.getEntity().getWorld())) {
return true;
}
event.getEntity().setHealth(0);
event.getEntity().remove();
event.setCancelled(true);
return false;
}
}

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -24,20 +25,15 @@ import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.teleport.SafeTeleportBuilder; import us.tastybento.bskyblock.util.teleport.SafeTeleportBuilder;
public class NetherPortals implements Listener { public class NetherPortals implements Listener {
private static final String ERROR_NO_PERMISSION = "general.errors.no-permission"; private static final String ERROR_NO_PERMISSION = "general.errors.no-permission";
private final BSkyBlock plugin; private final BSkyBlock plugin;
private World world;
private World nether;
private World theEnd;
public NetherPortals(BSkyBlock plugin) { public NetherPortals(BSkyBlock plugin) {
this.plugin = plugin; this.plugin = plugin;
world = plugin.getIslandWorldManager().getIslandWorld();
nether = plugin.getIslandWorldManager().getNetherWorld();
theEnd = plugin.getIslandWorldManager().getEndWorld();
} }
/** /**
@ -50,20 +46,25 @@ public class NetherPortals implements Listener {
private boolean awayFromSpawn(Location location) { private boolean awayFromSpawn(Location location) {
Vector p = location.toVector().multiply(new Vector(1, 0, 1)); Vector p = location.toVector().multiply(new Vector(1, 0, 1));
Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1)); Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
return (spawn.distanceSquared(p) < (plugin.getSettings().getNetherSpawnRadius() * plugin.getSettings().getNetherSpawnRadius())) ? false : true; int radiusSquared = plugin.getIWM().getNetherSpawnRadius(location.getWorld()) ^ 2;
return (spawn.distanceSquared(p) < radiusSquared) ? false : true;
} }
/** /**
* If the player is in the standard nether or standard end or op, do nothing. * If the player is not in the standard nether or standard end or op, do nothing.
* Used to protect the standard spawn for nether or end * Used to protect the standard spawn for nether or end
* @param player - the player * @param player - the player
* @return true if nothing needs to be done * @return true if nothing needs to be done
*/ */
private boolean noAction(Player player) { private boolean noAction(Player player) {
return (player.isOp() if (player.isOp()
|| (!player.getWorld().equals(nether) && !player.getWorld().equals(theEnd)) || player.getWorld().getEnvironment().equals(Environment.NORMAL)
|| (player.getWorld().equals(nether) && plugin.getSettings().isNetherIslands()) || !plugin.getIWM().inWorld(player.getLocation())) {
|| (player.getWorld().equals(theEnd) && plugin.getSettings().isEndIslands())) ? true: false; return true;
}
// Player is in an island world and in a nether or end
return (player.getWorld().getEnvironment().equals(Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|| (player.getWorld().getEnvironment().equals(Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld())) ? true: false;
} }
/** /**
@ -103,28 +104,28 @@ public class NetherPortals implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndIslandPortal(PlayerPortalEvent e) { public void onEndIslandPortal(PlayerPortalEvent e) {
if (!e.getCause().equals(TeleportCause.END_PORTAL) || !plugin.getSettings().isEndGenerate()) { if (!e.getCause().equals(TeleportCause.END_PORTAL) || !plugin.getIWM().inWorld(e.getFrom())) {
return;
}
if (!plugin.getIslandWorldManager().inWorld(e.getFrom())) {
return; return;
} }
World overWorld = Util.getWorld(e.getFrom().getWorld());
// If entering a portal in the end, teleport home if you have one, else do nothing // If entering a portal in the end, teleport home if you have one, else do nothing
if (e.getFrom().getWorld().equals(theEnd)) { if (e.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getIslands().hasIsland(e.getPlayer().getWorld(), e.getPlayer().getUniqueId())) { if (plugin.getIslands().hasIsland(overWorld, e.getPlayer().getUniqueId())) {
e.setCancelled(true); e.setCancelled(true);
plugin.getIslands().homeTeleport(e.getPlayer().getWorld(), e.getPlayer()); plugin.getIslands().homeTeleport(overWorld, e.getPlayer());
} }
return; return;
} }
// If this is island end, then go to the same location, otherwise try spawn // Going to the end, then go to the same location in the end world
Location to = plugin.getSettings().isEndIslands() ? e.getFrom().toVector().toLocation(theEnd) : theEnd.getSpawnLocation(); if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) {
// Else other worlds teleport to the end World endWorld = plugin.getIWM().getEndWorld(overWorld);
e.setCancelled(true); // End exists and end islands are being used
new SafeTeleportBuilder(plugin) e.setCancelled(true);
.entity(e.getPlayer()) new SafeTeleportBuilder(plugin)
.location(to) .entity(e.getPlayer())
.build(); .location(e.getFrom().toVector().toLocation(endWorld))
.build();
}
return; return;
} }
@ -136,7 +137,7 @@ public class NetherPortals implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityPortal(EntityPortalEvent e) { public void onEntityPortal(EntityPortalEvent e) {
if (plugin.getIslandWorldManager().inWorld(e.getFrom())) { if (plugin.getIWM().inWorld(e.getFrom())) {
// Disable entity portal transfer due to dupe glitching // Disable entity portal transfer due to dupe glitching
e.setCancelled(true); e.setCancelled(true);
} }
@ -149,11 +150,9 @@ public class NetherPortals implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onExplosion(EntityExplodeEvent e) { public boolean onExplosion(EntityExplodeEvent e) {
if (!plugin.getIslandWorldManager().inWorld(e.getLocation())) { if (!plugin.getIWM().inWorld(e.getLocation())
return false; || plugin.getIWM().isIslandNether(e.getLocation().getWorld())
} || plugin.getIWM().isIslandEnd(e.getLocation().getWorld())) {
if ((e.getLocation().getWorld().equals(nether) && plugin.getSettings().isNetherIslands())
|| (e.getLocation().getWorld().equals(theEnd) && plugin.getSettings().isEndIslands())) {
// Not used in island worlds // Not used in island worlds
return false; return false;
} }
@ -178,13 +177,17 @@ public class NetherPortals implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onNetherPortal(PlayerPortalEvent e) { public boolean onNetherPortal(PlayerPortalEvent e) {
if (!e.getCause().equals(TeleportCause.NETHER_PORTAL) || !plugin.getIslandWorldManager().inWorld(e.getFrom())) { if (!e.getCause().equals(TeleportCause.NETHER_PORTAL) || !plugin.getIWM().inWorld(e.getFrom())) {
return false; return false;
} }
// Get the overworld, which may be the same world
World overWorld = Util.getWorld(e.getFrom().getWorld());
// If entering a portal in the nether, teleport to portal in overworld if there is one // If entering a portal in the nether, teleport to portal in overworld if there is one
if (e.getFrom().getWorld().equals(nether)) { if (e.getFrom().getWorld().getEnvironment().equals(Environment.NETHER)) {
// If this is from the island nether, then go to the same vector, otherwise try island home location // If this is from the island nether, then go to the same vector, otherwise try island home location
Location to = plugin.getSettings().isNetherIslands() ? e.getFrom().toVector().toLocation(world) : plugin.getIslands().getIslandLocation(e.getPlayer().getWorld(), e.getPlayer().getUniqueId()); Location to = plugin.getIWM().isNetherIslands(overWorld)
? e.getFrom().toVector().toLocation(overWorld)
: plugin.getIslands().getIslandLocation(overWorld, e.getPlayer().getUniqueId());
e.setCancelled(true); e.setCancelled(true);
// Else other worlds teleport to the nether // Else other worlds teleport to the nether
new SafeTeleportBuilder(plugin) new SafeTeleportBuilder(plugin)
@ -194,8 +197,11 @@ public class NetherPortals implements Listener {
.build(); .build();
return true; return true;
} }
// If this is island nether, then go to the same vector, otherwise try spawn World nether = plugin.getIWM().getNetherWorld(overWorld);
Location to = plugin.getSettings().isNetherIslands() ? e.getFrom().toVector().toLocation(nether) : nether.getSpawnLocation(); // If this is to island nether, then go to the same vector, otherwise try spawn
Location to = (plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().isNetherGenerate(overWorld))
? e.getFrom().toVector().toLocation(nether)
: nether.getSpawnLocation();
e.setCancelled(true); e.setCancelled(true);
// Else other worlds teleport to the nether // Else other worlds teleport to the nether
new SafeTeleportBuilder(plugin) new SafeTeleportBuilder(plugin)
@ -229,7 +235,7 @@ public class NetherPortals implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onTreeGrow(StructureGrowEvent e) { public boolean onTreeGrow(StructureGrowEvent e) {
if (!plugin.getSettings().isNetherTrees() || !e.getWorld().equals(nether)) { if (!plugin.getIWM().isNetherTrees(e.getWorld()) || !e.getWorld().getEnvironment().equals(Environment.NETHER)) {
return false; return false;
} }
for (BlockState b : e.getBlocks()) { for (BlockState b : e.getBlocks()) {

View File

@ -44,7 +44,7 @@ public class ObsidianToLava implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public boolean onPlayerInteract(final PlayerInteractEvent e) { public boolean onPlayerInteract(final PlayerInteractEvent e) {
if (!plugin.getSettings().isAllowObsidianScooping() if (!plugin.getSettings().isAllowObsidianScooping()
|| !plugin.getIslandWorldManager().inWorld(e.getPlayer().getLocation()) || !plugin.getIWM().inWorld(e.getPlayer().getLocation())
|| !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL) || !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
|| !e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || !e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|| !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET)) || !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET))

View File

@ -124,10 +124,9 @@ public abstract class AbstractFlagListener implements Listener {
*/ */
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) { public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
// If this is not an Island World, skip // If this is not an Island World, skip
if (!plugin.getIslandWorldManager().inWorld(loc)) { if (!plugin.getIWM().inWorld(loc)) {
return true; return true;
} }
// Get the island and if present // Get the island and if present
Optional<Island> island = getIslands().getIslandAt(loc); Optional<Island> island = getIslands().getIslandAt(loc);
// Handle Settings Flag // Handle Settings Flag
@ -137,7 +136,6 @@ public abstract class AbstractFlagListener implements Listener {
} }
// Protection flag // Protection flag
// If the user is not set already, try to get it from the event // If the user is not set already, try to get it from the event
if (user == null) { if (user == null) {
// Set the user associated with this event // Set the user associated with this event
@ -195,6 +193,6 @@ public abstract class AbstractFlagListener implements Listener {
* @return Island World Manager * @return Island World Manager
*/ */
protected IslandWorldManager getIslandWorldManager() { protected IslandWorldManager getIslandWorldManager() {
return plugin.getIslandWorldManager(); return plugin.getIWM();
} }
} }

View File

@ -44,9 +44,9 @@ public class PVPListener extends AbstractFlagListener {
public void onEntityDamage(final EntityDamageByEntityEvent e) { public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
Flag flag = Flags.PVP_OVERWORLD; Flag flag = Flags.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { if (e.getEntity().getWorld().equals(getPlugin().getIWM().getNetherWorld())) {
flag = Flags.PVP_NETHER; flag = Flags.PVP_NETHER;
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { } else if (e.getEntity().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
flag = Flags.PVP_END; flag = Flags.PVP_END;
} }
respond(e, e.getDamager(), flag); respond(e, e.getDamager(), flag);
@ -74,9 +74,9 @@ public class PVPListener extends AbstractFlagListener {
public void onFishing(PlayerFishEvent e) { public void onFishing(PlayerFishEvent e) {
if (e.getCaught() != null && e.getCaught() instanceof Player) { if (e.getCaught() != null && e.getCaught() instanceof Player) {
Flag flag = Flags.PVP_OVERWORLD; Flag flag = Flags.PVP_OVERWORLD;
if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { if (e.getCaught().getWorld().equals(getPlugin().getIWM().getNetherWorld())) {
flag = Flags.PVP_NETHER; flag = Flags.PVP_NETHER;
} else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { } else if (e.getCaught().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
flag = Flags.PVP_END; flag = Flags.PVP_END;
} }
if (checkIsland(e, e.getCaught().getLocation(), flag)) { if (checkIsland(e, e.getCaught().getLocation(), flag)) {
@ -93,9 +93,9 @@ public class PVPListener extends AbstractFlagListener {
public void onSplashPotionSplash(final PotionSplashEvent e) { public void onSplashPotionSplash(final PotionSplashEvent e) {
// Deduce the world // Deduce the world
Flag flag = Flags.PVP_OVERWORLD; Flag flag = Flags.PVP_OVERWORLD;
if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { if (e.getPotion().getWorld().equals(getPlugin().getIWM().getNetherWorld())) {
flag = Flags.PVP_NETHER; flag = Flags.PVP_NETHER;
} else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { } else if (e.getPotion().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
flag = Flags.PVP_END; flag = Flags.PVP_END;
} }
@ -142,9 +142,9 @@ public class PVPListener extends AbstractFlagListener {
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) { if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
// Deduce the world // Deduce the world
Flag flag = Flags.PVP_OVERWORLD; Flag flag = Flags.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { if (e.getEntity().getWorld().equals(getPlugin().getIWM().getNetherWorld())) {
flag = Flags.PVP_NETHER; flag = Flags.PVP_NETHER;
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { } else if (e.getEntity().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
flag = Flags.PVP_END; flag = Flags.PVP_END;
} }

View File

@ -70,7 +70,7 @@ public class FlyingMobEvents implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMobSpawn(CreatureSpawnEvent e) { public void onMobSpawn(CreatureSpawnEvent e) {
// Only cover withers in the island world // Only cover withers in the island world
if (!plugin.getIslandWorldManager().inWorld(e.getEntity().getLocation()) || !(e.getEntityType().equals(EntityType.WITHER) if (!plugin.getIWM().inWorld(e.getEntity().getLocation()) || !(e.getEntityType().equals(EntityType.WITHER)
|| e.getEntityType().equals(EntityType.BLAZE) || e.getEntityType().equals(EntityType.BLAZE)
|| e.getEntityType().equals(EntityType.GHAST))) { || e.getEntityType().equals(EntityType.GHAST))) {
return; return;
@ -87,7 +87,7 @@ public class FlyingMobEvents implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onMobExplosion(EntityExplodeEvent e) { public boolean onMobExplosion(EntityExplodeEvent e) {
// Only cover in the island world // Only cover in the island world
if (e.getEntity() == null || !plugin.getIslandWorldManager().inWorld(e.getEntity().getLocation())) { if (e.getEntity() == null || !plugin.getIWM().inWorld(e.getEntity().getLocation())) {
return false; return false;
} }
if (mobSpawnInfo.containsKey(e.getEntity()) && !mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) { if (mobSpawnInfo.containsKey(e.getEntity()) && !mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) {
@ -105,7 +105,7 @@ public class FlyingMobEvents implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public boolean onWitherExplode(ExplosionPrimeEvent e) { public boolean onWitherExplode(ExplosionPrimeEvent e) {
// Only cover withers in the island world // Only cover withers in the island world
if (!plugin.getIslandWorldManager().inWorld(e.getEntity().getLocation()) || e.getEntity() == null) { if (!plugin.getIWM().inWorld(e.getEntity().getLocation()) || e.getEntity() == null) {
return false; return false;
} }
// The wither or wither skulls can both blow up // The wither or wither skulls can both blow up
@ -139,7 +139,7 @@ public class FlyingMobEvents implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onWitherChangeBlocks(EntityChangeBlockEvent e) { public void onWitherChangeBlocks(EntityChangeBlockEvent e) {
// Only cover withers in the island world // Only cover withers in the island world
if (e.getEntityType() != EntityType.WITHER || !plugin.getIslandWorldManager().inWorld(e.getEntity().getLocation()) ) { if (e.getEntityType() != EntityType.WITHER || !plugin.getIWM().inWorld(e.getEntity().getLocation()) ) {
return; return;
} }
if (mobSpawnInfo.containsKey(e.getEntity())) { if (mobSpawnInfo.containsKey(e.getEntity())) {

View File

@ -9,13 +9,21 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.entity.EntityType;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.generators.ChunkGeneratorWorld; import us.tastybento.bskyblock.generators.ChunkGeneratorWorld;
import us.tastybento.bskyblock.util.Util;
/**
* Handles registration and management of worlds
* @author tastybento
*
*/
public class IslandWorldManager { public class IslandWorldManager {
private static final String MULTIVERSE_SET_GENERATOR = "mv modify set generator "; private static final String MULTIVERSE_SET_GENERATOR = "mv modify set generator ";
@ -29,6 +37,7 @@ public class IslandWorldManager {
private World netherWorld; private World netherWorld;
private World endWorld; private World endWorld;
private Map<World, String> worlds; private Map<World, String> worlds;
private Map<World, WorldSettings> worldSettings;
/** /**
* Generates the Skyblock worlds. * Generates the Skyblock worlds.
@ -36,6 +45,7 @@ public class IslandWorldManager {
public IslandWorldManager(BSkyBlock plugin) { public IslandWorldManager(BSkyBlock plugin) {
this.plugin = plugin; this.plugin = plugin;
worlds = new HashMap<>(); worlds = new HashMap<>();
worldSettings = new HashMap<>();
if (plugin.getSettings().isUseOwnGenerator()) { if (plugin.getSettings().isUseOwnGenerator()) {
// Do nothing // Do nothing
return; return;
@ -46,7 +56,7 @@ public class IslandWorldManager {
// Create the world if it does not exist // Create the world if it does not exist
islandWorld = WorldCreator.name(plugin.getSettings().getWorldName()).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(plugin)) islandWorld = WorldCreator.name(plugin.getSettings().getWorldName()).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld(plugin))
.createWorld(); .createWorld();
addWorld("bsb", islandWorld); addWorld(islandWorld, plugin.getSettings());
// Make the nether if it does not exist // Make the nether if it does not exist
if (plugin.getSettings().isNetherGenerate()) { if (plugin.getSettings().isNetherGenerate()) {
if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + NETHER) == null) { if (plugin.getServer().getWorld(plugin.getSettings().getWorldName() + NETHER) == null) {
@ -58,7 +68,6 @@ public class IslandWorldManager {
netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + NETHER).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin)) netherWorld = WorldCreator.name(plugin.getSettings().getWorldName() + NETHER).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin))
.environment(World.Environment.NETHER).createWorld(); .environment(World.Environment.NETHER).createWorld();
} }
addWorld("bsb_nether", netherWorld);
} }
// Make the end if it does not exist // Make the end if it does not exist
if (plugin.getSettings().isEndGenerate()) { if (plugin.getSettings().isEndGenerate()) {
@ -71,7 +80,6 @@ public class IslandWorldManager {
endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + THE_END).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin)) endWorld = WorldCreator.name(plugin.getSettings().getWorldName() + THE_END).type(WorldType.FLAT).generator(new ChunkGeneratorWorld(plugin))
.environment(World.Environment.THE_END).createWorld(); .environment(World.Environment.THE_END).createWorld();
} }
addWorld("bsb_end", endWorld);
} }
} }
@ -124,7 +132,7 @@ public class IslandWorldManager {
* @return true if in a world or false if not * @return true if in a world or false if not
*/ */
public boolean inWorld(Location loc) { public boolean inWorld(Location loc) {
return worlds.containsKey(loc.getWorld()); return worlds.containsKey(Util.getWorld(loc.getWorld()));
} }
/** /**
@ -164,14 +172,24 @@ public class IslandWorldManager {
/** /**
* Add world to the list of known worlds along with a friendly name that will be used in commands * Add world to the list of known worlds along with a friendly name that will be used in commands
* @param friendlyName - string
* @param world - world * @param world - world
*/ */
public void addWorld(String friendlyName, World world) { public void addWorld(World world, WorldSettings settings) {
String friendlyName = settings.getFriendlyName().isEmpty() ? world.getName() : settings.getFriendlyName();
plugin.log("Adding world " + friendlyName); plugin.log("Adding world " + friendlyName);
worlds.put(world, friendlyName); worlds.put(world, friendlyName);
worldSettings.put(world, settings);
multiverseReg(world); multiverseReg(world);
} }
/**
* Get the settings for this world or sub-worlds (nether, end)
* @param world - world
* @return world settings, or null if world is unknown
*/
public WorldSettings getWorldSettings(World world) {
return worldSettings.get(Util.getWorld(world));
}
/** /**
* Get the world based on friendly name. * Get the world based on friendly name.
@ -182,4 +200,201 @@ public class IslandWorldManager {
return worlds.entrySet().stream().filter(n -> n.getValue().equalsIgnoreCase(friendlyName)).map(e -> e.getKey()).findFirst().orElse(null); return worlds.entrySet().stream().filter(n -> n.getValue().equalsIgnoreCase(friendlyName)).map(e -> e.getKey()).findFirst().orElse(null);
} }
/**
* @return the entityLimits
*/
public Map<EntityType, Integer> getEntityLimits(World world) {
return worldSettings.get(Util.getWorld(world)).getEntityLimits();
}
/**
* @return the islandDistance
*/
public int getIslandDistance(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandDistance();
}
/**
* @return the islandHeight
*/
public int getIslandHeight(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandHeight();
}
/**
* @return the islandProtectionRange
*/
public int getIslandProtectionRange(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandProtectionRange();
}
/**
* @return the islandStartX
*/
public int getIslandStartX(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandStartX();
}
/**
* @return the islandStartZ
*/
public int getIslandStartZ(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandStartZ();
}
/**
* @return the islandXOffset
*/
public int getIslandXOffset(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandXOffset();
}
/**
* @return the islandZOffset
*/
public int getIslandZOffset(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandZOffset();
}
/**
* @return the maxIslands
*/
public int getMaxIslands(World world) {
return worldSettings.get(Util.getWorld(world)).getMaxIslands();
}
/**
* @return the netherSpawnRadius
*/
public int getNetherSpawnRadius(World world) {
return worldSettings.get(Util.getWorld(world)).getNetherSpawnRadius();
}
/**
* @return the seaHeight
*/
public int getSeaHeight(World world) {
return worldSettings.get(Util.getWorld(world)).getSeaHeight();
}
/**
* @return the tileEntityLimits
*/
public Map<String, Integer> getTileEntityLimits(World world) {
return worldSettings.get(Util.getWorld(world)).getTileEntityLimits();
}
/**
* @return the worldName
*/
public String getWorldName(World world) {
return worldSettings.get(Util.getWorld(world)).getWorldName();
}
/**
* @return the endGenerate
*/
public boolean isEndGenerate(World world) {
return worldSettings.get(Util.getWorld(world)).isEndGenerate();
}
/**
* @return the endIslands
*/
public boolean isEndIslands(World world) {
return worldSettings.get(Util.getWorld(world)).isEndIslands();
}
/**
* @return the netherGenerate
*/
public boolean isNetherGenerate(World world) {
return worldSettings.get(Util.getWorld(world)).isNetherGenerate();
}
/**
* @return the netherIslands
*/
public boolean isNetherIslands(World world) {
return worldSettings.get(Util.getWorld(world)).isNetherIslands();
}
/**
* Checks if a world is a known nether world
* @param world - world
* @return true if world is a known and valid nether world
*/
public boolean isNether(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate()) ? true : false;
}
/**
* Checks if a world is a known island nether world
* @param world - world
* @return true if world is a known and valid nether world
*/
public boolean isIslandNether(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate() && worldSettings.get(w).isNetherIslands()) ? true : false;
}
/**
* Checks if a world is a known end world
* @param world - world
* @return true if world is a known and valid nether world
*/
public boolean isEnd(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate()) ? true : false;
}
/**
* Checks if a world is a known island end world
* @param world - world
* @return true if world is a known and valid nether world
*/
public boolean isIslandEnd(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate() && worldSettings.get(w).isEndIslands()) ? true : false;
}
/**
* Get the nether world of this overWorld
* @param overWorld - overworld
* @return nether world, or null if it does not exist
*/
public World getNetherWorld(World overWorld) {
return Bukkit.getWorld(overWorld.getName() + "_nether");
}
/**
* Get the end world of this overWorld
* @param overWorld - overworld
* @return end world, or null if it does not exist
*/
public World getEndWorld(World overWorld) {
return Bukkit.getWorld(overWorld.getName() + "_the_end");
}
/**
* Check if nether trees should be created in the nether or not
* @param world - world
* @return true or false
*/
public boolean isNetherTrees(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && worldSettings.get(w).isNetherTrees()) ? true : false;
}
/**
* Whether the End Dragon can spawn or not in this world
* @param world - world
* @return true (default) if it can spawn or not
*/
public boolean isDragonSpawn(World world) {
World w = Util.getWorld(world);
return (worldSettings.containsKey(w) && !worldSettings.get(w).isDragonSpawn()) ? false : true;
}
} }

View File

@ -237,7 +237,7 @@ public class IslandsManager {
* @return Island or null if the island could not be created for some reason * @return Island or null if the island could not be created for some reason
*/ */
public Island createIsland(Location location, UUID owner){ public Island createIsland(Location location, UUID owner){
Island island = new Island(location, owner, plugin.getSettings().getIslandProtectionRange()); Island island = new Island(location, owner, plugin.getIWM().getIslandProtectionRange(location.getWorld()));
if (islandCache.addIsland(island)) { if (islandCache.addIsland(island)) {
return island; return island;
} }
@ -596,11 +596,10 @@ public class IslandsManager {
* @return Location of closest island * @return Location of closest island
*/ */
public Location getClosestIsland(Location location) { public Location getClosestIsland(Location location) {
long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance()) int dist = plugin.getIWM().getIslandDistance(location.getWorld());
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset(); long x = Math.round((double) location.getBlockX() / dist) * dist + plugin.getIWM().getIslandXOffset(location.getWorld());
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance()) long z = Math.round((double) location.getBlockZ() / dist) * dist + plugin.getIWM().getIslandZOffset(location.getWorld());
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset(); long y = plugin.getIWM().getIslandHeight(location.getWorld());
long y = plugin.getSettings().getIslandHeight();
if (location.getBlockX() == x && location.getBlockZ() == z) { if (location.getBlockX() == x && location.getBlockZ() == z) {
return location; return location;
} }

View File

@ -17,6 +17,7 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
public class IslandCache { public class IslandCache {
private BiMap<Location, Island> islandsByLocation; private BiMap<Location, Island> islandsByLocation;
@ -25,13 +26,11 @@ public class IslandCache {
*/ */
private Map<World, Map<UUID, Island>> islandsByUUID; private Map<World, Map<UUID, Island>> islandsByUUID;
private Map<World, IslandGrid> grids; private Map<World, IslandGrid> grids;
private IslandGrid defaultGrid;
public IslandCache() { public IslandCache() {
islandsByLocation = HashBiMap.create(); islandsByLocation = HashBiMap.create();
islandsByUUID = new HashMap<>(); islandsByUUID = new HashMap<>();
grids = new HashMap<>(); grids = new HashMap<>();
defaultGrid = new IslandGrid();
} }
/** /**
@ -65,7 +64,8 @@ public class IslandCache {
* @return true if successfully added, false if not * @return true if successfully added, false if not
*/ */
private boolean addToGrid(Island newIsland) { private boolean addToGrid(Island newIsland) {
return grids.getOrDefault(newIsland.getWorld(), defaultGrid).addToGrid(newIsland); grids.putIfAbsent(newIsland.getWorld(), new IslandGrid());
return grids.get(newIsland.getWorld()).addToGrid(newIsland);
} }
public void clear() { public void clear() {
@ -90,7 +90,8 @@ public class IslandCache {
} }
} }
// Remove from grid // Remove from grid
return grids.getOrDefault(island.getWorld(), defaultGrid).removeFromGrid(island); grids.putIfAbsent(island.getWorld(), new IslandGrid());
return grids.get(island.getWorld()).removeFromGrid(island);
} }
/** /**
@ -109,7 +110,7 @@ public class IslandCache {
* @return island or null if none * @return island or null if none
*/ */
public Island get(World world, UUID uuid) { public Island get(World world, UUID uuid) {
return islandsByUUID.containsKey(world) ? islandsByUUID.get(world).get(uuid) : null; return islandsByUUID.containsKey(Util.getWorld(world)) ? islandsByUUID.get(Util.getWorld(world)).get(uuid) : null;
} }
/** /**
@ -120,10 +121,10 @@ public class IslandCache {
* @return Island object * @return Island object
*/ */
public Island getIslandAt(Location location) { public Island getIslandAt(Location location) {
if (location == null) { if (location == null || !grids.containsKey(Util.getWorld(location.getWorld()))) {
return null; return null;
} }
return grids.getOrDefault(location.getWorld(), defaultGrid).getIslandAt(location.getBlockX(), location.getBlockZ()); return grids.get(Util.getWorld(location.getWorld())).getIslandAt(location.getBlockX(), location.getBlockZ());
} }
public Collection<Island> getIslands() { public Collection<Island> getIslands() {
@ -136,8 +137,8 @@ public class IslandCache {
* @return set of UUID's of island members. If there is no island, this set will be empty * @return set of UUID's of island members. If there is no island, this set will be empty
*/ */
public Set<UUID> getMembers(World world, UUID uuid) { public Set<UUID> getMembers(World world, UUID uuid) {
islandsByUUID.putIfAbsent(world, new HashMap<>()); islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
Island island = islandsByUUID.get(world).get(uuid); Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
if (island != null) { if (island != null) {
return island.getMemberSet(); return island.getMemberSet();
} }
@ -150,8 +151,8 @@ public class IslandCache {
* @return team leader's UUID, the player UUID if they are not in a team, or null if there is no island * @return team leader's UUID, the player UUID if they are not in a team, or null if there is no island
*/ */
public UUID getTeamLeader(World world, UUID uuid) { public UUID getTeamLeader(World world, UUID uuid) {
islandsByUUID.putIfAbsent(world, new HashMap<>()); islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
Island island = islandsByUUID.get(world).get(uuid); Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
if (island != null) { if (island != null) {
return island.getOwner(); return island.getOwner();
} }
@ -164,8 +165,8 @@ public class IslandCache {
* @return true if player has island and owns it * @return true if player has island and owns it
*/ */
public boolean hasIsland(World world, UUID uuid) { public boolean hasIsland(World world, UUID uuid) {
islandsByUUID.putIfAbsent(world, new HashMap<>()); islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
Island island = islandsByUUID.get(world).get(uuid); Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
if (island != null) { if (island != null) {
return island.getOwner().equals(uuid); return island.getOwner().equals(uuid);
} }
@ -178,8 +179,8 @@ public class IslandCache {
* @param playerUUID - player's UUID * @param playerUUID - player's UUID
*/ */
public void removePlayer(World world, UUID uuid) { public void removePlayer(World world, UUID uuid) {
islandsByUUID.putIfAbsent(world, new HashMap<>()); islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
Island island = islandsByUUID.get(world).get(uuid); Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
if (island != null) { if (island != null) {
if (island.getOwner() != null && island.getOwner().equals(uuid)) { if (island.getOwner() != null && island.getOwner().equals(uuid)) {
// Clear ownership and members // Clear ownership and members
@ -190,7 +191,7 @@ public class IslandCache {
island.removeMember(uuid); island.removeMember(uuid);
} }
} }
islandsByUUID.get(world).remove(uuid); islandsByUUID.get(Util.getWorld(world)).remove(uuid);
} }
/** /**
@ -208,8 +209,8 @@ public class IslandCache {
*/ */
public void setOwner(Island island, UUID newOwnerUUID) { public void setOwner(Island island, UUID newOwnerUUID) {
island.setOwner(newOwnerUUID); island.setOwner(newOwnerUUID);
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>()); islandsByUUID.putIfAbsent(Util.getWorld(island.getWorld()), new HashMap<>());
islandsByUUID.get(island.getWorld()).put(newOwnerUUID, island); islandsByUUID.get(Util.getWorld(island.getWorld())).put(newOwnerUUID, island);
islandsByLocation.put(island.getCenter(), island); islandsByLocation.put(island.getCenter(), island);
} }

View File

@ -125,14 +125,14 @@ public class NewIsland {
.setChestItems(plugin.getSettings().getChestItems()) .setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.ISLAND) .setType(IslandType.ISLAND)
.build(); .build();
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIslandWorldManager().getNetherWorld() != null) { if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIWM().getNetherWorld() != null) {
new IslandBuilder(plugin,island) new IslandBuilder(plugin,island)
.setPlayer(user.getPlayer()) .setPlayer(user.getPlayer())
.setChestItems(plugin.getSettings().getChestItems()) .setChestItems(plugin.getSettings().getChestItems())
.setType(IslandType.NETHER) .setType(IslandType.NETHER)
.build(); .build();
} }
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIslandWorldManager().getEndWorld() != null) { if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIWM().getEndWorld() != null) {
new IslandBuilder(plugin,island) new IslandBuilder(plugin,island)
.setPlayer(user.getPlayer()) .setPlayer(user.getPlayer())
.setChestItems(plugin.getSettings().getChestItems()) .setChestItems(plugin.getSettings().getChestItems())
@ -169,8 +169,8 @@ public class NewIsland {
private Location getNextIsland() { private Location getNextIsland() {
Location last = plugin.getIslands().getLast(world); Location last = plugin.getIslands().getLast(world);
if (last == null) { if (last == null) {
last = new Location(world, plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(), last = new Location(world, plugin.getIWM().getIslandXOffset(world) + plugin.getIWM().getIslandStartX(world),
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ()); plugin.getIWM().getIslandHeight(world), plugin.getIWM().getIslandZOffset(world) + plugin.getIWM().getIslandStartZ(world));
} }
Location next = last.clone(); Location next = last.clone();
while (plugin.getIslands().isIsland(next)) { while (plugin.getIslands().isIsland(next)) {
@ -189,28 +189,29 @@ public class NewIsland {
private Location nextGridLocation(final Location lastIsland) { private Location nextGridLocation(final Location lastIsland) {
int x = lastIsland.getBlockX(); int x = lastIsland.getBlockX();
int z = lastIsland.getBlockZ(); int z = lastIsland.getBlockZ();
int d = plugin.getIWM().getIslandDistance(lastIsland.getWorld()) * 2;
Location nextPos = lastIsland; Location nextPos = lastIsland;
if (x < z) { if (x < z) {
if (-1 * x < z) { if (-1 * x < z) {
nextPos.setX(nextPos.getX() + plugin.getSettings().getIslandDistance()*2); nextPos.setX(nextPos.getX() + d);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2); nextPos.setZ(nextPos.getZ() + d);
return nextPos; return nextPos;
} }
if (x > z) { if (x > z) {
if (-1 * x >= z) { if (-1 * x >= z) {
nextPos.setX(nextPos.getX() - plugin.getSettings().getIslandDistance()*2); nextPos.setX(nextPos.getX() - d);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2); nextPos.setZ(nextPos.getZ() - d);
return nextPos; return nextPos;
} }
if (x <= 0) { if (x <= 0) {
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2); nextPos.setZ(nextPos.getZ() + d);
return nextPos; return nextPos;
} }
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2); nextPos.setZ(nextPos.getZ() - d);
return nextPos; return nextPos;
} }
} }

View File

@ -41,11 +41,11 @@ public class DeleteIslandChunks {
for (int z = minZChunk; z<=maxZChunk; z++) { for (int z = minZChunk; z<=maxZChunk; z++) {
world.regenerateChunk(x, z); world.regenerateChunk(x, z);
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) { if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands()) {
plugin.getIslandWorldManager().getNetherWorld().regenerateChunk(x, z); plugin.getIWM().getNetherWorld().regenerateChunk(x, z);
} }
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) { if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands()) {
plugin.getIslandWorldManager().getEndWorld().regenerateChunk(x, z); plugin.getIWM().getEndWorld().regenerateChunk(x, z);
} }
} }
} }

View File

@ -12,6 +12,7 @@ import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -227,5 +228,14 @@ public class Util {
return worldName.equalsIgnoreCase(world2Name); return worldName.equalsIgnoreCase(world2Name);
} }
/**
* Convert world to an overworld
* @param world - world
* @return over world
*/
public static World getWorld(World world) {
return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll("_nether", "").replaceAll("_the_end", ""));
}
} }

View File

@ -122,7 +122,7 @@ public class SafeSpotTeleport {
List<Pair<Integer, Integer>> result = new ArrayList<>(); List<Pair<Integer, Integer>> result = new ArrayList<>();
// Get island if available // Get island if available
Optional<Island> island = plugin.getIslands().getIslandAt(location); Optional<Island> island = plugin.getIslands().getIslandAt(location);
int maxRadius = island.map(Island::getProtectionRange).orElse(plugin.getSettings().getIslandProtectionRange()); int maxRadius = island.map(Island::getProtectionRange).orElse(plugin.getIWM().getIslandProtectionRange(location.getWorld()));
maxRadius = maxRadius > MAX_RADIUS ? MAX_RADIUS : maxRadius; maxRadius = maxRadius > MAX_RADIUS ? MAX_RADIUS : maxRadius;
int x = location.getBlockX(); int x = location.getBlockX();

View File

@ -66,7 +66,7 @@ import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ BSkyBlock.class, Flags.class}) @PrepareForTest({ BSkyBlock.class, Flags.class, Util.class})
public class TestBSkyBlock { public class TestBSkyBlock {
private static final UUID MEMBER_UUID = UUID.randomUUID(); private static final UUID MEMBER_UUID = UUID.randomUUID();
private static final UUID OWNER_UUID = UUID.randomUUID(); private static final UUID OWNER_UUID = UUID.randomUUID();
@ -142,12 +142,13 @@ public class TestBSkyBlock {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
Mockito.when(plugin.getIslandWorldManager()).thenReturn(iwm); Mockito.when(plugin.getIWM()).thenReturn(iwm);
Mockito.when(iwm.getIslandWorld()).thenReturn(world); Mockito.when(iwm.getIslandWorld()).thenReturn(world);
Mockito.when(iwm.getNetherWorld()).thenReturn(world); Mockito.when(iwm.getNetherWorld()).thenReturn(world);
Mockito.when(iwm.getEndWorld()).thenReturn(world); Mockito.when(iwm.getEndWorld()).thenReturn(world);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// Islands // Islands
IslandsManager im = mock(IslandsManager.class); IslandsManager im = mock(IslandsManager.class);

View File

@ -454,6 +454,7 @@ public class UserTest {
Mockito.verify(pl).performCommand("test"); Mockito.verify(pl).performCommand("test");
} }
@SuppressWarnings("unlikely-arg-type")
@Test @Test
public void testEqualsObject() { public void testEqualsObject() {
User user1 = User.getInstance(UUID.randomUUID()); User user1 = User.getInstance(UUID.randomUUID());
@ -463,15 +464,11 @@ public class UserTest {
assertFalse(user1.equals(null)); assertFalse(user1.equals(null));
assertFalse(user2.equals(user1)); assertFalse(user2.equals(user1));
assertFalse(user2.equals(null)); assertFalse(user2.equals(null));
assertFalse(user2.equals("an string")); assertFalse(user2.equals("a string"));
user1 = User.getInstance((UUID)null); user1 = User.getInstance((UUID)null);
assertFalse(user1.equals(user2));
assertFalse(user2.equals(user1)); assertFalse(user2.equals(user1));
user2 = User.getInstance((UUID)null);
assertTrue(user1.equals(user2));
assertTrue(user2.equals(user1));
} }
@Test @Test

View File

@ -79,7 +79,7 @@ public class IslandCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getWorld(Mockito.anyString())).thenReturn(world); when(iwm.getWorld(Mockito.anyString())).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
} }
@Test @Test

View File

@ -96,7 +96,7 @@ public class AdminInfoCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -97,7 +97,7 @@ public class AdminRegisterCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -96,7 +96,7 @@ public class AdminUnregisterCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -118,7 +118,7 @@ public class AdminTeamAddCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
} }

View File

@ -95,7 +95,7 @@ public class AdminTeamDisbandCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -97,7 +97,7 @@ public class AdminTeamKickCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -95,7 +95,7 @@ public class AdminTeamMakeLeaderCommandTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
World world = mock(World.class); World world = mock(World.class);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with

View File

@ -0,0 +1,96 @@
package us.tastybento.bskyblock.listeners;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class, Util.class })
public class BlockEndDragonTest {
@Test
public void testBlockEndDragon() {
BSkyBlock plugin = mock(BSkyBlock.class);
assertNotNull(new BlockEndDragon(plugin));
}
@Test
public void testOnDragonSpawnWrongEntityOkayToSpawn() {
LivingEntity le = mock(LivingEntity.class);
when(le.getType()).thenReturn(EntityType.AREA_EFFECT_CLOUD);
CreatureSpawnEvent event = new CreatureSpawnEvent(le, null);
BSkyBlock plugin = mock(BSkyBlock.class);
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// allow dragon spawn
when(iwm.isDragonSpawn(Mockito.any())).thenReturn(true);
BlockEndDragon bed = new BlockEndDragon(plugin);
assertTrue(bed.onDragonSpawn(event));
assertFalse(event.isCancelled());
}
@Test
public void testOnDragonSpawnWrongEntityNoDragonSpawn() {
LivingEntity le = mock(LivingEntity.class);
when(le.getType()).thenReturn(EntityType.AREA_EFFECT_CLOUD);
CreatureSpawnEvent event = new CreatureSpawnEvent(le, null);
BSkyBlock plugin = mock(BSkyBlock.class);
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// allow dragon spawn
when(iwm.isDragonSpawn(Mockito.any())).thenReturn(false);
BlockEndDragon bed = new BlockEndDragon(plugin);
assertTrue(bed.onDragonSpawn(event));
assertFalse(event.isCancelled());
}
@Test
public void testOnDragonSpawnRightEntityOkayToSpawn() {
LivingEntity le = mock(LivingEntity.class);
when(le.getType()).thenReturn(EntityType.ENDER_DRAGON);
CreatureSpawnEvent event = new CreatureSpawnEvent(le, null);
BSkyBlock plugin = mock(BSkyBlock.class);
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// allow dragon spawn
when(iwm.isDragonSpawn(Mockito.any())).thenReturn(true);
BlockEndDragon bed = new BlockEndDragon(plugin);
assertTrue(bed.onDragonSpawn(event));
assertFalse(event.isCancelled());
}
@Test
public void testOnDragonSpawnRightEntityNotOkayToSpawn() {
LivingEntity le = mock(LivingEntity.class);
when(le.getType()).thenReturn(EntityType.ENDER_DRAGON);
CreatureSpawnEvent event = new CreatureSpawnEvent(le, null);
BSkyBlock plugin = mock(BSkyBlock.class);
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// allow dragon spawn
when(iwm.isDragonSpawn(Mockito.any())).thenReturn(false);
BlockEndDragon bed = new BlockEndDragon(plugin);
assertFalse(bed.onDragonSpawn(event));
Mockito.verify(le).remove();
Mockito.verify(le).setHealth(0);
assertTrue(event.isCancelled());
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.TreeType; import org.bukkit.TreeType;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -84,14 +85,22 @@ public class NetherPortalsTest {
// island world mgr // island world mgr
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
world = mock(World.class); world = mock(World.class);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
nether = mock(World.class); nether = mock(World.class);
when(nether.getEnvironment()).thenReturn(Environment.NETHER);
when(nether.getSpawnLocation()).thenReturn(mock(Location.class));
end = mock(World.class); end = mock(World.class);
when(iwm.getEndWorld()).thenReturn(end); when(end.getEnvironment()).thenReturn(Environment.THE_END);
when(iwm.getEndWorld(Mockito.any())).thenReturn(end);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(nether); when(iwm.getNetherWorld(Mockito.any())).thenReturn(nether);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(iwm.getNetherSpawnRadius(Mockito.any())).thenReturn(100);
when(plugin.getIWM()).thenReturn(iwm);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// Settings // Settings
s = mock(Settings.class); s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s); when(plugin.getSettings()).thenReturn(s);
@ -100,7 +109,6 @@ public class NetherPortalsTest {
Location netherSpawn = mock(Location.class); Location netherSpawn = mock(Location.class);
when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0)); when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0));
when(nether.getSpawnLocation()).thenReturn(netherSpawn); when(nether.getSpawnLocation()).thenReturn(netherSpawn);
when(s.getNetherSpawnRadius()).thenReturn(100);
// Player // Player
Player p = mock(Player.class); Player p = mock(Player.class);
@ -146,9 +154,6 @@ public class NetherPortalsTest {
@Test @Test
public void testNetherPortals() { public void testNetherPortals() {
assertNotNull(new NetherPortals(plugin)); assertNotNull(new NetherPortals(plugin));
Mockito.verify(iwm).getIslandWorld();
Mockito.verify(iwm).getNetherWorld();
Mockito.verify(iwm).getEndWorld();
} }
/** /**
@ -166,7 +171,9 @@ public class NetherPortalsTest {
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// not op, but not in right world // not op, but not in right world
when(player.isOp()).thenReturn(false); when(player.isOp()).thenReturn(false);
when(player.getWorld()).thenReturn(mock(World.class)); World w = mock(World.class);
when(w.getEnvironment()).thenReturn(Environment.NORMAL);
when(player.getWorld()).thenReturn(w);
np.onBlockBreak(e); np.onBlockBreak(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// not op, island world // not op, island world
@ -175,12 +182,12 @@ public class NetherPortalsTest {
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// Nether, but not standard nether // Nether, but not standard nether
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(true); when(iwm.isNetherIslands(Mockito.any())).thenReturn(true);
np.onBlockBreak(e); np.onBlockBreak(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// End, but not standard end // End, but not standard end
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isEndIslands()).thenReturn(true); when(iwm.isEndIslands(Mockito.any())).thenReturn(true);
np.onBlockBreak(e); np.onBlockBreak(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -199,7 +206,7 @@ public class NetherPortalsTest {
Player player = mock(Player.class); Player player = mock(Player.class);
// Standard nether // Standard nether
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
BlockBreakEvent e = new BlockBreakEvent(block, player); BlockBreakEvent e = new BlockBreakEvent(block, player);
np.onBlockBreak(e); np.onBlockBreak(e);
@ -220,7 +227,7 @@ public class NetherPortalsTest {
Player player = mock(Player.class); Player player = mock(Player.class);
// Standard nether // Standard nether
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
BlockBreakEvent e = new BlockBreakEvent(block, player); BlockBreakEvent e = new BlockBreakEvent(block, player);
np.onBlockBreak(e); np.onBlockBreak(e);
@ -242,7 +249,7 @@ public class NetherPortalsTest {
Player player = mock(Player.class); Player player = mock(Player.class);
// Standard nether // Standard nether
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, null, null, null); PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, null, null, null);
np.onBucketEmpty(e); np.onBucketEmpty(e);
@ -262,19 +269,6 @@ public class NetherPortalsTest {
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
/**
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/
@Test
public void testOnEndIslandPortalNoEnd() {
NetherPortals np = new NetherPortals(plugin);
// Right cause, no end
PlayerPortalEvent e = new PlayerPortalEvent(null, null, null, null, TeleportCause.END_PORTAL);
when(s.isEndGenerate()).thenReturn(false);
np.onEndIslandPortal(e);
assertFalse(e.isCancelled());
}
/** /**
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}. * Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onEndIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}.
*/ */
@ -287,7 +281,7 @@ public class NetherPortalsTest {
when(loc.getWorld()).thenReturn(mock(World.class)); when(loc.getWorld()).thenReturn(mock(World.class));
when(iwm.inWorld(any())).thenReturn(false); when(iwm.inWorld(any())).thenReturn(false);
PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL);
when(s.isEndGenerate()).thenReturn(true); when(iwm.isEndGenerate(world)).thenReturn(true);
np.onEndIslandPortal(e); np.onEndIslandPortal(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -308,7 +302,7 @@ public class NetherPortalsTest {
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
// Right cause, end exists, right world // Right cause, end exists, right world
PlayerPortalEvent e = new PlayerPortalEvent(player, from, null, null, TeleportCause.END_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(player, from, null, null, TeleportCause.END_PORTAL);
when(s.isEndGenerate()).thenReturn(true); when(iwm.isEndGenerate(world)).thenReturn(true);
np.onEndIslandPortal(e); np.onEndIslandPortal(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// Give player an island // Give player an island
@ -408,14 +402,14 @@ public class NetherPortalsTest {
// In world, in nether, nether islands // In world, in nether, nether islands
when(from.getWorld()).thenReturn(nether); when(from.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(true); when(iwm.isNetherIslands(world)).thenReturn(true);
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0); EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
assertFalse(np.onExplosion(e)); assertFalse(np.onExplosion(e));
// In world, in end, end islands // In world, in end, end islands
when(from.getWorld()).thenReturn(end); when(from.getWorld()).thenReturn(end);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
when(s.isEndIslands()).thenReturn(true); when(iwm.isEndIslands(world)).thenReturn(true);
assertFalse(np.onExplosion(e)); assertFalse(np.onExplosion(e));
} }
@ -435,7 +429,7 @@ public class NetherPortalsTest {
Location from = mock(Location.class); Location from = mock(Location.class);
// In world, in nether, nether islands // In world, in nether, nether islands
when(from.getWorld()).thenReturn(nether); when(from.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
EntityExplodeEvent e = new EntityExplodeEvent(null, from, affectedBlocks, 0); EntityExplodeEvent e = new EntityExplodeEvent(null, from, affectedBlocks, 0);
assertFalse(np.onExplosion(e)); assertFalse(np.onExplosion(e));
} }
@ -459,7 +453,7 @@ public class NetherPortalsTest {
// In world, in nether, standard nether, null entity // In world, in nether, standard nether, null entity
when(from.getWorld()).thenReturn(nether); when(from.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0); EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
// Real entity, away from spawn // Real entity, away from spawn
@ -487,7 +481,7 @@ public class NetherPortalsTest {
when(from.getWorld()).thenReturn(mock(World.class)); when(from.getWorld()).thenReturn(mock(World.class));
// In world, in nether, standard nether, null entity // In world, in nether, standard nether, null entity
when(from.getWorld()).thenReturn(nether); when(from.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
// Real entity, next to spawn // Real entity, next to spawn
@ -538,7 +532,8 @@ public class NetherPortalsTest {
when(from.toVector()).thenReturn(new Vector(1,2,3)); when(from.toVector()).thenReturn(new Vector(1,2,3));
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
// Nether islands active // Nether islands active
when(s.isNetherIslands()).thenReturn(true); when(iwm.isNetherIslands(world)).thenReturn(true);
when(iwm.isNetherGenerate(world)).thenReturn(true);
assertTrue(np.onNetherPortal(e)); assertTrue(np.onNetherPortal(e));
// Verify // Verify
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
@ -560,7 +555,8 @@ public class NetherPortalsTest {
when(from.toVector()).thenReturn(new Vector(1,2,3)); when(from.toVector()).thenReturn(new Vector(1,2,3));
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
// Nether islands inactive // Nether islands inactive
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
when(iwm.isNetherGenerate(world)).thenReturn(true);
assertTrue(np.onNetherPortal(e)); assertTrue(np.onNetherPortal(e));
// Verify // Verify
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
@ -571,19 +567,24 @@ public class NetherPortalsTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onNetherPortal(org.bukkit.event.player.PlayerPortalEvent)}. * Test method for {@link us.tastybento.bskyblock.listeners.NetherPortals#onNetherPortal(org.bukkit.event.player.PlayerPortalEvent)}.
* @throws Exception
*/ */
@Test @Test
public void testOnNetherPortalFromNetherStandard() { public void testOnNetherPortalFromNetherStandard() throws Exception {
NetherPortals np = new NetherPortals(plugin); NetherPortals np = new NetherPortals(plugin);
Location from = mock(Location.class); Location from = mock(Location.class);
// Teleport from nether to world // Teleport from nether to world
when(from.getWorld()).thenReturn(nether); when(from.getWorld()).thenReturn(nether);
when(from.toVector()).thenReturn(new Vector(1,2,3)); when(from.toVector()).thenReturn(new Vector(1,2,3));
Player player = mock(Player.class); Player p = mock(Player.class);
when(player.getUniqueId()).thenReturn(UUID.randomUUID()); when(p.getUniqueId()).thenReturn(UUID.randomUUID());
PlayerPortalEvent e = new PlayerPortalEvent(player, from, null, null, TeleportCause.NETHER_PORTAL);
PlayerPortalEvent e = new PlayerPortalEvent(p, from, null, null, TeleportCause.NETHER_PORTAL);
// Nether islands inactive // Nether islands inactive
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
when(iwm.isNetherGenerate(world)).thenReturn(true);
// Player should be teleported to their island
assertTrue(np.onNetherPortal(e)); assertTrue(np.onNetherPortal(e));
// Verify // Verify
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
@ -604,7 +605,8 @@ public class NetherPortalsTest {
when(from.toVector()).thenReturn(new Vector(1,2,3)); when(from.toVector()).thenReturn(new Vector(1,2,3));
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
// Nether islands active // Nether islands active
when(s.isNetherIslands()).thenReturn(true); when(iwm.isNetherIslands(world)).thenReturn(true);
when(iwm.isNetherGenerate(world)).thenReturn(true);
assertTrue(np.onNetherPortal(e)); assertTrue(np.onNetherPortal(e));
// Verify // Verify
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
@ -627,8 +629,8 @@ public class NetherPortalsTest {
Player player = mock(Player.class); Player player = mock(Player.class);
// Standard nether // Standard nether
when(player.getWorld()).thenReturn(nether); when(player.getWorld()).thenReturn(nether);
when(s.isNetherIslands()).thenReturn(false); when(iwm.isNetherIslands(world)).thenReturn(false);
when(iwm.isNetherGenerate(world)).thenReturn(true);
BlockPlaceEvent e = new BlockPlaceEvent(block, null, block, null, player, false, null); BlockPlaceEvent e = new BlockPlaceEvent(block, null, block, null, player, false, null);
np.onPlayerBlockPlace(e); np.onPlayerBlockPlace(e);
Mockito.verify(block).getLocation(); Mockito.verify(block).getLocation();
@ -659,13 +661,14 @@ public class NetherPortalsTest {
blocks.add(leaves2); blocks.add(leaves2);
StructureGrowEvent e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); StructureGrowEvent e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
// No nether trees // No nether trees
when(s.isNetherTrees()).thenReturn(false); when(iwm.isNetherTrees(world)).thenReturn(false);
assertFalse(np.onTreeGrow(e)); assertFalse(np.onTreeGrow(e));
// nether trees, wrong world // nether trees, wrong world
e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
when(s.isNetherTrees()).thenReturn(true); when(iwm.isNetherTrees(world)).thenReturn(true);
assertFalse(np.onTreeGrow(e)); assertFalse(np.onTreeGrow(e));
// Make the world nether // Make the world nether
when(iwm.isNetherTrees(nether)).thenReturn(true);
when(loc.getWorld()).thenReturn(nether); when(loc.getWorld()).thenReturn(nether);
e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks); e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
assertTrue(np.onTreeGrow(e)); assertTrue(np.onTreeGrow(e));

View File

@ -96,7 +96,7 @@ public class ObsidianToLavaTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);

View File

@ -49,9 +49,10 @@ import us.tastybento.bskyblock.managers.FlagsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.LocalesManager;
import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( {BSkyBlock.class, Flags.class} ) @PrepareForTest( {BSkyBlock.class, Flags.class, Util.class} )
public class FireListenerTest { public class FireListenerTest {
private static Location location; private static Location location;
@ -99,12 +100,15 @@ public class FireListenerTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// Monsters and animals // Monsters and animals
zombie = mock(Zombie.class); zombie = mock(Zombie.class);

View File

@ -104,12 +104,12 @@ public class MobSpawnListenerTest {
public void setUp() { public void setUp() {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);
when(iwm.inWorld(any(Location.class))).thenReturn(true); when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
} }

View File

@ -121,7 +121,7 @@ public class FlyingMobEventsTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
} }

View File

@ -151,11 +151,14 @@ public class IslandsManagerTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
} }
@ -378,7 +381,7 @@ public class IslandsManagerTest {
when(plugin.getSettings()).thenReturn(settings); when(plugin.getSettings()).thenReturn(settings);
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
@ -700,10 +703,10 @@ public class IslandsManagerTest {
*/ */
@Test @Test
public void testGetClosestIsland() throws Exception { public void testGetClosestIsland() throws Exception {
when(s.getIslandDistance()).thenReturn(100); when(iwm.getIslandDistance(world)).thenReturn(100);
when(s.getIslandXOffset()).thenReturn(0); when(iwm.getIslandXOffset(world)).thenReturn(0);
when(s.getIslandZOffset()).thenReturn(0); when(iwm.getIslandZOffset(world)).thenReturn(0);
when(s.getIslandHeight()).thenReturn(120); when(iwm.getIslandHeight(world)).thenReturn(120);
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
when(location.getBlockX()).thenReturn(456); when(location.getBlockX()).thenReturn(456);
when(location.getBlockZ()).thenReturn(456); when(location.getBlockZ()).thenReturn(456);

View File

@ -83,7 +83,7 @@ public class PlayersManagerTest {
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(nether); when(iwm.getNetherWorld()).thenReturn(nether);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Settings // Settings
s = mock(Settings.class); s = mock(Settings.class);

View File

@ -18,6 +18,8 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -30,6 +32,7 @@ import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest(Util.class)
public class IslandCacheTest { public class IslandCacheTest {
BSkyBlock plugin; BSkyBlock plugin;
@ -48,11 +51,14 @@ public class IslandCacheTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIslandWorldManager()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any())).thenReturn(true);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// Mock up IslandsManager // Mock up IslandsManager
IslandsManager im = mock(IslandsManager.class); IslandsManager im = mock(IslandsManager.class);

View File

@ -32,6 +32,7 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager; import us.tastybento.bskyblock.managers.LocalesManager;
@ -91,6 +92,11 @@ public class SafeSpotTeleportTest {
when(settings.getIslandProtectionRange()).thenReturn(1); when(settings.getIslandProtectionRange()).thenReturn(1);
when(plugin.getSettings()).thenReturn(settings); when(plugin.getSettings()).thenReturn(settings);
// Island world manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(1);
when(plugin.getIWM()).thenReturn(iwm);
// Server & Scheduler // Server & Scheduler
sch = mock(BukkitScheduler.class); sch = mock(BukkitScheduler.class);
when(server.getScheduler()).thenReturn(sch); when(server.getScheduler()).thenReturn(sch);