Added default Game Mode to world settings.

https://github.com/tastybento/bskyblock/issues/179

Removed references to acid from settings for BSB.
This commit is contained in:
tastybento 2018-06-24 16:22:44 -07:00
parent 617fc712aa
commit 8125ec52af
11 changed files with 194 additions and 271 deletions

View File

@ -131,6 +131,11 @@ world:
# If the number of islands is greater than this number, no new island will be created. # If the number of islands is greater than this number, no new island will be created.
max-islands: 0 max-islands: 0
# The default game mode for this world. Players will be set to this mode when they create
# a new island for example. Options are SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR
default-game-mode: SURVIVAL
### Nether-related Settings ### ### Nether-related Settings ###
nether: nether:
# Generate Nether - if this is false, the nether world will not be made and access to # Generate Nether - if this is false, the nether world will not be made and access to

View File

@ -1,7 +1,6 @@
package us.tastybento.bskyblock; package us.tastybento.bskyblock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -9,11 +8,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.GameMode;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import us.tastybento.bskyblock.Constants.GameType;
import us.tastybento.bskyblock.api.configuration.ConfigComment; 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.StoreAt; import us.tastybento.bskyblock.api.configuration.StoreAt;
@ -21,8 +19,6 @@ 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.DataObject; import us.tastybento.bskyblock.database.objects.DataObject;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.PotionEffectListAdapter;
/** /**
* All the plugin settings are here * All the plugin settings are here
@ -185,6 +181,11 @@ public class Settings implements DataObject, WorldSettings {
@ConfigEntry(path = "world.max-islands") @ConfigEntry(path = "world.max-islands")
private int maxIslands = -1; private int maxIslands = -1;
@ConfigComment("The default game mode for this world. Players will be set to this mode when they create")
@ConfigComment("a new island for example. Options are SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR")
@ConfigEntry(path = "world.default-game-mode")
private GameMode defaultGameMode = GameMode.SURVIVAL;
// Nether // Nether
@ConfigComment("Generate Nether - if this is false, the nether world will not be made and access to") @ConfigComment("Generate Nether - if this is false, the nether world will not be made and access to")
@ConfigComment("the nether will not occur. Other plugins may still enable portal usage.") @ConfigComment("the nether will not occur. Other plugins may still enable portal usage.")
@ -235,7 +236,7 @@ public class Settings implements DataObject, WorldSettings {
@ConfigComment("World flags. These are boolean settings for various flags for this world") @ConfigComment("World flags. These are boolean settings for various flags for this world")
@ConfigEntry(path = "world.flags") @ConfigEntry(path = "world.flags")
private Map<String, Boolean> worldFlags = new HashMap<>(); private Map<String, Boolean> worldFlags = new HashMap<>();
// --------------------------------------------- // ---------------------------------------------
/* ISLAND */ /* ISLAND */
@ -252,7 +253,7 @@ public class Settings implements DataObject, WorldSettings {
private int maxTeamSize = 4; private int maxTeamSize = 4;
@ConfigComment("Default maximum number of homes a player can have. Min = 1") @ConfigComment("Default maximum number of homes a player can have. Min = 1")
@ConfigComment("Accessed via sethome <number> or go <number>") @ConfigComment("Accessed via sethome <number> or go <number>")
@ConfigComment("Use this permission to set for specific user groups: askyblock.island.maxhomes.<number>") @ConfigComment("Use this permission to set for specific user groups: askyblock.island.maxhomes.<number>")
@ConfigEntry(path = "island.max-homes") @ConfigEntry(path = "island.max-homes")
private int maxHomes = 5; private int maxHomes = 5;
@ConfigComment("Island naming") @ConfigComment("Island naming")
@ -351,34 +352,9 @@ public class Settings implements DataObject, WorldSettings {
private List<String> ivSettings = new ArrayList<>(); private List<String> ivSettings = new ArrayList<>();
//TODO flags //TODO flags
// --------------------------------------------- // ---------------------------------------------
/* ACID */
/*
* This settings category only exists if the GameType is ACIDISLAND.
*/
@ConfigEntry(path = "acid.damage-op", specificTo = GameType.ACIDISLAND)
private boolean acidDamageOp = false;
@ConfigEntry(path = "acid.damage-chickens", specificTo = GameType.ACIDISLAND)
private boolean acidDamageChickens = false;
@ConfigEntry(path = "acid.options.item-destroy-time", specificTo = GameType.ACIDISLAND)
private int acidDestroyItemTime = 0;
// Damage
@ConfigEntry(path = "acid.damage.acid.player", specificTo = GameType.ACIDISLAND)
private int acidDamage = 10;
@ConfigEntry(path = "acid.damage.rain", specificTo = GameType.ACIDISLAND)
private int acidRainDamage = 1;
@ConfigEntry(path = "acid.damage.effects", specificTo = GameType.ACIDISLAND)
@Adapter(PotionEffectListAdapter.class)
private List<PotionEffectType> acidEffects = new ArrayList<>(Arrays.asList(PotionEffectType.CONFUSION, PotionEffectType.SLOW));
/* SCHEMATICS */ /* SCHEMATICS */
private List<String> companionNames = new ArrayList<>(); private List<String> companionNames = new ArrayList<>();
@ -475,30 +451,6 @@ public class Settings implements DataObject, WorldSettings {
public void setDisableOfflineRedstone(boolean disableOfflineRedstone) { public void setDisableOfflineRedstone(boolean disableOfflineRedstone) {
this.disableOfflineRedstone = disableOfflineRedstone; this.disableOfflineRedstone = disableOfflineRedstone;
} }
/**
* @return the acidDamage
*/
public int getAcidDamage() {
return acidDamage;
}
/**
* @return the acidDestroyItemTime
*/
public int getAcidDestroyItemTime() {
return acidDestroyItemTime;
}
/**
* @return the acidEffects
*/
public List<PotionEffectType> getAcidEffects() {
return acidEffects;
}
/**
* @return the acidRainDamage
*/
public int getAcidRainDamage() {
return acidRainDamage;
}
/** /**
* @return the chestItems * @return the chestItems
*/ */
@ -586,6 +538,7 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the entityLimits * @return the entityLimits
*/ */
@Override
public Map<EntityType, Integer> getEntityLimits() { public Map<EntityType, Integer> getEntityLimits() {
return entityLimits; return entityLimits;
} }
@ -599,42 +552,49 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the islandDistance * @return the islandDistance
*/ */
@Override
public int getIslandDistance() { public int getIslandDistance() {
return islandDistance; return islandDistance;
} }
/** /**
* @return the islandHeight * @return the islandHeight
*/ */
@Override
public int getIslandHeight() { public int getIslandHeight() {
return islandHeight; return islandHeight;
} }
/** /**
* @return the islandProtectionRange * @return the islandProtectionRange
*/ */
@Override
public int getIslandProtectionRange() { public int getIslandProtectionRange() {
return islandProtectionRange; return islandProtectionRange;
} }
/** /**
* @return the islandStartX * @return the islandStartX
*/ */
@Override
public int getIslandStartX() { public int getIslandStartX() {
return islandStartX; return islandStartX;
} }
/** /**
* @return the islandStartZ * @return the islandStartZ
*/ */
@Override
public int getIslandStartZ() { public int getIslandStartZ() {
return islandStartZ; return islandStartZ;
} }
/** /**
* @return the islandXOffset * @return the islandXOffset
*/ */
@Override
public int getIslandXOffset() { public int getIslandXOffset() {
return islandXOffset; return islandXOffset;
} }
/** /**
* @return the islandZOffset * @return the islandZOffset
*/ */
@Override
public int getIslandZOffset() { public int getIslandZOffset() {
return islandZOffset; return islandZOffset;
} }
@ -666,12 +626,14 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the maxIslands * @return the maxIslands
*/ */
@Override
public int getMaxIslands() { public int getMaxIslands() {
return maxIslands; return maxIslands;
} }
/** /**
* @return the maxTeamSize * @return the maxTeamSize
*/ */
@Override
public int getMaxTeamSize() { public int getMaxTeamSize() {
return maxTeamSize; return maxTeamSize;
} }
@ -690,6 +652,7 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the netherSpawnRadius * @return the netherSpawnRadius
*/ */
@Override
public int getNetherSpawnRadius() { public int getNetherSpawnRadius() {
return netherSpawnRadius; return netherSpawnRadius;
} }
@ -714,12 +677,14 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the seaHeight * @return the seaHeight
*/ */
@Override
public int getSeaHeight() { public int getSeaHeight() {
return seaHeight; return seaHeight;
} }
/** /**
* @return the tileEntityLimits * @return the tileEntityLimits
*/ */
@Override
public Map<String, Integer> getTileEntityLimits() { public Map<String, Integer> getTileEntityLimits() {
return tileEntityLimits; return tileEntityLimits;
} }
@ -739,21 +704,10 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the worldName * @return the worldName
*/ */
@Override
public String getWorldName() { public String getWorldName() {
return worldName; return worldName;
} }
/**
* @return the acidDamageChickens
*/
public boolean isAcidDamageChickens() {
return acidDamageChickens;
}
/**
* @return the acidDamageOp
*/
public boolean isAcidDamageOp() {
return acidDamageOp;
}
/** /**
* @return the allowChestDamage * @return the allowChestDamage
*/ */
@ -823,12 +777,14 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the endGenerate * @return the endGenerate
*/ */
@Override
public boolean isEndGenerate() { public boolean isEndGenerate() {
return endGenerate; return endGenerate;
} }
/** /**
* @return the endIslands * @return the endIslands
*/ */
@Override
public boolean isEndIslands() { public boolean isEndIslands() {
return endIslands; return endIslands;
} }
@ -937,42 +893,6 @@ public class Settings implements DataObject, WorldSettings {
public boolean isUseOwnGenerator() { public boolean isUseOwnGenerator() {
return useOwnGenerator; return useOwnGenerator;
} }
/**
* @param acidDamage the acidDamage to set
*/
public void setAcidDamage(int acidDamage) {
this.acidDamage = acidDamage;
}
/**
* @param acidDamageChickens the acidDamageChickens to set
*/
public void setAcidDamageChickens(boolean acidDamageChickens) {
this.acidDamageChickens = acidDamageChickens;
}
/**
* @param acidDamageOp the acidDamageOp to set
*/
public void setAcidDamageOp(boolean acidDamageOp) {
this.acidDamageOp = acidDamageOp;
}
/**
* @param acidDestroyItemTime the acidDestroyItemTime to set
*/
public void setAcidDestroyItemTime(int acidDestroyItemTime) {
this.acidDestroyItemTime = acidDestroyItemTime;
}
/**
* @param acidEffects the acidEffects to set
*/
public void setAcidEffects(List<PotionEffectType> acidEffects) {
this.acidEffects = acidEffects;
}
/**
* @param acidRainDamage the acidRainDamage to set
*/
public void setAcidRainDamage(int acidRainDamage) {
this.acidRainDamage = acidRainDamage;
}
/** /**
* @param allowChestDamage the allowChestDamage to set * @param allowChestDamage the allowChestDamage to set
*/ */
@ -1436,6 +1356,7 @@ public class Settings implements DataObject, WorldSettings {
/** /**
* @return the dragonSpawn * @return the dragonSpawn
*/ */
@Override
public boolean isDragonSpawn() { public boolean isDragonSpawn() {
return dragonSpawn; return dragonSpawn;
} }
@ -1466,7 +1387,7 @@ public class Settings implements DataObject, WorldSettings {
public void setIvSettings(List<String> ivSettings) { public void setIvSettings(List<String> ivSettings) {
this.ivSettings = ivSettings; this.ivSettings = ivSettings;
} }
/** /**
* @return the worldFlags * @return the worldFlags
*/ */
@ -1495,5 +1416,19 @@ public class Settings implements DataObject, WorldSettings {
public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) { public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) {
this.closePanelOnClickOutside = closePanelOnClickOutside; this.closePanelOnClickOutside = closePanelOnClickOutside;
} }
/**
* @return the defaultGameMode
*/
@Override
public GameMode getDefaultGameMode() {
return defaultGameMode;
}
/**
* @param defaultGameMode the defaultGameMode to set
*/
public void setDefaultGameMode(GameMode defaultGameMode) {
this.defaultGameMode = defaultGameMode;
}
} }

View File

@ -97,24 +97,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
private static Map<User, Confirmer> toBeConfirmed = new HashMap<>(); private static Map<User, Confirmer> toBeConfirmed = new HashMap<>();
/**
* Used only for testing....
*/
public CompositeCommand(BSkyBlock plugin, String label, String... string) {
super(label);
this.plugin = plugin;
setAliases(new ArrayList<>(Arrays.asList(string)));
parent = null;
setUsage("");
subCommandLevel = 0; // Top level
subCommands = new LinkedHashMap<>();
subCommandAliases = new LinkedHashMap<>();
setup();
if (!getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this);
}
}
/** /**
* Top level command * Top level command
* @param addon - addon creating the command * @param addon - addon creating the command
@ -122,17 +104,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @param aliases - aliases * @param aliases - aliases
*/ */
public CompositeCommand(Addon addon, String label, String... aliases) { public CompositeCommand(Addon addon, String label, String... aliases) {
this(label, aliases);
this.addon = addon;
}
/**
* This is the top-level command constructor for commands that have no parent.
* @param label - string for this command
* @param aliases - aliases for this command
*/
public CompositeCommand(String label, String... aliases) {
super(label); super(label);
this.addon = addon;
this.topLabel = label; this.topLabel = label;
this.plugin = BSkyBlock.getInstance(); this.plugin = BSkyBlock.getInstance();
setAliases(new ArrayList<>(Arrays.asList(aliases))); setAliases(new ArrayList<>(Arrays.asList(aliases)));
@ -143,7 +116,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
subCommandAliases = new LinkedHashMap<>(); subCommandAliases = new LinkedHashMap<>();
// Register command if it is not already registered // Register command if it is not already registered
if (plugin.getCommand(label) == null) { if (plugin.getCommand(label) == null) {
plugin.getCommandsManager().registerCommand(this); plugin.getCommandsManager()
.registerCommand(this);
} }
setup(); setup();
if (!getSubCommand("help").isPresent() && !label.equals("help")) { if (!getSubCommand("help").isPresent() && !label.equals("help")) {
@ -151,6 +125,15 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
} }
} }
/**
* This is the top-level command constructor for commands that have no parent.
* @param label - string for this command
* @param aliases - aliases for this command
*/
public CompositeCommand(String label, String... aliases) {
this((Addon)null, label, aliases);
}
/** /**
* Sub-command constructor * Sub-command constructor
* @param parent - the parent composite command * @param parent - the parent composite command
@ -333,7 +316,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
} }
// Try aliases // Try aliases
if (subCommandAliases.containsKey(label.toLowerCase())) { if (subCommandAliases.containsKey(label.toLowerCase())) {
return Optional.ofNullable(subCommandAliases.get(label)); return Optional.ofNullable(subCommandAliases.get(label));
} }
return Optional.empty(); return Optional.empty();
} }
@ -434,7 +417,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/ */
public void inheritPermission() { public void inheritPermission() {
this.permission = parent.getPermission(); this.permission = parent.getPermission();
} }
/** /**
* This creates the full linking chain of commands * This creates the full linking chain of commands
@ -518,7 +501,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
} }
/** /**
* Set the permission prefix. This will be added automatically to the permission * Set the permission prefix. This will be added automatically to the permission
* and will apply to any sub commands too. * and will apply to any sub commands too.
* Do not put a dot on the end of it. * Do not put a dot on the end of it.
* @param permissionPrefix the permissionPrefix to set * @param permissionPrefix the permissionPrefix to set
@ -584,7 +567,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
user.sendMessage("general.request-cancelled"); user.sendMessage("general.request-cancelled");
toBeConfirmed.remove(user); toBeConfirmed.remove(user);
}, getPlugin().getSettings().getConfirmationTime() * 20L); }, getPlugin().getSettings().getConfirmationTime() * 20L);
// Add to the global confirmation map // Add to the global confirmation map
toBeConfirmed.put(user, new Confirmer(getTopLabel(), getLabel(), confirmed, task)); toBeConfirmed.put(user, new Confirmer(getTopLabel(), getLabel(), confirmed, task));
} }

View File

@ -3,6 +3,7 @@ package us.tastybento.bskyblock.api.configuration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.GameMode;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
/** /**
@ -11,7 +12,7 @@ import org.bukkit.entity.EntityType;
* *
*/ */
public interface WorldSettings { public interface WorldSettings {
/** /**
* @return the friendly name of the world. Used in player commands * @return the friendly name of the world. Used in player commands
*/ */
@ -21,7 +22,7 @@ public interface WorldSettings {
* @return the entityLimits * @return the entityLimits
*/ */
Map<EntityType, Integer> getEntityLimits(); Map<EntityType, Integer> getEntityLimits();
/** /**
* @return the islandDistance * @return the islandDistance
*/ */
@ -31,77 +32,77 @@ public interface WorldSettings {
* @return the islandHeight * @return the islandHeight
*/ */
int getIslandHeight(); int getIslandHeight();
/** /**
* @return the islandProtectionRange * @return the islandProtectionRange
*/ */
int getIslandProtectionRange(); int getIslandProtectionRange();
/** /**
* @return the islandStartX * @return the islandStartX
*/ */
int getIslandStartX(); int getIslandStartX();
/** /**
* @return the islandStartZ * @return the islandStartZ
*/ */
int getIslandStartZ(); int getIslandStartZ();
/** /**
* @return the islandXOffset * @return the islandXOffset
*/ */
int getIslandXOffset(); int getIslandXOffset();
/** /**
* @return the islandZOffset * @return the islandZOffset
*/ */
int getIslandZOffset(); int getIslandZOffset();
/** /**
* @return the maxIslands * @return the maxIslands
*/ */
int getMaxIslands(); int getMaxIslands();
/** /**
* @return the netherSpawnRadius * @return the netherSpawnRadius
*/ */
int getNetherSpawnRadius(); int getNetherSpawnRadius();
/** /**
* @return the seaHeight * @return the seaHeight
*/ */
int getSeaHeight(); int getSeaHeight();
/** /**
* @return the tileEntityLimits * @return the tileEntityLimits
*/ */
Map<String, Integer> getTileEntityLimits(); Map<String, Integer> getTileEntityLimits();
/** /**
* @return the worldName * @return the worldName
*/ */
String getWorldName(); String getWorldName();
/** /**
* @return the endGenerate * @return the endGenerate
*/ */
boolean isEndGenerate(); boolean isEndGenerate();
/** /**
* @return the endIslands * @return the endIslands
*/ */
boolean isEndIslands(); boolean isEndIslands();
/** /**
* @return the netherGenerate * @return the netherGenerate
*/ */
boolean isNetherGenerate(); boolean isNetherGenerate();
/** /**
* @return the netherIslands * @return the netherIslands
*/ */
boolean isNetherIslands(); boolean isNetherIslands();
/** /**
* @return the netherTrees * @return the netherTrees
*/ */
@ -137,5 +138,11 @@ public interface WorldSettings {
* @return Map of world flags * @return Map of world flags
*/ */
Map<String, Boolean> getWorldFlags(); Map<String, Boolean> getWorldFlags();
/**
* Get the default game mode for this game world, e.g. SURVIVAL
* @return game mode
*/
GameMode getDefaultGameMode();
} }

View File

@ -29,7 +29,6 @@ public class AdminInfoCommand extends CompositeCommand {
} }
// If there are no args, then the player wants info on the island at this location // If there are no args, then the player wants info on the island at this location
if (args.isEmpty()) { if (args.isEmpty()) {
getPlugin().log("DEBUG: getting info - no args");
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(getPlugin(), user, getWorld())).orElse(false)) { if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.showInfo(getPlugin(), user, getWorld())).orElse(false)) {
user.sendMessage("commands.admin.info.no-island"); user.sendMessage("commands.admin.info.no-island");
return false; return false;
@ -46,8 +45,8 @@ public class AdminInfoCommand extends CompositeCommand {
user.sendMessage("general.errors.player-has-no-island"); user.sendMessage("general.errors.player-has-no-island");
return false; return false;
} }
// Show info for this player // Show info for this player
getIslands().getIsland(getWorld(), targetUUID).showInfo(getPlugin(), user, getWorld()); getIslands().getIsland(getWorld(), targetUUID).showInfo(getPlugin(), user, getWorld());
return true; return true;
} }
} }

