diff --git a/.gitignore b/.gitignore
index a1c2a23..db13763 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+/target/
+/.DS_Store
+/.classpath
+/.project
+/dependency-reduced-pom.xml
diff --git a/README.md b/README.md
index a41610a..62645cc 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,13 @@
# Biomes Addon
+[](https://discord.bentobox.world)
[](https://ci.codemc.org/job/BentoBoxWorld/job/Biomes/)
Biomes addon for SkyBlock, SkyGrid, CaveBlock and AcidIsland. It allows to change biome on Island.
## Where to find
-Currently Biomes Addon is in **Alpha stage**, so it may or may not contain bugs... a lot of bugs. Also it means, that some features are not working or implemented.
-Latest official **Alpha Release is 0.4.5**, and you can download it from [Release tab](https://github.com/BentoBoxWorld/Biomes/releases)
+Currently Biomes Addon is in **Beta stage**, so it may or may not contain bugs... a lot of bugs. Also it means, that some features are not working or implemented.
+Latest official **Beta Release is 1.5.0.0**, and you can download it from [Release tab](https://github.com/BentoBoxWorld/Biomes/releases)
Or you can try **nightly builds** where you can check and test new features that will be implemented in next release from [Jenkins Server](https://ci.codemc.org/job/BentoBoxWorld/job/Biomes/lastStableBuild/).
diff --git a/pom.xml b/pom.xml
index 0740782..7d3c667 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,14 +47,14 @@
1.7.4
1.13.2-R0.1-SNAPSHOT
- 1.4.0
- 1.3.0
+ 1.5.0
+ 1.4.0
1.7
1.2.1-SNAPSHOT
${build.version}-SNAPSHOT
- 0.4.5
+ 1.5.0.0
-LOCAL
@@ -70,7 +70,7 @@
- -#${env.BUILD_NUMBER}
+ -b${env.BUILD_NUMBER}
@@ -126,6 +126,12 @@
${bentobox.version}
provided
+
+ world.bentobox
+ level
+ ${level.version}
+ provided
+
net.wesjd
anvilgui
@@ -140,6 +146,14 @@
+
+
+
+
+
+
+ ${project.name}-${revision}${build.number}
+
clean package
diff --git a/src/main/java/world/bentobox/biomes/BiomesAddon.java b/src/main/java/world/bentobox/biomes/BiomesAddon.java
index 0a22019..b38ff56 100644
--- a/src/main/java/world/bentobox/biomes/BiomesAddon.java
+++ b/src/main/java/world/bentobox/biomes/BiomesAddon.java
@@ -1,13 +1,26 @@
package world.bentobox.biomes;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
import world.bentobox.bentobox.api.addons.Addon;
+import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.Config;
-import world.bentobox.bentobox.managers.CommandsManager;
+import world.bentobox.bentobox.api.flags.Flag;
+import world.bentobox.bentobox.hooks.VaultHook;
+import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.biomes.commands.admin.AdminCommand;
import world.bentobox.biomes.commands.user.BiomesCommand;
+import world.bentobox.biomes.handlers.BiomeDataRequestHandler;
+import world.bentobox.biomes.handlers.BiomeListRequestHandler;
+import world.bentobox.biomes.handlers.ChangeBiomeRequestHandler;
import world.bentobox.biomes.listeners.ChangeOwnerListener;
-import world.bentobox.biomes.objects.Settings;
+import world.bentobox.biomes.config.Settings;
+import world.bentobox.level.Level;
/**
@@ -15,25 +28,42 @@
*/
public class BiomesAddon extends Addon
{
+ /**
+ * {@inheritDoc}
+ */
@Override
public void onLoad()
{
- // Load the plugin's config
+ // Save default config.yml
this.saveDefaultConfig();
-
+ // Load the plugin's config
this.loadSettings();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void onEnable()
{
- this.hooked = false;
- this.addonManager = new BiomesAddonManager(this);
+ // Check if it is enabled - it might be loaded, but not enabled.
+ if (this.getPlugin() == null || !this.getPlugin().isEnabled())
+ {
+ Bukkit.getLogger().severe("BentoBox is not available or disabled!");
+ this.setState(State.DISABLED);
+ return;
+ }
- CommandsManager commandsManager = this.getPlugin().getCommandsManager();
+ // Check if addon is not disabled before.
+ if (this.getState().equals(State.DISABLED))
+ {
+ Bukkit.getLogger().severe("Biomes Addon is not available or disabled!");
+ return;
+ }
+
+ this.hooked = false;
- // AcidIsland hook in
this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName()))
{
@@ -46,59 +76,113 @@ public void onEnable()
if (gameModeAddon.getAdminCommand().isPresent())
{
new AdminCommand(this, gameModeAddon.getAdminCommand().get());
- this.hooked = true;
}
+
+ // Add FLAGS
+ BIOMES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
+ BIOMES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
}
});
if (this.hooked)
{
- // This listener fires on each owner change.
- this.getServer().getPluginManager().registerEvents(
- new ChangeOwnerListener(this), this.getPlugin());
+ // If hooked init Manager
+ this.addonManager = new BiomesAddonManager(this);
+
+ // Try to find Level addon and if it does not exist, display a warning
+
+ Optional level = this.getAddonByName("Level");
+
+ if (!level.isPresent())
+ {
+ this.logWarning(
+ "Level add-on not found so level requirements will be ignored!");
+ this.levelAddon = null;
+ }
+ else
+ {
+ this.levelProvided = true;
+ this.levelAddon = (Level) level.get();
+ }
+
+ Optional vault = this.getPlugin().getVault();
+
+ if (!vault.isPresent() || !vault.get().hook())
+ {
+ this.vaultHook = null;
+ this.logWarning(
+ "Economy plugin not found so money requirements will be ignored!");
+ }
+ else
+ {
+ this.economyProvided = true;
+ this.vaultHook = vault.get();
+ }
+
+ // Register the reset listener
+ this.registerListener(new ChangeOwnerListener(this));
+
+ // Register Flags
+ this.registerFlag(BIOMES_WORLD_PROTECTION);
+ this.registerFlag(BIOMES_ISLAND_PROTECTION);
+
+ // Register Request Handlers
+ this.registerRequestHandler(new BiomeDataRequestHandler(this));
+ this.registerRequestHandler(new BiomeListRequestHandler(this));
+
+ this.registerRequestHandler(new ChangeBiomeRequestHandler(this));
}
else
{
- this.logError("Biomes addon is not loaded, as it does not find valid GameModes.");
+ this.logError(
+ "Biomes could not hook into any GameMode so will not do anything!");
this.setState(State.DISABLED);
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public void onDisable()
+ public void onReload()
{
+ super.onReload();
+
if (this.hooked)
{
- if (this.settings != null)
- {
- new Config<>(this, Settings.class).saveConfigObject(this.settings);
- }
+ this.loadSettings();
+ // Reload biomes manager.
+ this.addonManager.reload();
- if (this.addonManager != null)
- {
- this.addonManager.save(false);
- }
+ this.getLogger().info("Biomes addon reloaded.");
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public void onReload()
+ public void onDisable()
{
if (this.hooked)
{
- this.loadSettings();
- // Reload biomes manager.
- this.addonManager.reloadManager();
+ if (this.settings != null)
+ {
+ new Config<>(this, Settings.class).saveConfigObject(this.settings);
+ }
- this.getLogger().info("Biomes addon reloaded.");
+ if (this.addonManager != null)
+ {
+ this.addonManager.save();
+ }
}
}
/**
- * Load addon settings.
+ * This method loads addon configuration settings in memory.
*/
private void loadSettings()
{
@@ -113,8 +197,14 @@ private void loadSettings()
}
+// ---------------------------------------------------------------------
+// Section: Getters
+// ---------------------------------------------------------------------
+
+
/**
* This method returns addon manager.
+ *
* @return Addon manager object.
*/
public BiomesAddonManager getAddonManager()
@@ -125,6 +215,7 @@ public BiomesAddonManager getAddonManager()
/**
* This method returns addon settings.
+ *
* @return Addon settings object.
*/
public Settings getSettings()
@@ -133,6 +224,46 @@ public Settings getSettings()
}
+ /**
+ * This method returns the economyProvided value.
+ * @return the value of economyProvided.
+ */
+ public boolean isEconomyProvided()
+ {
+ return this.economyProvided;
+ }
+
+
+ /**
+ * This method returns the vaultHook value.
+ * @return the value of vaultHook.
+ */
+ public VaultHook getVaultHook()
+ {
+ return this.vaultHook;
+ }
+
+
+ /**
+ * This method returns the levelAddon value.
+ * @return the value of levelAddon.
+ */
+ public Level getLevelAddon()
+ {
+ return this.levelAddon;
+ }
+
+
+ /**
+ * This method returns the levelProvided value.
+ * @return the value of levelProvided.
+ */
+ public boolean isLevelProvided()
+ {
+ return this.levelProvided;
+ }
+
+
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
@@ -152,4 +283,57 @@ public Settings getSettings()
* This variable stores biomes addon settings.
*/
private Settings settings;
+
+ /**
+ * This boolean indicate if economy is enabled.
+ */
+ private boolean economyProvided;
+
+ /**
+ * VaultHook that process economy.
+ */
+ private VaultHook vaultHook;
+
+ /**
+ * Level addon.
+ */
+ private Level levelAddon;
+
+ /**
+ * This indicate if level addon exists.
+ */
+ private boolean levelProvided;
+
+
+// ---------------------------------------------------------------------
+// Section: Flags
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This flag allows to change biomes in any part of the world. It will not limit
+ * player to their island. Useful for skygrid without protection flags.
+ */
+ public static Flag BIOMES_WORLD_PROTECTION =
+ new Flag.Builder("BIOMES_WORLD_PROTECTION", Material.GRASS_BLOCK).type(Flag.Type.WORLD_SETTING).defaultSetting(true).build();
+
+ /**
+ * This flag allows to define which users can change biomes. F.e. it can be set
+ * that only Island owner can change biomes.
+ * By default it is set to Visitor.
+ */
+ public static Flag BIOMES_ISLAND_PROTECTION =
+ new Flag.Builder("BIOMES_ISLAND_PROTECTION", Material.GRASS_BLOCK).defaultRank(RanksManager.VISITOR_RANK).build();
+
+
+// ---------------------------------------------------------------------
+// Section: Constants
+// ---------------------------------------------------------------------
+
+ /**
+ * This ir ugly way how to fix comparability issues between 1.13 and 1.14 versions.
+ * @deprecated Should be removed as soon as 1.13 support are dropped down.
+ */
+ @Deprecated
+ public static final Material SIGN_MATERIAL = Bukkit.getBukkitVersion().startsWith("1.13") ? Material.valueOf("SIGN") : Material.valueOf("OAK_SIGN");
}
diff --git a/src/main/java/world/bentobox/biomes/BiomesAddonManager.java b/src/main/java/world/bentobox/biomes/BiomesAddonManager.java
index bdc9e7e..060e818 100644
--- a/src/main/java/world/bentobox/biomes/BiomesAddonManager.java
+++ b/src/main/java/world/bentobox/biomes/BiomesAddonManager.java
@@ -9,13 +9,15 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
+import java.util.stream.Collectors;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
+import world.bentobox.bentobox.util.ItemParser;
import world.bentobox.bentobox.util.Util;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.VisibilityMode;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.VisibilityMode;
+import world.bentobox.biomes.panels.GuiUtils;
/**
@@ -33,10 +35,7 @@ protected BiomesAddonManager(BiomesAddon addon)
this.addon = addon;
this.biomesDatabase = new Database<>(addon, BiomesObject.class);
-
- // Currently only 2 game modes.
- this.worldBiomeList = new HashMap<>(2);
- this.biomesMap = new HashMap<>(Biome.values().length * 2);
+ this.biomesCacheData = new HashMap<>(Biome.values().length * 2);
this.biomesFile = new File(this.addon.getDataFolder(), "biomes.yml");
@@ -45,7 +44,7 @@ protected BiomesAddonManager(BiomesAddon addon)
this.addon.saveResource("biomes.yml", false);
}
- this.initBiomes();
+ this.load();
}
@@ -57,34 +56,24 @@ protected BiomesAddonManager(BiomesAddon addon)
/**
* Creates biomes cache.
*/
- private void initBiomes()
+ private void load()
{
- this.worldBiomeList.clear();
+ this.biomesCacheData.clear();
this.addon.getLogger().info("Loading biomes...");
- this.biomesDatabase.loadObjects().forEach(this::storeBiome);
-
- for (Map.Entry> entry : this.worldBiomeList.entrySet())
- {
- entry.getValue().sort(Comparator.comparingInt(BiomesObject::getBiomeID));
- }
+ this.biomesDatabase.loadObjects().forEach(this::loadBiomes);
}
/**
* This class reload
*/
- public void reloadManager()
+ public void reload()
{
this.addon.getLogger().info("Reloading biomes...");
this.biomesDatabase = new Database<>(this.addon, BiomesObject.class);
- this.biomesDatabase.loadObjects().forEach(this::storeBiome);
-
- for (Map.Entry> entry : this.worldBiomeList.entrySet())
- {
- entry.getValue().sort(Comparator.comparingInt(BiomesObject::getBiomeID));
- }
+ this.biomesDatabase.loadObjects().forEach(this::loadBiomes);
}
@@ -95,7 +84,7 @@ public void reloadManager()
/**
* This method allows to store single biome object.
- * @param biome Biome that must be stored.
+ * @param biome Biome that must be saved in database.
*/
public void saveBiome(BiomesObject biome)
{
@@ -104,65 +93,43 @@ public void saveBiome(BiomesObject biome)
/**
- * Save configs and biomes data
- */
- private void save()
- {
- for (Map.Entry> entry : this.worldBiomeList.entrySet())
- {
- entry.getValue().forEach(this.biomesDatabase::saveObject);
- }
- }
-
-
- /**
- * Save to the database
- * @param async - if true, saving will be done async
+ * Save biomes from cache into database
*/
- public void save(boolean async)
+ public void save()
{
- if (async)
- {
- this.addon.getServer().getScheduler().
- runTaskAsynchronously(this.addon.getPlugin(), bukkitTask -> BiomesAddonManager.this.save());
- }
- else
- {
- this.save();
- }
+ this.biomesCacheData.values().forEach(this.biomesDatabase::saveObject);
}
-
/**
- * Store biomes silently. Used when loading.
+ * Loads biomes in cache silently. Used when loading.
* @param biome that must be stored.
* @return true if successful
*/
- private boolean storeBiome(BiomesObject biome)
+ private boolean loadBiomes(BiomesObject biome)
{
- return this.storeBiome(biome, true, null, true);
+ return this.loadBiomes(biome, true, null, true);
}
/**
- * Stores the biomes.
+ * Load biomes in the cache.
* @param biome - biome that must be stored.
* @param overwrite - true if previous biomes should be overwritten
* @param user - user making the request
* @param silent - if true, no messages are sent to user
* @return - true if imported
*/
- public boolean storeBiome(BiomesObject biome, boolean overwrite, User user, boolean silent)
+ public boolean loadBiomes(BiomesObject biome, boolean overwrite, User user, boolean silent)
{
// Contains in array list is not fast.. but list is not so large, so it is ok there.
- if (this.biomesMap.containsKey(biome.getUniqueId()))
+ if (this.biomesCacheData.containsKey(biome.getUniqueId()))
{
if (!overwrite)
{
if (!silent)
{
- user.sendMessage("biomes.messages.warnings.skipping",
+ user.sendMessage("biomes.messages.skipping",
"[biome]",
biome.getFriendlyName());
}
@@ -173,31 +140,24 @@ public boolean storeBiome(BiomesObject biome, boolean overwrite, User user, bool
{
if (!silent)
{
- user.sendMessage("biomes.messages.warnings.overwriting",
+ user.sendMessage("biomes.messages.overwriting",
"[biome]",
biome.getFriendlyName());
}
- this.biomesMap.replace(biome.getUniqueId(), biome);
- List biomesList = this.worldBiomeList.get(biome.getWorld());
- // Assert INDEX out of bounds. If happens then issue is in biome loading not here!
- biomesList.set(biomesList.indexOf(biome), biome);
-
+ this.biomesCacheData.replace(biome.getUniqueId(), biome);
return true;
}
}
if (!silent)
{
- user.sendMessage("biomes.messages.information.imported",
+ user.sendMessage("biomes.messages.imported",
"[biome]",
biome.getFriendlyName());
}
- this.biomesMap.put(biome.getUniqueId(), biome);
- this.worldBiomeList.computeIfAbsent(biome.getWorld(),
- s -> new ArrayList<>(Biome.values().length)).add(biome);
-
+ this.biomesCacheData.put(biome.getUniqueId(), biome);
return true;
}
@@ -233,7 +193,9 @@ public void importBiomes(String world)
ConfigurationSection reader = config.getConfigurationSection("biomes.biomesList");
- Map biomeNameMap = Utils.getBiomeNameMap();
+ Map biomeNameMap = BiomesAddonManager.getBiomeNameMap();
+
+ int counter = 0;
for (String biome : reader.getKeys(false))
{
@@ -247,23 +209,30 @@ public void importBiomes(String world)
newBiomeObject.setFriendlyName(details.getString("friendlyName", biome));
newBiomeObject.setDescription(
- Utils.splitString(details.getString("description", "")));
- newBiomeObject.setIcon(
- Utils.parseItem(this.addon, details.getString("icon") + ":1"));
+ GuiUtils.stringSplit(details.getString("description", ""),
+ this.addon.getSettings().getLoreLineLength()));
+ newBiomeObject.setIcon(ItemParser.parse(details.getString("icon") + ":1"));
newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0));
newBiomeObject.setRequiredCost(details.getInt("cost", 0));
- newBiomeObject.setPermission(details.getString("permission", ""));
- this.biomesMap.put(newBiomeObject.getUniqueId(), newBiomeObject);
- this.worldBiomeList.computeIfAbsent(newBiomeObject.getWorld(),
- s -> new ArrayList<>(Biome.values().length)).add(newBiomeObject);
+ List permissions = details.getStringList("permission");
+
+ if (permissions == null || permissions.isEmpty())
+ {
+ newBiomeObject.setRequiredPermissions(Collections.emptySet());
+ }
+ else
+ {
+ newBiomeObject.setRequiredPermissions(new HashSet<>(permissions));
+ }
+
+ this.biomesCacheData.put(newBiomeObject.getUniqueId(), newBiomeObject);
+ counter++;
}
}
- this.addon.log("Imported " + this.worldBiomeList.get(world).size() + " biomes into " + world);
-
- this.worldBiomeList.get(world).sort(Comparator.comparingInt(BiomesObject::getBiomeID));
+ this.addon.log("Imported " + counter + " biomes into " + world);
this.save();
}
@@ -294,7 +263,7 @@ public boolean importBiomes(User user, String world, boolean overwrite)
{
if (!this.biomesFile.exists())
{
- user.sendMessage("biomes.messages.errors.no-file");
+ user.sendMessage("biomes.errors.no-file");
return false;
}
@@ -306,7 +275,7 @@ public boolean importBiomes(User user, String world, boolean overwrite)
}
catch (IOException | InvalidConfigurationException e)
{
- user.sendMessage("biomes.messages.errors.no-load",
+ user.sendMessage("biomes.errors.no-load",
"[message]",
e.getMessage());
return false;
@@ -315,8 +284,7 @@ public boolean importBiomes(User user, String world, boolean overwrite)
this.readBiomes(config, user, world, overwrite);
// Update biome order.
- this.worldBiomeList.get(world).sort(Comparator.comparingInt(BiomesObject::getBiomeID));
- this.addon.getAddonManager().save(false);
+ this.addon.getAddonManager().save();
return true;
}
@@ -334,13 +302,13 @@ private void readBiomes(YamlConfiguration config, User user, String world, boole
ConfigurationSection reader = config.getConfigurationSection("biomes.biomesList");
- Map biomeNameMap = Utils.getBiomeNameMap();
+ Map biomeNameMap = BiomesAddonManager.getBiomeNameMap();
for (String biome : reader.getKeys(false))
{
if (biomeNameMap.containsKey(biome.toUpperCase()))
{
- BiomesObject newBiomeObject = new BiomesObject(biomeNameMap.get(biome.toUpperCase()), world);
+ BiomesObject newBiomeObject = new BiomesObject(Biome.valueOf(biome.toUpperCase()), world);
newBiomeObject.setDeployed(true);
ConfigurationSection details = reader.getConfigurationSection(biome);
@@ -348,15 +316,25 @@ private void readBiomes(YamlConfiguration config, User user, String world, boole
newBiomeObject.setFriendlyName(details.getString("friendlyName", biome));
newBiomeObject.setDescription(
- Utils.splitString(details.getString("description", "")));
- newBiomeObject.setIcon(
- Utils.parseItem(this.addon, details.getString("icon") + ":1"));
+ GuiUtils.stringSplit(details.getString("description", ""),
+ this.addon.getSettings().getLoreLineLength()));
+ newBiomeObject.setIcon(ItemParser.parse(details.getString("icon") + ":1"));
newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0));
newBiomeObject.setRequiredCost(details.getInt("cost", 0));
- newBiomeObject.setPermission(details.getString("permission", ""));
- if (this.addon.getAddonManager().storeBiome(
+ List permissions = details.getStringList("permission");
+
+ if (permissions == null || permissions.isEmpty())
+ {
+ newBiomeObject.setRequiredPermissions(Collections.emptySet());
+ }
+ else
+ {
+ newBiomeObject.setRequiredPermissions(new HashSet<>(permissions));
+ }
+
+ if (this.addon.getAddonManager().loadBiomes(
newBiomeObject, overwrite, user, false))
{
size++;
@@ -364,18 +342,50 @@ private void readBiomes(YamlConfiguration config, User user, String world, boole
}
else
{
- user.sendMessage("biomes.messages.errors.load-biome",
+ user.sendMessage("biomes.errors.load-biome",
"[biome]",
biome);
}
}
- user.sendMessage("biomes.messages.information.import-count",
+ user.sendMessage("biomes.messages.import-count",
"[number]",
String.valueOf(size));
}
+// ---------------------------------------------------------------------
+// Section: Creating
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method creates and returns new biome with given uniqueID.
+ * @param uniqueID - new ID for challenge.
+ * @return biome that is currently created.
+ */
+ public BiomesObject createBiome(String uniqueID)
+ {
+ if (!this.containsBiome(uniqueID))
+ {
+ BiomesObject biome = new BiomesObject();
+ biome.setUniqueId(uniqueID);
+
+ // Sets default biome as VOID.
+ biome.setBiome(Biome.THE_VOID);
+
+ this.saveBiome(biome);
+ this.loadBiomes(biome);
+
+ return biome;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
// ---------------------------------------------------------------------
// Section: Getters / Setters
// ---------------------------------------------------------------------
@@ -417,7 +427,8 @@ public List getBiomes(World world, User user, VisibilityMode visib
allBiomeList.forEach(biomesObject -> {
if (biomesObject.isDeployed() &&
(visibilityMode.equals(VisibilityMode.DEPLOYED) ||
- user.hasPermission(biomesObject.getPermission())))
+ biomesObject.getRequiredPermissions().isEmpty() ||
+ biomesObject.getRequiredPermissions().stream().allMatch(user::hasPermission)))
{
returnBiomesList.add(biomesObject);
}
@@ -434,7 +445,9 @@ public List getBiomes(World world, User user, VisibilityMode visib
*/
public List getBiomes(World world)
{
- return this.getBiomes(Util.getWorld(world).getName());
+ world = Util.getWorld(world);
+
+ return world == null ? Collections.emptyList() : this.getBiomes(world.getName());
}
@@ -445,7 +458,10 @@ public List getBiomes(World world)
*/
public List getBiomes(String worldName)
{
- return this.worldBiomeList.getOrDefault(worldName, Collections.emptyList());
+ return this.biomesCacheData.values().stream().
+ sorted(BiomesObject::compareTo).
+ filter(biome -> biome.getUniqueId().startsWith(worldName)).
+ collect(Collectors.toList());
}
@@ -457,7 +473,34 @@ public List getBiomes(String worldName)
*/
public BiomesObject getBiomeFromString(String biomeUniqueID)
{
- return this.biomesMap.getOrDefault(biomeUniqueID, null);
+ return this.biomesCacheData.getOrDefault(biomeUniqueID, null);
+ }
+
+
+ /**
+ * Check if a biome exists - case insensitive
+ *
+ * @param name - name of biome
+ * @return true if it exists, otherwise false
+ */
+ public boolean containsBiome(String name)
+ {
+ if (this.biomesCacheData.containsKey(name))
+ {
+ return true;
+ }
+ else
+ {
+ // check database.
+ if (this.biomesDatabase.objectExists(name))
+ {
+ BiomesObject biome = this.biomesDatabase.loadObject(name);
+ this.biomesCacheData.put(name, biome);
+ return true;
+ }
+ }
+
+ return false;
}
@@ -467,15 +510,47 @@ public BiomesObject getBiomeFromString(String biomeUniqueID)
*/
public void removeBiome(BiomesObject biome)
{
- if (this.biomesMap.containsKey(biome.getUniqueId()))
+ if (this.biomesCacheData.containsKey(biome.getUniqueId()))
{
- this.biomesMap.remove(biome.getUniqueId());
- this.worldBiomeList.get(biome.getWorld()).remove(biome);
+ this.biomesCacheData.remove(biome.getUniqueId());
this.biomesDatabase.deleteObject(biome);
}
}
+ /**
+ * This method returns map that contains biomes name as key and biome as value.
+ * @return Map that contains relation from biome name to biome.
+ */
+ public static Map getBiomeNameMap()
+ {
+ Biome[] biomes = Biome.values();
+
+ Map returnMap = new HashMap<>(biomes.length);
+
+ for (Biome biome : biomes)
+ {
+ returnMap.put(biome.name(), biome);
+ }
+
+ return returnMap;
+ }
+
+
+ /**
+ * This method returns if in given world biomes are setup.
+ * @param world World that must be checked.
+ * @return True if in given world exist biomes.
+ */
+ public boolean hasAnyBiome(World world)
+ {
+ String worldName = Util.getWorld(world) == null ? "" : Util.getWorld(world).getName();
+
+ return !worldName.isEmpty() &&
+ this.biomesCacheData.values().stream().anyMatch(biome -> biome.getUniqueId().startsWith(worldName));
+ }
+
+
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
@@ -485,15 +560,10 @@ public void removeBiome(BiomesObject biome)
*/
private BiomesAddon addon;
- /**
- * Variable stores map that links worlds to their biomes.
- */
- private Map> worldBiomeList;
-
/**
* Variable stores map that links String to loaded biomes object.
*/
- private Map biomesMap;
+ private Map biomesCacheData;
/**
* Variable stores database of biomes objects.
diff --git a/src/main/java/world/bentobox/biomes/commands/ExpandedCompositeCommand.java b/src/main/java/world/bentobox/biomes/commands/ExpandedCompositeCommand.java
index d5dc2c6..cb7dfb7 100644
--- a/src/main/java/world/bentobox/biomes/commands/ExpandedCompositeCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/ExpandedCompositeCommand.java
@@ -11,9 +11,8 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.UpdateMode;
/**
@@ -40,12 +39,19 @@ protected BiomesObject getBiomeObject(List args, int index, User user)
{
if (args.size() > index)
{
- BiomesObject biome = this.addon.getAddonManager().getBiomeFromString(
- Util.getWorld(this.getWorld()).getName() + "-" + args.get(index).toLowerCase());
+ String uniqueID = args.get(index).toLowerCase();
+ String worldName = Util.getWorld(this.getWorld()).getName();
+
+ if (!uniqueID.startsWith(worldName))
+ {
+ uniqueID = worldName + "-" + uniqueID;
+ }
+
+ BiomesObject biome = this.addon.getAddonManager().getBiomeFromString(uniqueID);
if (biome == null)
{
- user.sendMessage(user.getTranslation("biomes.messages.errors.incorrect-biome",
+ user.sendMessage(user.getTranslation("biomes.errors.incorrect-object",
"[biome]",
args.get(index)));
}
@@ -54,7 +60,7 @@ protected BiomesObject getBiomeObject(List args, int index, User user)
}
else
{
- user.sendMessage(user.getTranslation("biomes.messages.errors.missing-biome"));
+ user.sendMessage(user.getTranslation("biomes.errors.missing-biome"));
return null;
}
}
@@ -71,11 +77,11 @@ protected UpdateMode getUpdateMode(List args, int index, User user)
{
if (args.size() > index)
{
- UpdateMode mode = Utils.parseStrictToUpdateMode(args.get(index));
+ UpdateMode mode = UpdateMode.getMode(args.get(index));
if (mode == null)
{
- user.sendMessage(user.getTranslation("biomes.messages.errors.incorrect-mode",
+ user.sendMessage(user.getTranslation("biomes.errors.incorrect-mode",
"[mode]",
args.get(index)));
}
@@ -114,7 +120,7 @@ protected int getUpdateRange(List args, int index, User user)
if (range < 1)
{
- user.sendMessage(user.getTranslation("biomes.messages.errors.incorrect-range",
+ user.sendMessage(user.getTranslation("biomes.errors.incorrect-range",
TextVariables.NUMBER,
args.get(index)));
}
@@ -160,7 +166,7 @@ protected User getPlayer(List args, int index, User user)
}
else
{
- user.sendMessage(user.getTranslation("biomes.messages.errors.missing-user"));
+ user.sendMessage(user.getTranslation("biomes.errors.missing-user"));
return null;
}
}
diff --git a/src/main/java/world/bentobox/biomes/commands/admin/AddBiomeCommand.java b/src/main/java/world/bentobox/biomes/commands/admin/AddBiomeCommand.java
index 79d9d77..99376ae 100644
--- a/src/main/java/world/bentobox/biomes/commands/admin/AddBiomeCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/admin/AddBiomeCommand.java
@@ -1,19 +1,16 @@
package world.bentobox.biomes.commands.admin;
-import org.bukkit.block.Biome;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Optional;
+import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.panel.admin.AdminBiomeEditPanel;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.panels.admin.EditBiomeGUI;
/**
@@ -22,12 +19,19 @@
*/
public class AddBiomeCommand extends ExpandedCompositeCommand
{
+ /**
+ * Default constructor. Inits command with "add" parameter.
+ */
public AddBiomeCommand(Addon addon, CompositeCommand parent)
{
super(addon, parent, "add");
}
+ /**
+ * This method setup this command permissions, parameters and descriptions.
+ * {@inheritDoc}
+ */
@Override
public void setup()
{
@@ -37,90 +41,96 @@ public void setup()
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public boolean execute(User user, String label, List args)
+ public boolean canExecute(User user, String label, List args)
{
if (user.isPlayer() && args.isEmpty())
{
- // Shows BiomesPanel in Edit mode.
- new AdminBiomeEditPanel(this.addon,
- this.getWorld(),
- user,
- null,
- this.getTopLabel(),
- this.getPermissionPrefix()).build();
-
return true;
}
- else
- if (args.isEmpty())
- {
- this.showHelp(this, user);
- return false;
- }
else if (args.size() > 1)
{
- user.sendMessage("biomes.messages.errors.too-many-arguments");
- this.showHelp(this, user);
- return false;
+ user.sendMessage("biomes.errors.too-many-arguments");
}
- else
+ else if (args.size() == 1)
{
- Biome newBiome = Utils.getBiomeNameMap().getOrDefault(args.get(0).toUpperCase(), null);
-
- if (newBiome == null)
+ // If biome with given ID already exist, then show error. Otherwise process command.
+ if (!this.addon.getAddonManager().containsBiome(Util.getWorld(this.getWorld()).getName() + "-" + args.get(0).toLowerCase()))
{
- user.sendMessage("biomes.messages.errors.incorrect-biome",
- "[biome]",
- args.get(0));
- return false;
+ return true;
}
else
{
- BiomesObject biomesObject = new BiomesObject(newBiome, this.getWorld());
- biomesObject.setFriendlyName(newBiome.name());
-
- if (this.addon.getAddonManager().storeBiome(biomesObject, false, user, false))
- {
- user.sendMessage("biomes.messages.information.biome-created",
- "[biome]",
- args.get(0));
- return true;
- }
-
+ user.sendMessage("biomes.errors.unique-id", "[id]", args.get(0).toLowerCase());
return false;
}
}
+
+ this.showHelp(this, user);
+ return false;
}
+ /**
+ *
+ * {@inheritDoc}
+ */
@Override
- public Optional> tabComplete(User user, String alias, List args)
+ public boolean execute(User user, String label, List args)
{
- String lastString = args.get(args.size() - 1);
-
- final List returnList = new ArrayList<>();
- final int size = args.size();
-
- switch (size)
+ if (user.isPlayer() && args.isEmpty())
{
- case 3:
- // Add all biomes that is not in BiomesObject but is defined in game.
- returnList.addAll(Utils.getBiomeNameMap().keySet());
-
- // Remove biomes that is already added, to avoid overlaps.
- List biomes = this.addon.getAddonManager().getBiomes(this.getWorld());
- biomes.forEach(biomesObject -> {
- returnList.remove(biomesObject.getBiomeName());
+ // Shows BiomesPanel in Edit mode.
+ new AnvilGUI(this.addon.getPlugin(),
+ user.getPlayer(),
+ "unique_id",
+ (player, reply) -> {
+ String newName = Util.getWorld(this.getWorld()).getName() + "-" + reply.toLowerCase();
+
+ if (!this.addon.getAddonManager().containsBiome(newName))
+ {
+ new EditBiomeGUI(this.addon,
+ this.getWorld(),
+ user,
+ this.getTopLabel(),
+ this.getPermissionPrefix(),
+ this.addon.getAddonManager().createBiome(newName)).build();
+ }
+ else
+ {
+ user.sendMessage("biomes.errors.unique-id", "[id]", reply);
+ }
+
+ return reply;
});
- break;
- default:
+ return true;
+ }
+ else
+ {
+ BiomesObject biome = this.addon.getAddonManager().createBiome(
+ Util.getWorld(this.getWorld()).getName() + "-" + args.get(0).toLowerCase());
+
+ if (user.isPlayer())
{
- break;
+ new EditBiomeGUI(this.addon,
+ this.getWorld(),
+ user,
+ this.getTopLabel(),
+ this.getPermissionPrefix(),
+ biome).build();
+ }
+ else
+ {
+ user.sendMessage("biomes.messages.biome-created",
+ "[id]",
+ args.get(0).toLowerCase());
}
- }
- return Optional.of(Util.tabLimit(returnList, lastString));
+ return true;
+ }
}
}
diff --git a/src/main/java/world/bentobox/biomes/commands/admin/AdminCommand.java b/src/main/java/world/bentobox/biomes/commands/admin/AdminCommand.java
index a0b9d2b..2133aa0 100644
--- a/src/main/java/world/bentobox/biomes/commands/admin/AdminCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/admin/AdminCommand.java
@@ -7,7 +7,7 @@
import world.bentobox.bentobox.api.commands.admin.AdminReloadCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.panel.admin.AdminMainPanel;
+import world.bentobox.biomes.panels.admin.AdminGUI;
/**
@@ -52,7 +52,7 @@ public boolean execute(User user, String label, List args)
if (user.isPlayer())
{
// Create GUI
- new AdminMainPanel(this.addon,
+ new AdminGUI(this.addon,
this.getWorld(),
user,
this.getTopLabel(),
diff --git a/src/main/java/world/bentobox/biomes/commands/admin/EditBiomeCommand.java b/src/main/java/world/bentobox/biomes/commands/admin/EditBiomeCommand.java
index d6e534d..fe95183 100644
--- a/src/main/java/world/bentobox/biomes/commands/admin/EditBiomeCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/admin/EditBiomeCommand.java
@@ -4,18 +4,17 @@
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
+import world.bentobox.biomes.BiomesAddonManager;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.panel.admin.AdminBiomeListPanel;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.panels.admin.ListBiomesGUI;
+import world.bentobox.biomes.panels.GuiUtils;
/**
@@ -37,64 +36,76 @@ public void setup()
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute(User user, String label, List args)
+ {
+ if (user.isPlayer() && args.isEmpty())
+ {
+ return true;
+ }
+ else if (args.size() < 3)
+ {
+ user.sendMessage("biomes.errors.missing-arguments");
+ }
+ else if (args.size() > 3)
+ {
+ user.sendMessage("biomes.errors.too-many-arguments");
+ }
+ else if (this.getBiomeObject(args, 0, user) != null)
+ {
+ if (CommandParameters.getParameter(args.get(1)) == null)
+ {
+ user.sendMessage("biomes.errors.unknown-argument");
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ this.showHelp(this, user);
+ return false;
+ }
+
+
@Override
public boolean execute(User user, String label, List args)
{
if (user.isPlayer() && args.isEmpty())
{
// Shows BiomesPanel in Edit mode.
- new AdminBiomeListPanel(this.addon,
+ new ListBiomesGUI(this.addon,
this.getWorld(),
user,
- true,
this.getTopLabel(),
- this.getPermissionPrefix()).build();
+ this.getPermissionPrefix(),
+ true).build();
return true;
}
- else if (args.isEmpty())
- {
- this.showHelp(this, user);
- return false;
- }
- else if (args.size() < 3)
- {
- user.sendMessage("biomes.messages.errors.missing-arguments");
- this.showHelp(this, user);
- return false;
- }
else
{
BiomesObject biomesObject = this.getBiomeObject(args, 0, user);
- if (biomesObject == null)
- {
- return false;
- }
-
// Use proper setter based on 2. argument.
-
- switch (args.get(1))
+ switch (CommandParameters.getParameter(args.get(1)))
{
case BIOME:
String newBiomeString = args.get(2);
-
- user.sendMessage("biomes.messages.warnings.may-break-others",
- "[biome]",
- newBiomeString);
-
- Biome newBiome = Utils.getBiomeNameMap().getOrDefault(newBiomeString.toUpperCase(), null);
+ Biome newBiome = BiomesAddonManager.getBiomeNameMap().getOrDefault(newBiomeString.toUpperCase(), null);
if (newBiome == null)
{
- user.sendMessage("biomes.messages.errors.incorrect-biome",
+ user.sendMessage("biomes.errors.incorrect-biome",
"[biome]",
newBiomeString);
return false;
}
else
{
- biomesObject.setBiomeName(newBiome.name());
- biomesObject.setBiomeID(newBiome.ordinal());
+ biomesObject.setBiome(newBiome);
}
break;
@@ -102,14 +113,14 @@ else if (args.size() < 3)
biomesObject.setFriendlyName(this.buildStringFromValue(args));
break;
case DESCRIPTION:
- biomesObject.setDescription(Utils.splitString(this.buildStringFromValue(args)));
+ biomesObject.setDescription(GuiUtils.stringSplit(this.buildStringFromValue(args), this.addon.getSettings().getLoreLineLength()));
break;
case ICON:
Material newIcon = Material.getMaterial(args.get(2).toUpperCase());
if (newIcon == null)
{
- user.sendMessage("biomes.messages.errors.incorrect-icon",
+ user.sendMessage("biomes.errors.incorrect-icon",
"[icon]",
args.get(2));
return false;
@@ -134,7 +145,7 @@ else if (args.get(2).equalsIgnoreCase("false"))
}
else
{
- user.sendMessage("biomes.messages.errors.incorrect-boolean",
+ user.sendMessage("biomes.errors.incorrect-boolean",
"[boolean]",
args.get(2));
return false;
@@ -149,12 +160,26 @@ else if (args.get(2).equalsIgnoreCase("false"))
}
catch (Exception e)
{
- user.sendMessage("biomes.messages.errors.incorrect-range",
+ user.sendMessage("biomes.errors.incorrect-range",
"[number]",
args.get(2));
return false;
}
-
+ case ORDER:
+ {
+ try
+ {
+ biomesObject.setOrder(Integer.parseUnsignedInt(args.get(2)));
+ break;
+ }
+ catch (Exception e)
+ {
+ user.sendMessage("biomes.errors.incorrect-range",
+ "[number]",
+ args.get(2));
+ return false;
+ }
+ }
case REQUIRED_LEVEL:
try
{
@@ -163,25 +188,18 @@ else if (args.get(2).equalsIgnoreCase("false"))
}
catch (Exception e)
{
- user.sendMessage("biomes.messages.errors.incorrect-range",
+ user.sendMessage("biomes.errors.incorrect-range",
"[number]",
args.get(2));
return false;
}
- case PERMISSION:
- // TODO: probably validation?
- biomesObject.setPermission(args.get(2));
+ case PERMISSIONS:
+ biomesObject.setRequiredPermissions(new HashSet<>(Arrays.asList(args.get(2).split(";"))));
break;
- default:
- user.sendMessage("biomes.messages.errors.incorrect-parameter",
- "[property]",
- args.get(1));
- return false;
}
-
this.addon.getAddonManager().saveBiome(biomesObject);
- user.sendMessage("biomes.messages.information.saved",
+ user.sendMessage("biomes.messages.saved",
"[biome]",
biomesObject.getFriendlyName());
return true;
@@ -189,6 +207,9 @@ else if (args.get(2).equalsIgnoreCase("false"))
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Optional> tabComplete(User user, String alias, List args)
{
@@ -200,37 +221,30 @@ public Optional> tabComplete(User user, String alias, List
switch (size)
{
case 3:
- List biomes = this.addon.getAddonManager().getBiomes(this.getWorld());
+ String worldName = this.getWorld() != null && Util.getWorld(this.getWorld()) != null ?
+ Util.getWorld(this.getWorld()).getName() : "";
// Create suggestions with all biomes that is available for users.
-
- biomes.forEach(biomesObject -> {
- returnList.add(biomesObject.getBiomeName());
+ this.addon.getAddonManager().getBiomes(worldName).forEach(biomesObject -> {
+ returnList.add(biomesObject.getUniqueId().replaceFirst(worldName + "-", ""));
});
break;
case 4:
// Create list with all biome properties values.
- returnList.add(BIOME);
- returnList.add(FRIENDLY_NAME);
- returnList.add(DESCRIPTION);
- returnList.add(ICON);
-
- returnList.add(DEPLOYED);
-
- returnList.add(REQUIRED_COST);
- returnList.add(REQUIRED_LEVEL);
- returnList.add(PERMISSION);
+ Arrays.stream(CommandParameters.values()).
+ map(properties -> properties.parameter).
+ forEach(returnList::add);
break;
case 5:
// Change last variable depending on previous value.
- switch (args.get(3))
+ switch (CommandParameters.getParameter(args.get(3)))
{
case BIOME:
- returnList.addAll(Utils.getBiomeNameMap().keySet());
+ returnList.addAll(BiomesAddonManager.getBiomeNameMap().keySet());
break;
case FRIENDLY_NAME:
returnList.add("");
@@ -250,13 +264,12 @@ public Optional> tabComplete(User user, String alias, List
returnList.add("");
break;
case REQUIRED_COST:
- returnList.add("");
- break;
+ case ORDER:
case REQUIRED_LEVEL:
returnList.add("");
break;
- case PERMISSION:
- returnList.add("");
+ case PERMISSIONS:
+ returnList.add("");
break;
}
@@ -295,19 +308,62 @@ private String buildStringFromValue(List args)
// ---------------------------------------------------------------------
- private static final String BIOME = "biomeName";
-
- private static final String DEPLOYED = "deployed";
+ /**
+ * This enum contains all values that can be changed in BiomeObject.
+ */
+ private enum CommandParameters
+ {
+ BIOME("biomeName"),
+ DEPLOYED("deployed"),
+ FRIENDLY_NAME("friendlyName"),
+ DESCRIPTION("description"),
+ ICON("icon"),
+ REQUIRED_COST("requiredCost"),
+ REQUIRED_LEVEL("requiredLevel"),
+ PERMISSIONS("requiredPermissions"),
+ ORDER("order");
+
+
+ /**
+ * Constructor.
+ * @param parameter of the command.
+ */
+ CommandParameters(String parameter)
+ {
+ this.parameter = parameter;
+ }
- private static final String FRIENDLY_NAME = "friendlyName";
- private static final String DESCRIPTION = "description";
+ /**
+ * This method returns stored parameter from string.
+ * @param parameter String of object that must be returned
+ * @return CommandParameters object or null.
+ */
+ public static CommandParameters getParameter(String parameter)
+ {
+ return BY_NAME.get(parameter);
+ }
- private static final String ICON = "icon";
- private static final String REQUIRED_COST = "requiredCost";
+ /**
+ * Parameter name.
+ */
+ private String parameter;
- private static final String REQUIRED_LEVEL = "requiredLevel";
+ /**
+ * This map allows to access all enum values via their string.
+ */
+ private final static Map BY_NAME = new HashMap<>();
- private static final String PERMISSION = "permission";
+ /**
+ * This static method populated BY_NAME map.
+ */
+ static
+ {
+ for (CommandParameters command : CommandParameters.values())
+ {
+ BY_NAME.put(command.parameter, command);
+ }
+ }
+ }
}
diff --git a/src/main/java/world/bentobox/biomes/commands/admin/SetBiomeCommand.java b/src/main/java/world/bentobox/biomes/commands/admin/SetBiomeCommand.java
index c2ce92b..a2e2b91 100644
--- a/src/main/java/world/bentobox/biomes/commands/admin/SetBiomeCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/admin/SetBiomeCommand.java
@@ -1,19 +1,17 @@
package world.bentobox.biomes.commands.admin;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
+import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.panel.admin.AdminUserListPanel;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.UpdateMode;
+import world.bentobox.biomes.panels.admin.ListUsersGUI;
import world.bentobox.biomes.tasks.BiomeUpdateHelper;
/**
@@ -21,121 +19,138 @@
*/
public class SetBiomeCommand extends ExpandedCompositeCommand
{
- public SetBiomeCommand(Addon addon, CompositeCommand parent)
- {
- super(addon, parent, "set");
- }
-
- @Override
- public void setup()
- {
- this.setPermission("admin.biomes.set");
- this.setParametersHelp("biomes.commands.admin.set.parameters");
- this.setDescription("biomes.commands.admin.set.description");
- }
-
-
- @Override
- public boolean execute(User user, String label, List args)
- {
- if (user.isPlayer() && args.isEmpty())
- {
- // Shows admin panel
- new AdminUserListPanel(this.addon,
- this.getWorld(),
- user,
- this.getTopLabel(),
- this.getPermissionPrefix()).build();
- return true;
- }
- else if (args.isEmpty())
- {
- this.showHelp(this, user);
- return false;
- }
- else
- {
- User targetUser = this.getPlayer(args, 0, user);
- BiomesObject biome = this.getBiomeObject(args, 1, user);
- UpdateMode updateMode = this.getUpdateMode(args, 2, user);
- int size = this.getUpdateRange(args, 3, user);
-
- if (targetUser == null || biome == null || updateMode == null || size < 1)
- {
- // Show help if something fails.
- this.showHelp(this, user);
- return false;
- }
- else
- {
- // Use BiomeUpdateHelper to change biome for user.
-
- BiomeUpdateHelper helper = new BiomeUpdateHelper(this.addon,
- user,
- targetUser,
- biome,
- user.getWorld(),
- updateMode,
- size,
- false);
-
- if (helper.canChangeBiome())
- {
- helper.updateIslandBiome();
- return true;
- }
-
- return false;
- }
- }
- }
-
-
- @Override
- public Optional> tabComplete(User user, String alias, List args)
- {
- String lastString = args.get(args.size() - 1);
-
- final List returnList = new ArrayList<>();
- final int size = args.size();
-
- switch (size)
- {
- case 3:
- returnList.addAll(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastString));
- break;
- case 4:
- List biomes = this.addon.getAddonManager().getBiomes(this.getWorld());
-
- // Create suggestions with all biomes that is available for users.
-
- biomes.forEach(biomesObject -> {
- returnList.addAll(Util.tabLimit(
- Collections.singletonList(biomesObject.getBiomeName()), lastString));
- });
-
- break;
- case 5:
- // Create suggestions with all biomes that is available for users.
-
- returnList.addAll(Util.tabLimit(Collections.singletonList("ISLAND"), lastString));
- returnList.addAll(Util.tabLimit(Collections.singletonList("CHUNK"), lastString));
- returnList.addAll(Util.tabLimit(Collections.singletonList("SQUARE"), lastString));
-
- break;
- case 6:
- if (lastString.isEmpty() || lastString.matches("[0-9]*"))
- {
- returnList.addAll(Util.tabLimit(Collections.singletonList(""), lastString));
- }
-
- break;
- default:
- {
- break;
- }
- }
-
- return Optional.of(returnList);
- }
+ public SetBiomeCommand(Addon addon, CompositeCommand parent)
+ {
+ super(addon, parent, "set");
+ }
+
+ @Override
+ public void setup()
+ {
+ this.setPermission("admin.biomes.set");
+ this.setParametersHelp("biomes.commands.admin.set.parameters");
+ this.setDescription("biomes.commands.admin.set.description");
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute(User user, String label, List args)
+ {
+ if (user.isPlayer() && args.isEmpty())
+ {
+ return true;
+ }
+ else
+ {
+ User targetUser = this.getPlayer(args, 0, user);
+ BiomesObject biome = this.getBiomeObject(args, 1, user);
+ UpdateMode updateMode = this.getUpdateMode(args, 2, user);
+ int size = this.getUpdateRange(args, 3, user);
+
+ if (targetUser != null && biome != null && updateMode != null && size >= 1)
+ {
+ return true;
+ }
+ }
+
+ this.showHelp(this, user);
+ return false;
+ }
+
+
+ @Override
+ public boolean execute(User user, String label, List args)
+ {
+ if (user.isPlayer() && args.isEmpty())
+ {
+ // Shows admin panel
+ new ListUsersGUI(this.addon,
+ this.getWorld(),
+ user,
+ this.getTopLabel(),
+ this.getPermissionPrefix()).build();
+ return true;
+ }
+ else
+ {
+ User targetUser = this.getPlayer(args, 0, user);
+ BiomesObject biome = this.getBiomeObject(args, 1, user);
+ UpdateMode updateMode = this.getUpdateMode(args, 2, user);
+ int size = this.getUpdateRange(args, 3, user);
+
+ // Use BiomeUpdateHelper to change biome for user.
+ BiomeUpdateHelper helper = new BiomeUpdateHelper(this.addon,
+ user,
+ targetUser,
+ biome,
+ getWorld(),
+ updateMode,
+ size,
+ false);
+
+ if (helper.canChangeBiome())
+ {
+ helper.updateIslandBiome();
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+
+ @Override
+ public Optional> tabComplete(User user, String alias, List args)
+ {
+ String lastString = args.get(args.size() - 1);
+
+ final List returnList = new ArrayList<>();
+ final int size = args.size();
+
+ switch (size)
+ {
+ case 3:
+ returnList.addAll(Util.getOnlinePlayerList(user));
+ break;
+ case 4:
+ String worldName = this.getWorld() != null && Util.getWorld(this.getWorld()) != null ?
+ Util.getWorld(this.getWorld()).getName() : "";
+
+ // Create suggestions with all biomes that is available for users.
+ this.addon.getAddonManager().getBiomes(worldName).forEach(biomesObject -> {
+ returnList.add(biomesObject.getUniqueId().replaceFirst(worldName + "-", ""));
+ });
+
+ break;
+ case 5:
+ // Create suggestions with all update modes that is available for users.
+ Arrays.stream(UpdateMode.values()).
+ map(Enum::name).
+ forEach(returnList::add);
+
+ if (!BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.getWorld()))
+ {
+ // Do not suggest island as it is not valid option
+ returnList.remove(UpdateMode.ISLAND.name());
+ }
+
+ break;
+ case 6:
+ if (lastString.isEmpty() || lastString.matches("[0-9]*"))
+ {
+ returnList.add("");
+ }
+
+ break;
+ default:
+ {
+ break;
+ }
+ }
+
+ return Optional.of(Util.tabLimit(returnList, lastString));
+ }
}
diff --git a/src/main/java/world/bentobox/biomes/commands/admin/SettingsCommand.java b/src/main/java/world/bentobox/biomes/commands/admin/SettingsCommand.java
index 292af57..a4aaab6 100644
--- a/src/main/java/world/bentobox/biomes/commands/admin/SettingsCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/admin/SettingsCommand.java
@@ -1,18 +1,16 @@
package world.bentobox.biomes.commands.admin;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.panel.admin.AdminSettingsPanel;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.config.Settings.UpdateMode;
+import world.bentobox.biomes.config.Settings.VisibilityMode;
+import world.bentobox.biomes.panels.admin.EditSettingsGUI;
/**
* This command allows to edit biomes addon settings.
@@ -33,33 +31,60 @@ public void setup()
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute(User user, String label, List args)
+ {
+ if (user.isPlayer() && args.isEmpty())
+ {
+ return true;
+ }
+ else if (args.size() < 2)
+ {
+ user.sendMessage("biomes.errors.missing-arguments");
+ }
+ else if (args.size() > 2)
+ {
+ user.sendMessage("biomes.errors.too-many-arguments");
+ }
+ else
+ {
+ if (CommandParameters.getParameter(args.get(0)) == null)
+ {
+ user.sendMessage("biomes.errors.unknown-argument");
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ this.showHelp(this, user);
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean execute(User user, String label, List args)
{
if (user.isPlayer() && args.isEmpty())
{
// Shows admin panel
- new AdminSettingsPanel(this.addon,
+ new EditSettingsGUI(this.addon,
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix()).build();
return true;
}
- else if (args.isEmpty())
- {
- this.showHelp(this, user);
- return false;
- }
- else if (args.size() < 2)
- {
- user.sendMessage("biomes.messages.errors.missing-arguments");
- this.showHelp(this, user);
- return false;
- }
else
{
- switch (args.get(0).toLowerCase())
+ switch (CommandParameters.getParameter(args.get(0)))
{
case MENU:
if (args.get(1).equalsIgnoreCase("true"))
@@ -74,17 +99,17 @@ else if (args.get(1).equalsIgnoreCase("false"))
}
else
{
- user.sendMessage("biomes.messages.errors.incorrect-boolean",
+ user.sendMessage("biomes.errors.incorrect-boolean",
"[boolean]",
args.get(1));
return false;
}
case TYPE:
- UpdateMode mode = Utils.parseStrictToUpdateMode(args.get(1).toUpperCase());
+ UpdateMode mode = UpdateMode.getMode(args.get(1).toUpperCase());
if (mode == null)
{
- user.sendMessage("biomes.messages.errors.incorrect-mode",
+ user.sendMessage("biomes.errors.incorrect-mode",
"[mode]",
args.get(1));
return false;
@@ -99,7 +124,7 @@ else if (args.get(1).equalsIgnoreCase("false"))
}
catch (Exception e)
{
- user.sendMessage("biomes.messages.errors.incorrect-range",
+ user.sendMessage("biomes.errors.incorrect-range",
"[number]",
args.get(1));
return false;
@@ -117,7 +142,7 @@ else if (args.get(1).equalsIgnoreCase("false"))
}
else
{
- user.sendMessage("biomes.messages.errors.incorrect-boolean",
+ user.sendMessage("biomes.errors.incorrect-boolean",
"[boolean]",
args.get(1));
return false;
@@ -130,24 +155,56 @@ else if (args.get(1).equalsIgnoreCase("false"))
}
catch (Exception e)
{
- user.sendMessage("biomes.messages.errors.incorrect-range",
+ user.sendMessage("biomes.errors.incorrect-range",
"[number]",
args.get(1));
return false;
}
- default:
- user.sendMessage("biomes.messages.errors.incorrect-parameter",
- "[property]",
- args.get(0));
- return false;
+ case VISIBILITY:
+ {
+ VisibilityMode visibility = VisibilityMode.getMode(args.get(1).toUpperCase());
+
+ if (visibility == null)
+ {
+ user.sendMessage("biomes.errors.incorrect-visibility",
+ "[mode]",
+ args.get(1));
+ return false;
+ }
+ this.addon.getSettings().setVisibilityMode(visibility);
+ break;
+ }
+ case LORE_LENGTH:
+ {
+ try
+ {
+ this.addon.getSettings().setLoreLineLength(Integer.parseInt(args.get(1)));
+ break;
+ }
+ catch (Exception e)
+ {
+ user.sendMessage("biomes.errors.incorrect-range",
+ "[number]",
+ args.get(1));
+ return false;
+ }
+ }
+ case LORE_MESSAGE:
+ {
+ this.addon.getSettings().setLoreMessage(args.get(1));
+ break;
+ }
}
- user.sendMessage("biomes.messages.information.saved-config");
+ user.sendMessage("biomes.messages.saved-config");
return true;
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Optional> tabComplete(User user, String alias, List args)
{
@@ -162,28 +219,35 @@ public Optional> tabComplete(User user, String alias, List
case 3:
// Create list with all addon settings values.
- returnList.add(MENU);
- returnList.add(TYPE);
- returnList.add(SIZE);
- returnList.add(RESET_BIOME);
- returnList.add(TIMEOUT);
+ Arrays.stream(CommandParameters.values()).
+ map(properties -> properties.parameter).
+ forEach(returnList::add);
break;
case 5:
// Change last variable depending on previous value.
- switch (args.get(3))
+ switch (CommandParameters.getParameter(args.get(3)))
{
case MENU:
case RESET_BIOME:
returnList.add("");
break;
case TYPE:
- returnList.add("island");
- returnList.add("chunk");
- returnList.add("square");
+ Arrays.stream(UpdateMode.values()).
+ map(Enum::name).
+ forEach(returnList::add);
+ break;
+ case VISIBILITY:
+ Arrays.stream(VisibilityMode.values()).
+ map(Enum::name).
+ forEach(returnList::add);
+ break;
+ case LORE_MESSAGE:
+ returnList.add("");
break;
case SIZE:
+ case LORE_LENGTH:
case TIMEOUT:
returnList.add("");
break;
@@ -205,13 +269,61 @@ public Optional> tabComplete(User user, String alias, List
// ---------------------------------------------------------------------
- private static final String MENU = "advancedmenu";
+ /**
+ * This enum contains all values that can be changed in BiomeObject.
+ */
+ private enum CommandParameters
+ {
+ MENU("advancedmenu"),
+ TYPE("defaulttype"),
+ SIZE("defaultsize"),
+ TIMEOUT("timeout"),
+ RESET_BIOME("resetbiomes"),
+ VISIBILITY("visibilitymode"),
+ LORE_LENGTH("lorelength"),
+ LORE_MESSAGE("loremessage");
+
+
+ /**
+ * Constructor.
+ * @param parameter of the command.
+ */
+ CommandParameters(String parameter)
+ {
+ this.parameter = parameter;
+ }
+
+
+ /**
+ * This method returns stored parameter from string.
+ * @param parameter String of object that must be returned
+ * @return CommandParameters object or null.
+ */
+ public static CommandParameters getParameter(String parameter)
+ {
+ return BY_NAME.get(parameter);
+ }
- private static final String TYPE = "defaulttype";
- private static final String SIZE = "defaultsize";
+ /**
+ * Parameter name.
+ */
+ private String parameter;
- private static final String TIMEOUT = "timeout";
+ /**
+ * This map allows to access all enum values via their string.
+ */
+ private final static Map BY_NAME = new HashMap<>();
- private static final String RESET_BIOME = "resetbiomes";
+ /**
+ * This static method populated BY_NAME map.
+ */
+ static
+ {
+ for (CommandParameters command : CommandParameters.values())
+ {
+ BY_NAME.put(command.parameter, command);
+ }
+ }
+ }
}
diff --git a/src/main/java/world/bentobox/biomes/commands/user/BiomesCommand.java b/src/main/java/world/bentobox/biomes/commands/user/BiomesCommand.java
index a5d1551..2539f57 100644
--- a/src/main/java/world/bentobox/biomes/commands/user/BiomesCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/user/BiomesCommand.java
@@ -2,11 +2,13 @@
import java.util.List;
+import java.util.Optional;
+import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.panel.user.ChangeBiomePanel;
+import world.bentobox.biomes.panels.user.BiomesChooseGUI;
/**
@@ -26,24 +28,70 @@ public void setup()
{
this.setPermission("biomes");
this.setOnlyPlayer(true);
- this.setParametersHelp("biomes.commands.help.parameters");
- this.setDescription("biomes.commands.help.description");
+ this.setParametersHelp("biomes.commands.user.help.parameters");
+ this.setDescription("biomes.commands.user.help.description");
new BiomesSetCommand(this.getAddon(), this);
new BiomesInfoCommand(this.getAddon(), this);
}
+ /**
+ * This method checks if user can execute this command.
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute(User user, String label, List args)
+ {
+ Optional optionalAddon = this.getAddon().getPlugin().getIWM().getAddon(this.getWorld());
+
+ if (!optionalAddon.isPresent())
+ {
+ // Not a GameMode world.
+ user.sendMessage("general.errors.wrong-world");
+ return false;
+ }
+
+ if (!((BiomesAddon) this.getAddon()).getAddonManager().hasAnyBiome(this.getWorld()))
+ {
+ // Do not open gui if there is no biomes.
+
+ this.getAddon().getLogger().severe("There are no biomes set up in " + this.getWorld() + "!");
+
+ // Show admin better explanation.
+ if (user.isOp() || user.hasPermission(this.getPermissionPrefix() + ".admin.biomes"))
+ {
+ String topLabel = optionalAddon.get().getAdminCommand().orElseGet(this::getParent).getTopLabel();
+ user.sendMessage("biomes.errors.no-biomes-admin", "[label]", topLabel);
+ }
+ else
+ {
+ user.sendMessage("biomes.errors.no-biomes");
+ }
+
+ return false;
+ }
+
+ if (this.getPlugin().getIslands().getIsland(this.getWorld(), user.getUniqueId()) == null)
+ {
+ // Do not open gui if there is no island for this player.
+ user.sendMessage("general.errors.no-island");
+ return false;
+ }
+
+ return true;
+ }
+
+
@Override
public boolean execute(User user, String string, List args)
{
// Open up the biomes GUI
if (user.isPlayer())
{
- new ChangeBiomePanel(this.addon,
+ new BiomesChooseGUI(this.addon,
this.getWorld(),
user,
- null,
this.getTopLabel(),
this.getPermissionPrefix()).build();
diff --git a/src/main/java/world/bentobox/biomes/commands/user/BiomesInfoCommand.java b/src/main/java/world/bentobox/biomes/commands/user/BiomesInfoCommand.java
index 18e6ae0..3ef0896 100644
--- a/src/main/java/world/bentobox/biomes/commands/user/BiomesInfoCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/user/BiomesInfoCommand.java
@@ -10,7 +10,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.BiomesObject;
+import world.bentobox.biomes.database.objects.BiomesObject;
/**
@@ -27,8 +27,8 @@ public BiomesInfoCommand(Addon addon, BiomesCommand command)
public void setup()
{
this.setPermission("biomes.info");
- this.setParametersHelp("biomes.commands.info.parameters");
- this.setDescription("biomes.commands.info.description");
+ this.setParametersHelp("biomes.commands.user.info.parameters");
+ this.setDescription("biomes.commands.user.info.description");
this.setOnlyPlayer(true);
}
@@ -41,12 +41,15 @@ public boolean execute(User user, String label, List args)
if (biomesObject != null)
{
- user.sendMessage("biomes.messages.biome-information.header", "[name]", biomesObject.getFriendlyName());
- user.sendMessage("biomes.messages.biome-information.type", "[type]", biomesObject.getBiomeName());
- user.sendMessage("biomes.messages.biome-information.description", "[description]", this.getSingleLineDescription(biomesObject.getDescription()));
- user.sendMessage("biomes.messages.biome-information.level", "[level]", Long.toString(biomesObject.getRequiredLevel()));
- user.sendMessage("biomes.messages.biome-information.cost","[cost]", Integer.toString(biomesObject.getRequiredCost()));
- user.sendMessage("biomes.messages.biome-information.permission","[permission]", biomesObject.getPermission());
+ user.sendMessage("biomes.information.header", "[name]", biomesObject.getFriendlyName());
+ user.sendMessage("biomes.information.type", "[type]", biomesObject.getBiome().name());
+ user.sendMessage("biomes.information.description", "[description]", this.getSingleLineDescription(biomesObject.getDescription()));
+ user.sendMessage("biomes.information.level", "[level]", Long.toString(biomesObject.getRequiredLevel()));
+ user.sendMessage("biomes.information.cost","[cost]", Integer.toString(biomesObject.getRequiredCost()));
+
+ biomesObject.getRequiredPermissions().forEach(s -> {
+ user.sendMessage("biomes.information.permission","[permission]", s);
+ });
return true;
}
@@ -67,19 +70,17 @@ public Optional> tabComplete(User user, String alias, List
return Optional.of(new ArrayList<>());
}
- String lastString = args.get(args.size() - 1);
-
final List returnList = new ArrayList<>();
- List biomes = this.addon.getAddonManager().getBiomes(this.getWorld());
+ String worldName = this.getWorld() != null && Util.getWorld(this.getWorld()) != null ?
+ Util.getWorld(this.getWorld()).getName() : "";
// Create suggestions with all biomes that is available for users.
- biomes.forEach(biomesObject -> {
- returnList.addAll(Util.tabLimit(
- Collections.singletonList(biomesObject.getBiomeName()), lastString));
+ this.addon.getAddonManager().getBiomes(worldName).forEach(biomesObject -> {
+ returnList.add(biomesObject.getUniqueId().replaceFirst(worldName + "-", ""));
});
- return Optional.of(returnList);
+ return Optional.of(Util.tabLimit(returnList, args.get(args.size() - 1)));
}
}
diff --git a/src/main/java/world/bentobox/biomes/commands/user/BiomesSetCommand.java b/src/main/java/world/bentobox/biomes/commands/user/BiomesSetCommand.java
index b9bebf5..a2f7621 100644
--- a/src/main/java/world/bentobox/biomes/commands/user/BiomesSetCommand.java
+++ b/src/main/java/world/bentobox/biomes/commands/user/BiomesSetCommand.java
@@ -1,18 +1,16 @@
package world.bentobox.biomes.commands.user;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
+import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.UpdateMode;
import world.bentobox.biomes.tasks.BiomeUpdateHelper;
@@ -31,8 +29,8 @@ public BiomesSetCommand(Addon addon, CompositeCommand command)
public void setup()
{
this.setPermission("biomes.set");
- this.setParametersHelp("biomes.commands.set.parameters");
- this.setDescription("biomes.commands.set.description");
+ this.setParametersHelp("biomes.commands.user.set.parameters");
+ this.setDescription("biomes.commands.user.set.description");
this.setOnlyPlayer(true);
}
@@ -87,38 +85,44 @@ public Optional> tabComplete(User user, String alias, List
switch (size)
{
case 3:
- List biomes = this.addon.getAddonManager().getBiomes(this.getWorld());
+ String worldName = this.getWorld() != null && Util.getWorld(this.getWorld()) != null ?
+ Util.getWorld(this.getWorld()).getName() : "";
- // Create suggestions with all biomes that is available for users.
+ List biomes = this.addon.getAddonManager().getBiomes(worldName);
+ // Create suggestions with all biomes that is available for users.
biomes.forEach(biomesObject -> {
- returnList.addAll(Util.tabLimit(
- Collections.singletonList(biomesObject.getBiomeName()), lastString));
+ returnList.add(biomesObject.getUniqueId().replaceFirst(worldName + "-", ""));
});
break;
case 4:
- // Create suggestions with all biomes that is available for users.
+ // Create suggestions with all update modes that is available for users.
+ Arrays.stream(UpdateMode.values()).
+ map(Enum::name).
+ forEach(returnList::add);
- returnList.addAll(Util.tabLimit(Collections.singletonList("ISLAND"), lastString));
- returnList.addAll(Util.tabLimit(Collections.singletonList("CHUNK"), lastString));
- returnList.addAll(Util.tabLimit(Collections.singletonList("SQUARE"), lastString));
+ if (!BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.getWorld()))
+ {
+ // Do not suggest island as it is not valid option
+ returnList.remove(UpdateMode.ISLAND.name());
+ }
break;
case 5:
if (lastString.isEmpty() || lastString.matches("[0-9]*"))
{
- returnList.addAll(Util.tabLimit(Collections.singletonList(""), lastString));
+ returnList.add("");
}
break;
default:
{
- returnList.addAll(Util.tabLimit(Collections.singletonList("help"), lastString));
+ returnList.add("help");
break;
}
}
- return Optional.of(returnList);
+ return Optional.of(Util.tabLimit(returnList, lastString));
}
}
diff --git a/src/main/java/world/bentobox/biomes/objects/Settings.java b/src/main/java/world/bentobox/biomes/config/Settings.java
similarity index 68%
rename from src/main/java/world/bentobox/biomes/objects/Settings.java
rename to src/main/java/world/bentobox/biomes/config/Settings.java
index 91afe10..5ca9a0a 100644
--- a/src/main/java/world/bentobox/biomes/objects/Settings.java
+++ b/src/main/java/world/bentobox/biomes/config/Settings.java
@@ -1,13 +1,15 @@
-package world.bentobox.biomes.objects;
+package world.bentobox.biomes.config;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
+import world.bentobox.bentobox.api.configuration.ConfigObject;
import world.bentobox.bentobox.api.configuration.StoreAt;
-import world.bentobox.bentobox.database.objects.DataObject;
/**
@@ -20,20 +22,13 @@
@ConfigComment("You cannot edit it while the server is running because changes will")
@ConfigComment("be lost! Use in-game settings GUI or edit when server is offline.")
@ConfigComment("")
-public class Settings implements DataObject
+public class Settings implements ConfigObject
{
// ---------------------------------------------------------------------
// Section: Getters
// ---------------------------------------------------------------------
- @Override
- public String getUniqueId()
- {
- return this.uniqueId;
- }
-
-
/**
* This method returns if advanced menu is enabled.
* @return true - if enabled, otherwise false.
@@ -104,18 +99,31 @@ public Set getDisabledGameModes()
}
-// ---------------------------------------------------------------------
-// Section: Setters
-// ---------------------------------------------------------------------
+ /**
+ * This method returns the loreMessage value.
+ * @return the value of loreMessage.
+ */
+ public String getLoreMessage()
+ {
+ return loreMessage;
+ }
- @Override
- public void setUniqueId(String uniqueId)
+ /**
+ * This method returns the loreLineLength value.
+ * @return the loreLineLength value.
+ */
+ public int getLoreLineLength()
{
- this.uniqueId = uniqueId;
+ return this.loreLineLength;
}
+// ---------------------------------------------------------------------
+// Section: Setters
+// ---------------------------------------------------------------------
+
+
/**
* This method sets value of advancedMenu variable.
* @param advancedMenu new value.
@@ -186,6 +194,27 @@ public void setDisabledGameModes(Set disabledGameModes)
}
+ /**
+ * This method sets the loreMessage value.
+ * @param loreMessage the loreMessage new value.
+ */
+ public void setLoreMessage(String loreMessage)
+ {
+ this.loreMessage = loreMessage;
+ }
+
+
+ /**
+ * This method sets the loreLineLength object value.
+ * @param loreLineLength the loreLineLength object new value.
+ *
+ */
+ public void setLoreLineLength(int loreLineLength)
+ {
+ this.loreLineLength = loreLineLength;
+ }
+
+
// ---------------------------------------------------------------------
// Section: Enums used for Settings.
// ---------------------------------------------------------------------
@@ -198,7 +227,33 @@ public enum UpdateMode
{
ISLAND,
CHUNK,
- SQUARE
+ RANGE;
+
+ /**
+ * This method returns stored parameter from string.
+ * @param parameter String of object that must be returned
+ * @return CommandParameters object or null.
+ */
+ public static UpdateMode getMode(String parameter)
+ {
+ return BY_NAME.get(parameter);
+ }
+
+ /**
+ * This map allows to access all enum values via their string.
+ */
+ private final static Map BY_NAME = new HashMap<>();
+
+ /**
+ * This static method populated BY_NAME map.
+ */
+ static
+ {
+ for (UpdateMode mode : UpdateMode.values())
+ {
+ BY_NAME.put(mode.name(), mode);
+ }
+ }
}
@@ -208,9 +263,36 @@ public enum UpdateMode
public enum VisibilityMode
{
ALL,
- ACCESSIBLE,
DEPLOYED,
- TOGGLEABLE
+ ACCESSIBLE,
+ TOGGLEABLE;
+
+
+ /**
+ * This method returns stored parameter from string.
+ * @param parameter String of object that must be returned
+ * @return CommandParameters object or null.
+ */
+ public static VisibilityMode getMode(String parameter)
+ {
+ return BY_NAME.get(parameter);
+ }
+
+ /**
+ * This map allows to access all enum values via their string.
+ */
+ private final static Map BY_NAME = new HashMap<>();
+
+ /**
+ * This static method populated BY_NAME map.
+ */
+ static
+ {
+ for (VisibilityMode visibility : VisibilityMode.values())
+ {
+ BY_NAME.put(visibility.name(), visibility);
+ }
+ }
}
@@ -232,7 +314,7 @@ public enum VisibilityMode
@ConfigComment("Valid values are:")
@ConfigComment(" 'ISLAND' - updates biome on whole island")
@ConfigComment(" 'CHUNK' - updates biome on whole chunks around player")
- @ConfigComment(" 'SQUARE' - updates biome by block in given range")
+ @ConfigComment(" 'RANGE' - updates biome by block in given range")
@ConfigEntry(path = "default-mode")
private UpdateMode defaultMode = UpdateMode.ISLAND;
@@ -265,6 +347,24 @@ public enum VisibilityMode
@ConfigEntry(path = "biomes-visibility")
private VisibilityMode visibilityMode = VisibilityMode.DEPLOYED;
+ @ConfigComment("")
+ @ConfigComment("This string allows to change element order in Biomes description. Each letter represents")
+ @ConfigComment("one object from Biomes description. If letter is not used, then its represented part")
+ @ConfigComment("will not be in description. If use any letter that is not recognized, then it will be")
+ @ConfigComment("ignored. Some strings can be customized via lang file under 'viomes.gui.biomes-description'.")
+ @ConfigComment("List of letters and their meaning: ")
+ @ConfigComment(" - D - description from biomes object")
+ @ConfigComment(" - N - defined minecraft biomes name: '*.biome-name'")
+ @ConfigComment(" - R - requirements for biome change: '*.required-money', '*.required-island-level' and '*.required-permission'")
+ @ConfigEntry(path = "lore-message")
+ private String loreMessage = "DNR";
+
+ @ConfigComment("")
+ @ConfigComment("This allows to change lore description line length. By default it is 25, but some server")
+ @ConfigComment("owners may like it to be larger.")
+ @ConfigEntry(path = "lore-length")
+ private int loreLineLength = 25;
+
@ConfigComment("")
@ConfigComment("This list stores GameModes in which Biomes addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
@@ -272,10 +372,4 @@ public enum VisibilityMode
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes")
private Set disabledGameModes = new HashSet<>();
-
- /**
- * Default variable.
- */
- @ConfigComment("")
- private String uniqueId = "config";
}
diff --git a/src/main/java/world/bentobox/biomes/objects/BiomesObject.java b/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java
similarity index 75%
rename from src/main/java/world/bentobox/biomes/objects/BiomesObject.java
rename to src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java
index 25360b5..89bc0ec 100644
--- a/src/main/java/world/bentobox/biomes/objects/BiomesObject.java
+++ b/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java
@@ -1,4 +1,4 @@
-package world.bentobox.biomes.objects;
+package world.bentobox.biomes.database.objects;
import com.google.gson.annotations.Expose;
@@ -7,7 +7,9 @@
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.database.objects.DataObject;
@@ -17,7 +19,7 @@
/**
* This class stores necessary information for each Biomes object.
*/
-public class BiomesObject implements DataObject
+public class BiomesObject implements DataObject, Comparable
{
/**
* Empty constructor for loader.
@@ -42,10 +44,10 @@ public BiomesObject(Biome biome, World world)
*/
public BiomesObject(Biome biome, String world)
{
- this.biomeName = biome.name();
- this.biomeID = biome.ordinal();
+ this.biome = biome;
this.world = world;
- this.setUniqueId(world + "-" + this.biomeName.toLowerCase());
+ this.friendlyName = biome.name();
+ this.setUniqueId(world + "-" + this.biome.toString().toLowerCase());
}
@@ -58,39 +60,19 @@ public BiomesObject(Biome biome, String world)
* This method returns biomes name.
* @return Biomes name.
*/
- public String getBiomeName()
+ public Biome getBiome()
{
- return this.biomeName;
+ return this.biome;
}
/**
* This method sets biomes name.
- * @param biomeName Biomes name.
+ * @param biome Biomes name.
*/
- public void setBiomeName(String biomeName)
+ public void setBiome(Biome biome)
{
- this.biomeName = biomeName;
- }
-
-
- /**
- * This method returns biomes ID.
- * @return Biomes ID.b
- */
- public int getBiomeID()
- {
- return this.biomeID;
- }
-
-
- /**
- * This method sets biomes ID.
- * @param biomeID biomes ID.
- */
- public void setBiomeID(int biomeID)
- {
- this.biomeID = biomeID;
+ this.biome = biome;
}
@@ -203,78 +185,83 @@ public void setRequiredCost(int requiredCost)
/**
- * @return the slot
+ *
+ * @return world in which biome operates
*/
- public int getSlot()
+ public String getWorld()
{
- return slot;
+ return this.world;
}
/**
- * @param slot the slot to set
+ * @param world where biome must operate.
*/
- public void setSlot(int slot)
+ public void setWorld(String world)
{
- this.slot = slot;
+ this.world = world;
}
/**
- *
- * @return world in which biome operates
+ * @return the uniqueId
*/
- public String getWorld()
+ @Override
+ public String getUniqueId()
{
- return this.world;
+ return uniqueId;
}
/**
- * @param world where biome must operate.
+ * @param uniqueId the uniqueId to set
*/
- public void setWorld(String world)
+ @Override
+ public void setUniqueId(String uniqueId)
{
- this.world = world;
+ this.uniqueId = uniqueId;
}
/**
- *
- * @return permission that allows biome to operate.
+ * This method returns the order object.
+ * @return the order object.
*/
- public String getPermission()
+ public int getOrder()
{
- return this.permission;
+ return order;
}
/**
- * @param permission which allows biome to operate.
+ * This method sets the order object value.
+ * @param order the order object new value.
+ *
*/
- public void setPermission(String permission)
+ public void setOrder(int order)
{
- this.permission = permission;
+ this.order = order;
}
/**
- * @return the uniqueId
+ * This method returns the permissions object.
+ * @return the permissions object.
*/
- @Override
- public String getUniqueId()
+ public Set getRequiredPermissions()
{
- return uniqueId;
+ return requiredPermissions;
}
/**
- * @param uniqueId the uniqueId to set
+ * This method sets the permissions object value.
+ * @param requiredPermissions the permissions object new value.
+ *
*/
- @Override
- public void setUniqueId(String uniqueId)
+ public void setRequiredPermissions(Set requiredPermissions)
{
- this.uniqueId = uniqueId;
+ this.requiredPermissions = requiredPermissions;
}
@@ -283,7 +270,8 @@ public void setUniqueId(String uniqueId)
// ---------------------------------------------------------------------
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
@@ -293,7 +281,8 @@ public int hashCode()
}
- /* (non-Javadoc)
+ /*
+ *(non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -313,7 +302,7 @@ public boolean equals(Object obj)
if (this.uniqueId == null && other.getUniqueId() == null)
{
- return this.biomeID == other.getBiomeID();
+ return this.biome == other.getBiome();
}
else if (this.uniqueId == null || other.getUniqueId() == null)
{
@@ -326,6 +315,19 @@ else if (this.uniqueId == null || other.getUniqueId() == null)
}
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public int compareTo(BiomesObject object)
+ {
+ int rc = Integer.compare(this.order, object.getOrder());
+
+ return rc == 0 ? this.biome.compareTo(object.getBiome()) : rc;
+ }
+
+
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
@@ -333,11 +335,7 @@ else if (this.uniqueId == null || other.getUniqueId() == null)
@ConfigComment("Official minecraft biome name.")
@Expose
- private String biomeName;
-
- @ConfigComment("Unique biome ID.")
- @Expose
- private int biomeID;
+ private Biome biome;
@ConfigComment("Whether this biome is deployed or not")
@Expose
@@ -355,9 +353,9 @@ else if (this.uniqueId == null || other.getUniqueId() == null)
@Expose
private ItemStack icon = new ItemStack(Material.PAPER);
- @ConfigComment("Icon slot where this biomes should be placed. 0 to 49. A negative value means any slot")
+ @ConfigComment("Order of biome. Biomes will be ordered in ascending order.")
@Expose
- private int slot = -1;
+ private int order = -1;
@ConfigComment("Required island level for this biome. Only works if Level Addon is being used.")
@Expose
@@ -367,13 +365,13 @@ else if (this.uniqueId == null || other.getUniqueId() == null)
@Expose
private int requiredCost;
- @ConfigComment("World where this biome operates. List only NORMAL. NETHER and THE_END are automatically covered.")
+ @ConfigComment("Set of String permission that is required for this biome to be activated.")
@Expose
- private String world;
+ private Set requiredPermissions = new HashSet<>();
- @ConfigComment("String of permission that is required for this biome to be activated.")
+ @ConfigComment("World where this biome operates. List only NORMAL. NETHER and THE_END are automatically covered.")
@Expose
- private String permission = "";
+ private String world;
@ConfigComment("Unique StringName of the biome")
@Expose
diff --git a/src/main/java/world/bentobox/biomes/events/BiomeChangedEvent.java b/src/main/java/world/bentobox/biomes/events/BiomeChangedEvent.java
new file mode 100644
index 0000000..c9d9e89
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/events/BiomeChangedEvent.java
@@ -0,0 +1,238 @@
+package world.bentobox.biomes.events;
+
+
+import org.bukkit.block.Biome;
+import java.util.UUID;
+
+import world.bentobox.bentobox.api.events.PremadeEvent;
+
+
+/**
+ * This event is fired when player changed biome.
+ * It is just informative and is fired when everything is done already.
+ */
+public class BiomeChangedEvent extends PremadeEvent
+{
+ /**
+ * Constructor BiomeChangeEvent creates a new BiomeChangeEvent instance.
+ *
+ * @param biomeID of type String that represents biome unique id. May be empty.
+ * @param biome name of biome that was applied.
+ * @param playerUUID of type UUID
+ * @param minX of type int represents minimal X coordinate
+ * @param minZ of type int represents minimal Z coordinate
+ * @param maxX of type int represents maximal X coordinate
+ * @param maxZ of type int represents maximal Z coordinate
+ */
+ public BiomeChangedEvent(
+ String biomeID,
+ Biome biome,
+ UUID playerUUID,
+ int minX,
+ int minZ,
+ int maxX,
+ int maxZ)
+ {
+ this.biomeID = biomeID;
+ this.biome = biome;
+ this.playerUUID = playerUUID;
+ this.minX = minX;
+ this.maxX = maxX;
+ this.minZ = minZ;
+ this.maxZ = maxZ;
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Getters and setters
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method returns the biomeID value.
+ * @return the value of biomeID.
+ */
+ public String getBiomeID()
+ {
+ return biomeID;
+ }
+
+
+ /**
+ * This method sets the biomeID value.
+ * @param biomeID the biomeID new value.
+ *
+ */
+ public void setBiomeID(String biomeID)
+ {
+ this.biomeID = biomeID;
+ }
+
+
+ /**
+ * This method returns the biome value.
+ * @return the value of biome.
+ */
+ public Biome getBiome()
+ {
+ return biome;
+ }
+
+
+ /**
+ * This method sets the biome value.
+ * @param biome the biome new value.
+ *
+ */
+ public void setBiome(Biome biome)
+ {
+ this.biome = biome;
+ }
+
+
+ /**
+ * This method returns the playerUUID value.
+ * @return the value of playerUUID.
+ */
+ public UUID getPlayerUUID()
+ {
+ return playerUUID;
+ }
+
+
+ /**
+ * This method sets the playerUUID value.
+ * @param playerUUID the playerUUID new value.
+ *
+ */
+ public void setPlayerUUID(UUID playerUUID)
+ {
+ this.playerUUID = playerUUID;
+ }
+
+
+ /**
+ * This method returns the minX value.
+ * @return the value of minX.
+ */
+ public int getMinX()
+ {
+ return minX;
+ }
+
+
+ /**
+ * This method sets the minX value.
+ * @param minX the minX new value.
+ *
+ */
+ public void setMinX(int minX)
+ {
+ this.minX = minX;
+ }
+
+
+ /**
+ * This method returns the minZ value.
+ * @return the value of minZ.
+ */
+ public int getMinZ()
+ {
+ return minZ;
+ }
+
+
+ /**
+ * This method sets the minZ value.
+ * @param minZ the minZ new value.
+ *
+ */
+ public void setMinZ(int minZ)
+ {
+ this.minZ = minZ;
+ }
+
+
+ /**
+ * This method returns the maxX value.
+ * @return the value of maxX.
+ */
+ public int getMaxX()
+ {
+ return maxX;
+ }
+
+
+ /**
+ * This method sets the maxX value.
+ * @param maxX the maxX new value.
+ *
+ */
+ public void setMaxX(int maxX)
+ {
+ this.maxX = maxX;
+ }
+
+
+ /**
+ * This method returns the maxZ value.
+ * @return the value of maxZ.
+ */
+ public int getMaxZ()
+ {
+ return maxZ;
+ }
+
+
+ /**
+ * This method sets the maxZ value.
+ * @param maxZ the maxZ new value.
+ *
+ */
+ public void setMaxZ(int maxZ)
+ {
+ this.maxZ = maxZ;
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Unique ID of changed biomeObject.
+ */
+ private String biomeID;
+
+ /**
+ * Biome that is defined in Minecraft.
+ */
+ private Biome biome;
+
+ /**
+ * Player who was targeted by biome change.
+ */
+ private UUID playerUUID;
+
+ /**
+ * Minimal X coordinate of change range.
+ */
+ private int minX;
+
+ /**
+ * Minimal Z coordinate of change range.
+ */
+ private int minZ;
+
+ /**
+ * Maximal X coordinate of change range.
+ */
+ private int maxX;
+
+ /**
+ * Maximal Z coordinate of change range.
+ */
+ private int maxZ;
+}
+
diff --git a/src/main/java/world/bentobox/biomes/handlers/BiomeDataRequestHandler.java b/src/main/java/world/bentobox/biomes/handlers/BiomeDataRequestHandler.java
new file mode 100644
index 0000000..276a175
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/handlers/BiomeDataRequestHandler.java
@@ -0,0 +1,111 @@
+package world.bentobox.biomes.handlers;
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+
+
+/**
+ * This handler returns data for requested challenge.
+ */
+public class BiomeDataRequestHandler extends AddonRequestHandler
+{
+
+ /**
+ * Constructor creates a new BiomeDataRequestHandler instance.
+ *
+ * @param addon of type BiomesAddon
+ */
+ public BiomeDataRequestHandler(BiomesAddon addon)
+ {
+ super("biome-data");
+ this.addon = addon;
+ }
+
+
+ /**
+ * @param metaData Required meta data.
+ * @return Map that returns information about biome
+ * @see AddonRequestHandler#handle(Map)
+ */
+ @Override
+ public Object handle(Map metaData)
+ {
+ /*
+ What we need in the metaData:
+ 0. "biomeId" -> String
+ What we will return:
+ - Empty Map if biome is not given or not found
+ - Map that contains information about given biome:
+ - uniqueId: the same id that was passed to this handler.
+ - world: string that represents world name where biome operates.
+ - biome: string that represents Minecraft Biome name.
+
+ - name: String object of display name for biome.
+ - deployed: boolean object of deployment status.
+ - description: List of strings that represents biomes description.
+
+ - icon: ItemStack object that represents biome.
+ - order: Integer object of order number for given biome.
+
+ - cost: Integer that represents biomes change cost.
+ - level: Long that represents minimal island level for this biome to work.
+ - permissions: Set of strings that represents required permissions.
+ */
+
+ if (metaData == null ||
+ metaData.isEmpty() ||
+ metaData.get("biomeId") == null ||
+ !(metaData.get("biomeId") instanceof String))
+ {
+ return Collections.emptyMap();
+ }
+
+ BiomesObject biome =
+ this.addon.getAddonManager().getBiomeFromString((String) metaData.get("biomeId"));
+
+ Map biomesDataMap;
+
+ if (biome == null)
+ {
+ biomesDataMap = Collections.emptyMap();
+ }
+ else
+ {
+ biomesDataMap = new HashMap<>();
+
+ biomesDataMap.put("uniqueId", biome.getUniqueId());
+ biomesDataMap.put("world", biome.getWorld());
+ biomesDataMap.put("biome", biome.getBiome().name());
+
+ biomesDataMap.put("name", biome.getFriendlyName());
+ biomesDataMap.put("description", biome.getDescription());
+ biomesDataMap.put("deployed", biome.isDeployed());
+
+ biomesDataMap.put("icon", biome.getIcon());
+ biomesDataMap.put("order", biome.getOrder());
+
+ biomesDataMap.put("cost", biome.getRequiredCost());
+ biomesDataMap.put("level", biome.getRequiredLevel());
+ biomesDataMap.put("permissions", biome.getRequiredPermissions());
+ }
+
+ return biomesDataMap;
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Variable stores biomes addon.
+ */
+ private BiomesAddon addon;
+}
diff --git a/src/main/java/world/bentobox/biomes/handlers/BiomeListRequestHandler.java b/src/main/java/world/bentobox/biomes/handlers/BiomeListRequestHandler.java
new file mode 100644
index 0000000..d62031e
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/handlers/BiomeListRequestHandler.java
@@ -0,0 +1,72 @@
+package world.bentobox.biomes.handlers;
+
+
+import org.bukkit.Bukkit;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+
+
+/**
+ * This handler returns all biomes uniqueIDs that is operating in given world.
+ */
+public class BiomeListRequestHandler extends AddonRequestHandler
+{
+ /**
+ * Constructor creates a new BiomeListRequestHandler instance.
+ *
+ * @param addon of type BiomesAddon
+ */
+ public BiomeListRequestHandler(BiomesAddon addon)
+ {
+ super("biomes-list");
+ this.addon = addon;
+ }
+
+
+ /**
+ * @param metaData Required meta data.
+ * @return Set of strings that contains completed challenges.
+ * @see AddonRequestHandler#handle(Map )
+ */
+ @Override
+ public Object handle(Map metaData)
+ {
+ /*
+ What we need in the metaData:
+ 0. "world-name" -> String
+ What we will return:
+ - List of biomes in given world.
+ */
+
+ if (metaData == null ||
+ metaData.isEmpty() ||
+ metaData.get("world-name") == null ||
+ !(metaData.get("world-name") instanceof String) ||
+ Bukkit.getWorld((String) metaData.get("world-name")) == null)
+ {
+ return Collections.emptyList();
+ }
+
+ // Return list of biomes unique IDs from given world.
+
+ return this.addon.getAddonManager().
+ getBiomes(Bukkit.getWorld((String) metaData.get("world-name"))).
+ stream().map(BiomesObject::getUniqueId).collect(Collectors.toList());
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Variable stores challenges addon.
+ */
+ private BiomesAddon addon;
+}
diff --git a/src/main/java/world/bentobox/biomes/handlers/ChangeBiomeRequestHandler.java b/src/main/java/world/bentobox/biomes/handlers/ChangeBiomeRequestHandler.java
new file mode 100644
index 0000000..74da2f3
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/handlers/ChangeBiomeRequestHandler.java
@@ -0,0 +1,166 @@
+package world.bentobox.biomes.handlers;
+
+
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.config.Settings;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.tasks.BiomeUpdateHelper;
+
+
+/**
+ * This Request Handler returns if requested inputdata can be enough to change biome.
+ */
+public class ChangeBiomeRequestHandler extends AddonRequestHandler
+{
+ /**
+ * Constructor creates a new ChangeBiomeRequestHandler instance.
+ *
+ * @param addon of type ChallengesAddon
+ */
+ public ChangeBiomeRequestHandler(BiomesAddon addon)
+ {
+ super("biome-request-change");
+ this.addon = addon;
+ }
+
+
+ /**
+ * @param metaData Required meta data.
+ * @return Set of strings that contains completed challenges.
+ * @see AddonRequestHandler#handle(Map)
+ */
+ @Override
+ public Object handle(Map metaData)
+ {
+ /*
+ What we need in the metaData:
+ 0. "player" -> UUID that represents targeted player UUID.
+ 1. "world-name" -> String that represents world name where biome must be changed
+ 2. "biomeId" -> String that represents biome unique ID.
+ What you can specify more in metaData:
+ 0. "updateMode" -> String that represents how biome is necessary to be changed.
+ 1. "range" -> Integer that represents range of biome update change.
+ 2. "checkRequirements" -> Boolean that represents if requirements must be checked or not. By default it is true.
+ 3. "withdraw" -> Boolean that indicates that money will be withdraw from players account. By default it is true.
+ What we will return:
+ - Map that contains:
+ 1. key "status" which is boolean that indicate if biome change was successful.
+ 2. key "reason" which is string that returns errror message.
+ */
+
+
+ Map returnMap = new HashMap<>(2);
+
+ if (metaData == null || metaData.isEmpty())
+ {
+ returnMap.put("status", false);
+ returnMap.put("reason", "Given MetaData map is not defined!");
+ }
+ else if (!metaData.containsKey("world-name") ||
+ !(metaData.get("world-name") instanceof String) ||
+ Bukkit.getWorld((String) metaData.get("world-name")) == null)
+ {
+ returnMap.put("status", false);
+ returnMap.put("reason", "Missing 'world-name' or it is not valid!");
+ }
+ else if (!metaData.containsKey("player") ||
+ !(metaData.get("player") instanceof UUID))
+ {
+ returnMap.put("status", false);
+ returnMap.put("reason", "Missing 'player' or it is not valid!");
+ }
+ else if (!metaData.containsKey("biomeId") ||
+ !(metaData.get("biomeId") instanceof String) ||
+ this.addon.getAddonManager().getBiomeFromString((String) metaData.get("biomeId")) == null)
+ {
+ returnMap.put("status", false);
+ returnMap.put("reason", "Missing 'biomeId' or it is not valid!");
+ }
+ else
+ {
+ World world = Bukkit.getWorld((String) metaData.get("world-name"));
+ UUID player = (UUID) metaData.get("player");
+ BiomesObject biome = this.addon.getAddonManager().
+ getBiomeFromString((String) metaData.get("biomeId"));
+
+ // Get Update Mode.
+
+ Settings.UpdateMode mode = metaData.containsKey("updateMode") &&
+ metaData.get("updateMode") instanceof String &&
+ Settings.UpdateMode.getMode((String) metaData.get("updateMode")) != null ?
+ Settings.UpdateMode.getMode((String) metaData.get("updateMode")) :
+ this.addon.getSettings().getDefaultMode();
+
+ // Get Update Range.
+
+ int range = metaData.containsKey("range") &&
+ metaData.get("range") instanceof Integer ? (int) metaData.get("range") :
+ this.addon.getSettings().getDefaultSize();
+
+ // Get Requirement Checking
+
+ boolean checkRequirements = !metaData.containsKey("checkRequirements") ||
+ !(metaData.get("checkRequirements") instanceof Boolean) ||
+ (boolean) metaData.get("checkRequirements");
+
+ // Get Withdraw value
+
+ boolean withdraw = !metaData.containsKey("withdraw") ||
+ !(metaData.get("withdraw") instanceof Boolean) ||
+ (boolean) metaData.get("withdraw");
+
+ BiomeUpdateHelper helper = new BiomeUpdateHelper(this.addon,
+ User.getInstance(player),
+ User.getInstance(player),
+ biome,
+ world,
+ mode,
+ range,
+ withdraw);
+
+ if (checkRequirements)
+ {
+ if (helper.canChangeBiome())
+ {
+ helper.updateIslandBiome();
+
+ returnMap.put("status", true);
+ returnMap.put("reason", "Biome is updated by checking all requirements!");
+ }
+ else
+ {
+ returnMap.put("status", false);
+ returnMap.put("reason", "Player does not met requirements for biome changing!");
+ }
+ }
+ else
+ {
+ helper.updateIslandBiome();
+
+ returnMap.put("status", true);
+ returnMap.put("reason", "Biome is updated by skipping all requirements!");
+ }
+ }
+
+ return returnMap;
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Variable stores biomes addon.
+ */
+ private BiomesAddon addon;
+}
diff --git a/src/main/java/world/bentobox/biomes/listeners/ChangeOwnerListener.java b/src/main/java/world/bentobox/biomes/listeners/ChangeOwnerListener.java
index 622c17f..dc3c38f 100644
--- a/src/main/java/world/bentobox/biomes/listeners/ChangeOwnerListener.java
+++ b/src/main/java/world/bentobox/biomes/listeners/ChangeOwnerListener.java
@@ -7,15 +7,14 @@
import org.bukkit.event.Listener;
import java.util.Optional;
-import world.bentobox.bentobox.api.addons.Addon;
+import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamSetownerEvent;
import world.bentobox.bentobox.api.user.User;
-import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
+import world.bentobox.biomes.BiomesAddonManager;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.UpdateMode;
import world.bentobox.biomes.tasks.BiomeUpdateHelper;
-import world.bentobox.biomes.utils.Utils;
/**
@@ -39,30 +38,19 @@ public void onTeamSetOwnerEvent(TeamSetownerEvent event)
return;
}
- boolean hasPermissions;
-
User newUser = User.getInstance(event.getNewOwner());
- Optional skyBlock = this.addon.getPlugin().getAddonsManager().getAddonByName("BSkyBlock");
- Optional acidIsland = this.addon.getPlugin().getAddonsManager().getAddonByName("AcidIsland");
+ Optional gameModeAddon =
+ this.addon.getPlugin().getIWM().getAddon(event.getIsland().getWorld());
- String defaultBiome;
+ final boolean hasPermissions;
+ final String defaultBiome;
- // TODO: The same issue as with BiomesAddon class. It gets values but better would be to add them as
- // dependencies.
- if (skyBlock.isPresent() &&
- skyBlock.get().getConfig().getString("world.world-name").
- equalsIgnoreCase(Util.getWorld(event.getIsland().getWorld()).getName()))
- {
- hasPermissions = newUser.hasPermission("bskyblock.biomes.set");
- defaultBiome = skyBlock.get().getConfig().getString("world.default-biome");
- }
- else if (acidIsland.isPresent() &&
- acidIsland.get().getConfig().getString("world.world-name").
- equalsIgnoreCase(Util.getWorld(event.getIsland().getWorld()).getName()))
+ if (gameModeAddon.isPresent())
{
- hasPermissions = newUser.hasPermission("acidisland.biomes.set");
- defaultBiome = acidIsland.get().getConfig().getString("world.default-biome");
+ GameModeAddon addon = gameModeAddon.get();
+ hasPermissions = newUser.hasPermission(addon.getPermissionPrefix() + ".biomes.set");
+ defaultBiome = addon.getConfig().getString("world.default-biome", "PLAINS");
}
else
{
@@ -71,27 +59,24 @@ else if (acidIsland.isPresent() &&
defaultBiome = "";
}
+ // It is assumed that biomes.set permission is required to change biome.
if (!hasPermissions)
{
- BiomesObject defaultBiomeObject = this.addon.getAddonManager().getBiomeFromString(defaultBiome);
+ BiomesObject defaultBiomeObject;
- if (!defaultBiome.isEmpty() && defaultBiomeObject == null)
+ Biome biome = BiomesAddonManager.getBiomeNameMap().getOrDefault(defaultBiome.toUpperCase(), null);
+
+ if (biome == null)
+ {
+ this.addon.logError("Biome defined in GameMode addon is not valid!!!");
+ return;
+ }
+ else
{
- Biome biome = Utils.getBiomeNameMap().getOrDefault(defaultBiome.toUpperCase(), null);
-
- if (biome == null)
- {
- this.addon.logError("Biome defined in GameMode addon is not valid!!!");
- return;
- }
- else
- {
- defaultBiomeObject = new BiomesObject();
- defaultBiomeObject.setBiomeName(biome.name().toUpperCase());
- defaultBiomeObject.setBiomeID(biome.ordinal());
- defaultBiomeObject.setRequiredCost(0);
- defaultBiomeObject.setRequiredLevel(0);
- }
+ defaultBiomeObject = new BiomesObject();
+ defaultBiomeObject.setBiome(biome);
+ defaultBiomeObject.setRequiredCost(0);
+ defaultBiomeObject.setRequiredLevel(0);
}
// Forcefully update biome on whole user island.
diff --git a/src/main/java/world/bentobox/biomes/panel/CommonPanel.java b/src/main/java/world/bentobox/biomes/panel/CommonPanel.java
deleted file mode 100644
index 8eb0e09..0000000
--- a/src/main/java/world/bentobox/biomes/panel/CommonPanel.java
+++ /dev/null
@@ -1,621 +0,0 @@
-package world.bentobox.biomes.panel;
-
-
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.inventory.ItemStack;
-import java.util.Collections;
-import java.util.List;
-
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.objects.Settings.VisibilityMode;
-
-
-/**
- * This class contains common methods that is necessary for biomes addon panels.
- */
-public abstract class CommonPanel
-{
- /**
- * Default constructor that inits panels with minimal requirements, without parent panel.
- *
- * @param addon Addon where panel operates.
- * @param world World from which panel was created.
- * @param user User who created panel.
- * @param topLabel Command top label which creates panel (f.e. island or ai)
- * @param permissionPrefix Command permission prefix (f.e. bskyblock.)
- */
- public CommonPanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix)
- {
- this(addon, world, user, topLabel, permissionPrefix, null);
- }
-
-
- /**
- * Default constructor that inits panels with minimal requirements.
- *
- * @param addon Addon where panel operates.
- * @param world World from which panel was created.
- * @param user User who created panel.
- * @param topLabel Command top label which creates panel (f.e. island or ai)
- * @param permissionPrefix Command permission prefix (f.e. bskyblock.)
- * @param parentPanel Parent panel for current panel.
- */
- public CommonPanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix,
- CommonPanel parentPanel)
- {
- this.addon = addon;
- this.world = world;
- this.user = user;
-
- this.topLabel = topLabel;
- this.permissionPrefix = permissionPrefix;
-
- this.parentPanel = parentPanel;
-
- this.pageIndex = 0;
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Methods
-// ---------------------------------------------------------------------
-
-
- /**
- * This method is necessary to build panel.
- */
- public abstract void build();
-
-
- /**
- * This method returns button from CommonButtons enum.
- * @param button Necessary button.
- * @return new PanelItem button.
- */
- protected PanelItem createCommonButton(CommonButtons button)
- {
- return this.createCommonButton(button, null);
- }
-
-
- /**
- * This method returns button from CommonButtons enum.
- * @param button Necessary button.
- * @param handler Custom click handler
- * @return new PanelItem button.
- */
- protected PanelItem createCommonButton(CommonButtons button, PanelItem.ClickHandler handler)
- {
- ItemStack icon;
- String name;
- List description;
- boolean glow;
- PanelItem.ClickHandler clickHandler;
-
- switch (button)
- {
- case RETURN:
- {
- name = this.user.getTranslation("biomes.gui.buttons.back");
- description = Collections.emptyList();
- icon = new ItemStack(Material.OAK_DOOR);
- clickHandler = (panel, user, clickType, slot) -> {
- // Build parent panel is missing, then close inventory.
- if (this.parentPanel == null)
- {
- this.user.closeInventory();
- }
-
- this.parentPanel.build();
- return true;
- };
- glow = false;
-
- break;
- }
- case NEXT:
- {
- name = this.user.getTranslation("biomes.gui.buttons.next");
- description = Collections.emptyList();
- icon = new ItemStack(Material.SIGN);
- clickHandler = (panel, user, clickType, slot) -> {
- this.pageIndex++;
- this.build();
- return true;
- };
- glow = false;
-
- break;
- }
- case PREVIOUS:
- {
- name = this.user.getTranslation("biomes.gui.buttons.previous");
- description = Collections.emptyList();
- icon = new ItemStack(Material.SIGN);
- clickHandler = (panel, user, clickType, slot) -> {
- this.pageIndex--;
- this.build();
- return true;
- };
- glow = false;
-
- break;
- }
- case SAVE:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.save");
- description = Collections.emptyList();
- icon = new ItemStack(Material.PAPER);
- // This will be overwrite by use case.
- clickHandler = handler;
- glow = false;
-
- break;
- }
- case CANCEL:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.cancel");
- description = Collections.emptyList();
- icon = new ItemStack(Material.BARRIER);
- clickHandler = handler;
- glow = false;
-
- break;
- }
- case ENABLED:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.enabled");
- description = Collections.emptyList();
- icon = new ItemStack(Material.GREEN_CONCRETE);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = true;
- this.build();
- return true;
- };
- glow = (boolean) this.valueObject;
-
- break;
- }
- case DISABLED:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.disabled");
- description = Collections.emptyList();
- icon = new ItemStack(Material.RED_CONCRETE);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = false;
- this.build();
- return true;
- };
- glow = !(boolean) this.valueObject;
-
- break;
- }
- case ISLAND:
- {
- name = this.user.getTranslation("biomes.gui.buttons.island");
- description = Collections.emptyList();
- icon = new ItemStack(Material.GRASS_BLOCK);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = UpdateMode.ISLAND;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(UpdateMode.ISLAND);
-
- break;
- }
- case CHUNK:
- {
- name = this.user.getTranslation("biomes.gui.buttons.chunk");
- description = Collections.emptyList();
- icon = new ItemStack(Material.DIRT);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = UpdateMode.CHUNK;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(UpdateMode.CHUNK);
-
- break;
- }
- case SQUARE:
- {
- name = this.user.getTranslation("biomes.gui.buttons.region");
- description = Collections.emptyList();
- icon = new ItemStack(Material.GLASS);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = UpdateMode.SQUARE;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(UpdateMode.SQUARE);
-
- break;
- }
- case VISIBLE_ALL:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.visible-all");
- description = Collections.emptyList();
- icon = new ItemStack(Material.BIRCH_PLANKS);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = VisibilityMode.ALL;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(VisibilityMode.ALL);
-
- break;
- }
- case VISIBLE_ACTIVE:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.visible-active");
- description = Collections.emptyList();
- icon = new ItemStack(Material.BIRCH_STAIRS);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = VisibilityMode.DEPLOYED;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(VisibilityMode.DEPLOYED);
- break;
- }
- case VISIBLE_UNLOCKED:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.visible-accessible");
- description = Collections.emptyList();
- icon = new ItemStack(Material.BIRCH_SLAB);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = VisibilityMode.ACCESSIBLE;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(VisibilityMode.ACCESSIBLE);
- break;
- }
- case VISIBLE_TOGGLE:
- {
- name = this.user.getTranslation("biomes.gui.admin.buttons.visible-toggle");
- description = Collections.emptyList();
- icon = new ItemStack(Material.BIRCH_BUTTON);
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = VisibilityMode.TOGGLEABLE;
- this.build();
- return true;
- };
- glow = this.valueObject.equals(VisibilityMode.TOGGLEABLE);
- break;
- }
- default:
- // All buttons should be in switch case.
- return new PanelItemBuilder().build();
- }
-
- return new PanelItemBuilder().
- icon(icon).
- name(name).
- description(description).
- glow(glow).
- clickHandler(handler == null ? clickHandler : handler).
- build();
- }
-
-
- /**
- * This method returns button from NumberButtons enum.
- * @param button Necessary button.
- * @return new PanelItem button.
- */
- protected PanelItem createCommonButton(NumberButtons button)
- {
- return this.createCommonButton(button, null);
- }
-
-
- /**
- * This method returns button from NumberButtons enum.
- * @param button Necessary button.
- * @param handler Custom Click handling.
- * @return new PanelItem button.
- */
- protected PanelItem createCommonButton(NumberButtons button, PanelItem.ClickHandler handler)
- {
- int number;
-
- boolean increase = false;
- boolean reduce = false;
-
- switch (button)
- {
- case SET_1:
- number = 1;
- break;
- case SET_5:
- number = 5;
- break;
- case SET_10:
- number = 10;
- break;
- case SET_50:
- number = 50;
- break;
- case SET_100:
- number = 100;
- break;
- case SET_500:
- number = 500;
- break;
- case SET_1000:
- number = 1000;
- break;
- case INCREASE_1:
- number = 1;
- increase = true;
- break;
- case INCREASE_5:
- number = 5;
- increase = true;
- break;
- case INCREASE_10:
- number = 10;
- increase = true;
- break;
- case INCREASE_50:
- number = 50;
- increase = true;
- break;
- case INCREASE_100:
- number = 100;
- increase = true;
- break;
- case INCREASE_500:
- number = 500;
- increase = true;
- break;
- case INCREASE_1000:
- number = 1000;
- increase = true;
- break;
- case DECREASE_1:
- number = 1;
- reduce = true;
- break;
- case DECREASE_5:
- number = 5;
- reduce = true;
- break;
- case DECREASE_10:
- number = 10;
- reduce = true;
- break;
- case DECREASE_50:
- number = 50;
- reduce = true;
- break;
- case DECREASE_100:
- number = 100;
- reduce = true;
- break;
- case DECREASE_500:
- number = 500;
- reduce = true;
- break;
- case DECREASE_1000:
- number = 1000;
- reduce = true;
- break;
- case VALUE:
- number = (int) this.valueObject;
- increase = true;
- reduce = true;
- break;
- default:
- // All buttons should be in switch case.
- return null;
- }
-
- ItemStack icon;
- String name;
- PanelItem.ClickHandler clickHandler;
-
- if (increase && reduce)
- {
- icon = new ItemStack(Material.PAPER);
- name = this.user.getTranslation("biomes.gui.buttons.value","[number]", Integer.toString(number));
- clickHandler = (panel, user1, clickType, slot) -> true;
- }
- else if (increase)
- {
- icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
- name = this.user.getTranslation("biomes.gui.buttons.increase","[number]", Integer.toString(number));
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = (int) this.valueObject + number;
- this.build();
- return true;
- };
- }
- else if (reduce)
- {
- icon = new ItemStack(Material.RED_STAINED_GLASS_PANE);
- name = this.user.getTranslation("biomes.gui.buttons.reduce","[number]", Integer.toString(number));
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = (int) this.valueObject - number;
- this.build();
- return true;
- };
- }
- else
- {
- icon = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE);
- name = this.user.getTranslation("biomes.gui.buttons.set","[number]", Integer.toString(number));
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = number;
- this.build();
- return true;
- };
- }
-
- return new PanelItemBuilder().
- icon(icon).
- name(name).
- description(Collections.emptyList()).
- glow(false).
- clickHandler(handler == null ? clickHandler : handler).
- build();
- }
-
-
- /**
- * This method sets new value for ValueObject.
- * @param newValue new value of valueObject.
- */
- public void setValueObject(Object newValue)
- {
- this.valueObject = newValue;
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Enums
-// ---------------------------------------------------------------------
-
-
- /**
- * This enum contains all common buttons that is used in more then 1 panel.
- */
- protected enum CommonButtons
- {
- RETURN,
- NEXT,
- PREVIOUS,
-
- SAVE,
- CANCEL,
-
- ENABLED,
- DISABLED,
-
- ISLAND,
- CHUNK,
- SQUARE,
-
- VISIBLE_ALL,
- VISIBLE_ACTIVE,
- VISIBLE_UNLOCKED,
- VISIBLE_TOGGLE,
- }
-
-
- /**
- * This enum contains buttons that is made of numbers.
- */
- @Deprecated
- protected enum NumberButtons
- {
- SET_1,
- SET_5,
- SET_10,
- SET_50,
- SET_100,
- SET_500,
- SET_1000,
-
- INCREASE_1,
- INCREASE_5,
- INCREASE_10,
- INCREASE_50,
- INCREASE_100,
- INCREASE_500,
- INCREASE_1000,
-
- DECREASE_1,
- DECREASE_5,
- DECREASE_10,
- DECREASE_50,
- DECREASE_100,
- DECREASE_500,
- DECREASE_1000,
-
- VALUE
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
- /**
- * Variable stores biomes addon.
- */
- protected BiomesAddon addon;
-
- /**
- * Variable stores world in which panel is referred to.
- */
- protected World world;
-
- /**
- * Variable stores user who created this panel.
- */
- protected User user;
-
- /**
- * Variable stores top label of command from which panel was called.
- */
- protected String topLabel;
-
- /**
- * Variable stores permission prefix of command from which panel was called.
- */
- protected String permissionPrefix;
-
- /**
- * Variable stores parent of current panel.
- */
- protected CommonPanel parentPanel;
-
- /**
- * Variable stores any value.
- */
- protected Object valueObject;
-
- /**
- * This object holds current page index.
- */
- protected int pageIndex;
-
-
-// ---------------------------------------------------------------------
-// Section: Constants for permission and command generation
-// ---------------------------------------------------------------------
-
- protected final static String BIOMES = "biomes";
-
- protected final static String ADMIN = "admin";
-
- protected final static String SET = "set";
-
- protected final static String ADD = "add";
-
- protected final static String EDIT = "edit";
-
- protected final static String DELETE = "remove";
-
- protected final static String SETTINGS = "settings";
-
- protected final static String IMPORT = "import";
-
- protected final static String INFO = "info";
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeEditPanel.java b/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeEditPanel.java
deleted file mode 100644
index 3c413fc..0000000
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeEditPanel.java
+++ /dev/null
@@ -1,739 +0,0 @@
-package world.bentobox.biomes.panel.admin;
-
-
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Biome;
-import org.bukkit.inventory.ItemStack;
-import java.util.Collections;
-import java.util.List;
-
-import net.wesjd.anvilgui.AnvilGUI;
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.panel.CommonPanel;
-import world.bentobox.biomes.utils.Utils;
-
-
-/**
- * This panel allows to edit given biome properties.
- */
-public class AdminBiomeEditPanel extends CommonPanel
-{
- /**
- * @inheritDoc
- * @param biome Biome that must be edited.
- */
- public AdminBiomeEditPanel(BiomesAddon addon,
- World world,
- User user,
- BiomesObject biome,
- String topLabel,
- String permissionPrefix)
- {
- this(addon, world, user, biome, topLabel, permissionPrefix, null);
- }
-
-
- /**
- * @inheritDoc
- * @param biome Biome that must be edited.
- */
- public AdminBiomeEditPanel(BiomesAddon addon,
- World world,
- User user,
- BiomesObject biome,
- String topLabel,
- String permissionPrefix,
- CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
- this.currentEditMode = PropertyButtons.NULL;
- this.returnButton = this.parentPanel == null ? null : this.createCommonButton(CommonButtons.RETURN);
-
- if (biome == null)
- {
- this.biome = new BiomesObject();
- this.biome.setFriendlyName("New Biome");
- this.disableButtons = true;
- }
- else
- {
- this.biome = biome;
- }
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Methods
-// ---------------------------------------------------------------------
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user);
-
- if (this.disableButtons)
- {
- this.disableButtons = this.biome.getBiomeName() == null;
- panelBuilder.name(this.user.getTranslation("biomes.gui.admin.add-title"));
- }
- else
- {
- panelBuilder.name(this.user.getTranslation("biomes.gui.admin.edit-title", "[biome]", this.biome.getFriendlyName()));
- }
-
- // If current edit mode is name, then shift biome and description 4 blocks to right.
- int biomeSlot = this.currentEditMode.equals(PropertyButtons.NAME) ? 5 : 1;
- // If current edit mode is biome, then shift description 4 blocks to right.
- int descriptionSlot = this.currentEditMode.equals(PropertyButtons.BIOME) ? 6 : biomeSlot + 1;
-
- panelBuilder.item(0, this.createPropertyButton(PropertyButtons.NAME));
- panelBuilder.item(biomeSlot, this.createPropertyButton(PropertyButtons.BIOME));
- panelBuilder.item(descriptionSlot, this.createPropertyButton(PropertyButtons.DESCRIPTION));
- panelBuilder.item(9, this.createPropertyButton(PropertyButtons.DEPLOYED));
- panelBuilder.item(18, this.createPropertyButton(PropertyButtons.ICON));
-
- panelBuilder.item(27, this.createPropertyButton(PropertyButtons.LEVEL));
- panelBuilder.item(36, this.createPropertyButton(PropertyButtons.COST));
- panelBuilder.item(45, this.createPropertyButton(PropertyButtons.PERMISSION));
-
- switch (this.currentEditMode)
- {
- case BIOME:
- {
- // Create save button with custom handler
- panelBuilder.item(2, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- if (this.disableButtons)
- {
- // Create tempBiome and try to save it.
- BiomesObject tempBiome =
- new BiomesObject((Biome) this.valueObject, this.world);
- tempBiome.setFriendlyName("New Biome");
-
- if (this.addon.getAddonManager().storeBiome(tempBiome, false, this.user, true))
- {
- // If save was successful then send information about it to user, and set tempBiome as current biome.
- this.user.sendMessage("biomes.messages.information.saved", "[biome]", tempBiome.getFriendlyName());
- this.currentEditMode = PropertyButtons.NULL;
- this.biome = tempBiome;
- }
- else
- {
- // If biome saving was not successful, then throw error.
- this.user.sendMessage("biomes.messages.errors.exist-biome");
- }
- }
- else
- {
- if (!(this.valueObject instanceof Biome))
- {
- this.user.sendMessage("biomes.messages.errors.incorrect-biome");
- this.currentEditMode = PropertyButtons.NULL;
- }
- else if (this.biome.getBiomeID() == ((Biome) this.valueObject).ordinal())
- {
- this.user.sendMessage("biomes.messages.warning.same-biome");
- this.currentEditMode = PropertyButtons.NULL;
- }
- else
- {
- // Create tempBiome to check if exist biome with the same ID.
- BiomesObject tempBiome = new BiomesObject((Biome) this.valueObject, this.world);
-
- if (this.addon.getAddonManager().getBiomeFromString(tempBiome.getUniqueId()) != null)
- {
- // Throw error if biome is find.
- this.user.sendMessage("biomes.messages.errors.exist-biome");
- }
- else
- {
- // Remove biome from memory as it is necessary to change its unique id.
- this.addon.getAddonManager().removeBiome(this.biome);
-
- // Update biomeName, biome ID, uniqueID
- this.biome.setBiomeName(tempBiome.getBiomeName());
- this.biome.setBiomeID(tempBiome.getBiomeID());
- this.biome.setUniqueId(tempBiome.getUniqueId());
-
- this.addon.getAddonManager().saveBiome(this.biome);
-
- this.currentEditMode = PropertyButtons.NULL;
- }
- }
- }
-
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(3, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // TODO: Button that opens CHOOSE BIOME GUI
-// panelBuilder.item(4, this.createCommonButton(CommonButtons.ENABLED));
-
- break;
- }
- case NAME:
- {
- // Create save button with custom handler
- panelBuilder.item(1, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setFriendlyName((String) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(2, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(3, this.reopenAnvilGui());
-
- break;
- }
- case DEPLOYED:
- {
- // Create save button with custom handler
- panelBuilder.item(10, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setDeployed((boolean) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(11, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(14, this.createCommonButton(CommonButtons.ENABLED));
- panelBuilder.item(15, this.createCommonButton(CommonButtons.DISABLED));
-
- break;
- }
- case DESCRIPTION:
- {
- // Create save button with custom handler
- panelBuilder.item(3, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setDescription(Utils.splitString((String) this.valueObject));
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(4, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(5, this.reopenAnvilGui());
-
- break;
- }
- case ICON:
- {
- // Create save button with custom handler
- panelBuilder.item(19, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setIcon((ItemStack) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(20, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // TODO: Button that opens CHOOSE ICON GUI
-// panelBuilder.item(21, this.createCommonButton(CommonButtons.ENABLED));
-
- break;
- }
- case LEVEL:
- {
- // Create save button with custom handler
- panelBuilder.item(19, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setRequiredLevel((int) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(20, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(5, this.createCommonButton(NumberButtons.SET_1));
- panelBuilder.item(14, this.createCommonButton(NumberButtons.SET_5));
- panelBuilder.item(23, this.createCommonButton(NumberButtons.SET_10));
- panelBuilder.item(32, this.createCommonButton(NumberButtons.SET_50));
- panelBuilder.item(41, this.createCommonButton(NumberButtons.SET_100));
-
- panelBuilder.item(6, this.createCommonButton(NumberButtons.INCREASE_1));
- panelBuilder.item(15, this.createCommonButton(NumberButtons.INCREASE_5));
- panelBuilder.item(24, this.createCommonButton(NumberButtons.INCREASE_10));
- panelBuilder.item(33, this.createCommonButton(NumberButtons.INCREASE_50));
- panelBuilder.item(42, this.createCommonButton(NumberButtons.INCREASE_100));
-
- panelBuilder.item(7, this.createCommonButton(NumberButtons.DECREASE_1));
- panelBuilder.item(16, this.createCommonButton(NumberButtons.DECREASE_5));
- panelBuilder.item(25, this.createCommonButton(NumberButtons.DECREASE_10));
- panelBuilder.item(34, this.createCommonButton(NumberButtons.DECREASE_50));
- panelBuilder.item(43, this.createCommonButton(NumberButtons.DECREASE_100));
-
- panelBuilder.item(22, this.createCommonButton(NumberButtons.VALUE));
-
- break;
- }
- case COST:
- {
- // Create save button with custom handler
- panelBuilder.item(37, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setRequiredCost((int) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(38, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(5, this.createCommonButton(NumberButtons.SET_10));
- panelBuilder.item(14, this.createCommonButton(NumberButtons.SET_50));
- panelBuilder.item(23, this.createCommonButton(NumberButtons.SET_100));
- panelBuilder.item(32, this.createCommonButton(NumberButtons.SET_500));
- panelBuilder.item(41, this.createCommonButton(NumberButtons.SET_1000));
-
- panelBuilder.item(6, this.createCommonButton(NumberButtons.INCREASE_10));
- panelBuilder.item(15, this.createCommonButton(NumberButtons.INCREASE_50));
- panelBuilder.item(24, this.createCommonButton(NumberButtons.INCREASE_100));
- panelBuilder.item(33, this.createCommonButton(NumberButtons.INCREASE_500));
- panelBuilder.item(42, this.createCommonButton(NumberButtons.INCREASE_1000));
-
- panelBuilder.item(7, this.createCommonButton(NumberButtons.DECREASE_10));
- panelBuilder.item(16, this.createCommonButton(NumberButtons.DECREASE_50));
- panelBuilder.item(25, this.createCommonButton(NumberButtons.DECREASE_100));
- panelBuilder.item(34, this.createCommonButton(NumberButtons.DECREASE_500));
- panelBuilder.item(43, this.createCommonButton(NumberButtons.DECREASE_1000));
-
- panelBuilder.item(40, this.createCommonButton(NumberButtons.VALUE));
-
- break;
- }
- case PERMISSION:
- {
- // Create save button with custom handler
- panelBuilder.item(46, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.biome.setPermission((String) this.valueObject);
- this.addon.getAddonManager().saveBiome(this.biome);
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
-
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(47, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(48, this.reopenAnvilGui());
-
- break;
- }
- default:
- if (this.returnButton != null)
- {
- panelBuilder.item(53, this.returnButton);
- }
- }
-
- panelBuilder.build();
- }
-
-
- /**
- * This method creates button for each editable property for BiomeObject
- * @param button Property Button that must be created.
- * @return New PanelItem of requested property edit function.
- */
- private PanelItem createPropertyButton(PropertyButtons button)
- {
- ItemStack icon;
- String name;
- List description;
- PanelItem.ClickHandler clickHandler;
-
- switch (button)
- {
- case BIOME:
- {
- icon = new ItemStack(Material.BOOK);
- name = this.user.getTranslation("biomes.gui.admin.buttons.biome");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current", "[value]",
- this.biome.getBiomeName() == null ? "" : this.biome.getBiomeName()));
-
- clickHandler = (panel, user1, clickType, slot) -> {
- this.valueObject = this.biome.getBiomeName();
- this.currentEditMode = PropertyButtons.BIOME;
-
- // Open Biome Choose GUI
- new AdminBiomeTypePanel(this.addon,
- this.world,
- this.user,
- this.topLabel,
- this.permissionPrefix,
- this,
- this).build();
-
- return true;
- };
-
- break;
- }
- case NAME:
- {
- icon = new ItemStack(Material.BOOK);
- name = this.user.getTranslation("biomes.gui.admin.buttons.name");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current", "[value]", this.biome.getFriendlyName()));
- clickHandler = (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.NAME;
- this.valueObject = this.biome.getFriendlyName();
-
- // Open AnvilGUI that allows to change text.
- new AnvilGUI(this.addon.getPlugin(),
- this.user.getPlayer(),
- this.biome.getFriendlyName(),
- (player, reply) -> {
- if (reply.equalsIgnoreCase(Material.PAPER.name()))
- {
- // Weird anvilGui glitch. Does not allow empty values.
- reply = "";
- }
-
- // Sets anvil text output as new value object
- this.valueObject = reply;
- // rebuild gui.
- this.build();
-
- return reply;
- });
-
- return true;
- };
-
- break;
- }
- case DEPLOYED:
- {
- icon = this.biome.isDeployed() ? new ItemStack(Material.GREEN_CONCRETE) : new ItemStack(Material.RED_CONCRETE);
- name = this.user.getTranslation("biomes.gui.admin.buttons.deployed");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current",
- "[value]", this.biome.isDeployed() ?
- this.user.getTranslation("biomes.gui.admin.descriptions.enabled") :
- this.user.getTranslation("biomes.gui.admin.descriptions.disabled")));
- clickHandler = (panel, user1, clickType, slot) ->{
- this.currentEditMode = PropertyButtons.DEPLOYED;
- this.valueObject = this.biome.isDeployed();
- this.build();
- return true;
- };
-
- break;
- }
- case DESCRIPTION:
- {
- icon = new ItemStack(Material.BOOK);
- name = this.user.getTranslation("biomes.gui.admin.buttons.description");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current",
- "[value]", Utils.mergeStringList(this.biome.getDescription())));
-
- clickHandler = (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.DESCRIPTION;
- this.valueObject = Utils.mergeStringList(this.biome.getDescription());
-
- new AnvilGUI(this.addon.getPlugin(),
- this.user.getPlayer(),
- Utils.mergeStringList(this.biome.getDescription()),
- (player, reply) -> {
- if (reply.equalsIgnoreCase(Material.PAPER.name()))
- {
- // Weird anvilGui glitch. Does not allow empty values.
- reply = "";
- }
-
- this.valueObject = reply;
- this.build();
-
- return reply;
- });
-
- return true;
- };
-
- break;
- }
- case ICON:
- {
- icon = this.biome.getIcon();
- name = this.user.getTranslation("biomes.gui.admin.buttons.icon");
- description = Collections.emptyList();
-
- clickHandler = (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.ICON;
- this.valueObject = this.biome.getIcon();
- this.build();
- // TODO IMPLEMENT ICON CHOOSE GUI
- // Open Biome Choose GUI
- return false;
- };
-
- break;
- }
- case LEVEL:
- {
- icon = new ItemStack(Material.MAGENTA_GLAZED_TERRACOTTA);
- name = this.user.getTranslation("biomes.gui.admin.buttons.level");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current",
- "[value]",
- Long.toString(this.biome.getRequiredLevel())));
- clickHandler = (panel, user1, clickType, slot) ->{
- this.currentEditMode = PropertyButtons.LEVEL;
- this.valueObject = (int) this.biome.getRequiredLevel();
- this.build();
- return true;
- };
-
- break;
- }
- case COST:
- {
- icon = new ItemStack(Material.GOLD_BLOCK);
- name = this.user.getTranslation("biomes.gui.admin.buttons.cost");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current",
- "[value]",
- Integer.toString(this.biome.getRequiredCost())));
- clickHandler = (panel, user1, clickType, slot) ->{
- this.currentEditMode = PropertyButtons.COST;
- this.valueObject = this.biome.getRequiredCost();
- this.build();
- return true;
- };
-
- break;
- }
- case PERMISSION:
- {
- icon = new ItemStack(Material.BOOK);
- name = this.user.getTranslation("biomes.gui.admin.buttons.permission");
- description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current", "[value]", this.biome.getPermission()));
-
- clickHandler = (panel, user1, clickType, slot) -> {
- this.currentEditMode = PropertyButtons.PERMISSION;
- this.valueObject = this.biome.getPermission();
-
- new AnvilGUI(this.addon.getPlugin(),
- this.user.getPlayer(),
- this.biome.getPermission(),
- (player, reply) -> {
- if (reply.equalsIgnoreCase(Material.PAPER.name()))
- {
- // Weird anvilGui glitch. Does not allow empty values.
- reply = "";
- }
-
- this.valueObject = reply;
- this.build();
-
- return reply;
- });
-
- return true;
- };
-
- break;
- }
- default:
- // This should never happen.
- return null;
- }
-
- if (this.disableButtons && !button.equals(PropertyButtons.BIOME))
- {
- icon = new ItemStack(Material.BARRIER);
- clickHandler = (panel, user1, clickType, slot) -> true;
- }
-
- return new PanelItemBuilder().
- icon(icon).
- name(name).
- description(description).
- glow(this.currentEditMode.equals(button)).
- clickHandler(clickHandler).
- build();
- }
-
-
- /**
- * This method creates button that reopens anvil gui for editing last property.
- * @return New Button that opens anvil gui.
- */
- private PanelItem reopenAnvilGui()
- {
- ItemStack icon = new ItemStack(Material.ANVIL);
- String name = this.user.getTranslation("biomes.gui.admin.buttons.change-value");
- List description = Utils.splitString(
- this.user.getTranslation("biomes.gui.admin.descriptions.current", "[value]", (String) this.valueObject));
-
- PanelItem.ClickHandler clickHandler = (panel, user1, clickType, slot) -> {
- new AnvilGUI(this.addon.getPlugin(),
- this.user.getPlayer(),
- (String) this.valueObject,
- (player, reply) -> {
- if (reply.equalsIgnoreCase(Material.PAPER.name()))
- {
- // Weird anvilGui glitch. Does not allow empty values.
- reply = "";
- }
-
- this.valueObject = reply;
- this.build();
-
- return reply;
- });
-
- return true;
- };
-
- return new PanelItemBuilder().
- icon(icon).
- name(name).
- description(description).
- glow(false).
- clickHandler(clickHandler).
- build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Enums
-// ---------------------------------------------------------------------
-
-
- /**
- * This Enum contains all possible property values that can be edited.
- */
- private enum PropertyButtons
- {
- BIOME,
- NAME,
- DEPLOYED,
- DESCRIPTION,
- ICON,
- LEVEL,
- COST,
- PERMISSION,
-
- NULL
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
-
- /**
- * This boolean will be true only when adding new Biome. It will disable other buttons until biome is
- * selected and added.
- */
- private boolean disableButtons;
-
- private BiomesObject biome;
-
- private PropertyButtons currentEditMode;
-
- private PanelItem returnButton;
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeListPanel.java b/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeListPanel.java
deleted file mode 100644
index 54540f1..0000000
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeListPanel.java
+++ /dev/null
@@ -1,161 +0,0 @@
-package world.bentobox.biomes.panel.admin;
-
-
-import org.bukkit.World;
-import java.util.List;
-
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.panel.CommonPanel;
-
-
-/**
- * This Panel creates list with all biomes for their editing.
- */
-public class AdminBiomeListPanel extends CommonPanel
-{
- /**
- * @inheritDoc
- * @param editPanel boolean that indicate if biomes must be edited or removed.
- */
- public AdminBiomeListPanel(BiomesAddon addon,
- World world,
- User user,
- boolean editPanel,
- String topLabel,
- String permissionPrefix)
- {
- this(addon, world, user, editPanel, topLabel, permissionPrefix, null);
- }
-
- /**
- * @inheritDoc
- * @param editPanel boolean that indicate if biomes must be edited or removed.
- */
- public AdminBiomeListPanel(BiomesAddon addon,
- World world,
- User user,
- boolean editPanel,
- String topLabel,
- String permissionPrefix,
- CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
-
- this.editPanel = editPanel;
- this.returnButton = this.parentPanel == null ? null : this.createCommonButton(CommonButtons.RETURN);
- }
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user);
-
- if (this.editPanel)
- {
- panelBuilder.name(this.user.getTranslation("biomes.gui.admin.edit-title"));
- }
- else
- {
- panelBuilder.name(this.user.getTranslation("biomes.gui.admin.remove-title"));
- }
-
- List biomes = this.addon.getAddonManager().getBiomes(this.world);
-
- int MAX_ELEMENTS = 45;
- if (this.pageIndex < 0)
- {
- this.pageIndex = 0;
- }
- else if (this.pageIndex > (biomes.size() / MAX_ELEMENTS))
- {
- this.pageIndex = biomes.size() / MAX_ELEMENTS;
- }
-
- int playerIndex = MAX_ELEMENTS * this.pageIndex;
-
- while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
- playerIndex < biomes.size())
- {
- panelBuilder.item(this.createBiomeIcon(biomes.get(playerIndex)));
- playerIndex++;
- }
-
- int nextIndex = playerIndex % MAX_ELEMENTS == 0 ?
- MAX_ELEMENTS :
- (((playerIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9;
-
- if (playerIndex > MAX_ELEMENTS)
- {
- panelBuilder.item(nextIndex, this.createCommonButton(CommonButtons.PREVIOUS));
- }
-
- if (playerIndex < biomes.size())
- {
- panelBuilder.item(nextIndex + 8, this.createCommonButton(CommonButtons.NEXT));
- }
-
- if (this.returnButton != null)
- {
- panelBuilder.item(nextIndex + 4, this.returnButton);
- }
-
- panelBuilder.build();
- }
-
-
- /**
- * This method creates biomes icon. It sets it to glow, if biome is not deployed.
- * @param biome Biome which icon must be created.
- * @return New Biome Icon.
- */
- private PanelItem createBiomeIcon(BiomesObject biome)
- {
- return new PanelItemBuilder().
- name(biome.getFriendlyName()).
- icon(biome.getIcon()).
- description(biome.getDescription()).
- clickHandler((panel, user1, clickType, slot) -> {
- if (this.editPanel)
- {
- new AdminBiomeEditPanel(this.addon,
- this.world,
- this.user,
- biome,
- this.topLabel,
- this.permissionPrefix,
- this).build();
- }
- else
- {
- this.addon.getAddonManager().removeBiome(biome);
-
- this.user.sendMessage("biomes.messages.information.biome-removed", "[biome]", biome.getFriendlyName());
-
- this.pageIndex = 0;
- this.build();
- }
-
- return true;
- }).
- glow(!biome.isDeployed()).
- build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
- /**
- * This indicate if current mode is edit or delete.
- */
- private boolean editPanel;
-
- private PanelItem returnButton;
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeTypePanel.java b/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeTypePanel.java
deleted file mode 100644
index 3b4389f..0000000
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminBiomeTypePanel.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package world.bentobox.biomes.panel.admin;
-
-
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Biome;
-
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.panel.CommonPanel;
-
-
-/**
- * This panel will open menu with all biomes that are available in current Minecraft server.
- */
-public class AdminBiomeTypePanel extends CommonPanel
-{
- /**
- * @inheritDoc
- * @param targetPanel Panel that is necessary to open when biome is choosed.
- */
- public AdminBiomeTypePanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix,
- CommonPanel targetPanel)
- {
- this(addon, world, user, topLabel, permissionPrefix, targetPanel, null);
- }
-
-
- /**
- * @inheritDoc
- * @param targetPanel Panel that is necessary to open when biome is choosed.
- */
- public AdminBiomeTypePanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix,
- CommonPanel targetPanel,
- CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
- this.targetPanel = targetPanel;
- this.cancelButton =
- this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- if (this.parentPanel != null)
- {
- this.parentPanel.build();
- }
- else
- {
- this.user.closeInventory();
- }
-
- return false;
- });
- }
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
- this.user.getTranslation("biomes.gui.admin.choose-biome-title"));
-
- int MAX_ELEMENTS = 45;
- if (this.pageIndex < 0)
- {
- this.pageIndex = 0;
- }
- else if (this.pageIndex > (Biome.values().length / MAX_ELEMENTS))
- {
- this.pageIndex = Biome.values().length / MAX_ELEMENTS;
- }
-
- int biomeIndex = MAX_ELEMENTS * this.pageIndex;
-
- while (biomeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
- biomeIndex < Biome.values().length)
- {
- panelBuilder.item(this.createBiomeButton(Biome.values()[biomeIndex]));
- biomeIndex++;
- }
-
- int nextIndex = biomeIndex % MAX_ELEMENTS == 0 ?
- MAX_ELEMENTS :
- (((biomeIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9;
-
- if (biomeIndex > MAX_ELEMENTS)
- {
- panelBuilder.item(nextIndex, this.createCommonButton(CommonButtons.PREVIOUS));
- }
-
- if (biomeIndex < Biome.values().length)
- {
- panelBuilder.item(nextIndex + 8, this.createCommonButton(CommonButtons.NEXT));
- }
-
- panelBuilder.item(nextIndex + 4, this.cancelButton);
-
- panelBuilder.build();
- }
-
-
- /**
- * This method creates biomes button.
- * @param biome Biome which button is necessary.
- * @return PanelItem button.
- */
- private PanelItem createBiomeButton(Biome biome)
- {
- return new PanelItemBuilder().
- name(biome.name()).
- icon(Material.MAP).
- clickHandler((panel, user, clickType, slot) -> {
- this.targetPanel.setValueObject(biome);
- this.targetPanel.build();
- return true;
- }).build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
- private CommonPanel targetPanel;
-
- private PanelItem cancelButton;
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminSettingsPanel.java b/src/main/java/world/bentobox/biomes/panel/admin/AdminSettingsPanel.java
deleted file mode 100644
index 85180d2..0000000
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminSettingsPanel.java
+++ /dev/null
@@ -1,491 +0,0 @@
-package world.bentobox.biomes.panel.admin;
-
-
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.inventory.ItemStack;
-import java.util.List;
-
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.objects.Settings.VisibilityMode;
-import world.bentobox.biomes.panel.CommonPanel;
-import world.bentobox.biomes.utils.Utils;
-
-
-/**
- * This Panel allows to edit biome settings via GUI.
- */
-public class AdminSettingsPanel extends CommonPanel
-{
- /**
- * @inheritDoc
- */
- public AdminSettingsPanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix)
- {
- this(addon, world, user, topLabel, permissionPrefix, null);
- }
-
-
- /**
- * @inheritDoc
- */
- public AdminSettingsPanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix,
- CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
- this.initDefaultButtons();
- }
-
-
- /**
- * These buttons always will be enabled. Others must be generated only when needed.
- */
- private void initDefaultButtons()
- {
- this.currentEditMode = ConfigButtons.NULL;
- this.returnButton = this.parentPanel == null ? null : this.createCommonButton(CommonButtons.RETURN);
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Methods
-// ---------------------------------------------------------------------
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
- name(this.user.getTranslation("biomes.gui.admin.settings-title"));
-
- // Add Configuration buttons.
- panelBuilder.item(0,
- this.createConfigButtons(ConfigButtons.ADVANCED_MENU,
- this.currentEditMode.equals(ConfigButtons.ADVANCED_MENU)));
- panelBuilder.item(9,
- this.createConfigButtons(ConfigButtons.DEFAULT_MODE,
- this.currentEditMode.equals(ConfigButtons.DEFAULT_MODE)));
- panelBuilder.item(18,
- this.createConfigButtons(ConfigButtons.DEFAULT_SIZE,
- this.currentEditMode.equals(ConfigButtons.DEFAULT_SIZE)));
- panelBuilder.item(27,
- this.createConfigButtons(ConfigButtons.COOLDOWN,
- this.currentEditMode.equals(ConfigButtons.COOLDOWN)));
- panelBuilder.item(36,
- this.createConfigButtons(ConfigButtons.RESET_BIOMES,
- this.currentEditMode.equals(ConfigButtons.RESET_BIOMES)));
- panelBuilder.item(45,
- this.createConfigButtons(ConfigButtons.BIOMES_VISIBILITY,
- this.currentEditMode.equals(ConfigButtons.BIOMES_VISIBILITY)));
-
- // Add buttons that allows to change value.
- switch (this.currentEditMode)
- {
- case ADVANCED_MENU:
- {
- // Create save button with custom handler
- panelBuilder.item(1, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setAdvancedMenu((boolean) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(2, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(4, this.createCommonButton(CommonButtons.ENABLED));
- panelBuilder.item(5, this.createCommonButton(CommonButtons.DISABLED));
-
- break;
- }
- case DEFAULT_MODE:
- {
- // Create save button with custom handler
- panelBuilder.item(10, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setDefaultMode((UpdateMode) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(11, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(4, this.createCommonButton(CommonButtons.ISLAND));
- panelBuilder.item(13, this.createCommonButton(CommonButtons.CHUNK));
- panelBuilder.item(22, this.createCommonButton(CommonButtons.SQUARE));
-
- break;
- }
- case DEFAULT_SIZE:
- {
- // Create save button with custom handler
- panelBuilder.item(19, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setDefaultSize((int) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(20, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(14, this.createCommonButton(NumberButtons.SET_1));
- panelBuilder.item(23, this.createCommonButton(NumberButtons.SET_5));
- panelBuilder.item(32, this.createCommonButton(NumberButtons.SET_10));
- panelBuilder.item(41, this.createCommonButton(NumberButtons.SET_50));
-
- panelBuilder.item(15, this.createCommonButton(NumberButtons.INCREASE_1));
- panelBuilder.item(24, this.createCommonButton(NumberButtons.INCREASE_5));
- panelBuilder.item(33, this.createCommonButton(NumberButtons.INCREASE_10));
- panelBuilder.item(42, this.createCommonButton(NumberButtons.INCREASE_50));
-
- panelBuilder.item(16, this.createCommonButton(NumberButtons.DECREASE_1));
- panelBuilder.item(25, this.createCommonButton(NumberButtons.DECREASE_5));
- panelBuilder.item(34, this.createCommonButton(NumberButtons.DECREASE_10));
- panelBuilder.item(43, this.createCommonButton(NumberButtons.DECREASE_50));
-
- panelBuilder.item(22, this.createCommonButton(NumberButtons.VALUE));
-
- break;
- }
- case RESET_BIOMES:
- {
- // Create save button with custom handler
- panelBuilder.item(37, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setResetBiomes((boolean) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(38, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(40, this.createCommonButton(CommonButtons.ENABLED));
- panelBuilder.item(41, this.createCommonButton(CommonButtons.DISABLED));
-
- break;
- }
- case COOLDOWN:
- {
- // Create save button with custom handler
- panelBuilder.item(28, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setCoolDown((int) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(29, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(14, this.createCommonButton(NumberButtons.SET_10));
- panelBuilder.item(23, this.createCommonButton(NumberButtons.SET_50));
- panelBuilder.item(32, this.createCommonButton(NumberButtons.SET_100));
- panelBuilder.item(41, this.createCommonButton(NumberButtons.SET_500));
-
- panelBuilder.item(15, this.createCommonButton(NumberButtons.INCREASE_10));
- panelBuilder.item(24, this.createCommonButton(NumberButtons.INCREASE_50));
- panelBuilder.item(33, this.createCommonButton(NumberButtons.INCREASE_100));
- panelBuilder.item(42, this.createCommonButton(NumberButtons.INCREASE_500));
-
- panelBuilder.item(16, this.createCommonButton(NumberButtons.DECREASE_10));
- panelBuilder.item(25, this.createCommonButton(NumberButtons.DECREASE_50));
- panelBuilder.item(34, this.createCommonButton(NumberButtons.DECREASE_100));
- panelBuilder.item(43, this.createCommonButton(NumberButtons.DECREASE_500));
-
- panelBuilder.item(22, this.createCommonButton(NumberButtons.VALUE));
-
- break;
- }
- case BIOMES_VISIBILITY:
- {
- // Create save button with custom handler
- panelBuilder.item(46, this.createCommonButton(CommonButtons.SAVE,
- (panel, user1, clickType, slot) -> {
- this.addon.getSettings().setVisibilityMode((VisibilityMode) this.valueObject);
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- // Create cancel button with custom handler
- panelBuilder.item(47, this.createCommonButton(CommonButtons.CANCEL,
- (panel, user1, clickType, slot) -> {
- this.currentEditMode = ConfigButtons.NULL;
- this.valueObject = null;
- this.build();
- return true;
- }));
-
- panelBuilder.item(4, this.createCommonButton(CommonButtons.VISIBLE_ALL));
- panelBuilder.item(13, this.createCommonButton(CommonButtons.VISIBLE_ACTIVE));
- panelBuilder.item(22, this.createCommonButton(CommonButtons.VISIBLE_UNLOCKED));
- panelBuilder.item(31, this.createCommonButton(CommonButtons.VISIBLE_TOGGLE));
-
- break;
- }
- default:
- if (this.returnButton != null)
- {
- panelBuilder.item(53, this.returnButton);
- }
- }
-
- panelBuilder.build();
- }
-
-
- /**
- * This method creates button with requested type.
- * @param buttonType Button type
- * @return Button that was requested.
- */
- private PanelItem createConfigButtons(ConfigButtons buttonType, boolean glow)
- {
- ItemStack icon;
- String name;
- List description;
- PanelItem.ClickHandler clickHandler;
-
- switch (buttonType)
- {
- case ADVANCED_MENU:
- {
- boolean advancedMenu = this.addon.getSettings().isAdvancedMenu();
-
- String valueString = advancedMenu ?
- this.user.getTranslation("biomes.gui.admin.descriptions.enabled") :
- this.user.getTranslation("biomes.gui.admin.descriptions.disabled");
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.advancedmenu", "[value]", valueString);
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.advancedmenu"));
- icon = new ItemStack(Material.COMMAND_BLOCK);
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = advancedMenu;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- case DEFAULT_MODE:
- {
- UpdateMode updateMode = this.addon.getSettings().getDefaultMode();
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.type", "[value]", updateMode.name());
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.type"));
-
- if (updateMode.equals(UpdateMode.ISLAND))
- {
- icon = new ItemStack(Material.GRASS_BLOCK);
- }
- else if (updateMode.equals(UpdateMode.CHUNK))
- {
- icon = new ItemStack(Material.DIRT);
- }
- else
- {
- icon = new ItemStack(Material.GLASS);
- }
-
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = updateMode;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- case DEFAULT_SIZE:
- {
- int size = this.addon.getSettings().getDefaultSize();
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.size", "[number]", Integer.toString(size));
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.size"));
- icon = new ItemStack(Material.PISTON);
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = size;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- case RESET_BIOMES:
- {
- boolean resetBiomes = this.addon.getSettings().isResetBiomes();
-
- String valueString = resetBiomes ?
- this.user.getTranslation("biomes.gui.admin.descriptions.enabled") :
- this.user.getTranslation("biomes.gui.admin.descriptions.disabled");
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.resetBiomes", "[value]", valueString);
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.resetbiomes"));
- icon = new ItemStack(Material.DROPPER);
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = resetBiomes;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- case COOLDOWN:
- {
- int cooldown = this.addon.getSettings().getCoolDown();
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.timeout", "[number]", Integer.toString(cooldown));
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.timeout"));
- icon = new ItemStack(Material.DAYLIGHT_DETECTOR);
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = cooldown;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- case BIOMES_VISIBILITY:
- {
- VisibilityMode visibilityMode = this.addon.getSettings().getVisibilityMode();
-
- name = this.user.getTranslation("biomes.gui.admin.buttons.visibility", "[value]", visibilityMode.name());
- description = Utils.splitString(this.user.getTranslation("biomes.gui.admin.descriptions.visibility"));
-
- if (visibilityMode.equals(VisibilityMode.ALL))
- {
- icon = new ItemStack(Material.BIRCH_PLANKS);
- }
- else if (visibilityMode.equals(VisibilityMode.DEPLOYED))
- {
- icon = new ItemStack(Material.BIRCH_STAIRS);
- }
- else if (visibilityMode.equals(VisibilityMode.ACCESSIBLE))
- {
- icon = new ItemStack(Material.BIRCH_SLAB);
- }
- else
- {
- icon = new ItemStack(Material.BIRCH_BUTTON);
- }
-
- clickHandler = (panel, user, clickType, slot) -> {
- this.valueObject = visibilityMode;
- this.currentEditMode = buttonType;
- this.build();
- return true;
- };
-
- break;
- }
- default:
- // This should never happen.
- return null;
- }
-
- return new PanelItemBuilder().
- icon(icon).
- name(name).
- description(description).
- glow(glow).
- clickHandler(clickHandler).
- build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Enums
-// ---------------------------------------------------------------------
-
-
- /**
- * This are all settings buttons. Each setting has own button.
- */
- private enum ConfigButtons
- {
- ADVANCED_MENU,
- DEFAULT_MODE,
- DEFAULT_SIZE,
- RESET_BIOMES,
- COOLDOWN,
- BIOMES_VISIBILITY,
- NULL
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
- /**
- * Mode in which panel currently is hanging.
- */
- private ConfigButtons currentEditMode;
-
- /**
- * Return button. Not necessary to generate all time.
- */
- private PanelItem returnButton;
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminUserListPanel.java b/src/main/java/world/bentobox/biomes/panel/admin/AdminUserListPanel.java
deleted file mode 100644
index 55c7fef..0000000
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminUserListPanel.java
+++ /dev/null
@@ -1,230 +0,0 @@
-package world.bentobox.biomes.panel.admin;
-
-
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.List;
-
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.panel.CommonPanel;
-import world.bentobox.biomes.panel.user.ChangeBiomePanel;
-
-
-/**
- * This method creates panel that contains users. It will be used to allow select user which island
- * will change biome.
- */
-public class AdminUserListPanel extends CommonPanel
-{
- public AdminUserListPanel(BiomesAddon addon,
- World world,
- User user, String topLabel, String permissionPrefix)
- {
- this(addon, world, user, topLabel, permissionPrefix, null);
- }
-
-
- public AdminUserListPanel(BiomesAddon addon,
- World world,
- User user,
- String topLabel,
- String permissionPrefix, CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
-
- this.returnButton = this.parentPanel == null ? null : this.createCommonButton(CommonButtons.RETURN);
-
- // Create list with users to avoid issues when user logs out in a process and mess element count.
- this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD);
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Methods
-// ---------------------------------------------------------------------
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
- this.user.getTranslation("biomes.gui.admin.choose-user-title"));
-
- int MAX_ELEMENTS = 45;
- if (this.pageIndex < 0)
- {
- this.pageIndex = 0;
- }
- else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS))
- {
- this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS;
- }
-
- int playerIndex = MAX_ELEMENTS * this.pageIndex;
-
- while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
- playerIndex < this.onlineUsers.size())
- {
- panelBuilder.item(this.createPlayerIcon(this.onlineUsers.get(playerIndex)));
- playerIndex++;
- }
-
- int nextIndex = playerIndex % MAX_ELEMENTS == 0 ?
- MAX_ELEMENTS :
- (((playerIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9;
-
- if (playerIndex > MAX_ELEMENTS)
- {
- panelBuilder.item(nextIndex, this.createCommonButton(CommonButtons.PREVIOUS));
- }
-
- if (playerIndex < this.onlineUsers.size())
- {
- panelBuilder.item(nextIndex + 8, this.createCommonButton(CommonButtons.NEXT));
- }
-
- if (this.returnButton != null)
- {
- panelBuilder.item(nextIndex + 6, this.returnButton);
- }
-
- panelBuilder.item(nextIndex + 3, this.createToggleButton());
-
- panelBuilder.build();
- }
-
-
- /**
- * This method creates button for given user. If user has island it will add valid click handler.
- * @param player Player which button must be created.
- * @return Player button.
- */
- private PanelItem createPlayerIcon(Player player)
- {
- if (this.addon.getIslands().hasIsland(this.world, player.getUniqueId()))
- {
- return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler(
- (panel, user1, clickType, slot) -> {
- // Open Biome Choose panel.
- new ChangeBiomePanel(this.addon,
- this.world,
- this.user,
- User.getInstance(player),
- this.topLabel,
- this.permissionPrefix,
- this).build();
- return true;
- }).build();
- }
- else
- {
- return new PanelItemBuilder().
- name(player.getName()).
- icon(Material.BARRIER).
- description(this.user.getTranslation("general.errors.player-has-no-island")).
- clickHandler((panel, user1, clickType, slot) -> false).
- build();
- }
- }
-
-
- /**
- * This method collects users based on view mode.
- * @param mode Given view mode.
- * @return List with players in necessary view mode.
- */
- private List collectUsers(ViewMode mode)
- {
- if (mode.equals(ViewMode.ONLINE))
- {
- return new ArrayList<>(Bukkit.getOnlinePlayers());
- }
- else if (mode.equals(ViewMode.OFFLINE))
- {
- List offlinePlayer = new ArrayList<>(Bukkit.getOfflinePlayers().length);
-
- for (int index = 0; index < Bukkit.getOfflinePlayers().length; index++)
- {
- OfflinePlayer player = Bukkit.getOfflinePlayers()[index];
- offlinePlayer.add(player.getPlayer());
- }
-
- return offlinePlayer;
- }
- else
- {
- return new ArrayList<>(this.world.getPlayers());
- }
- }
-
-
- /**
- * This method creates Player List view Mode toggle button.
- * @return Button that toggles through player view mode.
- */
- private PanelItem createToggleButton()
- {
- List values = new ArrayList<>(ViewMode.values().length);
-
- for (int i = 0; i < ViewMode.values().length; i++)
- {
- values.add((this.modeIndex == i ? "§2" : "§c") +
- this.user.getTranslation("biomes.gui.admin.descriptions." +
- ViewMode.values()[i].name().toLowerCase()));
- }
-
- return new PanelItemBuilder().
- name(this.user.getTranslation("biomes.gui.admin.buttons.toggle-users",
- "[value]",
- this.user.getTranslation("biomes.gui.admin.descriptions." + ViewMode.values()[this.modeIndex].name().toLowerCase()))).
- description(values).
- icon(Material.STONE_BUTTON).
- clickHandler(
- (panel, user1, clickType, slot) -> {
- this.modeIndex++;
-
- if (this.modeIndex >= ViewMode.values().length)
- {
- this.modeIndex = 0;
- }
-
- this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]);
- this.pageIndex = 0;
- this.build();
- return true;
- }).build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Private enums
-// ---------------------------------------------------------------------
-
-
- private enum ViewMode
- {
- ONLINE,
- OFFLINE,
- IN_WORLD
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
-
- private PanelItem returnButton;
-
- private List onlineUsers;
-
- private int modeIndex = 2;
-}
diff --git a/src/main/java/world/bentobox/biomes/panel/user/ChangeBiomePanel.java b/src/main/java/world/bentobox/biomes/panel/user/ChangeBiomePanel.java
deleted file mode 100644
index 167b91b..0000000
--- a/src/main/java/world/bentobox/biomes/panel/user/ChangeBiomePanel.java
+++ /dev/null
@@ -1,377 +0,0 @@
-package world.bentobox.biomes.panel.user;
-
-
-import org.bukkit.Material;
-import org.bukkit.World;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-import world.bentobox.bentobox.api.commands.CompositeCommand;
-import world.bentobox.bentobox.api.panels.PanelItem;
-import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
-import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
-import world.bentobox.bentobox.api.user.User;
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-import world.bentobox.biomes.objects.Settings.VisibilityMode;
-import world.bentobox.biomes.panel.CommonPanel;
-
-
-/**
- * This panel allows to change biome for user.
- */
-public class ChangeBiomePanel extends CommonPanel
-{
- /**
- * @inheritDoc
- * @param target Targeted user. Can be null.
- */
- public ChangeBiomePanel(BiomesAddon addon,
- World world,
- User user,
- User target,
- String topLabel,
- String permissionPrefix)
- {
- this(addon, world, user, target, topLabel, permissionPrefix, null);
- }
-
-
- /**
- * @inheritDoc
- * @param target Targeted user. Can be null.
- */
- public ChangeBiomePanel(BiomesAddon addon,
- World world,
- User user,
- User target,
- String topLabel,
- String permissionPrefix,
- CommonPanel parentPanel)
- {
- super(addon, world, user, topLabel, permissionPrefix, parentPanel);
- this.targetUser = target;
-
- this.biomeList = this.addon.getAddonManager().getBiomes(this.world, this.user);
- this.returnButton = this.parentPanel == null ? null : this.createCommonButton(CommonButtons.RETURN);
- this.currentVisibilityMode = VisibilityMode.ACCESSIBLE;
- this.valueObject = this.addon.getSettings().getDefaultMode();
- this.updateRange = this.addon.getSettings().getDefaultSize();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Methods
-// ---------------------------------------------------------------------
-
-
- @Override
- public void build()
- {
- PanelBuilder panelBuilder = new PanelBuilder().user(this.user);
-
- if (this.targetUser == null)
- {
- panelBuilder.name(
- this.user.getTranslation("biomes.gui.title"));
- }
- else
- {
- panelBuilder.name(
- this.user.getTranslation("biomes.gui.admin.gui-title"));
- }
-
- int MAX_ELEMENTS = this.addon.getSettings().isAdvancedMenu() ? 18 : 45;
-
- if (this.pageIndex < 0)
- {
- this.pageIndex = 0;
- }
- else if (this.pageIndex > (this.biomeList.size() / MAX_ELEMENTS))
- {
- this.pageIndex = this.biomeList.size() / MAX_ELEMENTS;
- }
-
- int playerIndex = MAX_ELEMENTS * this.pageIndex;
-
- while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
- playerIndex < this.biomeList.size())
- {
- panelBuilder.item(this.createBiomeIcon(this.biomeList.get(playerIndex)));
- playerIndex++;
- }
-
- int nextIndex = playerIndex % MAX_ELEMENTS == 0 ?
- MAX_ELEMENTS :
- (((playerIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9;
-
- if (this.addon.getSettings().isAdvancedMenu())
- {
- panelBuilder.item(nextIndex + 2, this.createCommonButton(CommonButtons.ISLAND));
- panelBuilder.item(nextIndex + 11, this.createCommonButton(CommonButtons.CHUNK));
- panelBuilder.item(nextIndex + 20, this.createCommonButton(CommonButtons.SQUARE));
-
- // Value Paper
- panelBuilder.item(nextIndex + 12, this.createCurrentRangeButton());
-
- // Setters.
- panelBuilder.item(nextIndex + 4,
- this.createCommonButton(NumberButtons.SET_1, (panel, user1, clickType, slot) -> {
- this.updateRange = 1;
- this.build();
- return true;
- }));
- panelBuilder.item(nextIndex + 4 + 9,
- this.createCommonButton(NumberButtons.SET_5, (panel, user1, clickType, slot) -> {
- this.updateRange = 5;
- this.build();
- return true;
- }));;
- panelBuilder.item(nextIndex + 4 + 18,
- this.createCommonButton(NumberButtons.SET_10, (panel, user1, clickType, slot) -> {
- this.updateRange = 10;
- this.build();
- return true;
- }));
-
- // Increases.
- panelBuilder.item(nextIndex + 5,
- this.createCommonButton(NumberButtons.INCREASE_1, (panel, user1, clickType, slot) -> {
- this.updateRange += 1;
- this.build();
- return true;
- }));
- panelBuilder.item(nextIndex + 5 + 9,
- this.createCommonButton(NumberButtons.INCREASE_5, (panel, user1, clickType, slot) -> {
- this.updateRange += 5;
- this.build();
- return true;
- }));
- panelBuilder.item(nextIndex + 5 + 18,
- this.createCommonButton(NumberButtons.INCREASE_10, (panel, user1, clickType, slot) -> {
- this.updateRange += 10;
- this.build();
- return true;
- }));
-
- // Reducers.
- panelBuilder.item(nextIndex + 6,
- this.createCommonButton(NumberButtons.DECREASE_1, (panel, user1, clickType, slot) -> {
- this.updateRange = Math.max(1, this.updateRange - 1);
- this.build();
- return true;
- }));
- panelBuilder.item(nextIndex + 6 + 9,
- this.createCommonButton(NumberButtons.DECREASE_5, (panel, user1, clickType, slot) -> {
- this.updateRange = Math.max(1, this.updateRange - 5);
- this.build();
- return true;
- }));
- panelBuilder.item(nextIndex + 6 + 18,
- this.createCommonButton(NumberButtons.DECREASE_10, (panel, user1, clickType, slot) -> {
- this.updateRange = Math.max(1, this.updateRange - 10);
- this.build();
- return true;
- }));
-
- if (playerIndex > MAX_ELEMENTS)
- {
- panelBuilder.item(nextIndex + 9, this.createCommonButton(CommonButtons.PREVIOUS));
- }
-
- if (playerIndex < this.biomeList.size())
- {
- panelBuilder.item(nextIndex + 17, this.createCommonButton(CommonButtons.NEXT));
- }
-
- if (this.addon.getSettings().getVisibilityMode().equals(VisibilityMode.TOGGLEABLE))
- {
- panelBuilder.item(nextIndex + 18, this.createToggleButton());
- }
-
- if (this.returnButton != null)
- {
- // If advanced menu is active, then return button has no place in middle. But it can be placed
- // in corner.
- panelBuilder.item(nextIndex + 26, this.returnButton);
- }
- }
- else
- {
- if (playerIndex > MAX_ELEMENTS)
- {
- panelBuilder.item(nextIndex, this.createCommonButton(CommonButtons.PREVIOUS));
- }
-
- if (playerIndex < this.biomeList.size())
- {
- panelBuilder.item(nextIndex + 8, this.createCommonButton(CommonButtons.NEXT));
- }
-
- if (this.addon.getSettings().getVisibilityMode().equals(VisibilityMode.TOGGLEABLE))
- {
- panelBuilder.item(nextIndex + 3, this.createToggleButton());
- nextIndex++;
- }
-
- if (this.returnButton != null)
- {
- panelBuilder.item(nextIndex + 4, this.returnButton);
- }
- }
-
-
- panelBuilder.build();
-
- }
-
-
- /**
- * This method creates biomes icon. It sets it to glow, if biome is not deployed.
- * @param biome Biome which icon must be created.
- * @return New Biome Icon.
- */
- private PanelItem createBiomeIcon(BiomesObject biome)
- {
- return new PanelItemBuilder().
- name(biome.getFriendlyName()).
- icon(biome.getIcon()).
- description(biome.getDescription()).
- clickHandler((panel, user1, clickType, slot) -> {
- // Use command Manager to get necessary command. Biome changing will be processed via command only.
-
- CompositeCommand command = this.addon.getPlugin().getCommandsManager().getCommand(this.topLabel);
- Optional commandOptional = command.getSubCommand(BIOMES);
-
- if (!commandOptional.isPresent())
- {
- // Throw error that biomes command not found.
- return true;
- }
-
- commandOptional = commandOptional.get().getSubCommand(SET);
-
- if (!commandOptional.isPresent())
- {
- // Throw error that biomes command not found.
- return true;
- }
-
- command = commandOptional.get();
-
- List arguments = new ArrayList<>(4);
-
- if (this.targetUser != null)
- {
- arguments.add(this.targetUser.getName());
- }
-
- arguments.add(biome.getBiomeName());
- arguments.add(((UpdateMode) this.valueObject).name());
- arguments.add(Integer.toString(this.updateRange));
-
- if (command.execute(this.user, SET, arguments))
- {
- // Resets cursor to default option
- this.user.closeInventory();
- this.build();
-
- return true;
- }
-
- return true;
- }).
- glow(!biome.isDeployed()).
- build();
- }
-
-
- /**
- * This method creates toggle button that changes which biomes is visible.
- * @return New Toggle Icon.
- */
- private PanelItem createToggleButton()
- {
- List values = new ArrayList<>(3);
-
- for (int i = 0; i < VisibilityMode.values().length; i++)
- {
- // Toggle is not mode.
- if (!VisibilityMode.values()[i].equals(VisibilityMode.TOGGLEABLE))
- {
- values.add((VisibilityMode.values()[i].equals(this.currentVisibilityMode) ? "§2" : "§c")
- + this.user.getTranslation("biomes.gui.descriptions." + VisibilityMode.values()[i].name().toLowerCase())
- );
- }
- }
-
- return new PanelItemBuilder().
- name(this.user.getTranslation("biomes.gui.buttons.visibility", "[value]", this.currentVisibilityMode.name())).
- description(values).
- icon(Material.BIRCH_BUTTON).
- clickHandler((panel, user1, clickType, slot) -> {
- switch (this.currentVisibilityMode)
- {
- case ALL:
- this.currentVisibilityMode = VisibilityMode.ACCESSIBLE;
- break;
- case ACCESSIBLE:
- this.currentVisibilityMode = VisibilityMode.DEPLOYED;
- break;
- case DEPLOYED:
- case TOGGLEABLE:
- this.currentVisibilityMode = VisibilityMode.ALL;
- break;
- }
-
- this.biomeList = this.addon.getAddonManager().getBiomes(this.world, this.user, this.currentVisibilityMode);
- this.pageIndex = 0;
- this.build();
-
- return true;
- }).
- glow(false).
- build();
- }
-
-
- /**
- * This method creates value icon. It shows current value for updateRange.
- * @return New values Icon.
- */
- private PanelItem createCurrentRangeButton()
- {
- return new PanelItemBuilder().
- name(this.user.getTranslation("biomes.gui.buttons.value","[number]", Integer.toString(this.updateRange))).
- icon(Material.PAPER).
- clickHandler((panel, user1, clickType, slot) -> true).
- build();
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
-
- private PanelItem returnButton;
-
- private User targetUser;
-
- /**
- * Biome List cache as each list can be toggleable.
- */
- private List biomeList;
-
- /**
- * This variable stores current biomes visibility mode.
- */
- private VisibilityMode currentVisibilityMode;
-
- /**
- * This variable stores current update range.
- */
- private int updateRange;
-}
diff --git a/src/main/java/world/bentobox/biomes/panels/CommonGUI.java b/src/main/java/world/bentobox/biomes/panels/CommonGUI.java
new file mode 100644
index 0000000..797ad39
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/CommonGUI.java
@@ -0,0 +1,372 @@
+package world.bentobox.biomes.panels;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.inventory.ItemStack;
+import org.eclipse.jdt.annotation.NonNull;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import world.bentobox.bentobox.api.commands.CompositeCommand;
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+
+
+/**
+ * This class contains common methods that will be used over all GUIs. It also allows
+ * easier navigation between different GUIs.
+ */
+public abstract class CommonGUI
+{
+// ---------------------------------------------------------------------
+// Section: Constructors
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Default constructor that inits panels with minimal requirements, without parent panel.
+ *
+ * @param addon Addon where panel operates.
+ * @param world World from which panel was created.
+ * @param user User who created panel.
+ * @param topLabel Command top label which creates panel (f.e. island or ai)
+ * @param permissionPrefix Command permission prefix (f.e. bskyblock.)
+ */
+ public CommonGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix)
+ {
+ this(addon, world, user, topLabel, permissionPrefix, null);
+ }
+
+
+ /**
+ * Default constructor that inits panels with minimal requirements, without parent panel.
+ *
+ * @param parentGUI ParentGUI of current GUI.
+ */
+ public CommonGUI(@NonNull CommonGUI parentGUI)
+ {
+ this(parentGUI.addon,
+ parentGUI.world,
+ parentGUI.user,
+ parentGUI.topLabel,
+ parentGUI.permissionPrefix,
+ parentGUI);
+ }
+
+
+ /**
+ * Default constructor that inits panels with minimal requirements.
+ *
+ * @param addon Addon where panel operates.
+ * @param world World from which panel was created.
+ * @param user User who created panel.
+ * @param topLabel Command top label which creates panel (f.e. island or ai)
+ * @param permissionPrefix Command permission prefix (f.e. bskyblock.)
+ * @param parentGUI Parent panel for current panel.
+ */
+ public CommonGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix,
+ CommonGUI parentGUI)
+ {
+ this.addon = addon;
+ this.world = world;
+ this.user = user;
+
+ this.topLabel = topLabel;
+ this.permissionPrefix = permissionPrefix;
+
+ this.parentGUI = parentGUI;
+
+ this.pageIndex = 0;
+
+ this.returnButton = new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.return")).
+ icon(Material.OAK_DOOR).
+ clickHandler((panel, user1, clickType, i) -> {
+ if (this.parentGUI == null)
+ {
+ this.user.closeInventory();
+ return true;
+ }
+
+ this.parentGUI.build();
+ return true;
+ }).build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Common methods
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method builds all necessary elements in GUI panel.
+ */
+ public abstract void build();
+
+
+ /**
+ * This method returns PanelItem that represents given Button.
+ * @param button Button that must be returned.
+ * @return PanelItem with requested functionality.
+ */
+ protected PanelItem getButton(CommonButtons button)
+ {
+ ItemStack icon;
+ String name;
+ List description;
+ PanelItem.ClickHandler clickHandler;
+
+ switch (button)
+ {
+ case NEXT:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.next");
+ description = Collections.emptyList();
+ icon = new ItemStack(BiomesAddon.SIGN_MATERIAL);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.pageIndex++;
+ this.build();
+ return true;
+ };
+
+ break;
+ }
+ case PREVIOUS:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.previous");
+ description = Collections.emptyList();
+ icon = new ItemStack(BiomesAddon.SIGN_MATERIAL);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.pageIndex--;
+ this.build();
+ return true;
+ };
+
+ break;
+ }
+ case RETURN:
+ return this.returnButton;
+ default:
+ return null;
+ }
+
+ return new PanelItemBuilder().
+ icon(icon).
+ name(name).
+ description(description).
+ glow(false).
+ clickHandler(clickHandler).
+ build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Calling command from GUI
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method finds and try to execute given sub command with given arguments.
+ * @param subCommand Sub Command that need to be called.
+ * @param arguments List of arguments for current command.
+ * @return true;
+ */
+ protected boolean callCommand(String subCommand, List arguments)
+ {
+ CompositeCommand command = this.addon.getPlugin().getCommandsManager().getCommand(this.topLabel);
+ Optional commandOptional = command.getSubCommand(BIOMES);
+
+ if (!commandOptional.isPresent())
+ {
+ // Throw error that biomes command not found.
+ return true;
+ }
+
+ commandOptional = commandOptional.get().getSubCommand(subCommand);
+
+ if (!commandOptional.isPresent())
+ {
+ // Throw error that biomes sub-command not found.
+ return true;
+ }
+
+ command = commandOptional.get();
+
+ if (command.canExecute(this.user, subCommand, arguments))
+ {
+ command.execute(this.user, subCommand, arguments);
+ }
+
+ this.user.closeInventory();
+ return true;
+ }
+
+// ---------------------------------------------------------------------
+// Section: Generate Biomes Object Description
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method generates and returns given biomesObject description. It is used here to avoid multiple
+ * duplicates, as it would be nice to have single place where biomesObject could be generated.
+ * @param biomesObject BiomesObject which description must be generated.
+ * @return List of strings that will be used in Biomes description.
+ */
+ protected List generateBiomesDescription(BiomesObject biomesObject)
+ {
+ List result = new ArrayList<>();
+
+ for (char c : this.addon.getSettings().getLoreMessage().toLowerCase().toCharArray())
+ {
+ switch (c)
+ {
+ case 'd':
+ {
+ // This adds biomes description
+ result.addAll(biomesObject.getDescription());
+ break;
+ }
+ case 'n':
+ {
+ // This adds biomes original name.
+ result.add(this.user.getTranslation("biomes.gui.biomes-description.biome-name",
+ "[value]", biomesObject.getBiome().name()));
+
+ break;
+ }
+ case 'r':
+ {
+ // Add message about required money
+ if (this.addon.isEconomyProvided() && biomesObject.getRequiredCost() > 0)
+ {
+ result.add(this.user.getTranslation("biomes.gui.biomes-description.required-money",
+ "[value]", Integer.toString(biomesObject.getRequiredCost())));
+ }
+
+ // Add message about required island level
+ if (this.addon.isLevelProvided() && biomesObject.getRequiredLevel() > 0)
+ {
+ result.add(this.user.getTranslation("biomes.gui.biomes-description.required-island-level",
+ "[value]", Long.toString(biomesObject.getRequiredLevel())));
+ }
+
+ if (!biomesObject.getRequiredPermissions().isEmpty())
+ {
+ result.add(this.user.getTranslation("biomes.gui.biomes-description.required-permissions"));
+
+ biomesObject.getRequiredPermissions().forEach(permission ->
+ {
+ result.add(this.user.getTranslation("biomes.gui.descriptions.permission",
+ "[permission]", permission));
+ });
+ }
+
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
+ result.replaceAll(x -> x.replace("[label]", this.topLabel));
+
+ return result;
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * This variable stores parent gui.
+ */
+ private CommonGUI parentGUI;
+
+ /**
+ * Variable stores Biomes addon.
+ */
+ protected BiomesAddon addon;
+
+ /**
+ * Variable stores world in which panel is referred to.
+ */
+ protected World world;
+
+ /**
+ * Variable stores user who created this panel.
+ */
+ protected User user;
+
+ /**
+ * Variable stores top label of command from which panel was called.
+ */
+ protected String topLabel;
+
+ /**
+ * Variable stores permission prefix of command from which panel was called.
+ */
+ protected String permissionPrefix;
+
+ /**
+ * This object holds current page index.
+ */
+ protected int pageIndex;
+
+ /**
+ * This object holds PanelItem that allows to return to previous panel.
+ */
+ protected PanelItem returnButton;
+
+
+ /**
+ * This enum contains buttons that is offten used in multiple GUIs.
+ */
+ protected enum CommonButtons
+ {
+ NEXT,
+ PREVIOUS,
+ RETURN
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Constants
+// ---------------------------------------------------------------------
+
+
+ protected final static String BIOMES = "biomes";
+
+ protected final static String ADMIN = "admin";
+
+ protected final static String SET = "set";
+
+ protected final static String ADD = "add";
+
+ protected final static String EDIT = "edit";
+
+ protected final static String DELETE = "remove";
+
+ protected final static String SETTINGS = "settings";
+
+ protected final static String IMPORT = "import";
+
+ protected final static String INFO = "info";
+}
\ No newline at end of file
diff --git a/src/main/java/world/bentobox/biomes/panels/GuiUtils.java b/src/main/java/world/bentobox/biomes/panels/GuiUtils.java
new file mode 100644
index 0000000..c7b382a
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/GuiUtils.java
@@ -0,0 +1,174 @@
+package world.bentobox.biomes.panels;
+
+
+import org.apache.commons.lang.WordUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+
+
+/**
+ * This class contains static methods that is used through multiple GUIs.
+ */
+public class GuiUtils
+{
+// ---------------------------------------------------------------------
+// Section: Border around GUIs
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This method creates border of black panes around given panel with 5 rows.
+ * @param panelBuilder PanelBuilder which must be filled with border blocks.
+ */
+ public static void fillBorder(PanelBuilder panelBuilder)
+ {
+ GuiUtils.fillBorder(panelBuilder, 5, Material.BLACK_STAINED_GLASS_PANE);
+ }
+
+
+ /**
+ * This method sets black stained glass pane around Panel with given row count.
+ * @param panelBuilder object that builds Panel.
+ * @param rowCount in Panel.
+ */
+ public static void fillBorder(PanelBuilder panelBuilder, int rowCount)
+ {
+ GuiUtils.fillBorder(panelBuilder, rowCount, Material.BLACK_STAINED_GLASS_PANE);
+ }
+
+
+ /**
+ * This method sets blocks with given Material around Panel with 5 rows.
+ * @param panelBuilder object that builds Panel.
+ * @param material that will be around Panel.
+ */
+ public static void fillBorder(PanelBuilder panelBuilder, Material material)
+ {
+ GuiUtils.fillBorder(panelBuilder, 5, material);
+ }
+
+
+ /**
+ * This method sets blocks with given Material around Panel with given row count.
+ * @param panelBuilder object that builds Panel.
+ * @param rowCount in Panel.
+ * @param material that will be around Panel.
+ */
+ public static void fillBorder(PanelBuilder panelBuilder, int rowCount, Material material)
+ {
+ // Only for useful filling.
+ if (rowCount < 3)
+ {
+ return;
+ }
+
+ for (int i = 0; i < 9 * rowCount; i++)
+ {
+ // First (i < 9) and last (i > 35) rows must be filled
+ // First column (i % 9 == 0) and last column (i % 9 == 8) also must be filled.
+
+ if (i < 9 || i > 9 * (rowCount - 1) || i % 9 == 0 || i % 9 == 8)
+ {
+ panelBuilder.item(i, BorderBlock.getPanelBorder(material));
+ }
+ }
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: ItemStack transformations
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This BorderBlock is simple PanelItem but without item meta data.
+ */
+ private static class BorderBlock extends PanelItem
+ {
+ private BorderBlock(ItemStack icon)
+ {
+ super(new PanelItemBuilder().
+ icon(icon.clone()).
+ name(" ").
+ description(Collections.emptyList()).
+ glow(false).
+ clickHandler(null));
+ }
+
+
+ /**
+ * This method retunrs BorderBlock with requested item stack.
+ * @param material of which broder must be created.
+ * @return PanelItem that acts like border.
+ */
+ private static BorderBlock getPanelBorder(Material material)
+ {
+ ItemStack itemStack = new ItemStack(material);
+ itemStack.getItemMeta().setDisplayName(" ");
+
+ return new BorderBlock(itemStack);
+ }
+ }
+
+
+ /**
+ * Simple splitter
+ *
+ * @param string - string to be split
+ * @param warpLength - whn warp should be affected.
+ * @return list of split strings
+ */
+ public static List stringSplit(String string, int warpLength)
+ {
+ // Remove all ending lines from string.
+ string = string.replaceAll("([\\r\\n])", "\\|");
+ string = ChatColor.translateAlternateColorCodes('&', string);
+ // Check length of lines
+ List result = new ArrayList<>();
+
+ Arrays.stream(string.split("\\|")).
+ map(line -> Arrays.asList(WordUtils.wrap(line, warpLength).split(System.getProperty("line.separator")))).
+ forEach(result::addAll);
+
+ // Fix colors, as splitting my lost that information.
+
+ for (int i = 0, resultSize = result.size(); i < resultSize; i++)
+ {
+ if (i > 0)
+ {
+ String lastColor = ChatColor.getLastColors(result.get(i - 1));
+ result.set(i, lastColor + result.get(i));
+ }
+ }
+
+ return result;
+ }
+
+
+ /**
+ * Simple splitter for all strings in list.
+ * @param stringList - list of string to be split
+ * @param warpLength - whn warp should be affected.
+ * @return list of split strings
+ */
+ public static List stringSplit(List stringList, int warpLength)
+ {
+ if (stringList.isEmpty())
+ {
+ return stringList;
+ }
+
+ List newList = new ArrayList<>(stringList.size());
+ stringList.stream().map(string -> GuiUtils.stringSplit(string, warpLength)).forEach(newList::addAll);
+ return newList;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/world/bentobox/biomes/panel/admin/AdminMainPanel.java b/src/main/java/world/bentobox/biomes/panels/admin/AdminGUI.java
similarity index 58%
rename from src/main/java/world/bentobox/biomes/panel/admin/AdminMainPanel.java
rename to src/main/java/world/bentobox/biomes/panels/admin/AdminGUI.java
index 61bf232..472531e 100644
--- a/src/main/java/world/bentobox/biomes/panel/admin/AdminMainPanel.java
+++ b/src/main/java/world/bentobox/biomes/panels/admin/AdminGUI.java
@@ -1,26 +1,33 @@
-package world.bentobox.biomes.panel.admin;
+package world.bentobox.biomes.panels.admin;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
+
import java.util.Collections;
import java.util.List;
+import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
+import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.panel.CommonPanel;
+import world.bentobox.biomes.panels.CommonGUI;
+import world.bentobox.biomes.panels.GuiUtils;
/**
- * This is Admin Main Panel. It contains all abilities that admin has available.
+ * This is main Admin GUI that is opened with admin command.
*/
-public class AdminMainPanel extends CommonPanel
+public class AdminGUI extends CommonGUI
{
- public AdminMainPanel(BiomesAddon addon,
+ /**
+ * {@inheritDoc}
+ */
+ public AdminGUI(BiomesAddon addon,
World world,
User user,
String topLabel,
@@ -30,6 +37,7 @@ public AdminMainPanel(BiomesAddon addon,
}
+
/**
* This method construct admin panel with predefined button placements.
*/
@@ -37,25 +45,24 @@ public AdminMainPanel(BiomesAddon addon,
public void build()
{
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
- this.user.getTranslation("biomes.gui.admin.gui-title"));
+ this.user.getTranslation("biomes.gui.title.admin.main-gui"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.ORANGE_STAINED_GLASS_PANE);
// Change Other players Biome
- panelBuilder.item(1, this.createButton(ButtonType.CHANGE_USER_BIOME));
+ panelBuilder.item(20, this.createButton(Button.CHANGE_USER_BIOME));
// Add New Biome
- panelBuilder.item(3, this.createButton(ButtonType.ADD_BIOME));
-
+ panelBuilder.item(13, this.createButton(Button.ADD_BIOME));
// Edit Biome
- panelBuilder.item(4, this.createButton(ButtonType.EDIT_BIOME));
-
+ panelBuilder.item(22, this.createButton(Button.EDIT_BIOME));
// Remove Biome
- panelBuilder.item(5, this.createButton(ButtonType.DELETE_BIOME));
+ panelBuilder.item(31, this.createButton(Button.DELETE_BIOME));
// Import Biomes
- panelBuilder.item(7, this.createButton(ButtonType.IMPORT_BIOMES));
-
+ panelBuilder.item(24, this.createButton(Button.IMPORT_BIOMES));
// Edit Addon Settings
- panelBuilder.item(8, this.createButton(ButtonType.EDIT_SETTINGS));
+ panelBuilder.item(25, this.createButton(Button.EDIT_SETTINGS));
panelBuilder.build();
}
@@ -63,10 +70,10 @@ public void build()
/**
* This method returns button for admin panel of given type.
- * @param buttonType Type of button.
+ * @param button Type of button.
* @return new panel button with requested type.
*/
- private PanelItem createButton(ButtonType buttonType)
+ private PanelItem createButton(Button button)
{
ItemStack icon;
String name;
@@ -76,22 +83,17 @@ private PanelItem createButton(ButtonType buttonType)
String permissionSuffix;
- switch (buttonType)
+ switch (button)
{
case CHANGE_USER_BIOME:
{
permissionSuffix = SET;
- name = this.user.getTranslation("biomes.gui.admin.buttons.change");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.change");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.change"));
icon = new ItemStack(Material.LEVER);
clickHandler = (panel, user, clickType, slot) -> {
- new AdminUserListPanel(this.addon,
- this.world,
- this.user,
- this.topLabel,
- this.permissionPrefix,
- this).build();
+ new ListUsersGUI(this).build();
return true;
};
glow = false;
@@ -102,17 +104,27 @@ private PanelItem createButton(ButtonType buttonType)
{
permissionSuffix = ADD;
- name = this.user.getTranslation("biomes.gui.admin.buttons.add");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.add");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.add"));
icon = new ItemStack(Material.BOOK);
clickHandler = (panel, user, clickType, slot) -> {
- new AdminBiomeEditPanel(this.addon,
- this.world,
- this.user,
- null,
- this.topLabel,
- this.permissionPrefix,
- this).build();
+ new AnvilGUI(this.addon.getPlugin(),
+ this.user.getPlayer(),
+ "unique_id",
+ (player, reply) -> {
+ String newName = Util.getWorld(this.world).getName() + "-" + reply.toLowerCase();
+
+ if (!this.addon.getAddonManager().containsBiome(newName))
+ {
+ new EditBiomeGUI(AdminGUI.this, this.addon.getAddonManager().createBiome(newName)).build();
+ }
+ else
+ {
+ this.user.sendMessage("biomes.errors.unique-id", "[id]", reply);
+ }
+
+ return reply;
+ });
return true;
};
@@ -124,17 +136,11 @@ private PanelItem createButton(ButtonType buttonType)
{
permissionSuffix = EDIT;
- name = this.user.getTranslation("biomes.gui.admin.buttons.edit");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.edit");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.edit"));
icon = new ItemStack(Material.ANVIL);
clickHandler = (panel, user, clickType, slot) -> {
- new AdminBiomeListPanel(this.addon,
- this.world,
- this.user,
- true,
- this.topLabel,
- this.permissionPrefix,
- this).build();
+ new ListBiomesGUI(this, true).build();
return true;
};
glow = false;
@@ -145,17 +151,11 @@ private PanelItem createButton(ButtonType buttonType)
{
permissionSuffix = DELETE;
- name = this.user.getTranslation("biomes.gui.admin.buttons.remove");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.remove");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.remove"));
icon = new ItemStack(Material.LAVA_BUCKET);
clickHandler = (panel, user, clickType, slot) -> {
- new AdminBiomeListPanel(this.addon,
- this.world,
- this.user,
- false,
- this.topLabel,
- this.permissionPrefix,
- this).build();
+ new ListBiomesGUI(this, false).build();
return true;
};
glow = false;
@@ -166,8 +166,8 @@ private PanelItem createButton(ButtonType buttonType)
{
permissionSuffix = IMPORT;
- name = this.user.getTranslation("biomes.gui.admin.buttons.import");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.import");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.import"));
icon = new ItemStack(Material.HOPPER);
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
@@ -191,16 +191,11 @@ private PanelItem createButton(ButtonType buttonType)
{
permissionSuffix = SETTINGS;
- name = this.user.getTranslation("biomes.gui.admin.buttons.settings");
- description = Collections.emptyList();
+ name = this.user.getTranslation("biomes.gui.buttons.admin.settings");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.settings"));
icon = new ItemStack(Material.CRAFTING_TABLE);
clickHandler = (panel, user, clickType, slot) -> {
- new AdminSettingsPanel(this.addon,
- this.world,
- this.user,
- this.topLabel,
- this.permissionPrefix,
- this).build();
+ new EditSettingsGUI(this).build();
return true;
};
glow = false;
@@ -227,7 +222,7 @@ private PanelItem createButton(ButtonType buttonType)
return new PanelItemBuilder().
icon(icon).
name(name).
- description(description).
+ description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength())).
glow(glow).
clickHandler(clickHandler).
build();
@@ -242,7 +237,7 @@ private PanelItem createButton(ButtonType buttonType)
/**
* This enum shows which button should be created.
*/
- private enum ButtonType
+ private enum Button
{
CHANGE_USER_BIOME,
ADD_BIOME,
@@ -257,6 +252,8 @@ private enum ButtonType
// Section: Variables
// ---------------------------------------------------------------------
-
+ /**
+ * Overwrite mode for import manager.
+ */
private boolean overwriteMode;
}
diff --git a/src/main/java/world/bentobox/biomes/panels/admin/EditBiomeGUI.java b/src/main/java/world/bentobox/biomes/panels/admin/EditBiomeGUI.java
new file mode 100644
index 0000000..76e2538
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/admin/EditBiomeGUI.java
@@ -0,0 +1,370 @@
+package world.bentobox.biomes.panels.admin;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.*;
+
+import net.wesjd.anvilgui.AnvilGUI;
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.panels.CommonGUI;
+import world.bentobox.biomes.panels.util.NumberGUI;
+import world.bentobox.biomes.panels.util.SelectBiomeGUI;
+import world.bentobox.biomes.panels.util.StringListGUI;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This class contains methods that allows to edit specific biome object.
+ */
+public class EditBiomeGUI extends CommonGUI
+{
+ /**
+ * {@inheritDoc}
+ * @param biome Object that must be edited.
+ */
+ public EditBiomeGUI(CommonGUI parentPanel, BiomesObject biome)
+ {
+ super(parentPanel);
+ this.biome = biome;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ * @param biome Object that must be edited.
+ */
+ public EditBiomeGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix,
+ BiomesObject biome)
+ {
+ super(addon, world, user, topLabel, permissionPrefix);
+ this.biome = biome;
+ }
+
+
+ /**
+ * This method builds all necessary elements in GUI panel.
+ */
+ @Override
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
+ name(this.user.getTranslation("biomes.gui.title.admin.edit", "[biome]", this.biome.getFriendlyName()));
+
+ GuiUtils.fillBorder(panelBuilder, Material.PURPLE_STAINED_GLASS_PANE);
+
+ panelBuilder.item(19, this.createButton(Button.BIOME));
+
+ panelBuilder.item(11, this.createButton(Button.NAME));
+ panelBuilder.item(20, this.createButton(Button.ICON));
+ panelBuilder.item(29, this.createButton(Button.DESCRIPTION));
+
+ panelBuilder.item(21, this.createButton(Button.ORDER));
+
+
+ panelBuilder.item(14, this.createButton(Button.LEVEL));
+ panelBuilder.item(23, this.createButton(Button.COST));
+ panelBuilder.item(32, this.createButton(Button.PERMISSION));
+
+ panelBuilder.item(25, this.createButton(Button.DEPLOYED));
+
+ panelBuilder.item(44, this.returnButton);
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method returns button for edit panel of given type.
+ * @param button Type of button.
+ * @return new panel button with requested type.
+ */
+ private PanelItem createButton(Button button)
+ {
+ PanelItemBuilder itemBuilder = new PanelItemBuilder();
+ final int lineLength = this.addon.getSettings().getLoreLineLength();
+
+ switch (button)
+ {
+ case BIOME:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.change-biome"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.change-biome"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", this.biome.getBiome().name()));
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(Material.WATER_BUCKET);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ // Open select gui
+ new SelectBiomeGUI(this.user, this.biome.getBiome(), lineLength, (status, value) -> {
+ this.biome.setBiome(value);
+ this.build();
+ });
+
+ return true;
+ });
+ break;
+ }
+ case PERMISSION:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.required-permissions"));
+
+ List description = new ArrayList<>(this.biome.getRequiredPermissions().size() + 1);
+ description.add(this.user.getTranslation(
+ "biomes.gui.descriptions.admin.required-permissions"));
+
+ for (String permission : this.biome.getRequiredPermissions())
+ {
+ description.add(this.user.getTranslation("biomes.gui.descriptions.permission",
+ "[permission]", permission));
+ }
+
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(Material.REDSTONE_LAMP);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new StringListGUI(this.user, this.biome.getRequiredPermissions(), lineLength, (status, value) -> {
+ if (status)
+ {
+ this.biome.setRequiredPermissions(new HashSet<>(value));
+ }
+
+ this.build();
+ });
+
+ return true;
+ });
+ break;
+ }
+ case LEVEL:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.required-level"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.required-level"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Long.toString(this.biome.getRequiredLevel())));
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new NumberGUI(this.user, (int) this.biome.getRequiredLevel(), lineLength, (status, value) -> {
+ if (status)
+ {
+ this.biome.setRequiredLevel(value);
+ }
+
+ this.build();
+ });
+
+ return true;
+ });
+
+ break;
+ }
+ case COST:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.required-money"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.required-money"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Long.toString(this.biome.getRequiredCost())));
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new NumberGUI(this.user, this.biome.getRequiredCost(), 0, lineLength, (status, value) -> {
+ if (status)
+ {
+ this.biome.setRequiredCost(value);
+ }
+
+ this.build();
+ });
+ return true;
+ });
+
+ break;
+ }
+ case NAME:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.name"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.name"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", this.biome.getFriendlyName()));
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(Material.BOOK);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new AnvilGUI(this.addon.getPlugin(),
+ this.user.getPlayer(),
+ this.biome.getFriendlyName(),
+ (player, reply) -> {
+ this.biome.setFriendlyName(reply);
+ this.build();
+ return reply;
+ });
+
+ return true;
+ });
+ break;
+ }
+ case DEPLOYED:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.deployment"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.deployment"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]",
+ this.biome.isDeployed() ?
+ this.user.getTranslation("biomes.gui.descriptions.enabled") :
+ this.user.getTranslation("biomes.gui.descriptions.disabled")));
+ itemBuilder.description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength()));
+ itemBuilder.icon(Material.LEVER);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ this.biome.setDeployed(!this.biome.isDeployed());
+ panel.getInventory().setItem(slot, this.createButton(button).getItem());
+ return true;
+ });
+ itemBuilder.glow(this.biome.isDeployed());
+ break;
+ }
+ case ICON:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.icon"));
+
+ itemBuilder.description(GuiUtils.stringSplit(
+ this.user.getTranslation("biomes.gui.descriptions.admin.icon"),
+ this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(this.biome.getIcon());
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new AnvilGUI(this.addon.getPlugin(),
+ this.user.getPlayer(),
+ this.biome.getIcon().getType().name(),
+ (player, reply) -> {
+ Material material = Material.getMaterial(reply);
+
+ if (material != null)
+ {
+ this.biome.setIcon(new ItemStack(material));
+ this.build();
+ }
+ else
+ {
+ this.user.sendMessage("biomes.errors.wrong-icon", "[value]", reply);
+ }
+
+ return reply;
+ });
+
+ return true;
+ });
+ break;
+ }
+ case DESCRIPTION:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.description"));
+
+ List values = new ArrayList<>();
+ values.add(this.user.getTranslation("biomes.gui.descriptions.admin.description"));
+ values.add(this.user.getTranslation("biomes.gui.descriptions.current-value", "[value]", ""));
+ values.addAll(this.generateBiomesDescription(this.biome));
+
+ itemBuilder.description(GuiUtils.stringSplit(values, this.addon.getSettings().getLoreLineLength()));
+ itemBuilder.icon(Material.WRITTEN_BOOK);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new StringListGUI(this.user, this.biome.getDescription(), lineLength, (status, value) -> {
+ if (status)
+ {
+ this.biome.setDescription(value);
+ }
+
+ this.build();
+ });
+
+ return true;
+ });
+ break;
+ }
+ case ORDER:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.order"));
+
+ List description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.order"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Integer.toString(this.biome.getOrder())));
+ itemBuilder.description(description);
+
+ itemBuilder.icon(Material.DROPPER);
+ itemBuilder.clickHandler((panel, user, clickType, slot) -> {
+ new NumberGUI(this.user, this.biome.getOrder(), -1, 54, lineLength, (status, value) -> {
+ if (status)
+ {
+ this.biome.setOrder(value);
+ }
+
+ this.build();
+ });
+
+ return true;
+ });
+ break;
+ }
+ }
+
+ return itemBuilder.build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Enums
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This enum shows which button should be created.
+ */
+ private enum Button
+ {
+ BIOME,
+ PERMISSION,
+ COST,
+ LEVEL,
+ ORDER,
+ DESCRIPTION,
+ ICON,
+ NAME,
+ DEPLOYED
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variable
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Holds a biome object that is edited.
+ */
+ private BiomesObject biome;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/biomes/panels/admin/EditSettingsGUI.java
new file mode 100644
index 0000000..bcf721f
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/admin/EditSettingsGUI.java
@@ -0,0 +1,437 @@
+package world.bentobox.biomes.panels.admin;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.inventory.ItemStack;
+import org.eclipse.jdt.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.wesjd.anvilgui.AnvilGUI;
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.config.Settings;
+import world.bentobox.biomes.panels.CommonGUI;
+import world.bentobox.biomes.panels.util.NumberGUI;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+public class EditSettingsGUI extends CommonGUI
+{
+ /**
+ * {@inheritDoc}
+ */
+ public EditSettingsGUI(@NonNull CommonGUI parentGUI)
+ {
+ super(parentGUI);
+ this.settings = this.addon.getSettings();
+ }
+
+
+ public EditSettingsGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix)
+ {
+ super(addon, world, user, topLabel, permissionPrefix);
+ this.settings = this.addon.getSettings();
+ }
+
+
+ /**
+ * This method builds all necessary elements in GUI panel.
+ */
+ @Override
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
+ this.user.getTranslation("biomes.gui.title.admin.settings"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.ORANGE_STAINED_GLASS_PANE);
+
+ panelBuilder.item(19, this.createButton(Button.ADVANCED_MENU));
+
+ panelBuilder.item(11, this.createButton(Button.DEFAULT_MODE));
+ panelBuilder.item(20, this.createButton(Button.DEFAULT_SIZE));
+ panelBuilder.item(29, this.createButton(Button.VISIBILITY));
+
+ panelBuilder.item(21, this.createButton(Button.LORE_MESSAGE));
+ panelBuilder.item(30, this.createButton(Button.LORE_LENGTH));
+
+ panelBuilder.item(23, this.createButton(Button.COOLDOWN));
+ panelBuilder.item(25, this.createButton(Button.RESET));
+
+ panelBuilder.item(44, this.returnButton);
+
+ panelBuilder.build();
+ }
+
+
+ private PanelItem createButton(Button button)
+ {
+ ItemStack icon;
+ String name;
+ List description;
+ boolean glow;
+ PanelItem.ClickHandler clickHandler;
+
+ switch (button)
+ {
+ case ADVANCED_MENU:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.advanced-menu"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]",
+ this.settings.isAdvancedMenu() ?
+ this.user.getTranslation("biomes.gui.descriptions.enabled") :
+ this.user.getTranslation("biomes.gui.descriptions.disabled")));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.advanced-menu");
+ icon = new ItemStack(Material.COMMAND_BLOCK);
+
+ clickHandler = (panel, user1, clickType, i) -> {
+ this.settings.setAdvancedMenu(
+ !this.settings.isAdvancedMenu());
+
+ panel.getInventory().setItem(i, this.createButton(button).getItem());
+ return true;
+ };
+
+ glow = this.settings.isAdvancedMenu();
+ break;
+ }
+ case DEFAULT_MODE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.default-mode");
+
+ List values = new ArrayList<>(5);
+ values.add(this.user.getTranslation("biomes.gui.descriptions.admin.default-mode"));
+
+ values.add((this.settings.getDefaultMode().equals(Settings.UpdateMode.ISLAND) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.update-mode.island"));
+ values.add((this.settings.getDefaultMode().equals(Settings.UpdateMode.CHUNK) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.update-mode.chunk"));
+ values.add((this.settings.getDefaultMode().equals(Settings.UpdateMode.RANGE) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.update-mode.square"));
+ description = values;
+
+ if (this.settings.getDefaultMode().equals(Settings.UpdateMode.ISLAND))
+ {
+ icon = new ItemStack(Material.GRASS_BLOCK);
+ }
+ else if (this.settings.getDefaultMode().equals(Settings.UpdateMode.CHUNK))
+ {
+ icon = new ItemStack(Material.DIRT);
+ }
+ else if (this.settings.getDefaultMode().equals(Settings.UpdateMode.RANGE))
+ {
+ icon = new ItemStack(Material.GLASS);
+ }
+ else
+ {
+ icon = new ItemStack(Material.STRUCTURE_VOID);
+ }
+
+ clickHandler = (panel, user, clickType, slot) -> {
+ if (clickType.isRightClick())
+ {
+ this.settings.setDefaultMode(
+ Settings.UpdateMode.values()[
+ this.getPreviousMode(this.settings.getDefaultMode(),
+ Settings.UpdateMode.values())]);
+ }
+ else
+ {
+ this.settings.setDefaultMode(
+ Settings.UpdateMode.values()[
+ this.getNextMode(this.settings.getDefaultMode(),
+ Settings.UpdateMode.values())]);
+ }
+
+ panel.getInventory().setItem(slot, this.createButton(button).getItem());
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case DEFAULT_SIZE:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.default-size"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Integer.toString(this.settings.getDefaultSize())));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.default-size");
+ icon = new ItemStack(Material.PISTON);
+ clickHandler = (panel, user1, clickType, i) -> {
+ new NumberGUI(this.user,
+ this.settings.getDefaultSize(),
+ 0,
+ this.settings.getLoreLineLength(),
+ (status, value) -> {
+ if (status)
+ {
+ this.settings.setDefaultSize(value);
+ }
+
+ EditSettingsGUI.this.build();
+ });
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case VISIBILITY:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.visibility-mode");
+
+ List values = new ArrayList<>(5);
+ values.add(this.user.getTranslation("biomes.gui.descriptions.admin.visibility-mode"));
+
+ values.add((this.settings.getVisibilityMode().equals(Settings.VisibilityMode.ALL) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.all"));
+ values.add((this.settings.getVisibilityMode().equals(Settings.VisibilityMode.DEPLOYED) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.deployed"));
+ values.add((this.settings.getVisibilityMode().equals(Settings.VisibilityMode.ACCESSIBLE) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.accessible"));
+ values.add((this.settings.getVisibilityMode().equals(Settings.VisibilityMode.TOGGLEABLE) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.toggleable"));
+ description = values;
+
+ if (this.settings.getVisibilityMode().equals(Settings.VisibilityMode.ALL))
+ {
+ icon = new ItemStack(Material.BIRCH_PLANKS);
+ }
+ else if (this.settings.getVisibilityMode().equals(Settings.VisibilityMode.DEPLOYED))
+ {
+ icon = new ItemStack(Material.BIRCH_STAIRS);
+ }
+ else if (this.settings.getVisibilityMode().equals(Settings.VisibilityMode.ACCESSIBLE))
+ {
+ icon = new ItemStack(Material.BIRCH_SLAB);
+ }
+ else
+ {
+ icon = new ItemStack(Material.BIRCH_BUTTON);
+ }
+
+ clickHandler = (panel, user, clickType, slot) -> {
+ if (clickType.isRightClick())
+ {
+ this.settings.setVisibilityMode(
+ Settings.VisibilityMode.values()[
+ this.getPreviousMode(this.settings.getVisibilityMode(),
+ Settings.VisibilityMode.values())]);
+ }
+ else
+ {
+ this.settings.setVisibilityMode(
+ Settings.VisibilityMode.values()[
+ this.getNextMode(this.settings.getVisibilityMode(),
+ Settings.VisibilityMode.values())]);
+ }
+
+ panel.getInventory().setItem(slot, this.createButton(button).getItem());
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case LORE_LENGTH:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.line-length"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Integer.toString(this.settings.getLoreLineLength())));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.line-length");
+ icon = new ItemStack(Material.ANVIL);
+ clickHandler = (panel, user1, clickType, i) -> {
+ new NumberGUI(this.user,
+ this.settings.getLoreLineLength(),
+ 0,
+ this.settings.getLoreLineLength(),
+ (status, value) -> {
+ if (status)
+ {
+ this.settings.setLoreLineLength(value);
+ }
+
+ EditSettingsGUI.this.build();
+ });
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case LORE_MESSAGE:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.biomes-lore"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", this.settings.getLoreMessage()));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.biomes-lore");
+ icon = new ItemStack(Material.MAP);
+ clickHandler = (panel, user1, clickType, i) -> {
+ new AnvilGUI(this.addon.getPlugin(),
+ this.user.getPlayer(),
+ this.settings.getLoreMessage(),
+ (player, reply) -> {
+ this.settings.setLoreMessage(reply);
+ EditSettingsGUI.this.build();
+ return reply;
+ });
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case COOLDOWN:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.cooldown"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]", Integer.toString(this.settings.getCoolDown())));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.cooldown");
+ icon = new ItemStack(Material.DAYLIGHT_DETECTOR);
+ clickHandler = (panel, user1, clickType, i) -> {
+ new NumberGUI(this.user,
+ this.settings.getCoolDown(),
+ -1,
+ this.settings.getLoreLineLength(),
+ (status, value) -> {
+ if (status)
+ {
+ this.settings.setCoolDown(value);
+ }
+
+ EditSettingsGUI.this.build();
+ });
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case RESET:
+ {
+ description = new ArrayList<>(2);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.reset-biomes"));
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value",
+ "[value]",
+ this.settings.isResetBiomes() ?
+ this.user.getTranslation("biomes.gui.descriptions.enabled") :
+ this.user.getTranslation("biomes.gui.descriptions.disabled")));
+ name = this.user.getTranslation("biomes.gui.buttons.admin.reset-biomes");
+ icon = new ItemStack(Material.DROPPER);
+
+ clickHandler = (panel, user1, clickType, i) -> {
+ this.settings.setResetBiomes(
+ !this.settings.isResetBiomes());
+
+ panel.getInventory().setItem(i, this.createButton(button).getItem());
+ return true;
+ };
+
+ glow = this.settings.isResetBiomes();
+ break;
+ }
+ default:
+ {
+ return new PanelItemBuilder().build();
+ }
+ }
+
+ return new PanelItemBuilder().
+ icon(icon).
+ name(name).
+ description(GuiUtils.stringSplit(description, this.settings.getLoreLineLength())).
+ glow(glow).
+ clickHandler(clickHandler).
+ build();
+ }
+
+
+ /**
+ * Method iterates through given list in descending order
+ * @param mode Current object
+ * @param values Object array
+ * @return Previous object
+ */
+ private int getPreviousMode(Object mode, Object[] values)
+ {
+ for (int i = 0; i < values.length; i++)
+ {
+ if (values[i].equals(mode))
+ {
+ if (i > 0)
+ {
+ return i - 1;
+ }
+ else
+ {
+ return values.length - 1;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+
+ /**
+ * Method iterates through given list in ascending order
+ * @param mode Current object
+ * @param values Object array
+ * @return Next object
+ */
+ private int getNextMode(Object mode, Object[] values)
+ {
+ for (int i = 0; i < values.length; i++)
+ {
+ if (values[i].equals(mode))
+ {
+ if (i + 1 == values.length)
+ {
+ return 0;
+ }
+ else
+ {
+ return i + 1;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+
+ // ---------------------------------------------------------------------
+ // Section: Variables
+ // ---------------------------------------------------------------------
+
+
+ private enum Button
+ {
+ ADVANCED_MENU,
+ DEFAULT_MODE,
+ DEFAULT_SIZE,
+ VISIBILITY,
+ LORE_LENGTH,
+ LORE_MESSAGE,
+ COOLDOWN,
+ RESET
+ }
+
+
+ private Settings settings;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/admin/ListBiomesGUI.java b/src/main/java/world/bentobox/biomes/panels/admin/ListBiomesGUI.java
new file mode 100644
index 0000000..d0bae77
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/admin/ListBiomesGUI.java
@@ -0,0 +1,143 @@
+package world.bentobox.biomes.panels.admin;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import java.util.List;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.panels.CommonGUI;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+public class ListBiomesGUI extends CommonGUI
+{
+ /**
+ * {@inheritDoc}
+ */
+ public ListBiomesGUI(CommonGUI parentPanel, boolean editMode)
+ {
+ super(parentPanel);
+ this.editMode = editMode;
+ }
+
+
+ public ListBiomesGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix,
+ boolean editMode)
+ {
+ super(addon, world, user, topLabel, permissionPrefix);
+ this.editMode = editMode;
+ }
+
+
+ @Override
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user);
+
+ if (this.editMode)
+ {
+ panelBuilder.name(this.user.getTranslation("biomes.gui.title.admin.edit-list"));
+ GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE);
+ }
+ else
+ {
+ panelBuilder.name(this.user.getTranslation("biomes.gui.title.admin.remove-list"));
+ GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE);
+ }
+
+ List biomes = this.addon.getAddonManager().getBiomes(this.world);
+
+ final int MAX_ELEMENTS = 21;
+
+ if (this.pageIndex < 0)
+ {
+ this.pageIndex = biomes.size() / MAX_ELEMENTS;
+ }
+ else if (this.pageIndex > (biomes.size() / MAX_ELEMENTS))
+ {
+ this.pageIndex = 0;
+ }
+
+ int biomeIndex = MAX_ELEMENTS * this.pageIndex;
+
+ // I want first row to be only for navigation and return button.
+ int index = 10;
+
+ while (biomeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
+ biomeIndex < biomes.size() &&
+ index < 36)
+ {
+ if (!panelBuilder.slotOccupied(index))
+ {
+ panelBuilder.item(index, this.createBiomeIcon(biomes.get(biomeIndex++)));
+ }
+
+ index++;
+ }
+
+ // Navigation buttons only if necessary
+ if (biomes.size() > MAX_ELEMENTS)
+ {
+ panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
+ panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
+ }
+
+ panelBuilder.item(44, this.returnButton);
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method creates biomes icon. It sets it to glow, if biome is not deployed.
+ * @param biome Biome which icon must be created.
+ * @return New Biome Icon.
+ */
+ private PanelItem createBiomeIcon(BiomesObject biome)
+ {
+ return new PanelItemBuilder().
+ name(biome.getFriendlyName()).
+ icon(biome.getIcon()).
+ description(this.generateBiomesDescription(biome)).
+ clickHandler((panel, user1, clickType, slot) -> {
+ if (this.editMode)
+ {
+ new EditBiomeGUI(this, biome).build();
+ }
+ else
+ {
+ this.addon.getAddonManager().removeBiome(biome);
+
+ this.user.sendMessage("biomes.messages.biome-removed", "[biome]", biome.getUniqueId());
+
+ this.pageIndex = 0;
+ this.build();
+ }
+
+ return true;
+ }).
+ glow(!biome.isDeployed()).
+ build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Allows to change between edit and delete mode.
+ */
+ private boolean editMode;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/admin/ListUsersGUI.java b/src/main/java/world/bentobox/biomes/panels/admin/ListUsersGUI.java
new file mode 100644
index 0000000..57e0333
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/admin/ListUsersGUI.java
@@ -0,0 +1,237 @@
+package world.bentobox.biomes.panels.admin;
+
+
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.bentobox.database.objects.Players;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.panels.CommonGUI;
+import world.bentobox.biomes.panels.user.BiomesChooseGUI;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This class contains methods that allows to select specific user.
+ */
+public class ListUsersGUI extends CommonGUI
+{
+// ---------------------------------------------------------------------
+// Section: Constructors
+// ---------------------------------------------------------------------
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ListUsersGUI(CommonGUI parentPanel)
+ {
+ super(parentPanel);
+ this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD);
+ }
+
+
+ public ListUsersGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix)
+ {
+ super(addon, world, user, topLabel, permissionPrefix);
+ this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD);
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Methods
+// ---------------------------------------------------------------------
+
+
+ @Override
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
+ this.user.getTranslation("biomes.gui.title.admin.user-list"));
+
+ GuiUtils.fillBorder(panelBuilder);
+
+ final int MAX_ELEMENTS = 21;
+
+ if (this.pageIndex < 0)
+ {
+ this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS;
+ }
+ else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS))
+ {
+ this.pageIndex = 0;
+ }
+
+ int playerIndex = MAX_ELEMENTS * this.pageIndex;
+
+ // I want first row to be only for navigation and return button.
+ int index = 10;
+
+ while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) &&
+ playerIndex < this.onlineUsers.size() &&
+ index < 36)
+ {
+ if (!panelBuilder.slotOccupied(index))
+ {
+ panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++)));
+ }
+
+ index++;
+ }
+
+ // Add button that allows to toggle different player lists.
+ panelBuilder.item( 4, this.createToggleButton());
+
+ // Navigation buttons only if necessary
+ if (this.onlineUsers.size() > MAX_ELEMENTS)
+ {
+ panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS));
+ panelBuilder.item(26, this.getButton(CommonButtons.NEXT));
+ }
+
+ panelBuilder.item(44, this.returnButton);
+
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method creates button for given user. If user has island it will add valid click handler.
+ * @param player Player which button must be created.
+ * @return Player button.
+ */
+ private PanelItem createPlayerIcon(Player player)
+ {
+ int lineLength = this.addon.getSettings().getLoreLineLength();
+
+ if (this.addon.getIslands().getIsland(this.world, player.getUniqueId()) != null)
+ {
+ return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler(
+ (panel, user1, clickType, slot) -> {
+ new BiomesChooseGUI(this, User.getInstance(player)).build();
+
+ return true;
+ }).build();
+ }
+ else
+ {
+ return new PanelItemBuilder().
+ name(player.getName()).
+ icon(Material.BARRIER).
+ description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)).
+ clickHandler((panel, user1, clickType, slot) -> false).
+ build();
+ }
+ }
+
+
+ /**
+ * This method collects users based on view mode.
+ * @param mode Given view mode.
+ * @return List with players in necessary view mode.
+ */
+ private List collectUsers(ViewMode mode)
+ {
+ if (mode.equals(ViewMode.ONLINE))
+ {
+ return new ArrayList<>(Bukkit.getOnlinePlayers());
+ }
+ else if (mode.equals(ViewMode.WITH_ISLAND))
+ {
+ return this.addon.getPlayers().getPlayers().stream().
+ filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null).
+ map(Players::getPlayer).
+ collect(Collectors.toList());
+ }
+ else
+ {
+ return new ArrayList<>(this.world.getPlayers());
+ }
+ }
+
+
+ /**
+ * This method creates Player List view Mode toggle button.
+ * @return Button that toggles through player view mode.
+ */
+ private PanelItem createToggleButton()
+ {
+ List description = new ArrayList<>(ViewMode.values().length + 1);
+ description.add(this.user.getTranslation("biomes.gui.descriptions.admin.toggle-user-list"));
+ description.add((ViewMode.ONLINE == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.view-mode.online"));
+ description.add((ViewMode.WITH_ISLAND == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.view-mode.in-world"));
+ description.add((ViewMode.IN_WORLD == ViewMode.values()[this.modeIndex] ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.view-mode.with-island"));
+
+ return new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.admin.toggle-user-list")).
+ description(GuiUtils.stringSplit(description, this.addon.getSettings().getLoreLineLength())).
+ icon(Material.STONE_BUTTON).
+ clickHandler(
+ (panel, user1, clickType, slot) -> {
+ if (clickType.isRightClick())
+ {
+ this.modeIndex--;
+
+ if (this.modeIndex < 0)
+ {
+ this.modeIndex = ViewMode.values().length - 1;
+ }
+ }
+ else
+ {
+ this.modeIndex++;
+
+ if (this.modeIndex >= ViewMode.values().length)
+ {
+ this.modeIndex = 0;
+ }
+ }
+
+ this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]);
+ this.pageIndex = 0;
+ this.build();
+ return true;
+ }).build();
+ }
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * List with players that should be in GUI.
+ */
+ private List onlineUsers;
+
+ /**
+ * Current index of view mode
+ */
+ private int modeIndex = 2;
+
+ /**
+ * This allows to switch which users should be in the list.
+ */
+ private enum ViewMode
+ {
+ ONLINE,
+ WITH_ISLAND,
+ IN_WORLD
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/world/bentobox/biomes/panels/user/BiomesChooseGUI.java b/src/main/java/world/bentobox/biomes/panels/user/BiomesChooseGUI.java
new file mode 100644
index 0000000..7b85f3a
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/user/BiomesChooseGUI.java
@@ -0,0 +1,322 @@
+package world.bentobox.biomes.panels.user;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.config.Settings;
+import world.bentobox.biomes.database.objects.BiomesObject;
+
+import world.bentobox.biomes.panels.CommonGUI;
+
+import world.bentobox.biomes.config.Settings.UpdateMode;
+import world.bentobox.biomes.config.Settings.VisibilityMode;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This class manages Player GUI panel.
+ */
+public class BiomesChooseGUI extends CommonGUI
+{
+ /**
+ * Default constructor.
+ * {@inheritDoc}
+ */
+ public BiomesChooseGUI(BiomesAddon addon,
+ World world,
+ User user,
+ String topLabel,
+ String permissionPrefix)
+ {
+ super(addon, world, user, topLabel, permissionPrefix);
+
+ this.visibilityMode = this.addon.getSettings().getVisibilityMode().equals(VisibilityMode.TOGGLEABLE) ?
+ VisibilityMode.ACCESSIBLE :
+ this.addon.getSettings().getVisibilityMode();
+
+ // Allocate biomes for player
+ this.biomeList = this.addon.getAddonManager().getBiomes(this.world, this.user, this.visibilityMode);
+
+ this.target = null;
+ }
+
+
+ /**
+ * Default constructor.
+ * {@inheritDoc}
+ * @param target - Targeted player if Biome is changed by Administrator.
+ */
+ public BiomesChooseGUI(CommonGUI parentGui, User target)
+ {
+ super(parentGui);
+
+ // Admins should see all biomes.
+ this.visibilityMode = this.addon.getSettings().getVisibilityMode().equals(VisibilityMode.TOGGLEABLE) ?
+ (target == null ? VisibilityMode.ACCESSIBLE : VisibilityMode.ALL) :
+ this.addon.getSettings().getVisibilityMode();
+
+ // Allocate biomes for player
+ this.biomeList = this.addon.getAddonManager().getBiomes(this.world, this.user, this.visibilityMode);
+ this.target = target;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void build()
+ {
+ // Do not open gui if there is no challenges.
+ if (this.biomeList.isEmpty())
+ {
+ this.user.sendMessage("biomes.errors.no-biomes-for-you");
+ return;
+ }
+
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
+ name(this.user.getTranslation("biomes.gui.title.biomes-choose"));
+
+
+ // GUI should open with border around all elements, so need to calculate how large gui is necessary.
+ // Max will be 3 rows.
+ // As these operations are fast, then do not use extra memory.
+
+ int rowCount = this.biomeList.size() > 14 ? 3 : this.biomeList.size() > 7 ? 2 : 1;
+ // Maximal elements in page. This avoids flickering between different size GUIs.
+ final int MAX_ELEMENTS = rowCount * 7;
+
+ GuiUtils.fillBorder(panelBuilder, rowCount + 2, Material.GRAY_STAINED_GLASS_PANE);
+
+ final int correctPage;
+
+ if (this.pageIndex < 0)
+ {
+ correctPage = this.biomeList.size() / MAX_ELEMENTS;
+ }
+ else if (this.pageIndex > (this.biomeList.size() / MAX_ELEMENTS))
+ {
+ correctPage = 0;
+ }
+ else
+ {
+ correctPage = this.pageIndex;
+ }
+
+ if (this.biomeList.size() > MAX_ELEMENTS)
+ {
+ // Navigation buttons if necessary
+
+ panelBuilder.item(9, this.getButton(CommonButtons.PREVIOUS));
+
+ panelBuilder.item(17, this.getButton(CommonButtons.NEXT));
+ }
+
+ int biomesIndex = MAX_ELEMENTS * correctPage;
+
+ // I want first row to be only for navigation and return button.
+ int index = 10;
+
+ while (biomesIndex < ((correctPage + 1) * MAX_ELEMENTS) &&
+ biomesIndex < this.biomeList.size() &&
+ index < 36)
+ {
+ if (!panelBuilder.slotOccupied(index))
+ {
+ panelBuilder.item(index,
+ this.createBiomeIcon(this.biomeList.get(biomesIndex++)));
+ }
+
+ index++;
+ }
+
+ if (this.addon.getSettings().getVisibilityMode().equals(VisibilityMode.TOGGLEABLE))
+ {
+ panelBuilder.item(8, this.createVisibilityModeButton());
+ }
+
+ // Element in the corner should be CANCEL button
+ panelBuilder.item((rowCount + 2) * 9 - 1, this.getButton(CommonButtons.RETURN));
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method builds PanelItem for given biome.
+ * @param biome BiomesObject which PanelItem must be created.
+ * @return new PanelItem for given BiomesObject.
+ */
+ private PanelItem createBiomeIcon(BiomesObject biome)
+ {
+ List description = this.generateBiomesDescription(biome);
+
+ Settings settings = this.addon.getSettings();
+
+ return new PanelItemBuilder().
+ name(biome.getFriendlyName()).
+ description(GuiUtils.stringSplit(description, settings.getLoreLineLength())).
+ icon(biome.getIcon()).
+ clickHandler((panel, user1, clickType, slot) -> {
+
+ if (settings.isAdvancedMenu())
+ {
+ new UpdateModeGUI(this, this.target, biome).build();
+ }
+ else
+ {
+ List arguments = new ArrayList<>(4);
+
+ if (this.target != null)
+ {
+ arguments.add(this.target.getName());
+ }
+
+ arguments.add(biome.getUniqueId());
+
+ if (BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
+ {
+ arguments.add(settings.getDefaultMode().name());
+ arguments.add(Integer.toString(settings.getDefaultSize()));
+ }
+ else
+ {
+ // This fix issues when admin disables Advanced GUI and sets
+ // incompatible options
+
+ if (settings.getDefaultMode().equals(UpdateMode.ISLAND))
+ {
+ arguments.add(UpdateMode.RANGE.name());
+ arguments.add(Integer.toString(this.addon.getPlugin().getIWM().getIslandDistance(this.world)));
+ }
+ else
+ {
+ arguments.add(settings.getDefaultMode().name());
+ arguments.add(Integer.toString(settings.getDefaultSize()));
+ }
+ }
+
+ this.callCommand(SET, arguments);
+
+ this.user.closeInventory();
+ return true;
+ }
+
+ return true;
+ }).
+ glow(false).
+ build();
+ }
+
+
+ /**
+ * This method creates button that allows to switch which biomes are displayed.
+ * @return PanelItem that represents Visibility button.
+ */
+ private PanelItem createVisibilityModeButton()
+ {
+ List values = new ArrayList<>(4);
+ values.add(this.user.getTranslation("biomes.gui.descriptions.admin.visibility-mode.info"));
+
+ values.add((this.visibilityMode.equals(Settings.VisibilityMode.ALL) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.all"));
+ values.add((this.visibilityMode.equals(Settings.VisibilityMode.DEPLOYED) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.deployed"));
+ values.add((this.visibilityMode.equals(Settings.VisibilityMode.ACCESSIBLE) ? "&2" : "&c") +
+ this.user.getTranslation("biomes.gui.descriptions.visibility-mode.accessible"));
+
+ ItemStack icon;
+
+ if (this.visibilityMode.equals(Settings.VisibilityMode.ALL))
+ {
+ icon = new ItemStack(Material.BIRCH_PLANKS);
+ }
+ else if (this.visibilityMode.equals(Settings.VisibilityMode.DEPLOYED))
+ {
+ icon = new ItemStack(Material.BIRCH_STAIRS);
+ }
+ else if (this.visibilityMode.equals(Settings.VisibilityMode.ACCESSIBLE))
+ {
+ icon = new ItemStack(Material.BIRCH_SLAB);
+ }
+ else
+ {
+ icon = new ItemStack(Material.AIR);
+ }
+
+ return new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.admin.visibility-mode")).
+ description(GuiUtils.stringSplit(values, this.addon.getSettings().getLoreLineLength())).
+ icon(icon).
+ clickHandler((panel, user1, clickType, slot) -> {
+
+ if (clickType.isRightClick())
+ {
+ if (this.visibilityMode.equals(VisibilityMode.ALL))
+ {
+ this.visibilityMode = VisibilityMode.DEPLOYED;
+ }
+ else if (this.visibilityMode.equals(VisibilityMode.DEPLOYED))
+ {
+ this.visibilityMode = VisibilityMode.ACCESSIBLE;
+ }
+ else if (this.visibilityMode.equals(VisibilityMode.ACCESSIBLE))
+ {
+ this.visibilityMode = VisibilityMode.ALL;
+ }
+ }
+ else
+ {
+ if (this.visibilityMode.equals(VisibilityMode.ALL))
+ {
+ this.visibilityMode = VisibilityMode.ACCESSIBLE;
+ }
+ else if (this.visibilityMode.equals(VisibilityMode.DEPLOYED))
+ {
+ this.visibilityMode = VisibilityMode.ALL;
+ }
+ else if (this.visibilityMode.equals(VisibilityMode.ACCESSIBLE))
+ {
+ this.visibilityMode = VisibilityMode.DEPLOYED;
+ }
+ }
+
+ this.biomeList = this.addon.getAddonManager().getBiomes(this.world, this.user, this.visibilityMode);
+ this.build();
+
+ return true;
+ }).
+ glow(false).
+ build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * List of biomes that user can change.
+ */
+ private List biomeList;
+
+ /**
+ * Target player. Most of times it will be equal user, but if admin changes, target will be different user.
+ */
+ private User target;
+
+ /**
+ * Mode that shows which biomes users can see.
+ */
+ private VisibilityMode visibilityMode;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/user/UpdateModeGUI.java b/src/main/java/world/bentobox/biomes/panels/user/UpdateModeGUI.java
new file mode 100644
index 0000000..c0ad2c0
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/user/UpdateModeGUI.java
@@ -0,0 +1,380 @@
+package world.bentobox.biomes.panels.user;
+
+
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.database.objects.BiomesObject;
+
+import world.bentobox.biomes.panels.CommonGUI;
+
+import world.bentobox.biomes.config.Settings.UpdateMode;
+import world.bentobox.biomes.panels.util.NumberGUI;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This class manages Player GUI panel.
+ */
+public class UpdateModeGUI extends CommonGUI
+{
+ /**
+ * Default constructor.
+ * {@inheritDoc}
+ * @param target - Targeted player if Biome is changed by Administrator.
+ */
+ public UpdateModeGUI(CommonGUI parentGui, User target, BiomesObject biome)
+ {
+ super(parentGui);
+
+ this.target = target;
+ this.biome = biome;
+
+ this.updateMode = this.addon.getSettings().getDefaultMode();
+ this.distanceValue = this.addon.getSettings().getDefaultSize();
+
+ if (this.updateMode.equals(UpdateMode.ISLAND) &&
+ !BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
+ {
+ // Fix default mode and size if WORLD flag is disabled.
+ this.updateMode = UpdateMode.RANGE;
+ this.distanceValue = this.addon.getPlugin().getIWM().getIslandDistance(this.world);
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
+ name(this.user.getTranslation("biomes.gui.title.mode-choose"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.GRAY_STAINED_GLASS_PANE);
+
+ // Map at the top of the GUI
+ panelBuilder.item(4, this.createButton(Button.HEADER));
+
+ // Choose Update Mode Type
+ if (BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
+ {
+ // Island mode should be available only if world protection is enabled.
+ panelBuilder.item(12, this.createButton(Button.ISLAND));
+ }
+
+ panelBuilder.item(13, this.createButton(Button.CHUNK));
+ panelBuilder.item(14, this.createButton(Button.SQUARE));
+
+ // Decrease of current value
+ panelBuilder.item(19, this.createButton(Button.DECREASE, 10));
+ panelBuilder.item(20, this.createButton(Button.DECREASE, 5));
+ panelBuilder.item(21, this.createButton(Button.DECREASE, 1));
+ // Paper that shows current value
+ panelBuilder.item(22, this.createButton(Button.VALUE));
+ // Increase of current value
+ panelBuilder.item(23, this.createButton(Button.INCREASE, 1));
+ panelBuilder.item(24, this.createButton(Button.INCREASE, 5));
+ panelBuilder.item(25, this.createButton(Button.INCREASE, 10));
+
+ // Set values
+ panelBuilder.item(28, this.createButton(Button.SET, 0));
+ panelBuilder.item(29, this.createButton(Button.SET, 2));
+ panelBuilder.item(30, this.createButton(Button.SET, 4));
+ panelBuilder.item(31, this.createButton(Button.SET, 8));
+ panelBuilder.item(32, this.createButton(Button.SET, 16));
+ panelBuilder.item(33, this.createButton(Button.SET, 32));
+ panelBuilder.item(34, this.createButton(Button.SET, 64));
+
+ // Bottom buttons
+ panelBuilder.item(39, this.createButton(Button.DECLINE));
+ panelBuilder.item(41, this.createButton(Button.ACCEPT));
+
+ panelBuilder.item(44, this.returnButton);
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method returns PanelItem that represents required button with 1 amount.
+ * @param button Required button type.
+ * @return PanelItem that represents required button.
+ */
+ private PanelItem createButton(Button button)
+ {
+ return this.createButton(button, 1);
+ }
+
+
+ /**
+ * This method creates PanelItem button with number representing how many amount of item will be required.
+ * @param button Button that need to be created.
+ * @param number Amount that will represent item stack size and in math operations.
+ * @return Required type of PanelItem.
+ */
+ private PanelItem createButton(Button button, int number)
+ {
+ PanelItemBuilder itemBuilder = new PanelItemBuilder();
+
+ switch (button)
+ {
+ case VALUE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.value",
+ "[number]", Integer.toString(this.distanceValue)));
+ itemBuilder.icon(new ItemStack(Material.PAPER, number));
+
+ if (!this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+
+ // On right click open NumberGui for +/- manual input.
+ if (clickType.isRightClick())
+ {
+ new NumberGUI(this.user,
+ this.distanceValue,
+ 0,
+ this.addon.getSettings().getLoreLineLength(),
+ (status, value) -> {
+ if (status)
+ {
+ this.distanceValue = value;
+ }
+
+ UpdateModeGUI.this.build();
+ });
+ }
+ return true;
+ });
+ }
+
+ break;
+ }
+ case INCREASE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.increase", "[number]", Integer.toString(number)));
+
+ if (this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ itemBuilder.icon(new ItemStack(Material.BLACK_STAINED_GLASS_PANE, number));
+ }
+ else
+ {
+ itemBuilder.icon(new ItemStack(Material.GREEN_STAINED_GLASS_PANE, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.distanceValue += number;
+
+ // Several icons will be updated, so need to rebuild all?
+ this.build();
+ return true;
+ });
+ }
+
+ break;
+ }
+ case DECREASE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.decrease", "[number]", Integer.toString(number)));
+
+ if (this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ itemBuilder.icon(new ItemStack(Material.BLACK_STAINED_GLASS_PANE, number));
+ }
+ else
+ {
+ itemBuilder.icon(new ItemStack(Material.RED_STAINED_GLASS_PANE, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.distanceValue -= number;
+
+ if (this.distanceValue < 0)
+ {
+ this.distanceValue = 0;
+ // TODO: Probably need to inform or block - buttons.
+ }
+
+ // Several icons will be updated, so need to rebuild all?
+ this.build();
+ return true;
+ });
+ }
+
+ break;
+ }
+ case SET:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.set", "[number]", Integer.toString(number)));
+
+ if (this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ itemBuilder.icon(new ItemStack(Material.BLACK_STAINED_GLASS_PANE, number == 0 ? 1 : number));
+ }
+ else
+ {
+ if (number == 0)
+ {
+ itemBuilder.icon(new ItemStack(Material.YELLOW_STAINED_GLASS_PANE, 1));
+ }
+ else
+ {
+ itemBuilder.icon(new ItemStack(Material.WHITE_STAINED_GLASS_PANE, number));
+ }
+
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.distanceValue = number;
+ this.build();
+ return true;
+ });
+ }
+
+ break;
+ }
+ case ISLAND:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.descriptions.update-mode.island"));
+ itemBuilder.icon(new ItemStack(Material.GRASS_BLOCK, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.updateMode = UpdateMode.ISLAND;
+ this.build();
+ return true;
+ });
+ itemBuilder.glow(this.updateMode.equals(UpdateMode.ISLAND));
+
+ break;
+ }
+ case CHUNK:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.descriptions.update-mode.chunk"));
+ itemBuilder.icon(new ItemStack(Material.DIRT, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.updateMode = UpdateMode.CHUNK;
+ this.build();
+ return true;
+ });
+ itemBuilder.glow(this.updateMode.equals(UpdateMode.CHUNK));
+
+ break;
+ }
+ case SQUARE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.descriptions.update-mode.square"));
+ itemBuilder.icon(new ItemStack(Material.GLASS, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.updateMode = UpdateMode.RANGE;
+ this.build();
+ return true;
+ });
+ itemBuilder.glow(this.updateMode.equals(UpdateMode.RANGE));
+
+ break;
+ }
+ case ACCEPT:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.accept"));
+ itemBuilder.icon(new ItemStack(Material.GREEN_STAINED_GLASS_PANE, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ List arguments = new ArrayList<>(4);
+
+ if (this.target != null)
+ {
+ arguments.add(this.target.getName());
+ }
+
+ arguments.add(this.biome.getUniqueId());
+ arguments.add(this.updateMode.name());
+ arguments.add(Integer.toString(this.distanceValue));
+
+ this.callCommand(SET, arguments);
+
+ return true;
+ });
+
+ break;
+ }
+ case DECLINE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.decline"));
+ itemBuilder.icon(new ItemStack(Material.RED_STAINED_GLASS_PANE, number));
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.user.closeInventory();
+ return true;
+ });
+
+ break;
+ }
+ case HEADER:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.information"));
+
+ itemBuilder.description(GuiUtils.stringSplit(
+ this.user.getTranslation("biomes.gui.descriptions.information",
+ "[biome]", this.biome.getFriendlyName(),
+ "[mode]", this.user.getTranslation("biomes.gui.descriptions.update-mode." + this.updateMode.name().toLowerCase()),
+ "[range]", Integer.toString(this.distanceValue)),
+ this.addon.getSettings().getLoreLineLength()));
+
+ itemBuilder.icon(new ItemStack(Material.MAP, number));
+ }
+ }
+
+ return itemBuilder.build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Private Classes
+// ---------------------------------------------------------------------
+
+
+ /**
+ * Creates any button that may be created by current GUI.
+ */
+ private enum Button
+ {
+ SET,
+ INCREASE,
+ DECREASE,
+ VALUE,
+ ISLAND,
+ CHUNK,
+ SQUARE,
+ ACCEPT,
+ DECLINE,
+ HEADER
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * Biomes that user can be changed.
+ */
+ private BiomesObject biome;
+
+ /**
+ * Target player. Most of times it will be equal user, but if admin changes, target will be different user.
+ */
+ private User target;
+
+ /**
+ * Integer value that is larger then 0 and provides information about chunk radius or block radius where
+ * biome will be updated.
+ */
+ private int distanceValue;
+
+ /**
+ * Allows to change biomes update mode.
+ */
+ private UpdateMode updateMode;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/util/ConfirmationGUI.java b/src/main/java/world/bentobox/biomes/panels/util/ConfirmationGUI.java
new file mode 100644
index 0000000..4e190e6
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/util/ConfirmationGUI.java
@@ -0,0 +1,113 @@
+package world.bentobox.biomes.panels.util;
+
+
+import org.bukkit.Material;
+import java.util.function.Consumer;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This GUI is used to confirm that user wants to run command, that should be created from
+ * command string list.
+ */
+public class ConfirmationGUI
+{
+ /**
+ * This constructor inits and opens ConfirmationGUI.
+ *
+ * @param user Gui Caller.
+ */
+ public ConfirmationGUI(User user, Consumer consumer)
+ {
+ this.user = user;
+ this.consumer = consumer;
+
+ this.build();
+ }
+
+
+ /**
+ * This method builds confirmation panel with 2 buttons.
+ */
+ public void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("biomes.gui.title.admin.confirm-title"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE);
+
+ // Accept buttons
+ panelBuilder.item(10, this.getButton(true));
+ panelBuilder.item(11, this.getButton(true));
+ panelBuilder.item(12, this.getButton(true));
+
+ panelBuilder.item(19, this.getButton(true));
+ panelBuilder.item(20, this.getButton(true));
+ panelBuilder.item(21, this.getButton(true));
+
+ panelBuilder.item(28, this.getButton(true));
+ panelBuilder.item(29, this.getButton(true));
+ panelBuilder.item(30, this.getButton(true));
+
+ // Cancel Buttons
+ panelBuilder.item(14, this.getButton(false));
+ panelBuilder.item(15, this.getButton(false));
+ panelBuilder.item(16, this.getButton(false));
+
+ panelBuilder.item(23, this.getButton(false));
+ panelBuilder.item(24, this.getButton(false));
+ panelBuilder.item(25, this.getButton(false));
+
+ panelBuilder.item(32, this.getButton(false));
+ panelBuilder.item(33, this.getButton(false));
+ panelBuilder.item(34, this.getButton(false));
+
+ panelBuilder.item(44,
+ new PanelItemBuilder().
+ icon(Material.OAK_DOOR).
+ name(this.user.getTranslation("biomes.gui.buttons.return")).
+ clickHandler( (panel, user1, clickType, slot) -> {
+ this.consumer.accept(false);
+ return true;
+ }).build());
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method creates button with requested value.
+ * @param returnValue requested value
+ * @return PanelItem button.
+ */
+ private PanelItem getButton(boolean returnValue)
+ {
+ return new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.admin." + (returnValue ? "accept" : "decline"))).
+ icon(returnValue ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE).
+ clickHandler((panel, user1, clickType, i) -> {
+ this.consumer.accept(returnValue);
+ return true;
+ }).
+ build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * User who wants to run command.
+ */
+ private User user;
+
+ /**
+ * Stores current Consumer
+ */
+ private Consumer consumer;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/util/NumberGUI.java b/src/main/java/world/bentobox/biomes/panels/util/NumberGUI.java
new file mode 100644
index 0000000..1bc85c2
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/util/NumberGUI.java
@@ -0,0 +1,431 @@
+package world.bentobox.biomes.panels.util;
+
+
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import java.util.function.BiConsumer;
+
+import net.wesjd.anvilgui.AnvilGUI;
+import world.bentobox.bentobox.BentoBox;
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This gui allows to change current number and returns it to previous GUI
+ */
+public class NumberGUI
+{
+ public NumberGUI(User user, int value, int lineLength, BiConsumer consumer)
+ {
+ this(user, value, Integer.MIN_VALUE, Integer.MAX_VALUE, lineLength, consumer);
+ }
+
+
+ public NumberGUI(User user, int value, int minValue, int lineLength, BiConsumer consumer)
+ {
+ this(user, value, minValue, Integer.MAX_VALUE, lineLength, consumer);
+ }
+
+
+ public NumberGUI(User user, int value, int minValue, int maxValue, int lineLength, BiConsumer consumer)
+ {
+ this.user = user;
+ this.value = value;
+ this.consumer = consumer;
+
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+
+ this.currentOperation = Button.SET;
+
+ this.lineLength = lineLength;
+
+ this.build();
+ }
+
+
+ /**
+ * This method builds panel that allows to change given number value.
+ */
+ private void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("biomes.gui.title.admin.manage-numbers"));
+
+ GuiUtils.fillBorder(panelBuilder);
+
+ // Others
+ panelBuilder.item(1, this.getButton(Button.SAVE));
+
+ panelBuilder.item(19, this.getButton(Button.VALUE));
+ panelBuilder.item(44, this.getButton(Button.CANCEL));
+
+ panelBuilder.item(2, this.getButton(Button.INPUT));
+
+ // operations
+ panelBuilder.item(3, this.getButton(Button.SET));
+ panelBuilder.item(4, this.getButton(Button.INCREASE));
+ panelBuilder.item(5, this.getButton(Button.REDUCE));
+ panelBuilder.item(6, this.getButton(Button.MULTIPLY));
+
+ // Numbers
+ panelBuilder.item(11, this.createNumberButton(1));
+ panelBuilder.item(12, this.createNumberButton(10));
+ panelBuilder.item(13, this.createNumberButton(100));
+ panelBuilder.item(14, this.createNumberButton(1000));
+ panelBuilder.item(15, this.createNumberButton(10000));
+
+ panelBuilder.item(20, this.createNumberButton(2));
+ panelBuilder.item(21, this.createNumberButton(20));
+ panelBuilder.item(22, this.createNumberButton(200));
+ panelBuilder.item(23, this.createNumberButton(2000));
+ panelBuilder.item(24, this.createNumberButton(20000));
+
+ panelBuilder.item(29, this.createNumberButton(5));
+ panelBuilder.item(30, this.createNumberButton(50));
+ panelBuilder.item(31, this.createNumberButton(500));
+ panelBuilder.item(32, this.createNumberButton(5000));
+ panelBuilder.item(33, this.createNumberButton(50000));
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method creates PanelItem with required functionality.
+ * @param button Functionality requirement.
+ * @return PanelItem with functionality.
+ */
+ private PanelItem getButton(Button button)
+ {
+ ItemStack icon;
+ String name;
+ String description;
+ PanelItem.ClickHandler clickHandler;
+ boolean glow;
+
+ switch (button)
+ {
+ case SAVE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.save");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.save");
+ icon = new ItemStack(Material.COMMAND_BLOCK);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.consumer.accept(true, this.value);
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case CANCEL:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.cancel");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.cancel");
+ icon = new ItemStack(Material.OAK_DOOR);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.consumer.accept(false, this.value);
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case INPUT:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.input");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.input");
+ icon = new ItemStack(Material.ANVIL);
+ clickHandler = (panel, user, clickType, slot) -> {
+ new AnvilGUI(BentoBox.getInstance(),
+ this.user.getPlayer(),
+ Integer.toString(this.value),
+ (player, reply) -> {
+ try
+ {
+ this.value = Integer.parseInt(reply);
+
+ if (this.value > this.maxValue || this.value < this.minValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", reply,
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+ }
+ else
+ {
+ this.build();
+ }
+ }
+ catch (Exception e)
+ {
+ reply = Integer.toString(this.value);
+ this.user.sendMessage("biomes.errors.not-a-integer", "[value]", reply);
+ }
+
+ return reply;
+ });
+
+ return true;
+ };
+ glow = false;
+ break;
+ }
+ case VALUE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.value", "[number]", Integer.toString(this.value));
+ description = this.user.getTranslation("biomes.gui.descriptions.current-value", "[value]", Integer.toString(this.value));
+ icon = new ItemStack(Material.PAPER);
+ clickHandler = (panel, user, clickType, slot) -> true;
+ glow = false;
+ break;
+ }
+ case SET:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.set-mode");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.set-mode");
+ icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.currentOperation = Button.SET;
+ this.build();
+ return true;
+ };
+ glow = this.currentOperation.equals(Button.SET);
+ break;
+ }
+ case INCREASE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.increase-mode");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.increase-mode");
+ icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.currentOperation = Button.INCREASE;
+ this.build();
+ return true;
+ };
+ glow = this.currentOperation.equals(Button.INCREASE);
+ break;
+ }
+ case REDUCE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.reduce-mode");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.reduce-mode");
+ icon = new ItemStack(Material.RED_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.currentOperation = Button.REDUCE;
+ this.build();
+ return true;
+ };
+ glow = this.currentOperation.equals(Button.REDUCE);
+ break;
+ }
+ case MULTIPLY:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.multiply-mode");
+ description = this.user.getTranslation("biomes.gui.descriptions.admin.multiply-mode");
+ icon = new ItemStack(Material.BLUE_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.currentOperation = Button.MULTIPLY;
+ this.build();
+ return true;
+ };
+ glow = this.currentOperation.equals(Button.MULTIPLY);
+ break;
+ }
+ default:
+ return null;
+ }
+
+ return new PanelItemBuilder().
+ icon(icon).
+ name(name).
+ description(GuiUtils.stringSplit(description, this.lineLength)).
+ glow(glow).
+ clickHandler(clickHandler).
+ build();
+ }
+
+
+ /**
+ * This method creates Number Button based on input number.
+ * @param number Number which button must be created.
+ * @return PanelItem that represents number button.
+ */
+ private PanelItem createNumberButton(int number)
+ {
+ PanelItemBuilder itemBuilder = new PanelItemBuilder();
+
+ switch (this.currentOperation)
+ {
+ case SET:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.number","[number]", Integer.toString(number)));
+ itemBuilder.icon(Material.WHITE_STAINED_GLASS_PANE);
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.value = number;
+
+ if (this.value > this.maxValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", Integer.toString(this.value),
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+
+ this.value = this.maxValue;
+ }
+
+ if (this.value < this.minValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", Integer.toString(this.value),
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+
+ this.value = this.minValue;
+ }
+
+ this.build();
+ return true;
+ });
+
+ break;
+ }
+ case INCREASE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.number","[number]", Integer.toString(number)));
+ itemBuilder.icon(Material.GREEN_STAINED_GLASS_PANE);
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.value += number;
+
+ if (this.value > this.maxValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", Integer.toString(this.value),
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+
+ this.value = this.maxValue;
+ }
+
+ this.build();
+ return true;
+ });
+
+ break;
+ }
+ case REDUCE:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.number","[number]", Integer.toString(number)));
+ itemBuilder.icon(Material.RED_STAINED_GLASS_PANE);
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.value -= number;
+
+ if (this.value < this.minValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", Integer.toString(this.value),
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+
+ this.value = this.minValue;
+ }
+
+ this.build();
+ return true;
+ });
+
+ break;
+ }
+ case MULTIPLY:
+ {
+ itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.admin.number","[number]", Integer.toString(number)));
+ itemBuilder.icon(Material.BLUE_STAINED_GLASS_PANE);
+ itemBuilder.clickHandler((panel, user1, clickType, i) -> {
+ this.value *= number;
+
+ if (this.value > this.maxValue)
+ {
+ this.user.sendMessage("biomes.errors.not-valid-integer",
+ "[value]", Integer.toString(this.value),
+ "[min]", Integer.toString(this.minValue),
+ "[max]", Integer.toString(this.maxValue));
+
+ this.value = this.maxValue;
+ }
+
+ this.build();
+ return true;
+ });
+
+ break;
+ }
+ }
+
+ return itemBuilder.build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Enums
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This enum contains all button types.
+ */
+ private enum Button
+ {
+ SAVE,
+ CANCEL,
+ INPUT,
+
+ VALUE,
+
+ SET,
+ INCREASE,
+ REDUCE,
+ MULTIPLY
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * This variable stores current GUI consumer.
+ */
+ private BiConsumer consumer;
+
+ /**
+ * User who runs GUI.
+ */
+ private User user;
+
+ /**
+ * Current value.
+ */
+ private int value;
+
+ /**
+ * Minimal value that is allowed to set.
+ */
+ private int minValue;
+
+ /**
+ * Maximal value that is allowed to set.
+ */
+ private int maxValue;
+
+ /**
+ * This variable holds which operation now is processed.
+ */
+ private Button currentOperation;
+
+ /**
+ * This variable stores how large line can be, before warp it.
+ */
+ private int lineLength;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/util/SelectBiomeGUI.java b/src/main/java/world/bentobox/biomes/panels/util/SelectBiomeGUI.java
new file mode 100644
index 0000000..47f7231
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/util/SelectBiomeGUI.java
@@ -0,0 +1,171 @@
+package world.bentobox.biomes.panels.util;
+
+
+import org.bukkit.Material;
+import org.bukkit.block.Biome;
+import java.util.Collections;
+import java.util.function.BiConsumer;
+
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.BiomesAddon;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+public class SelectBiomeGUI
+{
+ public SelectBiomeGUI(User user, Biome inputBiome, int lineLength, BiConsumer consumer)
+ {
+ this.consumer = consumer;
+ this.user = user;
+ this.inputBiome = inputBiome;
+ this.lineLength = lineLength;
+
+ this.build(0);
+ }
+
+
+ /**
+ * This method builds panel that allows to select single challenge from input challenges.
+ */
+ private void build(int pageIndex)
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("biomes.gui.title.admin.select-biome"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE);
+
+ // Maximal elements in page.
+ final int MAX_ELEMENTS = 21;
+
+ final int correctPage;
+
+ if (pageIndex < 0)
+ {
+ correctPage = (Biome.values().length - 1) / MAX_ELEMENTS;
+ }
+ else if (pageIndex > ((Biome.values().length - 1) / MAX_ELEMENTS))
+ {
+ correctPage = 0;
+ }
+ else
+ {
+ correctPage = pageIndex;
+ }
+
+ panelBuilder.item(4,
+ new PanelItemBuilder().
+ icon(Material.RED_STAINED_GLASS_PANE).
+ name(this.user.getTranslation("biomes.gui.buttons.return")).
+ clickHandler( (panel, user1, clickType, slot) -> {
+ this.consumer.accept(true, this.inputBiome);
+ return true;
+ }).build());
+
+ if ((Biome.values().length - 1) > MAX_ELEMENTS)
+ {
+ // Navigation buttons if necessary
+
+ panelBuilder.item(18,
+ new PanelItemBuilder().
+ icon(BiomesAddon.SIGN_MATERIAL).
+ name(this.user.getTranslation("biomes.gui.buttons.previous")).
+ clickHandler((panel, user1, clickType, slot) -> {
+ this.build(correctPage - 1);
+ return true;
+ }).build());
+
+ panelBuilder.item(26,
+ new PanelItemBuilder().
+ icon(BiomesAddon.SIGN_MATERIAL).
+ name(this.user.getTranslation("biomes.gui.buttons.next")).
+ clickHandler((panel, user1, clickType, slot) -> {
+ this.build(correctPage + 1);
+ return true;
+ }).build());
+ }
+
+ int biomesIndex = MAX_ELEMENTS * correctPage;
+
+ // I want first row to be only for navigation and return button.
+ int index = 10;
+
+ while (biomesIndex < ((correctPage + 1) * MAX_ELEMENTS) &&
+ biomesIndex < (Biome.values().length - 1) &&
+ index < 36)
+ {
+ if (!panelBuilder.slotOccupied(index))
+ {
+ // Skip inputBiome
+ if (Biome.values()[biomesIndex] == this.inputBiome)
+ {
+ biomesIndex++;
+ }
+
+ if (Biome.values().length != biomesIndex)
+ {
+ panelBuilder.item(index,
+ this.createBiomeIcon(Biome.values()[(biomesIndex++)]));
+ }
+ }
+
+ index++;
+ }
+
+ panelBuilder.item(44,
+ new PanelItemBuilder().
+ icon(Material.OAK_DOOR).
+ name(this.user.getTranslation("biomes.gui.buttons.return")).
+ clickHandler( (panel, user1, clickType, slot) -> {
+ this.consumer.accept(true, this.inputBiome);
+ return true;
+ }).build());
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method builds PanelItem for given biome.
+ * @param biome Biome which PanelItem must be created.
+ * @return new PanelItem for given biome.
+ */
+ private PanelItem createBiomeIcon(Biome biome)
+ {
+ return new PanelItemBuilder().
+ name(biome.name()).
+ description(Collections.emptyList()).
+ icon(Material.MAP).
+ clickHandler((panel, user1, clickType, slot) -> {
+ this.consumer.accept(true, biome);
+
+ return true;
+ }).
+ glow(false).
+ build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This variable stores consumer.
+ */
+ private BiConsumer consumer;
+
+ /**
+ * User who runs GUI.
+ */
+ private User user;
+
+ private Biome inputBiome;
+
+ /**
+ * This variable stores how large line can be, before warp it.
+ */
+ private int lineLength;
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/util/SelectEnvironmentGUI.java b/src/main/java/world/bentobox/biomes/panels/util/SelectEnvironmentGUI.java
new file mode 100644
index 0000000..30d9d7d
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/util/SelectEnvironmentGUI.java
@@ -0,0 +1,147 @@
+package world.bentobox.biomes.panels.util;
+
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import java.util.Collections;
+import java.util.Set;
+import java.util.function.BiConsumer;
+
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This class creates panel that allows to select and deselect World Environments. On save it runs
+ * input consumer with true and selected values.
+ */
+public class SelectEnvironmentGUI
+{
+ public SelectEnvironmentGUI(User user, Set values, BiConsumer> consumer)
+ {
+ this.user = user;
+ this.values = values;
+ this.consumer = consumer;
+
+ this.build();
+ }
+
+
+ /**
+ * This method builds environment select panel.
+ */
+ private void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("biomes.gui.title.admin.toggle-environment"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE);
+
+ panelBuilder.item(3, new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.admin.save")).
+ icon(Material.GREEN_STAINED_GLASS_PANE).
+ clickHandler((panel, user1, clickType, index) -> {
+ this.consumer.accept(true, this.values);
+ return true;
+ }).
+ build());
+
+ panelBuilder.item(5, new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.admin.cancel")).
+ icon(Material.RED_STAINED_GLASS_PANE).
+ clickHandler((panel, user1, clickType, i) -> {
+ this.consumer.accept(false, Collections.emptySet());
+ return true;
+ }).
+ build());
+
+ panelBuilder.item(20, new PanelItemBuilder().
+ name(World.Environment.NETHER.name()).
+ icon(Material.NETHERRACK).
+ clickHandler((panel, user1, clickType, i) -> {
+ if (this.values.contains(World.Environment.NETHER))
+ {
+ this.values.remove(World.Environment.NETHER);
+ }
+ else
+ {
+ this.values.add(World.Environment.NETHER);
+ }
+
+ this.build();
+ return true;
+ }).
+ glow(this.values.contains(World.Environment.NETHER)).
+ build());
+ panelBuilder.item(22, new PanelItemBuilder().
+ name(World.Environment.NORMAL.name()).
+ icon(Material.DIRT).
+ clickHandler((panel, user1, clickType, i) -> {
+ if (this.values.contains(World.Environment.NORMAL))
+ {
+ this.values.remove(World.Environment.NORMAL);
+ }
+ else
+ {
+ this.values.add(World.Environment.NORMAL);
+ }
+
+ this.build();
+ return true;
+ }).
+ glow(this.values.contains(World.Environment.NORMAL)).
+ build());
+ panelBuilder.item(24, new PanelItemBuilder().
+ name(World.Environment.THE_END.name()).
+ icon(Material.END_STONE).
+ clickHandler((panel, user1, clickType, i) -> {
+ if (this.values.contains(World.Environment.THE_END))
+ {
+ this.values.remove(World.Environment.THE_END);
+ }
+ else
+ {
+ this.values.add(World.Environment.THE_END);
+ }
+
+ this.build();
+ return true;
+ }).
+ glow(this.values.contains(World.Environment.THE_END)).
+ build());
+
+
+ panelBuilder.item(44, new PanelItemBuilder().
+ name(this.user.getTranslation("biomes.gui.buttons.return")).
+ icon(Material.OAK_DOOR).
+ clickHandler((panel, user1, clickType, i) -> {
+ this.consumer.accept(false, Collections.emptySet());
+ return true;
+ }).
+ build());
+
+ panelBuilder.build();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+ /**
+ * User who wants to run command.
+ */
+ private User user;
+
+ /**
+ * List with selected environments.
+ */
+ private Set values;
+
+ /**
+ * Stores current Consumer
+ */
+ private BiConsumer> consumer;
+
+}
diff --git a/src/main/java/world/bentobox/biomes/panels/util/StringListGUI.java b/src/main/java/world/bentobox/biomes/panels/util/StringListGUI.java
new file mode 100644
index 0000000..e30f7ff
--- /dev/null
+++ b/src/main/java/world/bentobox/biomes/panels/util/StringListGUI.java
@@ -0,0 +1,386 @@
+package world.bentobox.biomes.panels.util;
+
+
+import org.bukkit.Material;
+import org.bukkit.conversations.*;
+import org.bukkit.inventory.ItemStack;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.wesjd.anvilgui.AnvilGUI;
+import world.bentobox.bentobox.BentoBox;
+import world.bentobox.bentobox.api.panels.PanelItem;
+import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
+import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.biomes.panels.GuiUtils;
+
+
+/**
+ * This GUI allows to edit List of strings. AnvilGUI has limited text space, so splitting
+ * text in multiple rows allows to edit each row separately.
+ */
+public class StringListGUI
+{
+ public StringListGUI(User user, String value, int lineLength, BiConsumer> consumer)
+ {
+ this(user, Collections.singleton(value), lineLength, consumer);
+ }
+
+
+ public StringListGUI(User user, Collection value, int lineLength, BiConsumer> consumer)
+ {
+ this(user, new ArrayList<>(value), lineLength, consumer);
+ }
+
+
+ public StringListGUI(User user, List value, int lineLength, BiConsumer> consumer)
+ {
+ this.consumer = consumer;
+ this.user = user;
+ this.value = value;
+ this.lineLength = lineLength;
+
+ if (this.value.size() > 21)
+ {
+ // TODO: throw error that so large list cannot be edited.
+ this.consumer.accept(false, this.value);
+ }
+ else
+ {
+ this.build();
+ }
+ }
+
+
+ /**
+ * This method builds panel that allows to change given string value.
+ */
+ private void build()
+ {
+ PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
+ name(this.user.getTranslation("biomes.gui.title.admin.edit-text-fields"));
+
+ GuiUtils.fillBorder(panelBuilder, Material.BLACK_STAINED_GLASS_PANE);
+
+ panelBuilder.item(1, this.getButton(Button.SAVE));
+ panelBuilder.item(2, this.getButton(Button.VALUE));
+
+ panelBuilder.item(4, this.getButton(Button.ADD));
+ panelBuilder.item(5, this.getButton(Button.REMOVE));
+ panelBuilder.item(6, this.getButton(Button.CLEAR));
+
+ panelBuilder.item(8, this.getButton(Button.MODE));
+
+ panelBuilder.item(44, this.getButton(Button.CANCEL));
+
+ int slot = 10;
+
+ for (int stringIndex = 0; stringIndex < this.value.size() && slot < 36; stringIndex++)
+ {
+ if (!panelBuilder.slotOccupied(slot))
+ {
+ panelBuilder.item(slot,
+ this.createStringElement(this.value.get(stringIndex), stringIndex));
+ }
+
+ slot++;
+ }
+
+ panelBuilder.build();
+ }
+
+
+ /**
+ * This method create button that does some functionality in current gui.
+ * @param button Button functionality.
+ * @return PanelItem.
+ */
+ private PanelItem getButton(Button button)
+ {
+ ItemStack icon;
+ String name;
+ List description;
+ PanelItem.ClickHandler clickHandler;
+
+ switch (button)
+ {
+ case SAVE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.save");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.save"));
+ icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.consumer.accept(true, this.value);
+
+ return true;
+ };
+ break;
+ }
+ case CANCEL:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.cancel");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.cancel"));
+ icon = new ItemStack(Material.OAK_DOOR);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.consumer.accept(false, this.value);
+
+ return true;
+ };
+ break;
+ }
+ case VALUE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.value");
+ description = new ArrayList<>();
+ description.add(this.user.getTranslation("biomes.gui.descriptions.current-value", "[value]", ""));
+ description.addAll(this.value);
+ icon = new ItemStack(Material.PAPER);
+ clickHandler = (panel, user, clickType, slot) -> true;
+ break;
+ }
+ case ADD:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.add-string");
+ description = Collections.emptyList();
+ icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+
+ if (this.useAnvil)
+ {
+ new AnvilGUI(BentoBox.getInstance(),
+ this.user.getPlayer(),
+ " ",
+ (player, reply) -> {
+ this.value.add(reply);
+ this.build();
+ return reply;
+ });
+ }
+ else
+ {
+ this.startConversion(value ->
+ this.value.add(value),
+ this.user.getTranslation("biomes.gui.descriptions.admin.add-text-line"));
+ }
+
+ return true;
+ };
+ break;
+ }
+ case CLEAR:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.clear");
+ description = Collections.emptyList();
+ icon = new ItemStack(Material.RED_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.value.clear();
+ this.build();
+ return true;
+ };
+ break;
+ }
+ case REMOVE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.remove-empty");
+ description = Collections.emptyList();
+ icon = new ItemStack(Material.BLUE_STAINED_GLASS_PANE);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.value.removeIf(String::isEmpty);
+
+ this.build();
+ return true;
+ };
+ break;
+ }
+ case MODE:
+ {
+ name = this.user.getTranslation("biomes.gui.buttons.admin.input-mode");
+ description = Collections.singletonList(this.user.getTranslation("biomes.gui.descriptions.admin.input-mode"));
+ icon = this.useAnvil ? new ItemStack(Material.ANVIL) : new ItemStack(Material.MAP);
+ clickHandler = (panel, user, clickType, slot) -> {
+ this.useAnvil = !this.useAnvil;
+ panel.getInventory().setItem(slot, this.getButton(button).getItem());
+ return true;
+ };
+ break;
+ }
+ default:
+ return null;
+ }
+
+ return new PanelItemBuilder().
+ icon(icon).
+ name(name).
+ description(GuiUtils.stringSplit(description, this.lineLength)).
+ glow(false).
+ clickHandler(clickHandler).
+ build();
+ }
+
+
+ /**
+ * This method creates paper icon that represents single line from list.
+ * @param element Paper Icon name
+ * @return PanelItem.
+ */
+ private PanelItem createStringElement(String element, int stringIndex)
+ {
+ return new PanelItemBuilder().
+ name(element).
+ icon(Material.PAPER).
+ clickHandler((panel, user1, clickType, i) -> {
+
+ if (this.useAnvil)
+ {
+ new AnvilGUI(BentoBox.getInstance(),
+ this.user.getPlayer(),
+ element,
+ (player, reply) -> {
+ this.value.set(stringIndex, reply);
+ this.build();
+ return reply;
+ });
+ }
+ else
+ {
+ this.startConversion(
+ value -> this.value.set(stringIndex, value),
+ this.user.getTranslation("biomes.gui.descriptions.admin.edit-text-line"),
+ element);
+ }
+
+ return true;
+ }).build();
+ }
+
+
+ /**
+ * This method will close opened gui and writes inputText in chat. After players answers on inputText in
+ * chat, message will trigger consumer and gui will reopen.
+ * @param consumer Consumer that accepts player output text.
+ * @param question Message that will be displayed in chat when player triggers conversion.
+ */
+ private void startConversion(Consumer consumer, @NonNull String question)
+ {
+ this.startConversion(consumer, question, null);
+ }
+
+
+ /**
+ * This method will close opened gui and writes inputText in chat. After players answers on inputText in
+ * chat, message will trigger consumer and gui will reopen.
+ * @param consumer Consumer that accepts player output text.
+ * @param question Message that will be displayed in chat when player triggers conversion.
+ * @param message Message that will be set in player text field when clicked on question.
+ */
+ private void startConversion(Consumer consumer, @NonNull String question, @Nullable String message)
+ {
+ final User user = this.user;
+
+ Conversation conversation =
+ new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
+ new StringPrompt()
+ {
+ /**
+ * @see Prompt#getPromptText(ConversationContext)
+ */
+ @Override
+ public String getPromptText(ConversationContext conversationContext)
+ {
+ // Close input GUI.
+ user.closeInventory();
+
+ if (message != null)
+ {
+ // Create Edit Text message.
+ TextComponent component = new TextComponent(user.getTranslation("biomes.gui.descriptions.admin.click-to-edit"));
+ component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message));
+ // Send question and message to player.
+ user.getPlayer().spigot().sendMessage(component);
+ }
+
+ // There are no editable message. Just return question.
+ return question;
+ }
+
+
+ /**
+ * @see Prompt#acceptInput(ConversationContext, String)
+ */
+ @Override
+ public Prompt acceptInput(ConversationContext conversationContext, String answer)
+ {
+ // Add answer to consumer.
+ consumer.accept(answer);
+ // Reopen GUI
+ StringListGUI.this.build();
+ // End conversation
+ return Prompt.END_OF_CONVERSATION;
+ }
+ }).
+ withLocalEcho(false).
+ buildConversation(user.getPlayer());
+
+ conversation.begin();
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Enums
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This enum holds all button values in current gui.
+ */
+ private enum Button
+ {
+ VALUE,
+ ADD,
+ REMOVE,
+ CANCEL,
+ CLEAR,
+ SAVE,
+ MODE
+ }
+
+
+// ---------------------------------------------------------------------
+// Section: Variables
+// ---------------------------------------------------------------------
+
+
+ /**
+ * This variable stores consumer.
+ */
+ private BiConsumer> consumer;
+
+ /**
+ * User who runs GUI.
+ */
+ private User user;
+
+ /**
+ * Boolean that indicate if editing should happen in anvil.
+ */
+ private boolean useAnvil;
+
+ /**
+ * Current value.
+ */
+ private List value;
+
+ /**
+ * This variable stores how large line can be, before warp it.
+ */
+ private int lineLength;
+}
diff --git a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
index efc3da2..9d1ceea 100644
--- a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
+++ b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
@@ -6,15 +6,14 @@
import org.bukkit.World;
import java.util.Optional;
-import world.bentobox.bentobox.api.addons.Addon;
-import world.bentobox.bentobox.api.addons.request.AddonRequestBuilder;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
-import world.bentobox.bentobox.hooks.VaultHook;
+import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.config.Settings.UpdateMode;
+import world.bentobox.level.objects.LevelsData;
/**
@@ -23,7 +22,7 @@
*/
public class BiomeUpdateHelper
{
- public BiomeUpdateHelper(Addon addon,
+ public BiomeUpdateHelper(BiomesAddon addon,
User callerUser,
User targetUser,
BiomesObject biome,
@@ -40,6 +39,8 @@ public BiomeUpdateHelper(Addon addon,
this.updateMode = updateMode;
this.updateNumber = updateNumber;
this.canWithdraw = canWithdraw;
+
+ this.worldProtectionFlag = BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world);
}
@@ -51,11 +52,9 @@ public boolean canChangeBiome()
{
if (this.callerUser == this.targetUser)
{
- if (!this.callerUser.hasPermission(this.biome.getPermission()))
+ if (!this.checkPermissions())
{
- this.callerUser.sendMessage("biomes.messages.errors.missing-permission",
- "[permission]",
- this.biome.getPermission());
+ this.callerUser.sendMessage("general.errors.no-permission");
return false;
}
@@ -63,85 +62,172 @@ public boolean canChangeBiome()
{
// Cannot update negative numbers.
- this.callerUser.sendMessage("biomes.messages.errors.incorrect-range",
+ this.callerUser.sendMessage("biomes.errors.incorrect-range",
TextVariables.NUMBER,
Integer.toString(this.updateNumber));
return false;
}
- Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
-
- if (island == null)
+ if (this.worldProtectionFlag)
{
- // User has no island.
- this.callerUser.sendMessage("biomes.messages.errors.missing-island");
- return false;
- }
+ Island island =
+ this.addon.getIslands().getIsland(this.world, this.targetUser);
- Optional onIsland =
- this.addon.getIslands().getIslandAt(this.callerUser.getLocation());
+ if (island == null)
+ {
+ // User has no island.
+ this.callerUser.sendMessage("general.errors.player-has-no-island");
+ return false;
+ }
- if (!onIsland.isPresent() || onIsland.get() != island)
- {
- // User is not on his island.
+ Optional onIsland =
+ this.addon.getIslands().getIslandAt(this.callerUser.getLocation());
+
+ if (!onIsland.isPresent() || onIsland.get() != island)
+ {
+ // User is not on his island.
+
+ this.callerUser.sendMessage("biomes.errors.not-on-island");
+ return false;
+ }
+
+ if (!island.isAllowed(this.callerUser, BiomesAddon.BIOMES_ISLAND_PROTECTION))
+ {
+ // This can be checked only if island exists.
+
+ this.callerUser.sendMessage("biomes.errors.no-rank");
+ return false;
+ }
- this.callerUser.sendMessage("biomes.messages.errors.not-on-island");
+ if (this.addon.isLevelProvided())
+ {
+ // This is here as I am not sure if Level addon can calculate island level
+ // if players can build anywhere.
+
+ LevelsData data = this.addon.getLevelAddon().getLevelsData(this.targetUser.getUniqueId());
+
+ if (data == null ||
+ !data.getLevels().containsKey(Util.getWorld(this.world).getName()) ||
+ this.biome.getRequiredLevel() > 0 &&
+ data.getLevel(Util.getWorld(this.world)) <= this.biome.getRequiredLevel())
+ {
+ // Not enough level
+
+ this.callerUser.sendMessage("biomes.errors.not-enough-level",
+ TextVariables.NUMBER,
+ String.valueOf(this.biome.getRequiredLevel()));
+ return false;
+ }
+ }
+ }
+ else if (this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ // User has no island.
+ this.callerUser.sendMessage(BiomesAddon.BIOMES_WORLD_PROTECTION.getHintReference());
return false;
}
- Optional vaultHook = this.addon.getPlugin().getVault();
- if (vaultHook.isPresent())
+ if (this.addon.isEconomyProvided())
{
- if (!vaultHook.get().has(this.callerUser, this.biome.getRequiredCost()))
+ if (!this.addon.getVaultHook().has(this.callerUser, this.biome.getRequiredCost()))
{
// Not enough money.
- this.callerUser.sendMessage("biomes.messages.errors.not-enough-money",
+ this.callerUser.sendMessage("biomes.errors.not-enough-money",
TextVariables.NUMBER,
Double.toString(this.biome.getRequiredCost()));
return false;
}
}
- Optional levelHook = this.addon.getAddonByName("Level");
-
- if (levelHook.isPresent())
+ // Init starting location.
+ this.standingLocation = this.targetUser.getLocation();
+ }
+ else
+ {
+ if (!this.worldProtectionFlag)
{
- Object levelObject = new AddonRequestBuilder().addon("Level").
- label("island-level").
- addMetaData("player", this.targetUser.getUniqueId()).
- addMetaData("world-name", this.world.getName()).
- request();
-
- if (levelObject != null &&
- this.biome.getRequiredLevel() > 0 &&
- (long) levelObject <= this.biome.getRequiredLevel())
+ if (this.updateMode.equals(UpdateMode.ISLAND))
{
- // Not enough level
+ // Island option is not possible for worlds without world protection.
+ if (this.callerUser.isPlayer())
+ {
+ this.callerUser.sendMessage(BiomesAddon.BIOMES_WORLD_PROTECTION.getHintReference());
+ }
+ else
+ {
+ this.addon.logWarning("Biome change is not possible with Island mode " +
+ "for this world as BIOMES_WORLD_PROTECTION is disabled!");
+ }
- this.callerUser.sendMessage("biomes.messages.errors.not-enough-level",
- TextVariables.NUMBER,
- String.valueOf(this.biome.getRequiredLevel()));
return false;
}
+ else
+ {
+ if (this.targetUser.isOnline())
+ {
+ this.standingLocation = this.targetUser.getLocation();
+ }
+ else if (this.callerUser.isPlayer())
+ {
+ this.standingLocation = this.callerUser.getLocation();
+ }
+ else
+ {
+ this.addon.logWarning("Target Player is not online. Cannot find biome change location!");
+ return false;
+ }
+ }
}
- }
- else
- {
- Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
+ else if (this.updateMode.equals(UpdateMode.ISLAND))
+ {
+ this.standingLocation = this.targetUser.getLocation();
- Optional onIsland =
- this.addon.getIslands().getIslandAt(this.callerUser.getLocation());
+ // Return false if targeted user has no island.
+ return this.addon.getIslands().getIsland(this.world, this.targetUser) != null;
+ }
+ else if (this.callerUser.isPlayer())
+ {
+ // Chunk and square based update modes can be called only by player.
+
+ Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
+
+ Optional onIsland =
+ this.addon.getIslands().getIslandAt(this.callerUser.getLocation());
+
+ if (this.updateMode != UpdateMode.ISLAND &&
+ (!onIsland.isPresent() || onIsland.get() != island))
+ {
+ // Admin is not on user island.
+ this.callerUser.sendMessage("biomes.errors.admin-not-on-island",
+ "[user]",
+ this.targetUser.getName());
- if (this.updateMode != UpdateMode.ISLAND &&
- (!onIsland.isPresent() || onIsland.get() != island))
+ return false;
+ }
+
+ // Admin must be located on island to change biome, as his location will be
+ // taken for update.
+ this.standingLocation = this.callerUser.getLocation();
+ }
+ else
{
- // Admin is not on user island.
- this.callerUser.sendMessage("biomes.messages.errors.missing-admin-island",
- "[user]",
- this.targetUser.getName());
- return false;
+ // Check if target user is his island.
+ Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
+
+ Optional onIsland =
+ this.addon.getIslands().getIslandAt(this.targetUser.getLocation());
+
+ if (!onIsland.isPresent() || onIsland.get() != island)
+ {
+ // Admin is not on user island.
+ this.addon.logWarning("Biome change for player " + this.targetUser.getName() + " is not possible as he is not on his island!");
+ return false;
+ }
+
+ // Init start location
+ this.standingLocation = this.targetUser.getLocation();
}
}
@@ -154,32 +240,52 @@ public boolean canChangeBiome()
*/
public void updateIslandBiome()
{
- Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
- int range = island.getRange();
+ int minX;
+ int minZ;
+ int maxX;
+ int maxZ;
+
+ // Limit island update range
+ if (this.worldProtectionFlag)
+ {
+ Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
+ int range = island.getRange();
+
+ minX = island.getMinX();
+ minZ = island.getMinZ();
+
+ // That's how it is in Island#inIslandSpace
- int minX = island.getMinX();
- int minZ = island.getMinZ();
+ maxX = island.getMinX() + range * 2 - 1;
+ maxZ = island.getMinZ() + range * 2 - 1;
+ }
+ else
+ {
+ // limit by island distance to avoid issues with long updating.
+ int range = this.addon.getPlugin().getIWM().getIslandDistance(this.world);
- int maxX = minX + 2 * range;
- int maxZ = minZ + 2 * range;
+ minX = this.standingLocation.getBlockX() - range;
+ minZ = this.standingLocation.getBlockZ() - range;
- Location playerLocation = this.callerUser.getLocation();
+ maxX = this.standingLocation.getBlockX() + range;
+ maxZ = this.standingLocation.getBlockZ() + range;
+ }
// Calculate minimal and maximal coordinate based on update mode.
- BiomeUpdateTask task = new BiomeUpdateTask((BiomesAddon) this.addon, this.callerUser, this.world, this.biome);
+ BiomeUpdateTask task = new BiomeUpdateTask(this.addon, this.callerUser, this.world, this.biome);
switch (this.updateMode)
{
case ISLAND:
- task.setMinX(minX > maxX ? maxX : minX);
- task.setMaxX(minX < maxX ? maxX : minX);
- task.setMinZ(minZ > maxZ ? maxZ : minZ);
- task.setMaxZ(minZ < maxZ ? maxZ : minZ);
+ task.setMinX(minX);
+ task.setMaxX(maxX);
+ task.setMinZ(minZ);
+ task.setMaxZ(maxZ);
break;
case CHUNK:
- Chunk chunk = playerLocation.getChunk();
+ Chunk chunk = this.standingLocation.getChunk();
task.setMinX(Math.max(minX, (chunk.getX() - (this.updateNumber - 1)) << 4));
task.setMaxX(Math.min(maxX, (chunk.getX() + this.updateNumber) << 4) - 1);
@@ -188,10 +294,10 @@ public void updateIslandBiome()
task.setMaxZ(Math.min(maxZ, (chunk.getZ() + this.updateNumber) << 4) - 1);
break;
- case SQUARE:
+ case RANGE:
int halfDiameter = this.updateNumber / 2;
- int x = playerLocation.getBlockX();
+ int x = this.standingLocation.getBlockX();
if (x < 0)
{
@@ -204,7 +310,7 @@ public void updateIslandBiome()
task.setMaxX(Math.min(maxX, x + halfDiameter));
}
- int z = playerLocation.getBlockZ();
+ int z = this.standingLocation.getBlockZ();
if (z < 0)
{
@@ -235,6 +341,17 @@ public void updateIslandBiome()
}
+ /**
+ * This method checks if user has all required permissions.
+ * @return true if user has all required permissions, otherwise false.
+ */
+ private boolean checkPermissions()
+ {
+ return this.biome.getRequiredPermissions().isEmpty() ||
+ this.biome.getRequiredPermissions().stream().allMatch(this.callerUser::hasPermission);
+ }
+
+
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
@@ -243,7 +360,7 @@ public void updateIslandBiome()
/**
* This variable stores caller addon.
*/
- private Addon addon;
+ private BiomesAddon addon;
/**
* This variable stores User that calls update.
@@ -255,6 +372,11 @@ public void updateIslandBiome()
*/
private User targetUser;
+ /**
+ * This variable holds from which location Update process should start.
+ */
+ private Location standingLocation;
+
/**
* This variable stores BiomesObject that must be applied.
*/
@@ -279,4 +401,10 @@ public void updateIslandBiome()
* This variable stores if money from caller can be withdrawn.
*/
private boolean canWithdraw;
+
+ /**
+ * This variable stores if world protection flag is enabled. Avoids checking it each
+ * time as flag will not change its value while updating.
+ */
+ private final boolean worldProtectionFlag;
}
diff --git a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java
index 04c3128..6eb78a8 100644
--- a/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java
+++ b/src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java
@@ -1,14 +1,15 @@
package world.bentobox.biomes.tasks;
+import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.scheduler.BukkitRunnable;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.utils.Utils;
+import world.bentobox.biomes.database.objects.BiomesObject;
+import world.bentobox.biomes.events.BiomeChangedEvent;
/**
@@ -16,104 +17,125 @@
*/
public class BiomeUpdateTask extends BukkitRunnable
{
- public BiomeUpdateTask(BiomesAddon addon, User user, World world, BiomesObject biome)
- {
- this.addon = addon;
- this.user = user;
- this.world = world;
- this.biome = biome;
- }
+ public BiomeUpdateTask(BiomesAddon addon, User user, World world, BiomesObject biome)
+ {
+ this.addon = addon;
+ this.user = user;
+ this.world = world;
+ this.biome = biome;
+ }
+
+
+ @Override
+ public void run()
+ {
+ if (this.user.isPlayer())
+ {
+ this.user.sendMessage("biomes.messages.update-start");
+ }
+
+ // Update world coordinates with new biomes.
+
+ Biome newBiome = this.biome.getBiome();
+
+ for (int x = this.minX; x <= this.maxX; x++)
+ {
+ for (int z = this.minZ; z <= this.maxZ; z++)
+ {
+ this.world.setBiome(x, z, newBiome);
+ }
+ }
+
+ if (this.user.isPlayer())
+ {
+ this.user.sendMessage("biomes.messages.update-done",
+ "[biome]",
+ this.biome.getFriendlyName());
+
+ this.addon.log(this.user.getName() + " change biome to " +
+ this.biome.getBiome() + " from x=" + this.minX + ":" + this.maxX + " z=" + this.minZ + ":" + this.maxZ +
+ " while standing on x=" + this.user.getLocation().getBlockX() + " z=" + this.user.getLocation().getBlockZ());
+ }
+ else
+ {
+ this.addon.log("Console changed biome to " +
+ this.biome.getBiome() + " from x=" + this.minX + ":" + this.maxX + " z=" + this.minZ + ":" + this.maxZ);
+ }
+
+ // Fire event that biome is changed.
+ Bukkit.getPluginManager().callEvent(
+ new BiomeChangedEvent(this.biome.getUniqueId(),
+ this.biome.getBiome(),
+ this.user.getUniqueId(),
+ this.minX,
+ this.minZ,
+ this.maxX,
+ this.maxZ));
+ }
+
+
+ // ---------------------------------------------------------------------
+ // Section: Setters
+ // ---------------------------------------------------------------------
+
+
+ /**
+ * Default Setter.
+ * @param minX Integer.
+ */
+ public void setMinX(int minX)
+ {
+ this.minX = minX;
+ }
+
+
+ /**
+ * Default Setter.
+ * @param maxX Integer.
+ */
+ public void setMaxX(int maxX)
+ {
+ this.maxX = maxX;
+ }
+
+
+ /**
+ * Default Setter.
+ * @param minZ Integer.
+ */
+ public void setMinZ(int minZ)
+ {
+ this.minZ = minZ;
+ }
+
+
+ /**
+ * Default Setter.
+ * @param maxZ Integer.
+ */
+ public void setMaxZ(int maxZ)
+ {
+ this.maxZ = maxZ;
+ }
+
+
+ // ---------------------------------------------------------------------
+ // Section: Variables
+ // ---------------------------------------------------------------------
+
+ private BiomesAddon addon;
+ private User user;
+
+ private World world;
+
+ private int minX;
+
+ private int maxX;
- @Override
- public void run()
- {
- this.user.sendMessage("biomes.messages.information.update-start");
-
- // Update world coordinates with new biomes.
-
- Biome newBiome = Utils.parseBiome(this.biome);
-
- for (int x = this.minX; x <= this.maxX; x++)
- {
- for (int z = this.minZ; z <= this.maxZ; z++)
- {
- this.world.setBiome(x, z, newBiome);
- }
- }
-
- this.user.sendMessage("biomes.messages.information.update-done",
- "[biome]",
- this.biome.getFriendlyName());
-
- this.addon.log(this.user.getName() + " changes biome to " +
- this.biome.getBiomeName() + " from x=" + this.minX + ":" + this.maxX + " z=" + this.minZ + ":" + this.maxZ +
- " while standing on x=" + this.user.getLocation().getBlockX() + " z=" + this.user.getLocation().getBlockZ());
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Setters
-// ---------------------------------------------------------------------
-
-
- /**
- * Default Setter.
- * @param minX Integer.
- */
- public void setMinX(int minX)
- {
- this.minX = minX;
- }
-
-
- /**
- * Default Setter.
- * @param maxX Integer.
- */
- public void setMaxX(int maxX)
- {
- this.maxX = maxX;
- }
-
-
- /**
- * Default Setter.
- * @param minZ Integer.
- */
- public void setMinZ(int minZ)
- {
- this.minZ = minZ;
- }
-
-
- /**
- * Default Setter.
- * @param maxZ Integer.
- */
- public void setMaxZ(int maxZ)
- {
- this.maxZ = maxZ;
- }
-
-
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
-
- private BiomesAddon addon;
-
- private User user;
-
- private World world;
-
- private int minX;
-
- private int maxX;
-
- private int minZ;
-
- private int maxZ;
-
- private BiomesObject biome;
+ private int minZ;
+
+ private int maxZ;
+
+ private BiomesObject biome;
}
diff --git a/src/main/java/world/bentobox/biomes/utils/Utils.java b/src/main/java/world/bentobox/biomes/utils/Utils.java
deleted file mode 100644
index 57fc11b..0000000
--- a/src/main/java/world/bentobox/biomes/utils/Utils.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package world.bentobox.biomes.utils;
-
-
-import org.apache.commons.lang.WordUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.Biome;
-import org.bukkit.inventory.ItemStack;
-import java.util.*;
-
-import world.bentobox.biomes.BiomesAddon;
-import world.bentobox.biomes.objects.BiomesObject;
-import world.bentobox.biomes.objects.Settings.UpdateMode;
-
-
-/**
- * Utils class that contains useful methods.
- */
-public class Utils
-{
- /**
- * Thus method parses input string to ItemStack.
- * @param inputString Splitted string.
- * @return ItemStack that represents input string.
- * @deprecated
- * @see world.bentobox.bentobox.util.ItemParser#parse(String)
- */
- @Deprecated
- private static ItemStack parse2ArrayString(String[] inputString)
- {
- int reqAmount;
-
- try
- {
- reqAmount = Integer.parseInt(inputString[1]);
- }
- catch (Exception e)
- {
- return null;
- }
-
- Material reqItem = Material.getMaterial(inputString[0].toUpperCase() + "_ITEM");
-
- if (reqItem == null)
- {
- reqItem = Material.getMaterial(inputString[0].toUpperCase());
- }
-
- if (reqItem == null)
- {
- return null;
- }
-
- return new ItemStack(reqItem, reqAmount);
- }
-
-
- /**
- * Create ItemStack from 3 string parts.
- * @param inputString Splitted string.
- * @return ItemStack that is created from input string.
- * @deprecated
- * @see world.bentobox.bentobox.util.ItemParser#parse(String)
- */
- @Deprecated
- private static ItemStack parse3ArrayString(String[] inputString)
- {
- String[] twoArrayString = {inputString[0], inputString[2]};
-
- return Utils.parse2ArrayString(twoArrayString);
- }
-
- /**
- * This method parse given string to ItemStack element.
- * @return the parsed ItemStack element.
- * @deprecated
- * @see world.bentobox.bentobox.util.ItemParser#parse(String)
- */
- @Deprecated
- public static ItemStack parseItem(BiomesAddon addon, String inputString)
- {
- String[] part = inputString.split(":");
-
- ItemStack itemStack;
-
- if (part.length == 2)
- {
- itemStack = Utils.parse2ArrayString(part);
- }
- else if (part.length == 3)
- {
- itemStack = Utils.parse3ArrayString(part);
- }
- else
- {
- itemStack = null;
- }
-
- if (itemStack == null)
- {
- addon.getLogger().severe(() -> "Problem with " + inputString + " in config.yml!");
- }
-
- return itemStack;
- }
-
-
- /**
- * This method splits input string in multiple string lists.
- * @param string String that must be splitted.
- * @return List of splited strings.
- */
- public static List splitString(String string)
- {
- string = ChatColor.translateAlternateColorCodes('&', string);
-
- List result = new ArrayList<>();
- Arrays.asList(string.split("\\|")).forEach(
- line -> result.addAll(Arrays.asList(WordUtils.wrap(line, 25).split("\\n"))));
-
- return result;
- }
-
-
- /**
- * This method combines input string array in single string.
- * @param args String list that must be combined.
- * @return Combined string.
- * @deprecated
- */
- @Deprecated
- public static String mergeStringList(List args)
- {
- if (args.isEmpty())
- {
- return "";
- }
-
- Iterator iterator = args.iterator();
-
- StringBuilder builder = new StringBuilder();
- builder.append(iterator.next());
-
- while (iterator.hasNext())
- {
- builder.append(" ");
- builder.append(iterator.next());
- }
-
- return builder.toString();
- }
-
-
- /**
- * This method parses BiomesObject to necessary Biome.
- * @param biomesObject BiomesObject.
- * @return Biome that is represented by BiomesObject.
- */
- public static Biome parseBiome(BiomesObject biomesObject)
- {
- int id = biomesObject.getBiomeID();
-
- if (id < 0 || Biome.values().length < id)
- {
- return null;
- }
-
- return Biome.values()[id];
- }
-
-
- /**
- * This method parses input string to valid list of environments.
- * @param environment Input string.
- * @return List with valid world environments.
- */
- public static List parseEnvironments(String environment)
- {
- List returnList = new ArrayList<>(3);
-
- String[] split = environment.split(":");
-
- for (String s : split)
- {
- if (s.toUpperCase().equals(World.Environment.NORMAL.name()))
- {
- returnList.add(World.Environment.NORMAL);
- }
- else if (s.toUpperCase().equals(World.Environment.NETHER.name()))
- {
- returnList.add(World.Environment.NETHER);
- }
- else if (s.toUpperCase().equals(World.Environment.THE_END.name()))
- {
- returnList.add(World.Environment.THE_END);
- }
- }
-
- return returnList;
- }
-
-
-
- /**
- * This method returns map that contains biomes name as key and biome as value.
- * @return Map that contains relation from biome name to biome.
- */
- public static Map getBiomeNameMap()
- {
- Biome[] biomes = Biome.values();
-
- Map returnMap = new HashMap<>(biomes.length);
-
- for (Biome biome : biomes)
- {
- returnMap.put(biome.name(), biome);
- }
-
- return returnMap;
- }
-
-
-
- /**
- * This method parse default input string type to corresponding update mode.
- * @return Default Update mode.
- */
- public static UpdateMode parseStringToUpdateMode(String type)
- {
- switch (type.toUpperCase())
- {
- case "ISLAND":
- return UpdateMode.ISLAND;
- case "CHUNK":
- return UpdateMode.CHUNK;
- case "SQUARE":
- return UpdateMode.SQUARE;
- default:
- return UpdateMode.ISLAND;
- }
- }
-
-
- /**
- * This method parse default input string type to corresponding update mode.
- * @return Update mode.
- */
- public static UpdateMode parseStrictToUpdateMode(String type)
- {
- switch (type.toUpperCase())
- {
- case "ISLAND":
- return UpdateMode.ISLAND;
- case "CHUNK":
- return UpdateMode.CHUNK;
- case "SQUARE":
- return UpdateMode.SQUARE;
- default:
- return null;
- }
- }
-}
diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml
index febc5bd..0cde3d5 100644
--- a/src/main/resources/addon.yml
+++ b/src/main/resources/addon.yml
@@ -1,8 +1,11 @@
-name: ${project.name}
+name: Biomes
main: world.bentobox.biomes.BiomesAddon
version: ${project.version}${build.number}
repository: 'BentoBoxWorld/Biomes'
+metrics: true
+
+icon: GRASS_BLOCK
authors: [BONNe]
softdepend: AcidIsland, BSkyBlock, CaveBlock, SkyGrid, Level
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index abeb0f4..20db4ca 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -14,7 +14,7 @@ advanced-menu: true
# Valid values are:
# 'ISLAND' - updates biome on whole island
# 'CHUNK' - updates biome on whole chunks around player
-# 'SQUARE' - updates biome by block in given range
+# 'RANGE' - updates biome by block in given range
default-mode: ISLAND
#
# For advanced menu this indicate how large range will be set on GUI opening.
@@ -36,12 +36,24 @@ cooldown: 60
# 'DEPLOYED' - shows all biomes that are deployed.
# 'ACCESSIBLE' - only biomes that is unlocked via permission or other unlock type will be visible in GUI.
# 'TOGGLEABLE' - there will be button in GUI that allows users to switch from ALL to ACCESSIBLE modes.
-biomes-visibility: DEPLOYED
+biomes-visibility: TOGGLEABLE
+#
+# This string allows to change element order in Biomes description. Each letter represents
+# one object from Biomes description. If letter is not used, then its represented part
+# will not be in description. If use any letter that is not recognized, then it will be
+# ignored. Some strings can be customized via lang file under 'viomes.gui.biomes-description'.
+# List of letters and their meaning:
+# - D - description from biomes object
+# - N - defined minecraft biomes name: '*.biome-name'
+# - R - requirements for biome change: '*.required-money', '*.required-island-level' and '*.required-permission'
+lore-message: DNR
+#
+# This allows to change lore description line length. By default it is 25, but some server
+# owners may like it to be larger.
+lore-length: 25
#
# This list stores GameModes in which Biomes addon should not work.
# To disable addon it is necessary to write its name in new line that starts with -. Example:
# disabled-gamemodes:
# - BSkyBlock
disabled-gamemodes: []
-#
-uniqueId: config
\ No newline at end of file
diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml
index 91c3931..3ec5c03 100644
--- a/src/main/resources/locales/en-US.yml
+++ b/src/main/resources/locales/en-US.yml
@@ -1,187 +1,249 @@
biomes:
- # Translation for GUI elements.
gui:
- # Admin GUI translations.
- admin:
- # Titles for different admin GUIs
- gui-title: "Admin Menu"
- edit-title: "Edit Biome"
- remove-title: "Remove Biome"
- add-title: "Add Biome Menu"
- settings-title: "Edit Settings Menu"
- choose-biome-title: "Choose new biome type"
- choose-user-title: "Choose user"
-
- buttons:
- # Main admin GUI related buttons.
- change: "Change biome in island"
- add: "Add new biome"
- edit: "Edit biome properties"
- import: "Import biomes"
- settings: "Edit addon settings"
- remove: "Remove biome from memory"
- # Biome edit GUI related buttons
- icon: "Biome icon"
- level: "Required island level"
- cost: "Required money"
- biome: "Change biome"
- name: "Edit friendly name"
- permission: "Edit required permission"
- deployed: "Set biome deployment"
- description: "Change description"
- # Addon settings edit related buttons
- advancedmenu: "Advanced Menu is [value]"
- type: "Default type is [value]"
- size: "Default size is [number]"
- resetBiomes: "Reset Biomes is [value]"
- timeout: "Timeout is [number]"
- visibility: "Biomes Visibility settings is [value]"
- # Common GUI buttons
- cancel: "Cancel"
- save: "Save"
- enabled: "Enable"
- disabled: "Disable"
- toggle-users: "Change Users in list"
- visible-all: "All biomes are visible."
- visible-active: "All deployed biomes are visible."
- visible-accessible: "Only if user has permission."
- visible-toggle: "Users can choose visibility mode in GUI."
- change-value: "Change value."
-
- # Admin GUI button description translations.
- descriptions:
- # GUI edit settings buttons:
- advancedmenu: "This enables or disables advanced menu when choosing biomes. It shows all possible biome changing options."
- type: "This changes default update type when opening biomes menu. It can be 'ISLAND', 'CHUNK' or 'SQUARE'"
- size: "This changes default size that is set when opening biomes menu."
- resetbiomes: "This enables or disables resetting to default biome whole island on owner change if new owner does not have biome.set permission."
- timeout: "This changes timeout between changing biomes."
- visibility: "This allows to change which biomes users can see. It can be 'ALL', 'DEPLOYED', 'ACCESSIBLE' or 'TOGGLEABLE'."
- # this will be added into biomes.gui.admin.buttons.advancedmenu [value]
- enabled: "enabled"
- disabled: "disabled"
- # Biome edit panel
- current: "Current value: [value]"
- change: "This will set [number] as new value."
- # For Toggle Users button
- online: "Online"
- offline: "Offline"
- in_world: "In current World"
+ title:
+ admin:
+ main-gui: "&6Admin Menu"
+ edit: "&6Edit [biome]"
+ settings: "&6Addon Settings"
+ edit-list: "&6Editable Biome List"
+ remove-list: "&6Removable Biome List"
+ user-list: "&6Choose Player"
+ confirm-title: "&6Confirm Previous Action"
+ manage-numbers: "&6Manage Numbers"
+ select-biome: "&6Select Biome"
+ toggle-environment: "&6Toggle Environment"
+ edit-text-fields: "&6Edit Text Fields"
+ biomes-choose: "&6Choose Biome"
+ mode-choose: "&6Choose Update Mode"
- # User GUI translations.
- title: "Biome change menu"
- choose-title: "Choose biome"
buttons:
- # Buttons in multi-page menu
- next: "Next page"
- previous: "Previous page"
- back: "Return to previous menu"
+ admin:
+ settings: "Settings"
+ import: "Import"
+ remove: "Remove Biome"
+ edit: "Edit Biome"
+ add: "Add Biome"
+ change: "Change User Biome"
+
+ change-biome: "Biome"
+ name: "Display Name"
+ icon: "Icon"
+ order: "Order"
+ description: "Description"
+ deployment: "Deployment"
+ required-permissions: "Required Permissions"
+ required-level: "Required Level"
+ required-money: "Required Money"
+
+ advanced-menu: "Advanced Menu"
+ default-mode: "Default Update Mode"
+ default-size: "Default Size"
+ visibility-mode: "Biomes Visibility"
+ line-length: "Lore Line Length"
+ biomes-lore: "Biome Lore"
+ cooldown: "Cooldown"
+ reset-biomes: "Reset Event"
+
+ toggle-user-list: "Toggle Player List"
- # Buttons in advanced menu that indicate biome change mode.
- island: "On whole island"
- chunk: "Per chunk"
- region: "On region"
-
- # Visibility button for biomes.
- visibility: "Biomes Visibility"
+ save: "Save"
+ cancel: "Cancel"
+ input: "Input"
+
+ set-mode: "="
+ increase-mode: "+"
+ reduce-mode: "-"
+ multiply-mode: "*"
+ number: "[number]"
+
+ add-string: "Add String"
+ clear: "Clear"
+ remove-empty: "Remove Empty"
+ input-mode: "Input Mode"
+ value: "Value"
+
+ value: "Current Value: [number]"
+ increase: "Increase by [number]"
+ decrease: "Decrease by [number]"
+ set: "Set value to [number]"
+ accept: "Accept"
+ decline: "Decline"
- # Button in advanced menu that indicate how large region will be updated.
- value: "New value: [number]"
+ information: "Information"
- # Buttons in advanced menu that allows to change update region size.
- set: "Set value to [number]"
- increase: "Increase value by [number]"
- reduce: "Reduce value by [number]"
+ return: "Return"
+ previous: "Previous"
+ next: "Next"
descriptions:
- # Used for biome visibility toggle button
- all: "Show all biomes"
- accessible: "Show all accessible biomes (by permission)"
- deployed: "Show all deployed biomes"
- # Translations for addon commands.
+ admin:
+ settings: "Allows to edit Addon Settings"
+ import: "Allows to import biomes from biomes.yml file.|Right click will enable/disable overwrite mode."
+ remove: "Allows to remove biome from memory"
+ edit: "Allows to edit biome properties"
+ add: "Allows to add new biome in current world"
+ change: "Allows to change players biome on their island"
+
+ change-biome: "Allows to change which Minecraft Biome will be used."
+ required-permissions: "Allows to change required permissions for this biome.|Without these permissions players will not be able to apply it!"
+ required-level: "Allows to change minimal island level.|&cRequires Level Addon."
+ required-money: "Allows to change how much changing to this biome cost.|&cRequires Economy Addon/Plugin."
+ name: "Allows to change display name for this Biome."
+ deployment: "Allows to disable/enable players ability to use this biome."
+ icon: "Allows to set different display icon for this biome."
+ description: "Allows to modify description of this biome."
+ order: "Allows to modify order of this biome."
+
+ advanced-menu: "Allows to enable/disable Advanced Menu with all change options for players."
+ default-mode: "Allows to change default biome update mode.|Will be used if Advanced Menu is disabled and as default values in this menu."
+ default-size: "Allows to change default biome update size.|Will be used if Advanced Menu is disabled and as default values in this menu."
+ visibility-mode: "Allows to modify which biomes players can see."
+ line-length: "Allows to automatically edit description lore line character length."
+ biomes-lore: "Allows to modify which elements in lore message will be displayed.|Check config for more infromation."
+ cooldown: "Allows to change cooldown in seconds between player can change biome again."
+ reset-biomes: "Allows to enable/disable biomes resetting if player with biome permission leave island."
+
+ toggle-user-list: "Allows to switch which players should be displayed in current Menu."
+
+ save: "Allows to save current value and return to previous Menu."
+ cancel: "Allows to return to previous Menu without changes."
+ input: "Allows to write number in AnvilGUI"
+
+ set-mode: "Allows to switch to set mode that will set current value to clicked number."
+ increase-mode: "Allows to switch to increase mode that will increase current value by clicked number."
+ reduce-mode: "Allows to switch to reduce mode that will reduce current value by clicked number."
+ multiply-mode: "Allows to switch to multiply mode that will multiply current value by clicked number."
+
+ click-to-edit: '&4Click here to edit input.'
+ edit-text-line: '&6 Edit text message!'
+ add-text-line: '&6 Add new text message!'
+ input-mode: 'Switch between chat and anvil input modes.'
+
+ update-mode:
+ island: "Island"
+ chunk: "Chunk"
+ square: "Range"
+ undefined: "Undefined"
+ visibility-mode:
+ info: "Allows to modify which biomes you can see."
+ all: "All &r- list all biomes"
+ deployed: "Deployed - list deployed biomes"
+ accessible: "Accessible - list accessible biomes"
+ toggleable: "Toggleable - toggleable button in Biomes Menu"
+ view-mode:
+ online: "Online"
+ in-world: "In this world"
+ with-island: "With island"
+
+ current-value: "Current value: [value]"
+ enabled: "enabled"
+ disabled: "disabled"
+ permission: " - [permission]"
+
+ information: "If you accept this changes, we will try to change your island biome to [biome] in update mode [mode] with range [range]."
+
+ biomes-description:
+ biome-name: "Minecraft Biome: [value]"
+ required-money: "Cost: [value]"
+ required-island-level: "Min island level: [value]"
+ required-permissions: "Permissions:"
+
commands:
- # Translations for addon admin commands.
admin:
+ add:
+ description: "Admin ADD command allows to add new biome. It creates empty biome object with default settings."
+ parameters: "[id]"
+ edit:
+ description: "Admin EDIT command allows to change given property. Allows to edit only existing properties."
+ parameters: " "
help:
description: "Main biome addon admin command. Opens Admin GUI for players."
parameters: ""
- set:
- description: "Admin SET command allows to change biome for island. and is not required."
- parameters: " [] []"
- add:
- description: "Admin ADD command allows to add new biome, if it does not exist. Will not override!"
- parameters: ""
- edit:
- description: "Admin EDIT command allows to change given property. Allows to edit only existing properties."
- parameters: " "
import:
description: "Admin IMPORT command allows to import biomes from biomes.yml file. Adding 'overwrite' at the end will overwrite existing biomes."
parameters: "[overwrite]"
+ set:
+ description: "Admin SET command allows to change biome for island. and is not required."
+ parameters: " [] []"
settings:
description: "Admin SETTINGS command allows to edit addon default settings via simple command. It allows to edit only existing settings."
parameters: " "
+ user:
+ help:
+ description: "Main biome addon command that opens biome change GUI."
+ parameters: ""
+ info:
+ description: "INFO command displays information about given biome."
+ parameters: ""
+ set:
+ description: "SET command allows to change biome on island. and is not required."
+ parameters: " [] []"
+
+ errors:
+ unique-id: "&cUnique id &d[id]&c is not valid!"
+ too-many-arguments: "&cToo many parameters. Please check help!"
+ missing-arguments: "&cMissing command parameters. Please check help!"
+ unknown-argument: "&cUnknown command parameters. Please check help!"
+
+ incorrect-range: "&cGiven number &d'[number]'&c is not valid. Valid are only positive integers."
+ incorrect-mode: "&cGiven value &d'[mode]'&c is not valid. Valid values are 'ISLAND', 'CHUNK' or 'SQUARE'."
+ incorrect-icon: "&cGiven icon &d'[icon]'&c cannot be parsed. Try different."
+ incorrect-biome: "&cGiven biome &d'[biome]'&c is not find in Minecraft. Use correct biome name."
+ incorrect-parameter: "&cGiven property &d'[property]'&c is not defined for biome."
+ incorrect-boolean: "&cGiven value &d'[boolean]'&c is not a boolean. Valid values are 'true' or 'false'."
+ incorrect-visibility: "&cGiven value &d'[mode]'&c is not valid."
+ incorrect-object: "&cCannot find biome with given ID &d'[biome]'."
+
+ no-biomes: '&cBiomes are not implemented in current world!'
+ no-biomes-admin: '&cBiomes are not implemented in current world! You should use &5/[command] &cto adding them!'
+ missing-user: "&cUser is not defined."
+ missing-biome: "&cBiome is not defined."
+ wrong-icon: "&cGiven material &6[value]&c cannot be parsed to ItemStack."
+ no-biomes-for-you: "&cUnfortunately, cannot find any biome that you could use."
+
+ not-valid-integer: '&cGiven integer "[value]" is not valid!|Value should be between [min] and [max].'
+ not-a-integer: '&cGiven value "[value]" is not integer!'
+
+ not-on-island: "&cYou are not on island."
+ not-enough-money: "&cYou do not have enough money. Changing biome requires $[number]"
+ not-enough-level: "&cYour island level is too small. Biome requires [number] level"
+ admin-not-on-island: "&cYou are not on [user] island."
+ disabled: "&cCurrently this biome is disabled."
+ missing-permission: "&cThis biome requires &6[permission]&c permission. You do not have it."
+
+ no-file: "&cbiomes.yml not found."
+ no-load: "&cAn error occur while importing biomes: [message]!"
+ load-biome: "&cCannot load biome '[biome]' as it is not defined in Minecraft. Use correct biome name."
+
+ no-rank: "&cYou do not have rank to do that."
+
+ information:
+ header: "Biome: [name]"
+ type: " Type: [type]"
+ description: " Description: [description]"
+ level: " Level: [level]"
+ cost: " Cost: [cost]"
+ permission: " Permission: [permission]"
- # User commands
- help:
- description: "Main biome addon command that opens biome change GUI."
- parameters: ""
- info:
- description: "INFO command displays information about given biome."
- parameters: ""
- set:
- description: "SET command allows to change biome without opening GUI. and is not required."
- parameters: " [] []"
-
- # Translations for addon messages.
messages:
- # Information contains all 5 lines that will be displayed on /biomes INFO command.
- biome-information:
- header: "Biome: [name]"
- type: " Type: [type]"
- description: " Description: [description]"
- level: " Level: [level]"
- cost: " Cost: [cost]"
- permission: " Permission: [permission]"
- information:
- biome-created: "Biome [biome] is created. To edit its properties use EDIT command."
- update-start: "Start Biome changing on island."
- update-done: "[biome] is set on island successfully."
-
- imported: "[biome] is imported."
- import-count: "Biomes importing ended. Imported [number] biomes."
-
- biome-removed: "Biome with type = '[biome]' is removed from memory."
-
- saved: "Biome [biome] is saved."
- saved-config: "Addon settings is updated."
- saved-value: "New [property] for [biome] is stored as [value]."
- warnings:
- may-break-others: "Changing biome type to [biome] may break other biomes with the same type!"
-
- skipping: "Skipping [biome] importing."
- overwriting: "Overwriting [biome]."
- errors:
- incorrect-range: "Given number '[number]' is not valid. Valid are only positive integers."
- incorrect-mode: "Given value '[mode]' is not valid. Valid values are 'ISLAND', 'CHUNK' or 'SQUARE'."
- incorrect-icon: "Given icon '[icon]' cannot be parsed. Try different."
- incorrect-biome: "Given biome '[biome]' is not find in Minecraft. Use correct biome name."
- incorrect-parameter: "Given property '[property]' is not defined for biome."
- incorrect-boolean: "Given value '[boolean]' is not a boolean. Valid values are 'true' or 'false'."
-
- missing-user: "User is not defined."
- missing-biome: "Biome is not defined."
- missing-arguments: "Command is missing some arguments."
- too-many-arguments: "Too many arguments for this command."
-
- missing-island: "You do not have an island!"
- missing-admin-island: "User [user] does not have an island!"
-
- not-on-island: "You are not on island."
- not-enough-money: "You do not have enough money. Changing biome requires $[number]"
- not-enough-level: "Your island level is too small. Biome requires [number] level"
- admin-not-on-island: "You are not on [user] island."
- disabled: "Currently this biome is disabled."
- missing-permission: "This biome requires [permission] permission. You do not have it."
-
- no-file: "biomes.yml not found."
- no-load: "An error occur while importing biomes: [message]!"
- load-biome: "Cannot load biome '[biome]' as it is not defined in Minecraft. Use correct biome name."
+ saved: "&dBiome [biome] is saved."
+ biome-created: "&dNew Biome object created with uniqueID: [id]"
+ saved-config: "Addon settings is updated."
+ biome-removed: "Biome with unique id = '[biome]' is removed from memory."
+
+ update-start: "&eBiome Updating started"
+ update-done: "&6[biome]&r&e is set on island successfully."
+
+ skipping: "Skipping [biome] importing."
+ overwriting: "Overwriting [biome]."
+ imported: "[biome] is imported."
+ import-count: "Biomes importing ended. Imported [number] biomes."
+
+protection:
+ flags:
+ BIOMES_ISLAND_PROTECTION:
+ description: "&5&oToggle who can\n&5&ochange Biome on island"
+ name: "Biomes protection"
+ BIOMES_WORLD_PROTECTION:
+ description: "&5&oThis allows to enable/disable\n&5&orequirement for players to\n&5&obe on their island to\n&5&ochange biome."
+ name: "Biome Island limitation"
+ hint: "Biome change are not allowed outside island!"
\ No newline at end of file
diff --git a/src/main/resources/locales/lv-LV.yml b/src/main/resources/locales/lv-LV.yml
new file mode 100644
index 0000000..d587f4b
--- /dev/null
+++ b/src/main/resources/locales/lv-LV.yml
@@ -0,0 +1,249 @@
+biomes:
+ gui:
+ title:
+ admin:
+ main-gui: "&6Administratora Izvēlne"
+ edit: "&6Labot [biome]"
+ settings: "&6Papildinājuma Iesatījumi"
+ edit-list: "&6Labojamo Biomu Saraksts"
+ remove-list: "&6Izmetamo Biomu Saraksts"
+ user-list: "&6Spēlētāju Saraksts"
+ confirm-title: "&6Apstiprināt Operāciju"
+ manage-numbers: "&6Pārvaldīt Skaitļus"
+ select-biome: "&6Izvēlēties Biomu"
+ toggle-environment: "&6Pārslēgt Vidi"
+ edit-text-fields: "&6Labot teksta laukus"
+ biomes-choose: "&6Izvēlēties Biomu"
+ mode-choose: "&6Izvēlēties Mainīšanas Metodi"
+
+ buttons:
+ admin:
+ settings: "Iestatījumi"
+ import: "Ielādēt"
+ remove: "Izdzēst Biomu"
+ edit: "Labot Biomu"
+ add: "Pievienot Biomu"
+ change: "Mainīt Lietotāja Biomu"
+
+ change-biome: "Bioms"
+ name: "Nosaukums"
+ icon: "Ikona"
+ order: "Secība"
+ description: "Apraksts"
+ deployment: "Pieejams"
+ required-permissions: "Nepieciešamās Atļaujas"
+ required-level: "Nepieciešamais Līmenis"
+ required-money: "Nepieciešamā nauda"
+
+ advanced-menu: "Papildinātā Izvēlne"
+ default-mode: "Noklusētā Atjaunošana"
+ default-size: "Noklusētais Izmērs"
+ visibility-mode: "Biomu Redzamība"
+ line-length: "Apraksta Līnijas Garums"
+ biomes-lore: "Biomu Apraksts"
+ cooldown: "Atlikšanas Laiks"
+ reset-biomes: "Noņemt Biomus"
+
+ toggle-user-list: "Pārslēgs Sarakstu"
+
+ save: "Saglabāt"
+ cancel: "Atcelt"
+ input: "Ievadīt"
+
+ set-mode: "="
+ increase-mode: "+"
+ reduce-mode: "-"
+ multiply-mode: "*"
+ number: "[number]"
+
+ add-string: "Pievienot"
+ clear: "Nodzēst"
+ remove-empty: "Iztīrīt tukšos"
+ input-mode: "Ievada metode"
+ value: "Vērtība"
+
+ value: "Esošā vērtība: [number]"
+ increase: "Palielināt par [number]"
+ decrease: "Samazināt par [number]"
+ set: "Uzstādīt [number]"
+ accept: "Apstiprināt"
+ decline: "Noraidīt"
+
+ information: "Informācija"
+
+ return: "Atgriezties"
+ previous: "Iepriekšējais"
+ next: "Nākošais"
+ descriptions:
+ admin:
+ settings: "Ļauj labot papildinājuma iestatījumus."
+ import: "Ļauj ielādēt biomus no biomes.yml faila.|Labais klikšķis pārslēdz pārrakstīšanas modi."
+ remove: "Ļauj nodzēst biomu no atmiņas."
+ edit: "Ļauj labot bioma iestatījumus."
+ add: "Ļauj pievienot jaunu biomu."
+ change: "Ļauj mainīt spēlētāja biomu."
+
+ change-biome: "Ļauj uzstādīt Minecraft Biomu, kurš tiks izmantots."
+ required-permissions: "Ļauj uzstādīt nepieciešamās atļaujas, lai uzstādītu šo biomu!"
+ required-level: "Ļauj uzstādīt minimālo salas līmeni bioma uzstādīšanai.|&cNepieciešams Level papildinājums."
+ required-money: "Ļauj uzstādīt maksu bioma uzstādīšanai.|&cNepieciešams Vault un Ekonomikas papildinājumi."
+ name: "Ļauj uzstādīt nosaukumu biomam."
+ deployment: "Ļauj pārslēgt iespēju spēlētājiem uzstādīt šo biomu."
+ icon: "Ļauj nomainīt ikonu šim biomam."
+ description: "Ļauj labot šī bioma aprakstu."
+ order: "Ļauj labot šī bioma secības numuru."
+
+ advanced-menu: "Ļauj ieslēgt/izslēgt papildināto izvēlni bioma uzstādīšanai."
+ default-mode: "Ļauj uzstādīt noklusēto atjaunošanas metodi.|Tiks pielietota, ja papildinātā izvēlne ir izslēgta, un kā sākotnējā metode iekš papildinātās izvēlnes."
+ default-size: "Ļauj uzstādīt noklusēto atjaunošanas distanci.|Tiks pielietota, ja papildinātā izvēlne ir izslēgta, un kā sākotnējā distance iekš papildinātās izvēlnes."
+ visibility-mode: "Ļauj pārslēgt kādus biomus lietotāji var redzēt."
+ line-length: "Ļauj ievadīt apraksta līnijas maksimālo garumu."
+ biomes-lore: "Ļauj mainīt kādus elementus bioma aprakstā rādīs.|Skatīt konfigurācijas failu, lai redzētu aprakstu."
+ cooldown: "Ļauj mainīt cik ilgi spēlētājam jāgaida pirms tiek ļauts nomainīt biomu vēlreiz."
+ reset-biomes: "Ļauj ieslēgt/izslēgt biomu noņemšanu, ja spēlētājs, kam bija bioma atļauja pamet salu, un pārējiem spēlētājiem nav atļauja lietot šo biomu."
+
+ toggle-user-list: "Ļauj pārslēgt spēlētāja sarakstus."
+
+ save: "Ļauj saglabāt pašreizējo vērtību un atgriezties iepriekšējā izvēlnē."
+ cancel: "Ļauj atgriezties iepriekšējā izvēlnē izmaiņas nesaglabājot."
+ input: "Ļauj ievadīt skaitli Lakts Izvēlnē"
+
+ set-mode: "Ļauj pārslēgties uz uzstādīšanas režīmu, kas uzstādīs vērtību uz numuru, kuram uzspiests."
+ increase-mode: "Ļauj pārslēgties uz palielināšanas režīmu, kas pieskaitīs vērtībai numuru, kuram uzspiests."
+ reduce-mode: "Ļauj pārslēgties uz samazināšanas režīmu, kas atņems vērtībai numuru, kuram uzspiests."
+ multiply-mode: "Ļauj pārslēgties uz reizināšanas režīmu, kas pareizinās vērtību ar numuru, kuram uzspiests."
+
+ click-to-edit: '&4Uzspied šeit, lai labotu.'
+ edit-text-line: '&6 Labo teksta ziņu'
+ add-text-line: '&6 Pievieno jaunu teksta ziņu!'
+ input-mode: 'Pārslēgties starp Sarakstes un Lakts ievades veidu.'
+
+ update-mode:
+ island: "Sala"
+ chunk: "Gabals"
+ square: "Distance"
+ undefined: "Neuzstādīts"
+ visibility-mode:
+ info: "Ļauj pārslēgt kādus biomus spēlētājs var redzēt."
+ all: "Visi &r- saraksts ar visiem biomiem"
+ deployed: "Ieslēgtie &r- sarakstas ar ieslēgtajiem biomiem"
+ accessible: "Pieejamie &r- saraksts ar pieejamajiem biomiem"
+ toggleable: "Pārslēgties &r- režīms, kas uzstāda pārslēgšanas pogu Biomu Izvēlnē"
+ view-mode:
+ online: "Tiešsaitē"
+ in-world: "Šajā pasaulē"
+ with-island: "Ar salu"
+
+ current-value: "Esošā vērtība: [value]"
+ enabled: "ieslēgts"
+ disabled: "izslēgts"
+ permission: " - [permission]"
+
+ information: "Ja apstiprināsi, tad tiks mainīts biomes uz [biome] ar atjaunošanas metodi [mode] un distanci [range]."
+
+ biomes-description:
+ biome-name: "Minecraft Bioms: [value]"
+ required-money: "Maksa: [value]"
+ required-island-level: "Salas līmenis: [value]"
+ required-permissions: "Atļaujas:"
+
+ commands:
+ admin:
+ add:
+ description: "Administratora ADD komanda ļauj pievienot jaunu biomu. Izveido tukšu biomu, ar noklusējuma iestatījumiem."
+ parameters: "[id]"
+ edit:
+ description: "Administratora EDIT komanda ļauj mainīt bioma iestatījumus."
+ parameters: " "
+ help:
+ description: "Galvenā komanda. Atver Galveno Izvēlni administratoriem."
+ parameters: ""
+ import:
+ description: "Administratora IMPORT komanda ļauj ielādēt biomus no biomes.yml faila. Pieveinojot 'overwrite' beigās ļaus pārrakstīt pāri biomiem ar tādiem pašiem ID."
+ parameters: "[overwrite]"
+ set:
+ description: "Administratora SET komanda ļauj uzstādīt spēlētājam biomu uz salas. [type] un [size] tiks aizstādi ar noklusējuma vērtību, ja nav norādīti."
+ parameters: " [] []"
+ settings:
+ description: "Administratora SETTINGS komanda ļauj mainīt noklusētās papildinājuma iestatījuma vērtības."
+ parameters: " "
+ user:
+ help:
+ description: "Galvenā komanda, kas atver Biomu Izvēlni."
+ parameters: ""
+ info:
+ description: "INFO komanda ļauj skatīt informāciju par biomiem sarakstē."
+ parameters: ""
+ set:
+ description: "SET komanda ļauj uzstādīt biomu uz salas. [type] un [size] tiks aizstādi ar noklusējuma vērtību, ja nav norādīti."
+ parameters: " [] []"
+
+ errors:
+ unique-id: "&cUnikālais ID &d[id]&c nav derīgs!"
+ too-many-arguments: "&cPārāk daudz parametri!"
+ missing-arguments: "&cTrūkst komandas parametri!"
+ unknown-argument: "&cNezināms parametrs!"
+
+ incorrect-range: "&cDotais skaitlis &d'[number]'&c nav derīgs. Derīgi ir tikai pozitīvi skaitļi."
+ incorrect-mode: "&cDotā vērtība &d'[mode]'&c nav derīga. Derīgas ir tikai 'ISLAND', 'CHUNK' vai 'SQUARE'."
+ incorrect-icon: "&cDotā ikona &d'[icon]'&c nav derīga. Izmanto citu."
+ incorrect-biome: "&cDotais bioms &d'[biome]'&c nav definēts iekš Minecraft. Izmanto korektu bioma nosaukumu."
+ incorrect-parameter: "&cDotais parametrs &d'[property]'&c nav definēts."
+ incorrect-boolean: "&cDotā vērtība &d'[boolean]'&c nav derīga. Derīgas ir tikai 'true' vai 'false'."
+ incorrect-visibility: "&cDotā vērtība &d'[mode]'&c nav derīga."
+ incorrect-object: "&cNevar atrast Biomu ar dodo ID &d'[biome]'."
+
+ no-biomes: '&cBiomes nav uzstādītas šajā pasaulē!'
+ no-biomes-admin: '&cBiomes nav uzstādītas šajā pasaulē! Lai uzstādītu izmanto &5/[command] &ckomandu!'
+ missing-user: "&cLietotājs nav definēts."
+ missing-biome: "&cBioms nav definēts."
+ wrong-icon: "&cDotais materiāls &6[value]&c nevar tikt izmantots par ikonu."
+ no-biomes-for-you: "&cDiemžēl tev nav pieejami nevieni Biomi."
+
+ not-valid-integer: '&cDotais skaitlis "[value]" nav derīgs!|Skaitlim jābūt no [min] līdz [max].'
+ not-a-integer: '&cDotā vērtība "[value]" nav skaitlis!'
+
+ not-on-island: "&cTu neesi uz salas."
+ not-enough-money: "&cTev nepietiek līdzekļi. Mainīt biomu izmaksā $[number]"
+ not-enough-level: "&cTavs salas līmenis ir pārāk mazs. Biomam nepieciešamas [number] līmenis"
+ admin-not-on-island: "&cTu neesi uz [user] salas."
+ disabled: "&cDiemžēl šobrīd šis bioms ir atslēgts."
+ missing-permission: "&cŠim biomam ir nepieciešama &6[permission]&c atļauja. Tev tā trūkst."
+
+ no-file: "&cbiomes.yml nav atrasts."
+ no-load: "&cRadās kļūda ielādējot biomus: [message]!"
+ load-biome: "&cNevar ielādēt biomu '[biome]', jo tas nav definēts iekš Minecraft. Izmanto korektus bioma nosaukumus."
+
+ no-rank: "&cTev nav nepieciešamais rangs šai darbībai!"
+
+ information:
+ header: "Nosaukums: [name]"
+ type: " Tips: [type]"
+ description: " Apraksts: [description]"
+ level: " Līmenis: [level]"
+ cost: " Maksa: [cost]"
+ permission: " Atļaujas: [permission]"
+
+ messages:
+ saved: "&dBioms [biome] ir saglabāts."
+ biome-created: "&dIzveidots jauns Bioms ar id: [id]"
+ saved-config: "Papildinājuma iestatījumi saglabāti."
+ biome-removed: "Bioms ar id = '[biome]' tika dzēsts."
+
+ update-start: "&eTiek uzsākta Bioma mainīšana."
+ update-done: "&6[biome]&r&e tika uzstādīts veiksmīgi."
+
+ skipping: "Izlaiž [biome] ielādēšānu."
+ overwriting: "Pārraksta [biome]."
+ imported: "[biome] ir ieladēts."
+ import-count: "Biomu ielādēšana pabeigta. Ielādēti [number] biomi."
+
+protection:
+ flags:
+ BIOMES_ISLAND_PROTECTION:
+ description: "&5&oĻauj pārslēgt kuri\n&5&ospēlētāji var pārslēgt\n&5&obiomu uz salas."
+ name: "Biomu maiņas aizsardzība"
+ BIOMES_WORLD_PROTECTION:
+ description: "&5&oĻauj pārslēgt nepieciešamību\n&5&ospēlētājiem būt uz savas\n&5&osalas, lai mainītu\n&5&obiomu."
+ name: "Biomu Salas Ierobežojums"
+ hint: "Biomu maiņa ārpus salas nav atļauta!"
\ No newline at end of file