mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 19:55:17 +01:00
More multi-world work.
This handles multiworld operation. Test with AcidIsland addon.
This commit is contained in:
parent
82ee6d746e
commit
6a18cc4ccc
@ -4,11 +4,13 @@ import org.bukkit.World;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
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.user.Notifier;
|
||||
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||
import us.tastybento.bskyblock.database.BSBDbSetup;
|
||||
import us.tastybento.bskyblock.listeners.BlockEndDragon;
|
||||
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
||||
import us.tastybento.bskyblock.listeners.NetherPortals;
|
||||
import us.tastybento.bskyblock.listeners.ObsidianToLava;
|
||||
@ -155,6 +157,8 @@ public class BSkyBlock extends JavaPlugin {
|
||||
manager.registerEvents(new ObsidianToLava(this), this);
|
||||
// Flying mobs protection
|
||||
manager.registerEvents(new FlyingMobEvents(this), this);
|
||||
// End dragon blocking
|
||||
manager.registerEvents(new BlockEndDragon(this), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -269,7 +273,7 @@ public class BSkyBlock extends JavaPlugin {
|
||||
/**
|
||||
* @return the Island World Manager
|
||||
*/
|
||||
public IslandWorldManager getIslandWorldManager() {
|
||||
public IslandWorldManager getIWM() {
|
||||
return islandWorldManager;
|
||||
}
|
||||
|
||||
@ -310,10 +314,11 @@ public class BSkyBlock extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
islandWorldManager.addWorld(name, world);
|
||||
public void registerWorld(World world, WorldSettings worldSettings) {
|
||||
islandWorldManager.addWorld(world, worldSettings);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import us.tastybento.bskyblock.api.configuration.ConfigComment;
|
||||
import us.tastybento.bskyblock.api.configuration.ConfigEntry;
|
||||
import us.tastybento.bskyblock.api.configuration.ISettings;
|
||||
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.database.BSBDbSetup.DatabaseType;
|
||||
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
|
||||
@ -28,7 +29,7 @@ import us.tastybento.bskyblock.database.objects.adapters.PotionEffectListAdapter
|
||||
* @author Tastybento
|
||||
*/
|
||||
@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";
|
||||
|
||||
@ -87,8 +88,11 @@ public class Settings implements ISettings<Settings> {
|
||||
// ---------------------------------------------
|
||||
|
||||
/* WORLD */
|
||||
@ConfigEntry(path = "world.friendly-name", needsReset = true)
|
||||
private String friendlyName = "BSkyBlock";
|
||||
|
||||
@ConfigEntry(path = "world.world-name", needsReset = true)
|
||||
private String worldName = "BSkyBlock";
|
||||
private String worldName = "BSkyBlock-world";
|
||||
|
||||
@ConfigEntry(path = "world.distance-between-islands", needsReset = true)
|
||||
private int islandDistance = 200;
|
||||
@ -136,16 +140,21 @@ public class Settings implements ISettings<Settings> {
|
||||
|
||||
@ConfigEntry(path = "world.end.islands", needsReset = true)
|
||||
private boolean endIslands = true;
|
||||
|
||||
@ConfigEntry(path = "world.end.dragon-spawn")
|
||||
private boolean dragonSpawn = false;
|
||||
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
/* ISLAND */
|
||||
// Entities
|
||||
@ConfigEntry(path = "island.limits.entities")
|
||||
private Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
|
||||
@ConfigEntry(path = "island.limits.tile-entities")
|
||||
private Map<String, Integer> tileEntityLimits = new HashMap<>();
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
/* ISLAND */
|
||||
|
||||
@ConfigEntry(path = "island.max-team-size")
|
||||
private int maxTeamSize = 4;
|
||||
@ConfigEntry(path = "island.max-homes")
|
||||
@ -685,12 +694,14 @@ public class Settings implements ISettings<Settings> {
|
||||
/**
|
||||
* @return the netherGenerate
|
||||
*/
|
||||
@Override
|
||||
public boolean isNetherGenerate() {
|
||||
return netherGenerate;
|
||||
}
|
||||
/**
|
||||
* @return the netherIslands
|
||||
*/
|
||||
@Override
|
||||
public boolean isNetherIslands() {
|
||||
return netherIslands;
|
||||
}
|
||||
@ -703,6 +714,7 @@ public class Settings implements ISettings<Settings> {
|
||||
/**
|
||||
* @return the netherTrees
|
||||
*/
|
||||
@Override
|
||||
public boolean isNetherTrees() {
|
||||
return netherTrees;
|
||||
}
|
||||
@ -1260,6 +1272,33 @@ public class Settings implements ISettings<Settings> {
|
||||
public void setConfirmationTime(int 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -68,6 +68,9 @@ public class User {
|
||||
* @return user
|
||||
*/
|
||||
public static User getInstance(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
if (users.containsKey(uuid)) {
|
||||
return users.get(uuid);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package us.tastybento.bskyblock.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.teams.IslandTeamCommand;
|
||||
import us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
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);
|
||||
} else if (args.size() == 1) {
|
||||
// Argument should be a world
|
||||
if (getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) {
|
||||
World world = getPlugin().getIslandWorldManager().getWorld(args.get(0));
|
||||
if (getPlugin().getIWM().isOverWorld(args.get(0))) {
|
||||
World world = getPlugin().getIWM().getWorld(args.get(0));
|
||||
if (getPlugin().getIslands().hasIsland(world, user.getUniqueId())) {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class AdminGetRankCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
|
@ -26,7 +26,7 @@ public class AdminInfoCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
if (args.size() > 1 || (args.isEmpty() && !user.isPlayer())) {
|
||||
// Show help
|
||||
|
@ -29,7 +29,7 @@ public class AdminRegisterCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
|
@ -43,7 +43,7 @@ public class AdminSetRankCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
if (args.size() != 2) {
|
||||
// Show help
|
||||
|
@ -31,7 +31,7 @@ public class AdminTeleportCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
if (args.isEmpty()) {
|
||||
this.showHelp(this, user);
|
||||
@ -45,11 +45,11 @@ public class AdminTeleportCommand extends CompositeCommand {
|
||||
return false;
|
||||
} else {
|
||||
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")) {
|
||||
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")) {
|
||||
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
|
||||
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
||||
|
@ -26,7 +26,7 @@ public class AdminUnregisterCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
|
@ -26,7 +26,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
// If args are not right, show help
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
|
@ -25,7 +25,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
|
@ -26,7 +26,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
|
@ -25,7 +25,7 @@ public class AdminTeamMakeLeaderCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// TODO: fix world
|
||||
World world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
World world = getPlugin().getIWM().getIslandWorld();
|
||||
|
||||
// If args are not right, show help
|
||||
if (args.size() != 1) {
|
||||
|
@ -40,12 +40,12 @@ public class IslandCreateCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
World world = null;
|
||||
if (args.size() == 1 && getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) {
|
||||
world = getPlugin().getIslandWorldManager().getWorld(args.get(0));
|
||||
if (args.size() == 1 && getPlugin().getIWM().isOverWorld(args.get(0))) {
|
||||
world = getPlugin().getIWM().getWorld(args.get(0));
|
||||
}
|
||||
if (world == null) {
|
||||
// See which worlds are available
|
||||
Set<String> worldNames = getPlugin().getIslandWorldManager().getFreeOverWorldNames(user);
|
||||
Set<String> worldNames = getPlugin().getIWM().getFreeOverWorldNames(user);
|
||||
if (!worldNames.isEmpty()) {
|
||||
// Make a list of worlds
|
||||
StringBuilder worlds = new StringBuilder();
|
||||
@ -60,7 +60,7 @@ public class IslandCreateCommand extends CompositeCommand {
|
||||
user.sendMessage("commands.island.create.pick-world", "[worlds]", worlds.toString());
|
||||
return false;
|
||||
} else {
|
||||
world = getPlugin().getIslandWorldManager().getIslandWorld();
|
||||
world = getPlugin().getIWM().getIslandWorld();
|
||||
}
|
||||
}
|
||||
if (getIslands().hasIsland(world, user.getUniqueId())) {
|
||||
|
@ -43,12 +43,12 @@ public class IslandGoCommand extends CompositeCommand {
|
||||
World world = user.getWorld();
|
||||
if (!args.isEmpty() && !NumberUtils.isDigits(args.get(0))) {
|
||||
// World?
|
||||
if (getPlugin().getIslandWorldManager().isOverWorld(args.get(0))) {
|
||||
world = getPlugin().getIslandWorldManager().getWorld(args.get(0));
|
||||
if (getPlugin().getIWM().isOverWorld(args.get(0))) {
|
||||
world = getPlugin().getIWM().getWorld(args.get(0));
|
||||
} else {
|
||||
// Make a list of worlds
|
||||
StringBuilder worlds = new StringBuilder();
|
||||
getPlugin().getIslandWorldManager().getOverWorldNames().forEach(w -> {
|
||||
getPlugin().getIWM().getOverWorldNames().forEach(w -> {
|
||||
worlds.append(w);
|
||||
worlds.append(", ");
|
||||
});
|
||||
|
@ -110,7 +110,7 @@ public class Island implements DataObject {
|
||||
updatedDate = System.currentTimeMillis();
|
||||
world = location.getWorld();
|
||||
center = location;
|
||||
range = BSkyBlock.getInstance().getSettings().getIslandDistance();
|
||||
range = BSkyBlock.getInstance().getIWM().getIslandDistance(world);
|
||||
minX = center.getBlockX() - range;
|
||||
minZ = center.getBlockZ() - range;
|
||||
this.protectionRange = protectionRange;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ import java.util.Iterator;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -24,20 +25,15 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
import us.tastybento.bskyblock.util.teleport.SafeTeleportBuilder;
|
||||
|
||||
public class NetherPortals implements Listener {
|
||||
private static final String ERROR_NO_PERMISSION = "general.errors.no-permission";
|
||||
private final BSkyBlock plugin;
|
||||
private World world;
|
||||
private World nether;
|
||||
private World theEnd;
|
||||
|
||||
public NetherPortals(BSkyBlock 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) {
|
||||
Vector p = location.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
|
||||
* @param player - the player
|
||||
* @return true if nothing needs to be done
|
||||
*/
|
||||
private boolean noAction(Player player) {
|
||||
return (player.isOp()
|
||||
|| (!player.getWorld().equals(nether) && !player.getWorld().equals(theEnd))
|
||||
|| (player.getWorld().equals(nether) && plugin.getSettings().isNetherIslands())
|
||||
|| (player.getWorld().equals(theEnd) && plugin.getSettings().isEndIslands())) ? true: false;
|
||||
if (player.isOp()
|
||||
|| player.getWorld().getEnvironment().equals(Environment.NORMAL)
|
||||
|| !plugin.getIWM().inWorld(player.getLocation())) {
|
||||
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)
|
||||
public void onEndIslandPortal(PlayerPortalEvent e) {
|
||||
if (!e.getCause().equals(TeleportCause.END_PORTAL) || !plugin.getSettings().isEndGenerate()) {
|
||||
return;
|
||||
}
|
||||
if (!plugin.getIslandWorldManager().inWorld(e.getFrom())) {
|
||||
if (!e.getCause().equals(TeleportCause.END_PORTAL) || !plugin.getIWM().inWorld(e.getFrom())) {
|
||||
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 (e.getFrom().getWorld().equals(theEnd)) {
|
||||
if (plugin.getIslands().hasIsland(e.getPlayer().getWorld(), e.getPlayer().getUniqueId())) {
|
||||
if (e.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
|
||||
if (plugin.getIslands().hasIsland(overWorld, e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
plugin.getIslands().homeTeleport(e.getPlayer().getWorld(), e.getPlayer());
|
||||
plugin.getIslands().homeTeleport(overWorld, e.getPlayer());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// If this is island end, then go to the same location, otherwise try spawn
|
||||
Location to = plugin.getSettings().isEndIslands() ? e.getFrom().toVector().toLocation(theEnd) : theEnd.getSpawnLocation();
|
||||
// Else other worlds teleport to the end
|
||||
e.setCancelled(true);
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.build();
|
||||
// Going to the end, then go to the same location in the end world
|
||||
if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) {
|
||||
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
||||
// End exists and end islands are being used
|
||||
e.setCancelled(true);
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(e.getFrom().toVector().toLocation(endWorld))
|
||||
.build();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ public class NetherPortals implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
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
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -149,11 +150,9 @@ public class NetherPortals implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public boolean onExplosion(EntityExplodeEvent e) {
|
||||
if (!plugin.getIslandWorldManager().inWorld(e.getLocation())) {
|
||||
return false;
|
||||
}
|
||||
if ((e.getLocation().getWorld().equals(nether) && plugin.getSettings().isNetherIslands())
|
||||
|| (e.getLocation().getWorld().equals(theEnd) && plugin.getSettings().isEndIslands())) {
|
||||
if (!plugin.getIWM().inWorld(e.getLocation())
|
||||
|| plugin.getIWM().isIslandNether(e.getLocation().getWorld())
|
||||
|| plugin.getIWM().isIslandEnd(e.getLocation().getWorld())) {
|
||||
// Not used in island worlds
|
||||
return false;
|
||||
}
|
||||
@ -178,13 +177,17 @@ public class NetherPortals implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
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;
|
||||
}
|
||||
// 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 (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
|
||||
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);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
@ -194,8 +197,11 @@ public class NetherPortals implements Listener {
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
// If this is island nether, then go to the same vector, otherwise try spawn
|
||||
Location to = plugin.getSettings().isNetherIslands() ? e.getFrom().toVector().toLocation(nether) : nether.getSpawnLocation();
|
||||
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
||||
// 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);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
@ -229,7 +235,7 @@ public class NetherPortals implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
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;
|
||||
}
|
||||
for (BlockState b : e.getBlocks()) {
|
||||
|
@ -44,7 +44,7 @@ public class ObsidianToLava implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public boolean onPlayerInteract(final PlayerInteractEvent e) {
|
||||
if (!plugin.getSettings().isAllowObsidianScooping()
|
||||
|| !plugin.getIslandWorldManager().inWorld(e.getPlayer().getLocation())
|
||||
|| !plugin.getIWM().inWorld(e.getPlayer().getLocation())
|
||||
|| !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
|
||||
|| !e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|
||||
|| !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET))
|
||||
|
@ -124,10 +124,9 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
*/
|
||||
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
|
||||
// If this is not an Island World, skip
|
||||
if (!plugin.getIslandWorldManager().inWorld(loc)) {
|
||||
if (!plugin.getIWM().inWorld(loc)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the island and if present
|
||||
Optional<Island> island = getIslands().getIslandAt(loc);
|
||||
// Handle Settings Flag
|
||||
@ -137,7 +136,6 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
}
|
||||
|
||||
// Protection flag
|
||||
|
||||
// If the user is not set already, try to get it from the event
|
||||
if (user == null) {
|
||||
// Set the user associated with this event
|
||||
@ -195,6 +193,6 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
* @return Island World Manager
|
||||
*/
|
||||
protected IslandWorldManager getIslandWorldManager() {
|
||||
return plugin.getIslandWorldManager();
|
||||
return plugin.getIWM();
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ public class PVPListener extends AbstractFlagListener {
|
||||
public void onEntityDamage(final EntityDamageByEntityEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
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;
|
||||
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||
} else if (e.getEntity().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
|
||||
flag = Flags.PVP_END;
|
||||
}
|
||||
respond(e, e.getDamager(), flag);
|
||||
@ -74,9 +74,9 @@ public class PVPListener extends AbstractFlagListener {
|
||||
public void onFishing(PlayerFishEvent e) {
|
||||
if (e.getCaught() != null && e.getCaught() instanceof Player) {
|
||||
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;
|
||||
} else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||
} else if (e.getCaught().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
|
||||
flag = Flags.PVP_END;
|
||||
}
|
||||
if (checkIsland(e, e.getCaught().getLocation(), flag)) {
|
||||
@ -93,9 +93,9 @@ public class PVPListener extends AbstractFlagListener {
|
||||
public void onSplashPotionSplash(final PotionSplashEvent e) {
|
||||
// Deduce the world
|
||||
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;
|
||||
} else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||
} else if (e.getPotion().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
|
||||
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())) {
|
||||
// Deduce the world
|
||||
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;
|
||||
} else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) {
|
||||
} else if (e.getEntity().getWorld().equals(getPlugin().getIWM().getEndWorld())) {
|
||||
flag = Flags.PVP_END;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class FlyingMobEvents implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onMobSpawn(CreatureSpawnEvent e) {
|
||||
// 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.GHAST))) {
|
||||
return;
|
||||
@ -87,7 +87,7 @@ public class FlyingMobEvents implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public boolean onMobExplosion(EntityExplodeEvent e) {
|
||||
// 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;
|
||||
}
|
||||
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)
|
||||
public boolean onWitherExplode(ExplosionPrimeEvent e) {
|
||||
// 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;
|
||||
}
|
||||
// The wither or wither skulls can both blow up
|
||||
@ -139,7 +139,7 @@ public class FlyingMobEvents implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onWitherChangeBlocks(EntityChangeBlockEvent e) {
|
||||
// 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;
|
||||
}
|
||||
if (mobSpawnInfo.containsKey(e.getEntity())) {
|
||||
|
@ -9,13 +9,21 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.configuration.WorldSettings;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.generators.ChunkGeneratorWorld;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* Handles registration and management of worlds
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class IslandWorldManager {
|
||||
|
||||
private static final String MULTIVERSE_SET_GENERATOR = "mv modify set generator ";
|
||||
@ -29,6 +37,7 @@ public class IslandWorldManager {
|
||||
private World netherWorld;
|
||||
private World endWorld;
|
||||
private Map<World, String> worlds;
|
||||
private Map<World, WorldSettings> worldSettings;
|
||||
|
||||
/**
|
||||
* Generates the Skyblock worlds.
|
||||
@ -36,6 +45,7 @@ public class IslandWorldManager {
|
||||
public IslandWorldManager(BSkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
worlds = new HashMap<>();
|
||||
worldSettings = new HashMap<>();
|
||||
if (plugin.getSettings().isUseOwnGenerator()) {
|
||||
// Do nothing
|
||||
return;
|
||||
@ -46,7 +56,7 @@ public class IslandWorldManager {
|
||||
// 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))
|
||||
.createWorld();
|
||||
addWorld("bsb", islandWorld);
|
||||
addWorld(islandWorld, plugin.getSettings());
|
||||
// Make the nether if it does not exist
|
||||
if (plugin.getSettings().isNetherGenerate()) {
|
||||
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))
|
||||
.environment(World.Environment.NETHER).createWorld();
|
||||
}
|
||||
addWorld("bsb_nether", netherWorld);
|
||||
}
|
||||
// Make the end if it does not exist
|
||||
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))
|
||||
.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
|
||||
*/
|
||||
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
|
||||
* @param friendlyName - string
|
||||
* @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);
|
||||
worlds.put(world, friendlyName);
|
||||
worldSettings.put(world, settings);
|
||||
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.
|
||||
@ -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 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public class IslandsManager {
|
||||
* @return Island or null if the island could not be created for some reason
|
||||
*/
|
||||
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)) {
|
||||
return island;
|
||||
}
|
||||
@ -596,11 +596,10 @@ public class IslandsManager {
|
||||
* @return Location of closest island
|
||||
*/
|
||||
public Location getClosestIsland(Location location) {
|
||||
long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance())
|
||||
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset();
|
||||
long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance())
|
||||
* plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset();
|
||||
long y = plugin.getSettings().getIslandHeight();
|
||||
int dist = plugin.getIWM().getIslandDistance(location.getWorld());
|
||||
long x = Math.round((double) location.getBlockX() / dist) * dist + plugin.getIWM().getIslandXOffset(location.getWorld());
|
||||
long z = Math.round((double) location.getBlockZ() / dist) * dist + plugin.getIWM().getIslandZOffset(location.getWorld());
|
||||
long y = plugin.getIWM().getIslandHeight(location.getWorld());
|
||||
if (location.getBlockX() == x && location.getBlockZ() == z) {
|
||||
return location;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
public class IslandCache {
|
||||
private BiMap<Location, Island> islandsByLocation;
|
||||
@ -25,13 +26,11 @@ public class IslandCache {
|
||||
*/
|
||||
private Map<World, Map<UUID, Island>> islandsByUUID;
|
||||
private Map<World, IslandGrid> grids;
|
||||
private IslandGrid defaultGrid;
|
||||
|
||||
public IslandCache() {
|
||||
islandsByLocation = HashBiMap.create();
|
||||
islandsByUUID = new HashMap<>();
|
||||
grids = new HashMap<>();
|
||||
defaultGrid = new IslandGrid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +64,8 @@ public class IslandCache {
|
||||
* @return true if successfully added, false if not
|
||||
*/
|
||||
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() {
|
||||
@ -90,7 +90,8 @@ public class IslandCache {
|
||||
}
|
||||
}
|
||||
// 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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public Island getIslandAt(Location location) {
|
||||
if (location == null) {
|
||||
if (location == null || !grids.containsKey(Util.getWorld(location.getWorld()))) {
|
||||
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() {
|
||||
@ -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
|
||||
*/
|
||||
public Set<UUID> getMembers(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||
Island island = islandsByUUID.get(world).get(uuid);
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
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
|
||||
*/
|
||||
public UUID getTeamLeader(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||
Island island = islandsByUUID.get(world).get(uuid);
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
return island.getOwner();
|
||||
}
|
||||
@ -164,8 +165,8 @@ public class IslandCache {
|
||||
* @return true if player has island and owns it
|
||||
*/
|
||||
public boolean hasIsland(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||
Island island = islandsByUUID.get(world).get(uuid);
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
return island.getOwner().equals(uuid);
|
||||
}
|
||||
@ -178,8 +179,8 @@ public class IslandCache {
|
||||
* @param playerUUID - player's UUID
|
||||
*/
|
||||
public void removePlayer(World world, UUID uuid) {
|
||||
islandsByUUID.putIfAbsent(world, new HashMap<>());
|
||||
Island island = islandsByUUID.get(world).get(uuid);
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(world), new HashMap<>());
|
||||
Island island = islandsByUUID.get(Util.getWorld(world)).get(uuid);
|
||||
if (island != null) {
|
||||
if (island.getOwner() != null && island.getOwner().equals(uuid)) {
|
||||
// Clear ownership and members
|
||||
@ -190,7 +191,7 @@ public class IslandCache {
|
||||
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) {
|
||||
island.setOwner(newOwnerUUID);
|
||||
islandsByUUID.putIfAbsent(island.getWorld(), new HashMap<>());
|
||||
islandsByUUID.get(island.getWorld()).put(newOwnerUUID, island);
|
||||
islandsByUUID.putIfAbsent(Util.getWorld(island.getWorld()), new HashMap<>());
|
||||
islandsByUUID.get(Util.getWorld(island.getWorld())).put(newOwnerUUID, island);
|
||||
islandsByLocation.put(island.getCenter(), island);
|
||||
}
|
||||
|
||||
|
@ -125,14 +125,14 @@ public class NewIsland {
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
.setType(IslandType.ISLAND)
|
||||
.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)
|
||||
.setPlayer(user.getPlayer())
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
.setType(IslandType.NETHER)
|
||||
.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)
|
||||
.setPlayer(user.getPlayer())
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
@ -169,8 +169,8 @@ public class NewIsland {
|
||||
private Location getNextIsland() {
|
||||
Location last = plugin.getIslands().getLast(world);
|
||||
if (last == null) {
|
||||
last = new Location(world, plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(),
|
||||
plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ());
|
||||
last = new Location(world, plugin.getIWM().getIslandXOffset(world) + plugin.getIWM().getIslandStartX(world),
|
||||
plugin.getIWM().getIslandHeight(world), plugin.getIWM().getIslandZOffset(world) + plugin.getIWM().getIslandStartZ(world));
|
||||
}
|
||||
Location next = last.clone();
|
||||
while (plugin.getIslands().isIsland(next)) {
|
||||
@ -189,28 +189,29 @@ public class NewIsland {
|
||||
private Location nextGridLocation(final Location lastIsland) {
|
||||
int x = lastIsland.getBlockX();
|
||||
int z = lastIsland.getBlockZ();
|
||||
int d = plugin.getIWM().getIslandDistance(lastIsland.getWorld()) * 2;
|
||||
Location nextPos = lastIsland;
|
||||
if (x < z) {
|
||||
if (-1 * x < z) {
|
||||
nextPos.setX(nextPos.getX() + plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setX(nextPos.getX() + d);
|
||||
return nextPos;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setZ(nextPos.getZ() + d);
|
||||
return nextPos;
|
||||
}
|
||||
if (x > z) {
|
||||
if (-1 * x >= z) {
|
||||
nextPos.setX(nextPos.getX() - plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setX(nextPos.getX() - d);
|
||||
return nextPos;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setZ(nextPos.getZ() - d);
|
||||
return nextPos;
|
||||
}
|
||||
if (x <= 0) {
|
||||
nextPos.setZ(nextPos.getZ() + plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setZ(nextPos.getZ() + d);
|
||||
return nextPos;
|
||||
}
|
||||
nextPos.setZ(nextPos.getZ() - plugin.getSettings().getIslandDistance()*2);
|
||||
nextPos.setZ(nextPos.getZ() - d);
|
||||
return nextPos;
|
||||
}
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ public class DeleteIslandChunks {
|
||||
for (int z = minZChunk; z<=maxZChunk; z++) {
|
||||
world.regenerateChunk(x, z);
|
||||
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()) {
|
||||
plugin.getIslandWorldManager().getEndWorld().regenerateChunk(x, z);
|
||||
plugin.getIWM().getEndWorld().regenerateChunk(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -227,5 +228,14 @@ public class Util {
|
||||
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", ""));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class SafeSpotTeleport {
|
||||
List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
// Get island if available
|
||||
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;
|
||||
|
||||
int x = location.getBlockX();
|
||||
|
@ -66,7 +66,7 @@ import us.tastybento.bskyblock.managers.RanksManager;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ BSkyBlock.class, Flags.class})
|
||||
@PrepareForTest({ BSkyBlock.class, Flags.class, Util.class})
|
||||
public class TestBSkyBlock {
|
||||
private static final UUID MEMBER_UUID = UUID.randomUUID();
|
||||
private static final UUID OWNER_UUID = UUID.randomUUID();
|
||||
@ -142,12 +142,13 @@ public class TestBSkyBlock {
|
||||
|
||||
// Worlds
|
||||
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.getNetherWorld()).thenReturn(world);
|
||||
Mockito.when(iwm.getEndWorld()).thenReturn(world);
|
||||
when(iwm.inWorld(any())).thenReturn(true);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
// Islands
|
||||
IslandsManager im = mock(IslandsManager.class);
|
||||
|
@ -454,6 +454,7 @@ public class UserTest {
|
||||
Mockito.verify(pl).performCommand("test");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unlikely-arg-type")
|
||||
@Test
|
||||
public void testEqualsObject() {
|
||||
User user1 = User.getInstance(UUID.randomUUID());
|
||||
@ -463,15 +464,11 @@ public class UserTest {
|
||||
assertFalse(user1.equals(null));
|
||||
assertFalse(user2.equals(user1));
|
||||
assertFalse(user2.equals(null));
|
||||
assertFalse(user2.equals("an string"));
|
||||
assertFalse(user2.equals("a string"));
|
||||
|
||||
user1 = User.getInstance((UUID)null);
|
||||
assertFalse(user1.equals(user2));
|
||||
assertFalse(user2.equals(user1));
|
||||
|
||||
user2 = User.getInstance((UUID)null);
|
||||
assertTrue(user1.equals(user2));
|
||||
assertTrue(user2.equals(user1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -79,7 +79,7 @@ public class IslandCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getWorld(Mockito.anyString())).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,7 +96,7 @@ public class AdminInfoCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -97,7 +97,7 @@ public class AdminRegisterCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -96,7 +96,7 @@ public class AdminUnregisterCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -118,7 +118,7 @@ public class AdminTeamAddCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class AdminTeamDisbandCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -97,7 +97,7 @@ public class AdminTeamKickCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -95,7 +95,7 @@ public class AdminTeamMakeLeaderCommandTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
World world = mock(World.class);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -84,14 +85,22 @@ public class NetherPortalsTest {
|
||||
// island world mgr
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
world = mock(World.class);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
nether = mock(World.class);
|
||||
when(nether.getEnvironment()).thenReturn(Environment.NETHER);
|
||||
when(nether.getSpawnLocation()).thenReturn(mock(Location.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.getNetherWorld()).thenReturn(nether);
|
||||
when(iwm.getNetherWorld(Mockito.any())).thenReturn(nether);
|
||||
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
|
||||
s = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -100,7 +109,6 @@ public class NetherPortalsTest {
|
||||
Location netherSpawn = mock(Location.class);
|
||||
when(netherSpawn.toVector()).thenReturn(new Vector(0,0,0));
|
||||
when(nether.getSpawnLocation()).thenReturn(netherSpawn);
|
||||
when(s.getNetherSpawnRadius()).thenReturn(100);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
@ -146,9 +154,6 @@ public class NetherPortalsTest {
|
||||
@Test
|
||||
public void testNetherPortals() {
|
||||
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());
|
||||
// not op, but not in right world
|
||||
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);
|
||||
assertFalse(e.isCancelled());
|
||||
// not op, island world
|
||||
@ -175,12 +182,12 @@ public class NetherPortalsTest {
|
||||
assertFalse(e.isCancelled());
|
||||
// Nether, but not standard nether
|
||||
when(player.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(true);
|
||||
when(iwm.isNetherIslands(Mockito.any())).thenReturn(true);
|
||||
np.onBlockBreak(e);
|
||||
assertFalse(e.isCancelled());
|
||||
// End, but not standard end
|
||||
when(player.getWorld()).thenReturn(nether);
|
||||
when(s.isEndIslands()).thenReturn(true);
|
||||
when(iwm.isEndIslands(Mockito.any())).thenReturn(true);
|
||||
np.onBlockBreak(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
@ -199,7 +206,7 @@ public class NetherPortalsTest {
|
||||
Player player = mock(Player.class);
|
||||
// Standard nether
|
||||
when(player.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
|
||||
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||
np.onBlockBreak(e);
|
||||
@ -220,7 +227,7 @@ public class NetherPortalsTest {
|
||||
Player player = mock(Player.class);
|
||||
// Standard nether
|
||||
when(player.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
|
||||
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||
np.onBlockBreak(e);
|
||||
@ -242,7 +249,7 @@ public class NetherPortalsTest {
|
||||
Player player = mock(Player.class);
|
||||
// Standard 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);
|
||||
np.onBucketEmpty(e);
|
||||
@ -262,19 +269,6 @@ public class NetherPortalsTest {
|
||||
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)}.
|
||||
*/
|
||||
@ -287,7 +281,7 @@ public class NetherPortalsTest {
|
||||
when(loc.getWorld()).thenReturn(mock(World.class));
|
||||
when(iwm.inWorld(any())).thenReturn(false);
|
||||
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);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
@ -308,7 +302,7 @@ public class NetherPortalsTest {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
// Right cause, end exists, right world
|
||||
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);
|
||||
assertFalse(e.isCancelled());
|
||||
// Give player an island
|
||||
@ -408,14 +402,14 @@ public class NetherPortalsTest {
|
||||
|
||||
// In world, in nether, nether islands
|
||||
when(from.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(true);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(true);
|
||||
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
|
||||
assertFalse(np.onExplosion(e));
|
||||
|
||||
// In world, in end, end islands
|
||||
when(from.getWorld()).thenReturn(end);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(s.isEndIslands()).thenReturn(true);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
when(iwm.isEndIslands(world)).thenReturn(true);
|
||||
assertFalse(np.onExplosion(e));
|
||||
}
|
||||
|
||||
@ -435,7 +429,7 @@ public class NetherPortalsTest {
|
||||
Location from = mock(Location.class);
|
||||
// In world, in nether, nether islands
|
||||
when(from.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
EntityExplodeEvent e = new EntityExplodeEvent(null, from, affectedBlocks, 0);
|
||||
assertFalse(np.onExplosion(e));
|
||||
}
|
||||
@ -459,7 +453,7 @@ public class NetherPortalsTest {
|
||||
|
||||
// In world, in nether, standard nether, null entity
|
||||
when(from.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
|
||||
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
|
||||
// Real entity, away from spawn
|
||||
@ -487,7 +481,7 @@ public class NetherPortalsTest {
|
||||
when(from.getWorld()).thenReturn(mock(World.class));
|
||||
// In world, in nether, standard nether, null entity
|
||||
when(from.getWorld()).thenReturn(nether);
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
|
||||
|
||||
// Real entity, next to spawn
|
||||
@ -538,7 +532,8 @@ public class NetherPortalsTest {
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// Nether islands active
|
||||
when(s.isNetherIslands()).thenReturn(true);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(true);
|
||||
when(iwm.isNetherGenerate(world)).thenReturn(true);
|
||||
assertTrue(np.onNetherPortal(e));
|
||||
// Verify
|
||||
assertTrue(e.isCancelled());
|
||||
@ -560,7 +555,8 @@ public class NetherPortalsTest {
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// Nether islands inactive
|
||||
when(s.isNetherIslands()).thenReturn(false);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(false);
|
||||
when(iwm.isNetherGenerate(world)).thenReturn(true);
|
||||
assertTrue(np.onNetherPortal(e));
|
||||
// Verify
|
||||
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)}.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testOnNetherPortalFromNetherStandard() {
|
||||
public void testOnNetherPortalFromNetherStandard() throws Exception {
|
||||
NetherPortals np = new NetherPortals(plugin);
|
||||
Location from = mock(Location.class);
|
||||
// Teleport from nether to world
|
||||
when(from.getWorld()).thenReturn(nether);
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
Player player = mock(Player.class);
|
||||
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(player, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
Player p = mock(Player.class);
|
||||
when(p.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(p, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// 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));
|
||||
// Verify
|
||||
assertTrue(e.isCancelled());
|
||||
@ -604,7 +605,8 @@ public class NetherPortalsTest {
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
|
||||
// Nether islands active
|
||||
when(s.isNetherIslands()).thenReturn(true);
|
||||
when(iwm.isNetherIslands(world)).thenReturn(true);
|
||||
when(iwm.isNetherGenerate(world)).thenReturn(true);
|
||||
assertTrue(np.onNetherPortal(e));
|
||||
// Verify
|
||||
assertTrue(e.isCancelled());
|
||||
@ -627,8 +629,8 @@ public class NetherPortalsTest {
|
||||
Player player = mock(Player.class);
|
||||
// Standard 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);
|
||||
np.onPlayerBlockPlace(e);
|
||||
Mockito.verify(block).getLocation();
|
||||
@ -659,13 +661,14 @@ public class NetherPortalsTest {
|
||||
blocks.add(leaves2);
|
||||
StructureGrowEvent e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
|
||||
// No nether trees
|
||||
when(s.isNetherTrees()).thenReturn(false);
|
||||
when(iwm.isNetherTrees(world)).thenReturn(false);
|
||||
assertFalse(np.onTreeGrow(e));
|
||||
// nether trees, wrong world
|
||||
e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
|
||||
when(s.isNetherTrees()).thenReturn(true);
|
||||
when(iwm.isNetherTrees(world)).thenReturn(true);
|
||||
assertFalse(np.onTreeGrow(e));
|
||||
// Make the world nether
|
||||
when(iwm.isNetherTrees(nether)).thenReturn(true);
|
||||
when(loc.getWorld()).thenReturn(nether);
|
||||
e = new StructureGrowEvent(loc, TreeType.ACACIA, false, null, blocks);
|
||||
assertTrue(np.onTreeGrow(e));
|
||||
|
@ -96,7 +96,7 @@ public class ObsidianToLavaTest {
|
||||
|
||||
// Worlds
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(world);
|
||||
when(iwm.getEndWorld()).thenReturn(world);
|
||||
|
@ -49,9 +49,10 @@ import us.tastybento.bskyblock.managers.FlagsManager;
|
||||
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( {BSkyBlock.class, Flags.class} )
|
||||
@PrepareForTest( {BSkyBlock.class, Flags.class, Util.class} )
|
||||
public class FireListenerTest {
|
||||
|
||||
private static Location location;
|
||||
@ -99,12 +100,15 @@ public class FireListenerTest {
|
||||
|
||||
// Worlds
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(world);
|
||||
when(iwm.getEndWorld()).thenReturn(world);
|
||||
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
|
||||
zombie = mock(Zombie.class);
|
||||
|
@ -104,12 +104,12 @@ public class MobSpawnListenerTest {
|
||||
public void setUp() {
|
||||
// Worlds
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(world);
|
||||
when(iwm.getEndWorld()).thenReturn(world);
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class FlyingMobEventsTest {
|
||||
|
||||
// Worlds
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.inWorld(any())).thenReturn(true);
|
||||
}
|
||||
|
||||
|
@ -151,11 +151,14 @@ public class IslandsManagerTest {
|
||||
|
||||
// Worlds
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(world);
|
||||
when(iwm.getEndWorld()).thenReturn(world);
|
||||
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);
|
||||
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
|
||||
|
||||
@ -700,10 +703,10 @@ public class IslandsManagerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetClosestIsland() throws Exception {
|
||||
when(s.getIslandDistance()).thenReturn(100);
|
||||
when(s.getIslandXOffset()).thenReturn(0);
|
||||
when(s.getIslandZOffset()).thenReturn(0);
|
||||
when(s.getIslandHeight()).thenReturn(120);
|
||||
when(iwm.getIslandDistance(world)).thenReturn(100);
|
||||
when(iwm.getIslandXOffset(world)).thenReturn(0);
|
||||
when(iwm.getIslandZOffset(world)).thenReturn(0);
|
||||
when(iwm.getIslandHeight(world)).thenReturn(120);
|
||||
IslandsManager im = new IslandsManager(plugin);
|
||||
when(location.getBlockX()).thenReturn(456);
|
||||
when(location.getBlockZ()).thenReturn(456);
|
||||
|
@ -83,7 +83,7 @@ public class PlayersManagerTest {
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(nether);
|
||||
when(iwm.inWorld(any())).thenReturn(true);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Settings
|
||||
s = mock(Settings.class);
|
||||
|
@ -18,6 +18,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -30,6 +32,7 @@ import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(Util.class)
|
||||
public class IslandCacheTest {
|
||||
|
||||
BSkyBlock plugin;
|
||||
@ -48,11 +51,14 @@ public class IslandCacheTest {
|
||||
|
||||
// Worlds
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIslandWorldManager()).thenReturn(iwm);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandWorld()).thenReturn(world);
|
||||
when(iwm.getNetherWorld()).thenReturn(world);
|
||||
when(iwm.getEndWorld()).thenReturn(world);
|
||||
when(iwm.inWorld(any())).thenReturn(true);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
// Mock up IslandsManager
|
||||
IslandsManager im = mock(IslandsManager.class);
|
||||
|
@ -32,6 +32,7 @@ import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.Settings;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||
|
||||
@ -91,6 +92,11 @@ public class SafeSpotTeleportTest {
|
||||
when(settings.getIslandProtectionRange()).thenReturn(1);
|
||||
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
|
||||
sch = mock(BukkitScheduler.class);
|
||||
when(server.getScheduler()).thenReturn(sch);
|
||||
|
Loading…
Reference in New Issue
Block a user