View File

@ -14,7 +14,7 @@ import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends CompositeCommand { public class IslandTeamInviteAcceptCommand extends CompositeCommand {
private IslandTeamCommand itc; private IslandTeamCommand itc;
public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) { public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) {
@ -89,7 +89,7 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
getPlayers().setDeaths(playerUUID, 0); getPlayers().setDeaths(playerUUID, 0);
} }
// Put player back into normal mode // Put player back into normal mode
user.setGameMode(GameMode.SURVIVAL); user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel()); user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID)); User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));

View File

@ -7,6 +7,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
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;
@ -162,7 +163,7 @@ public class IslandWorldManager {
.filter(w -> !plugin.getIslands().hasIsland(w.getKey(), user)) .filter(w -> !plugin.getIslands().hasIsland(w.getKey(), user))
.map(Map.Entry::getValue).collect(Collectors.toSet()); .map(Map.Entry::getValue).collect(Collectors.toSet());
} }
/** /**
* Check if a name is a known friendly world name, ignores case * Check if a name is a known friendly world name, ignores case
* @param name - world name * @param name - world name
@ -183,7 +184,7 @@ public class IslandWorldManager {
worldSettings.put(world, settings); worldSettings.put(world, settings);
multiverseReg(world); multiverseReg(world);
} }
/** /**
* Get the settings for this world or sub-worlds (nether, end) * Get the settings for this world or sub-worlds (nether, end)
* @param world - world * @param world - world
@ -208,7 +209,7 @@ public class IslandWorldManager {
public Map<EntityType, Integer> getEntityLimits(World world) { public Map<EntityType, Integer> getEntityLimits(World world) {
return worldSettings.get(Util.getWorld(world)).getEntityLimits(); return worldSettings.get(Util.getWorld(world)).getEntityLimits();
} }
/** /**
* @return the islandDistance * @return the islandDistance
*/ */
@ -222,98 +223,98 @@ public class IslandWorldManager {
public int getIslandHeight(World world) { public int getIslandHeight(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandHeight(); return worldSettings.get(Util.getWorld(world)).getIslandHeight();
} }
/** /**
* @return the islandProtectionRange * @return the islandProtectionRange
*/ */
public int getIslandProtectionRange(World world) { public int getIslandProtectionRange(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandProtectionRange(); return worldSettings.get(Util.getWorld(world)).getIslandProtectionRange();
} }
/** /**
* @return the islandStartX * @return the islandStartX
*/ */
public int getIslandStartX(World world) { public int getIslandStartX(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandStartX(); return worldSettings.get(Util.getWorld(world)).getIslandStartX();
} }
/** /**
* @return the islandStartZ * @return the islandStartZ
*/ */
public int getIslandStartZ(World world) { public int getIslandStartZ(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandStartZ(); return worldSettings.get(Util.getWorld(world)).getIslandStartZ();
} }
/** /**
* @return the islandXOffset * @return the islandXOffset
*/ */
public int getIslandXOffset(World world) { public int getIslandXOffset(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandXOffset(); return worldSettings.get(Util.getWorld(world)).getIslandXOffset();
} }
/** /**
* @return the islandZOffset * @return the islandZOffset
*/ */
public int getIslandZOffset(World world) { public int getIslandZOffset(World world) {
return worldSettings.get(Util.getWorld(world)).getIslandZOffset(); return worldSettings.get(Util.getWorld(world)).getIslandZOffset();
} }
/** /**
* @return the maxIslands * @return the maxIslands
*/ */
public int getMaxIslands(World world) { public int getMaxIslands(World world) {
return worldSettings.get(Util.getWorld(world)).getMaxIslands(); return worldSettings.get(Util.getWorld(world)).getMaxIslands();
} }
/** /**
* @return the netherSpawnRadius * @return the netherSpawnRadius
*/ */
public int getNetherSpawnRadius(World world) { public int getNetherSpawnRadius(World world) {
return worldSettings.get(Util.getWorld(world)).getNetherSpawnRadius(); return worldSettings.get(Util.getWorld(world)).getNetherSpawnRadius();
} }
/** /**
* @return the seaHeight * @return the seaHeight
*/ */
public int getSeaHeight(World world) { public int getSeaHeight(World world) {
return worldSettings.get(Util.getWorld(world)).getSeaHeight(); return worldSettings.get(Util.getWorld(world)).getSeaHeight();
} }
/** /**
* @return the tileEntityLimits * @return the tileEntityLimits
*/ */
public Map<String, Integer> getTileEntityLimits(World world) { public Map<String, Integer> getTileEntityLimits(World world) {
return worldSettings.get(Util.getWorld(world)).getTileEntityLimits(); return worldSettings.get(Util.getWorld(world)).getTileEntityLimits();
} }
/** /**
* @return the worldName * @return the worldName
*/ */
public String getWorldName(World world) { public String getWorldName(World world) {
return worldSettings.get(Util.getWorld(world)).getWorldName(); return worldSettings.get(Util.getWorld(world)).getWorldName();
} }
/** /**
* @return the endGenerate * @return the endGenerate
*/ */
public boolean isEndGenerate(World world) { public boolean isEndGenerate(World world) {
return worldSettings.get(Util.getWorld(world)).isEndGenerate(); return worldSettings.get(Util.getWorld(world)).isEndGenerate();
} }
/** /**
* @return the endIslands * @return the endIslands
*/ */
public boolean isEndIslands(World world) { public boolean isEndIslands(World world) {
return worldSettings.get(Util.getWorld(world)).isEndIslands(); return worldSettings.get(Util.getWorld(world)).isEndIslands();
} }
/** /**
* @return the netherGenerate * @return the netherGenerate
*/ */
public boolean isNetherGenerate(World world) { public boolean isNetherGenerate(World world) {
return worldSettings.get(Util.getWorld(world)).isNetherGenerate(); return worldSettings.get(Util.getWorld(world)).isNetherGenerate();
} }
/** /**
* @return the netherIslands * @return the netherIslands
*/ */
@ -330,7 +331,7 @@ public class IslandWorldManager {
World w = Util.getWorld(world); World w = Util.getWorld(world);
return worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate(); return worldSettings.containsKey(w) && worldSettings.get(w).isNetherGenerate();
} }
/** /**
* Checks if a world is a known island nether world * Checks if a world is a known island nether world
* @param world - world * @param world - world
@ -350,7 +351,7 @@ public class IslandWorldManager {
World w = Util.getWorld(world); World w = Util.getWorld(world);
return worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate(); return worldSettings.containsKey(w) && worldSettings.get(w).isEndGenerate();
} }
/** /**
* Checks if a world is a known island end world * Checks if a world is a known island end world
* @param world - world * @param world - world
@ -437,7 +438,7 @@ public class IslandWorldManager {
public int getMaxHomes(World world) { public int getMaxHomes(World world) {
return worldSettings.get(Util.getWorld(world)).getMaxHomes(); return worldSettings.get(Util.getWorld(world)).getMaxHomes();
} }
/** /**
* Get the friendly name for world or related nether or end * Get the friendly name for world or related nether or end
* @param world - world * @param world - world
@ -454,7 +455,7 @@ public class IslandWorldManager {
*/ */
public String getPermissionPrefix(World world) { public String getPermissionPrefix(World world) {
return worldSettings.get(Util.getWorld(world)).getPermissionPrefix(); return worldSettings.get(Util.getWorld(world)).getPermissionPrefix();
} }
/** /**
@ -477,4 +478,12 @@ public class IslandWorldManager {
return flag.isSetForWorld(world); return flag.isSetForWorld(world);
} }
/**
* Get the default game mode for this world.
* @param world - world
* @return GameMode: SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR
*/
public GameMode getDefaultGameMode(World world) {
return worldSettings.get(Util.getWorld(world)).getDefaultGameMode();
}
} }

View File

@ -74,11 +74,6 @@ public class IslandsManager {
|| space1.getType() == Material.ENDER_PORTAL || ground.getType() == Material.ENDER_PORTAL || space2.getType() == Material.ENDER_PORTAL) { || space1.getType() == Material.ENDER_PORTAL || ground.getType() == Material.ENDER_PORTAL || space2.getType() == Material.ENDER_PORTAL) {
return false; return false;
} }
// In BSkyBlock, liquid may be unsafe
// Check if acid has no damage
if (plugin.getSettings().getAcidDamage() > 0D && (ground.isLiquid() || space1.isLiquid() || space2.isLiquid())) {
return false;
}
if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) if (ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA)
|| space1.getType().equals(Material.STATIONARY_LAVA) || space1.getType().equals(Material.LAVA) || space1.getType().equals(Material.STATIONARY_LAVA) || space1.getType().equals(Material.LAVA)
|| space2.getType().equals(Material.STATIONARY_LAVA) || space2.getType().equals(Material.LAVA)) { || space2.getType().equals(Material.STATIONARY_LAVA) || space2.getType().equals(Material.LAVA)) {
@ -340,7 +335,7 @@ public class IslandsManager {
/** /**
* Determines a safe teleport spot on player's island or the team island * Determines a safe teleport spot on player's island or the team island
* they belong to. * they belong to.
* *
* @param world - world to check * @param world - world to check
* @param user - the player * @param user - the player
* @param number - a number - starting home location e.g., 1 * @param number - a number - starting home location e.g., 1
@ -362,11 +357,11 @@ public class IslandsManager {
// To cover slabs, stairs and other half blocks, try one block above // To cover slabs, stairs and other half blocks, try one block above
Location lPlusOne = l.clone(); Location lPlusOne = l.clone();
lPlusOne.add(new Vector(0, 1, 0)); lPlusOne.add(new Vector(0, 1, 0));
if (isSafeLocation(lPlusOne)) { if (isSafeLocation(lPlusOne)) {
// Adjust the home location accordingly // Adjust the home location accordingly
plugin.getPlayers().setHomeLocation(user, lPlusOne, number); plugin.getPlayers().setHomeLocation(user, lPlusOne, number);
return lPlusOne; return lPlusOne;
} }
} }
// Home location either isn't safe, or does not exist so try the island // Home location either isn't safe, or does not exist so try the island
// location // location
@ -517,7 +512,7 @@ public class IslandsManager {
} }
// Exit spectator mode if in it // Exit spectator mode if in it
if (player.getGameMode().equals(GameMode.SPECTATOR)) { if (player.getGameMode().equals(GameMode.SPECTATOR)) {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
} }
} }
@ -633,7 +628,7 @@ public class IslandsManager {
/** /**
* Checks if an online player is in the protected area of their island, a team island or a * Checks if an online player is in the protected area of their island, a team island or a
* coop island in the specific world in the arguments. Note that the user * coop island in the specific world in the arguments. Note that the user
* *
* @param world - the world to check * @param world - the world to check
* @param user - the user * @param user - the user

View File

@ -110,7 +110,7 @@ public class SafeSpotTeleport {
entity.sendMessage(failureMessage); entity.sendMessage(failureMessage);
} }
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) { if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
((Player)entity).setGameMode(GameMode.SURVIVAL); ((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld()));
} }
} }
@ -152,13 +152,13 @@ public class SafeSpotTeleport {
if (is.inIslandSpace(blockCoord)) { if (is.inIslandSpace(blockCoord)) {
result.add(chunkCoord); result.add(chunkCoord);
} }
}); });
} }
} }
} }
/** /**
* Loops through the chunks and if a safe spot is found, fires off the teleportation * Loops through the chunks and if a safe spot is found, fires off the teleportation
* @param chunkSnapshot - list of chunk snapshots to check * @param chunkSnapshot - list of chunk snapshots to check
*/ */
private void checkChunks(final List<ChunkSnapshot> chunkSnapshot) { private void checkChunks(final List<ChunkSnapshot> chunkSnapshot) {
@ -180,7 +180,7 @@ public class SafeSpotTeleport {
* @param chunk - chunk snapshot * @param chunk - chunk snapshot
* @return true if a safe spot was found * @return true if a safe spot was found
*/ */
private boolean scanChunk(ChunkSnapshot chunk) { private boolean scanChunk(ChunkSnapshot chunk) {
// Max height // Max height
int maxHeight = location.getWorld().getMaxHeight() - 20; int maxHeight = location.getWorld().getMaxHeight() - 20;
// Run through the chunk // Run through the chunk
@ -214,7 +214,7 @@ public class SafeSpotTeleport {
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player)entity; Player player = (Player)entity;
if (player.getGameMode().equals(GameMode.SPECTATOR)) { if (player.getGameMode().equals(GameMode.SPECTATOR)) {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(plugin.getIWM().getDefaultGameMode(loc.getWorld()));
} }
} else { } else {
entity.setVelocity(velocity); entity.setVelocity(velocity);

View File

@ -59,6 +59,7 @@ 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.listeners.flags.AbstractFlagListener; import us.tastybento.bskyblock.listeners.flags.AbstractFlagListener;
import us.tastybento.bskyblock.lists.Flags; import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.managers.CommandsManager;
import us.tastybento.bskyblock.managers.FlagsManager; 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;
@ -80,11 +81,12 @@ public class TestBSkyBlock {
private static Block block; private static Block block;
private static Player ownerOfIsland; private static Player ownerOfIsland;
private static Player visitorToIsland; private static Player visitorToIsland;
@BeforeClass @BeforeClass
public static void setUp() { public static void setUpBeforeClass() {
// Set up plugin // Set up plugin
plugin = mock(BSkyBlock.class); plugin = mock(BSkyBlock.class);
when(plugin.getCommandsManager()).thenReturn(mock(CommandsManager.class));
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin); Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
Server server = mock(Server.class); Server server = mock(Server.class);
@ -92,25 +94,25 @@ public class TestBSkyBlock {
Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger()); Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
Mockito.when(server.getWorld("world")).thenReturn(world); Mockito.when(server.getWorld("world")).thenReturn(world);
Mockito.when(server.getVersion()).thenReturn("BSB_Mocking"); Mockito.when(server.getVersion()).thenReturn("BSB_Mocking");
PluginManager pluginManager = mock(PluginManager.class); PluginManager pluginManager = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pluginManager); when(server.getPluginManager()).thenReturn(pluginManager);
ItemFactory itemFactory = mock(ItemFactory.class); ItemFactory itemFactory = mock(ItemFactory.class);
when(server.getItemFactory()).thenReturn(itemFactory); when(server.getItemFactory()).thenReturn(itemFactory);
Bukkit.setServer(server); Bukkit.setServer(server);
SkullMeta skullMeta = mock(SkullMeta.class); SkullMeta skullMeta = mock(SkullMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta); when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
OfflinePlayer offlinePlayer = mock(OfflinePlayer.class); OfflinePlayer offlinePlayer = mock(OfflinePlayer.class);
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(offlinePlayer); when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(offlinePlayer);
when(offlinePlayer.getName()).thenReturn("tastybento"); when(offlinePlayer.getName()).thenReturn("tastybento");
when(Bukkit.getItemFactory()).thenReturn(itemFactory); when(Bukkit.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
sender = mock(CommandSender.class); sender = mock(CommandSender.class);
player = mock(Player.class); player = mock(Player.class);
ownerOfIsland = mock(Player.class); ownerOfIsland = mock(Player.class);
@ -162,16 +164,12 @@ public class TestBSkyBlock {
members.put(OWNER_UUID, RanksManager.OWNER_RANK); members.put(OWNER_UUID, RanksManager.OWNER_RANK);
members.put(MEMBER_UUID, RanksManager.MEMBER_RANK); members.put(MEMBER_UUID, RanksManager.MEMBER_RANK);
island.setMembers(members); island.setMembers(members);
Bukkit.getLogger().info("SETUP: owner UUID = " + OWNER_UUID);
Bukkit.getLogger().info("SETUP: member UUID = " + MEMBER_UUID);
Bukkit.getLogger().info("SETUP: visitor UUID = " + VISITOR_UUID);
Mockito.when(im.getIslandAt(Matchers.any())).thenReturn(Optional.of(island)); Mockito.when(im.getIslandAt(Matchers.any())).thenReturn(Optional.of(island));
when(im.getProtectedIslandAt(Mockito.any())).thenReturn(Optional.of(island)); when(im.getProtectedIslandAt(Mockito.any())).thenReturn(Optional.of(island));
Settings settings = mock(Settings.class); Settings settings = mock(Settings.class);
Mockito.when(plugin.getSettings()).thenReturn(settings); Mockito.when(plugin.getSettings()).thenReturn(settings);
Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>()); Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>());
} }
@Test @Test
@ -252,7 +250,7 @@ public class TestBSkyBlock {
private class TestCommand extends CompositeCommand { private class TestCommand extends CompositeCommand {
public TestCommand() { public TestCommand() {
super(plugin, "test", "t", "tt"); super("test", "t", "tt");
setParameters("test.params"); setParameters("test.params");
} }
@ -354,7 +352,7 @@ public class TestBSkyBlock {
private class Test3ArgsCommand extends CompositeCommand { private class Test3ArgsCommand extends CompositeCommand {
public Test3ArgsCommand() { public Test3ArgsCommand() {
super(plugin, "args", ""); super("args", "");
} }
@Override @Override

View File

@ -100,7 +100,7 @@ public class IslandsManagerTest {
// Set up user already // Set up user already
User.getInstance(player); User.getInstance(player);
// Locales // Locales
LocalesManager lm = mock(LocalesManager.class); LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm); when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenReturn("mock translation"); when(lm.get(any(), any())).thenReturn("mock translation");
@ -118,7 +118,7 @@ public class IslandsManagerTest {
// Standard location // Standard location
manager = new IslandsManager(plugin); manager = new IslandsManager(plugin);
location = mock(Location.class); location = mock(Location.class);
when(location.getWorld()).thenReturn(world); when(location.getWorld()).thenReturn(world);
space1 = mock(Block.class); space1 = mock(Block.class);
ground = mock(Block.class); ground = mock(Block.class);
@ -148,7 +148,7 @@ public class IslandsManagerTest {
} }
}); });
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -156,10 +156,10 @@ public class IslandsManagerTest {
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); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);
// Scheduler // Scheduler
when(Bukkit.getScheduler()).thenReturn(mock(BukkitScheduler.class)); when(Bukkit.getScheduler()).thenReturn(mock(BukkitScheduler.class));
} }
@ -188,7 +188,7 @@ public class IslandsManagerTest {
*/ */
@Test @Test
public void testIsSafeLocationNonSolidGround() { public void testIsSafeLocationNonSolidGround() {
when(ground.getType()).thenReturn(Material.WATER); when(ground.getType()).thenReturn(Material.WATER);
assertFalse(manager.isSafeLocation(location)); assertFalse(manager.isSafeLocation(location));
} }
@ -207,7 +207,7 @@ public class IslandsManagerTest {
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
*/ */
@Test @Test
public void testIsSafeLocationPortals() { public void testIsSafeLocationPortals() {
when(ground.getType()).thenReturn(Material.STONE); when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.AIR); when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.PORTAL); when(space2.getType()).thenReturn(Material.PORTAL);
@ -234,31 +234,6 @@ public class IslandsManagerTest {
assertFalse(manager.isSafeLocation(location)); assertFalse(manager.isSafeLocation(location));
} }
/**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
*/
@Test
public void testIsSafeLocationAcid() {
when(ground.getType()).thenReturn(Material.GRASS);
when(space1.getType()).thenReturn(Material.STATIONARY_WATER);
when(space2.getType()).thenReturn(Material.AIR);
when(s.getAcidDamage()).thenReturn(10);
when(ground.isLiquid()).thenReturn(true);
when(space1.isLiquid()).thenReturn(false);
when(space2.isLiquid()).thenReturn(false);
assertFalse("In acid", manager.isSafeLocation(location));
when(ground.isLiquid()).thenReturn(false);
when(space1.isLiquid()).thenReturn(true);
when(space2.isLiquid()).thenReturn(false);
assertFalse("In acid", manager.isSafeLocation(location));
when(ground.isLiquid()).thenReturn(false);
when(space1.isLiquid()).thenReturn(false);
when(space2.isLiquid()).thenReturn(true);
assertFalse("In acid", manager.isSafeLocation(location));
}
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
*/ */
@ -288,7 +263,7 @@ public class IslandsManagerTest {
when(space1.getType()).thenReturn(Material.AIR); when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.STATIONARY_LAVA); when(space2.getType()).thenReturn(Material.STATIONARY_LAVA);
assertFalse("In lava", manager.isSafeLocation(location)); assertFalse("In lava", manager.isSafeLocation(location));
} }
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isSafeLocation(org.bukkit.Location)}.
@ -452,7 +427,7 @@ public class IslandsManagerTest {
public void testDeleteIslandIslandBoolean() { public void testDeleteIslandIslandBoolean() {
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
im.deleteIsland((Island)null, true); im.deleteIsland((Island)null, true);
UUID owner = UUID.randomUUID(); UUID owner = UUID.randomUUID();
Island island = im.createIsland(location, owner); Island island = im.createIsland(location, owner);
im.deleteIsland(island, false); im.deleteIsland(island, false);
@ -486,7 +461,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getIslandAt(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getIslandAt(org.bukkit.Location)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testGetIslandAtLocation() throws Exception { public void testGetIslandAtLocation() throws Exception {
@ -537,7 +512,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getMembers(java.util.UUID)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getMembers(java.util.UUID)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testGetMembers() throws Exception { public void testGetMembers() throws Exception {
@ -548,14 +523,14 @@ public class IslandsManagerTest {
members.add(UUID.randomUUID()); members.add(UUID.randomUUID());
members.add(UUID.randomUUID()); members.add(UUID.randomUUID());
when(ic.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); when(ic.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
PowerMockito.whenNew(IslandCache.class).withAnyArguments().thenReturn(ic); PowerMockito.whenNew(IslandCache.class).withAnyArguments().thenReturn(ic);
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
assertEquals(members, im.getMembers(world, UUID.randomUUID())); assertEquals(members, im.getMembers(world, UUID.randomUUID()));
} }
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getProtectedIslandAt(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getProtectedIslandAt(org.bukkit.Location)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testGetProtectedIslandAt() throws Exception { public void testGetProtectedIslandAt() throws Exception {
@ -575,7 +550,7 @@ public class IslandsManagerTest {
assertEquals(oi, im.getProtectedIslandAt(location)); assertEquals(oi, im.getProtectedIslandAt(location));
// Not in protected space // Not in protected space
when(is.onIsland(Mockito.any())).thenReturn(false); when(is.onIsland(Mockito.any())).thenReturn(false);
assertEquals(Optional.empty(), im.getProtectedIslandAt(location)); assertEquals(Optional.empty(), im.getProtectedIslandAt(location));
im.setSpawn(is); im.setSpawn(is);
@ -584,7 +559,7 @@ public class IslandsManagerTest {
assertEquals(oi, im.getProtectedIslandAt(location)); assertEquals(oi, im.getProtectedIslandAt(location));
// Not in protected space // Not in protected space
when(is.onIsland(Mockito.any())).thenReturn(false); when(is.onIsland(Mockito.any())).thenReturn(false);
assertEquals(Optional.empty(), im.getProtectedIslandAt(location)); assertEquals(Optional.empty(), im.getProtectedIslandAt(location));
} }
@ -623,6 +598,7 @@ public class IslandsManagerTest {
*/ */
@Test @Test
public void testHomeTeleportPlayerInt() { public void testHomeTeleportPlayerInt() {
when(iwm.getDefaultGameMode(world)).thenReturn(GameMode.SURVIVAL);
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(0))).thenReturn(null); when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(0))).thenReturn(null);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(1))).thenReturn(location); when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(1))).thenReturn(location);
@ -633,6 +609,22 @@ public class IslandsManagerTest {
} }
/**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#homeTeleport(org.bukkit.entity.Player, int)}.
*/
@Test
public void testHomeTeleportPlayerIntDifferentGameMode() {
when(iwm.getDefaultGameMode(world)).thenReturn(GameMode.CREATIVE);
IslandsManager im = new IslandsManager(plugin);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(0))).thenReturn(null);
when(pm.getHomeLocation(Mockito.any(), Mockito.any(User.class), Mockito.eq(1))).thenReturn(location);
when(player.getGameMode()).thenReturn(GameMode.SPECTATOR);
im.homeTeleport(world, player, 0);
Mockito.verify(player).teleport(location);
Mockito.verify(player).setGameMode(GameMode.CREATIVE);
}
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isAtSpawn(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isAtSpawn(org.bukkit.Location)}.
*/ */
@ -649,7 +641,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isIsland(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isIsland(org.bukkit.Location)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testIsIsland() throws Exception { public void testIsIsland() throws Exception {
@ -679,7 +671,7 @@ public class IslandsManagerTest {
// Location // Location
when(location.getWorld()).thenReturn(world); when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(10); when(location.getBlockX()).thenReturn(10);
when(location.getBlockZ()).thenReturn(10); when(location.getBlockZ()).thenReturn(10);
when(location.getBlock()).thenReturn(space1); when(location.getBlock()).thenReturn(space1);
PowerMockito.whenNew(Location.class).withAnyArguments().thenReturn(location); PowerMockito.whenNew(Location.class).withAnyArguments().thenReturn(location);
@ -693,7 +685,7 @@ public class IslandsManagerTest {
when(space1.isLiquid()).thenReturn(true); when(space1.isLiquid()).thenReturn(true);
assertTrue(im.isIsland(location)); assertTrue(im.isIsland(location));
// Empty space // Empty space
when(space1.isEmpty()).thenReturn(true); when(space1.isEmpty()).thenReturn(true);
when(space1.isLiquid()).thenReturn(false); when(space1.isLiquid()).thenReturn(false);
assertTrue(im.isIsland(location)); assertTrue(im.isIsland(location));
@ -702,7 +694,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getClosestIsland(org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#getClosestIsland(org.bukkit.Location)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testGetClosestIsland() throws Exception { public void testGetClosestIsland() throws Exception {
@ -720,7 +712,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isOwner(java.util.UUID)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#isOwner(java.util.UUID)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testIsOwner() throws Exception { public void testIsOwner() throws Exception {
@ -757,12 +749,12 @@ public class IslandsManagerTest {
public void testLoad() { public void testLoad() {
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
im.load(); im.load();
} }
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#locationIsOnIsland(org.bukkit.entity.Player, org.bukkit.Location)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#locationIsOnIsland(org.bukkit.entity.Player, org.bukkit.Location)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testLocationIsOnIsland() throws Exception { public void testLocationIsOnIsland() throws Exception {
@ -776,23 +768,23 @@ public class IslandsManagerTest {
// In world // In world
when(is.onIsland(Mockito.any())).thenReturn(true); when(is.onIsland(Mockito.any())).thenReturn(true);
Builder<UUID> members = new ImmutableSet.Builder<>(); Builder<UUID> members = new ImmutableSet.Builder<>();
members.add(uuid); members.add(uuid);
when(is.getMemberSet()).thenReturn(members.build()); when(is.getMemberSet()).thenReturn(members.build());
when(player.getUniqueId()).thenReturn(uuid); when(player.getUniqueId()).thenReturn(uuid);
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
assertFalse(im.locationIsOnIsland(null, null)); assertFalse(im.locationIsOnIsland(null, null));
assertTrue(im.locationIsOnIsland(player, location)); assertTrue(im.locationIsOnIsland(player, location));
// No members // No members
Builder<UUID> mem = new ImmutableSet.Builder<>(); Builder<UUID> mem = new ImmutableSet.Builder<>();
when(is.getMemberSet()).thenReturn(mem.build()); when(is.getMemberSet()).thenReturn(mem.build());
assertFalse(im.locationIsOnIsland(player, location)); assertFalse(im.locationIsOnIsland(player, location));
// Not on island // Not on island
when(is.getMemberSet()).thenReturn(members.build()); when(is.getMemberSet()).thenReturn(members.build());
when(is.onIsland(Mockito.any())).thenReturn(false); when(is.onIsland(Mockito.any())).thenReturn(false);
@ -801,7 +793,7 @@ public class IslandsManagerTest {
/** /**
* Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#userIsOnIsland(us.tastybento.bskyblock.api.user.User)}. * Test method for {@link us.tastybento.bskyblock.managers.IslandsManager#userIsOnIsland(us.tastybento.bskyblock.api.user.User)}.
* @throws Exception * @throws Exception
*/ */
@Test @Test
public void testUserIsOnIsland() throws Exception { public void testUserIsOnIsland() throws Exception {
@ -815,12 +807,12 @@ public class IslandsManagerTest {
IslandsManager im = new IslandsManager(plugin); IslandsManager im = new IslandsManager(plugin);
assertFalse(im.userIsOnIsland(world, null)); assertFalse(im.userIsOnIsland(world, null));
when(is.onIsland(Mockito.any())).thenReturn(false); when(is.onIsland(Mockito.any())).thenReturn(false);
assertFalse(im.userIsOnIsland(world, user)); assertFalse(im.userIsOnIsland(world, user));
when(is.onIsland(Mockito.any())).thenReturn(true); when(is.onIsland(Mockito.any())).thenReturn(true);
assertTrue(im.userIsOnIsland(world, user)); assertTrue(im.userIsOnIsland(world, user));
} }
/** /**