From f1ad9536440320bf12a5cc44ce39aa77627c7d55 Mon Sep 17 00:00:00 2001 From: Esophose Date: Sun, 10 Mar 2019 15:44:30 -0600 Subject: [PATCH] Bank & money stuff $$$ --- .../skyblock/command/CommandManager.java | 12 ++- .../command/commands/island/BankCommand.java | 84 +++++++++++++++---- .../commands/island/UnlockCommand.java | 3 +- .../goodandevil/skyblock/island/Island.java | 52 +++++------- .../skyblock/utils/NumberUtil.java | 3 +- src/main/resources/config.yml | 3 + src/main/resources/language.yml | 14 +++- 7 files changed, 117 insertions(+), 54 deletions(-) diff --git a/src/main/java/me/goodandevil/skyblock/command/CommandManager.java b/src/main/java/me/goodandevil/skyblock/command/CommandManager.java index 0052ae1b..7e0cfa2c 100644 --- a/src/main/java/me/goodandevil/skyblock/command/CommandManager.java +++ b/src/main/java/me/goodandevil/skyblock/command/CommandManager.java @@ -127,6 +127,16 @@ public class CommandManager implements CommandExecutor, TabCompleter { if (skyblock.getIslandManager().getIsland(player) == null) { Bukkit.getServer().getScheduler().runTask(skyblock, () -> Bukkit.getServer().dispatchCommand(sender, "island create")); } else { + boolean canUseControlPanel = player.hasPermission("fabledskyblock.*") + || player.hasPermission("fabledskyblock.island.*") + || player.hasPermission("fabledskyblock.island.controlpanel"); + + if (!canUseControlPanel) { + messageManager.sendMessage(player, configLoad.getString("Command.PermissionDenied.Island.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + ControlPanel.getInstance().open(player); soundManager.playSound(player, Sounds.CHEST_OPEN.bukkitSound(), 1.0F, 1.0F); } @@ -147,7 +157,7 @@ public class CommandManager implements CommandExecutor, TabCompleter { || player.hasPermission("fabledskyblock.island.help"); if (!canUseHelp) { - messageManager.sendMessage(player, configLoad.getString("Command.PermissionDenied.Admin.Message")); + messageManager.sendMessage(player, configLoad.getString("Command.PermissionDenied.Island.Message")); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); return; } diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/island/BankCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/island/BankCommand.java index ef57c9d1..bc82bc49 100644 --- a/src/main/java/me/goodandevil/skyblock/command/commands/island/BankCommand.java +++ b/src/main/java/me/goodandevil/skyblock/command/commands/island/BankCommand.java @@ -9,8 +9,8 @@ import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.island.IslandRole; import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.sound.SoundManager; +import me.goodandevil.skyblock.utils.NumberUtil; import me.goodandevil.skyblock.utils.version.Sounds; -import org.apache.commons.lang.WordUtils; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -30,14 +30,18 @@ public class BankCommand extends SubCommand { Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); + if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Bank.Disabled")) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Disabled.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + if (args.length == 0) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Invalid.Message")); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); return; } - String action = WordUtils.capitalize(args[0].toLowerCase()); - Island island = islandManager.getIslandAtLocation(player.getLocation()); if (island == null) { @@ -56,20 +60,45 @@ public class BankCommand extends SubCommand { double balance = island.getBankBalance(); - switch (action) { - case "Balance": - case "Bal": + switch (args[0].toLowerCase()) { + case "balance": + case "bal": messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Balance.Message").replace( - "%balance%", String.valueOf(balance))); + "%balance%", NumberUtil.formatNumberByDecimal(balance))); return; - case "Deposit": { + case "deposit": { if (args.length == 1) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short3.Message")); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); return; } - - double amt = Double.parseDouble(args[1]); + + // Parse the amount of money + double amt; + try { + amt = Double.parseDouble(args[1]); + + // Make sure the amount is positive + if (amt <= 0) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short5.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + + // If decimals aren't allowed, check for them + if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Bank.AllowDecimals")) { + int intAmt = (int) amt; + if (intAmt != amt) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short6.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + } + } catch (NumberFormatException ex) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short4.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } if (!economyManager.hasBalance(player, amt)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short.Message")); @@ -79,17 +108,42 @@ public class BankCommand extends SubCommand { economyManager.withdraw(player, amt); island.addToBank(amt); messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Deposit.Message").replace( - "%amount%", String.valueOf(amt))); + "%amount%", NumberUtil.formatNumberByDecimal(amt))); return; } - case "Withdraw": { + case "withdraw": { if (args.length == 1) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short3.Message")); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); return; } - - double amt = Double.parseDouble(args[1]); + + // Parse the amount of money + double amt; + try { + amt = Double.parseDouble(args[1]); + + // Make sure the amount is positive + if (amt <= 0) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short5.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + + // If decimals aren't allowed, check for them + if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Bank.AllowDecimals")) { + int intAmt = (int) amt; + if (intAmt != amt) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short6.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } + } + } catch (NumberFormatException ex) { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short4.Message")); + soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + return; + } if (amt > balance) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short2.Message")); @@ -98,7 +152,7 @@ public class BankCommand extends SubCommand { economyManager.deposit(player, amt); island.removeFromBank(amt); messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Withdraw.Message").replace( - "%amount%", String.valueOf(amt))); + "%amount%", NumberUtil.formatNumberByDecimal(amt))); return; } } diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/island/UnlockCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/island/UnlockCommand.java index 30d373dc..1d19be77 100644 --- a/src/main/java/me/goodandevil/skyblock/command/commands/island/UnlockCommand.java +++ b/src/main/java/me/goodandevil/skyblock/command/commands/island/UnlockCommand.java @@ -8,6 +8,7 @@ import me.goodandevil.skyblock.island.Island; import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.sound.SoundManager; +import me.goodandevil.skyblock.utils.NumberUtil; import me.goodandevil.skyblock.utils.version.Sounds; import org.apache.commons.lang.WordUtils; import org.bukkit.command.ConsoleCommandSender; @@ -68,7 +69,7 @@ public class UnlockCommand extends SubCommand { if (!economyManager.hasBalance(player, price)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Unlock.Money.Message").replace( - "%cost%", String.valueOf(price))); + "%cost%", NumberUtil.formatNumberByDecimal(price))); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); return; } diff --git a/src/main/java/me/goodandevil/skyblock/island/Island.java b/src/main/java/me/goodandevil/skyblock/island/Island.java index 5fa9da52..fc79c681 100644 --- a/src/main/java/me/goodandevil/skyblock/island/Island.java +++ b/src/main/java/me/goodandevil/skyblock/island/Island.java @@ -1,17 +1,19 @@ package me.goodandevil.skyblock.island; -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.api.event.island.*; +import me.goodandevil.skyblock.api.utils.APIUtil; +import me.goodandevil.skyblock.ban.Ban; +import me.goodandevil.skyblock.config.FileManager; +import me.goodandevil.skyblock.config.FileManager.Config; +import me.goodandevil.skyblock.message.MessageManager; +import me.goodandevil.skyblock.playerdata.PlayerData; +import me.goodandevil.skyblock.sound.SoundManager; +import me.goodandevil.skyblock.upgrade.Upgrade; +import me.goodandevil.skyblock.utils.NumberUtil; +import me.goodandevil.skyblock.utils.version.Sounds; +import me.goodandevil.skyblock.utils.world.WorldBorder; +import me.goodandevil.skyblock.visit.Visit; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -21,26 +23,10 @@ import org.bukkit.block.Biome; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -import me.goodandevil.skyblock.SkyBlock; -import me.goodandevil.skyblock.api.event.island.IslandBiomeChangeEvent; -import me.goodandevil.skyblock.api.event.island.IslandLocationChangeEvent; -import me.goodandevil.skyblock.api.event.island.IslandMessageChangeEvent; -import me.goodandevil.skyblock.api.event.island.IslandOpenEvent; -import me.goodandevil.skyblock.api.event.island.IslandPasswordChangeEvent; -import me.goodandevil.skyblock.api.event.island.IslandRoleChangeEvent; -import me.goodandevil.skyblock.api.event.island.IslandUpgradeEvent; -import me.goodandevil.skyblock.api.event.island.IslandWeatherChangeEvent; -import me.goodandevil.skyblock.api.utils.APIUtil; -import me.goodandevil.skyblock.ban.Ban; -import me.goodandevil.skyblock.config.FileManager; -import me.goodandevil.skyblock.config.FileManager.Config; -import me.goodandevil.skyblock.message.MessageManager; -import me.goodandevil.skyblock.playerdata.PlayerData; -import me.goodandevil.skyblock.sound.SoundManager; -import me.goodandevil.skyblock.upgrade.Upgrade; -import me.goodandevil.skyblock.utils.version.Sounds; -import me.goodandevil.skyblock.utils.world.WorldBorder; -import me.goodandevil.skyblock.visit.Visit; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.*; public class Island { @@ -810,7 +796,7 @@ public class Island { messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration() .getString("Island.Unlock." + type + ".Message").replace( - "%cost%", String.valueOf(price))); + "%cost%", NumberUtil.formatNumberByDecimal(price))); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); player.setVelocity(player.getLocation().getDirection().multiply(-.50)); diff --git a/src/main/java/me/goodandevil/skyblock/utils/NumberUtil.java b/src/main/java/me/goodandevil/skyblock/utils/NumberUtil.java index 7ef36766..ed0c2ee8 100644 --- a/src/main/java/me/goodandevil/skyblock/utils/NumberUtil.java +++ b/src/main/java/me/goodandevil/skyblock/utils/NumberUtil.java @@ -1,5 +1,6 @@ package me.goodandevil.skyblock.utils; +import java.text.DecimalFormat; import java.util.Date; public final class NumberUtil { @@ -9,7 +10,7 @@ public final class NumberUtil { } public static String formatNumberByDecimal(double number) { - String withoutDecimal = String.valueOf(number), withDecimal = ""; + String withoutDecimal = new DecimalFormat("0.#").format(number), withDecimal = ""; if (withoutDecimal.contains(".")) { withDecimal = "." + withoutDecimal.split("\\.")[1]; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 21465fee..f4fc4b52 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -256,6 +256,9 @@ Island: # end world rather than the island world. # [!] Recommend to keep this enabled to prevent performance drop with chunk loading. Island: true + Bank: + Enable: true + AllowDecimals: true Admin: Structure: # Item Material used to select positions for a structure. diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 0206ae02..eff8ee2b 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -1,9 +1,9 @@ Command: PermissionDenied: Island: - Message: "&bSkyBlock &8| &cError&8: &eYou don't have permission to perform that command" + Message: "&bSkyBlock &8| &cError&8: &eYou don't have permission to perform that command." Admin: - Message: "&bSkyBlock &8| &cError&8: &eYou don't have permission to perform that command" + Message: "&bSkyBlock &8| &cError&8: &eYou don't have permission to perform that command." Island: Argument: Unrecognised: @@ -24,12 +24,14 @@ Command: Bank: Info: Message: "&f&oAllows you to access your islands bank." + Disabled: + Message: '&bSkyBlock &8| &cError&8: &eThe bank has been disabled by a server administrator.' Unknown: Message: "&bSkyBlock &8| &cError&8: &eYou are not currently on an island." Perm: Message: "&bSkyBlock &8| &cError&8: &eYou do not have permission to access this islands bank." Balance: - Message: "&bSkyBlock &8| &aInfo&8: &eYour islands balance is '&7$%balance%&e'." + Message: "&bSkyBlock &8| &aInfo&8: &eYour island's balance is '&7$%balance%&e'." Deposit: Message: "&bSkyBlock &8| &aInfo&8: &eYou successfully deposited '&7$%amount%&e'." Withdraw: @@ -40,6 +42,12 @@ Command: Message: "&bSkyBlock &8| &cError&8: &eThere is not enough money to withdraw." Short3: Message: "&bSkyBlock &8| &cError&8: &eYou did not specify an amount." + Short4: + Message: "&bSkyBlock &8| &cError&8: &eThe amount you specified is invalid." + Short5: + Message: "&bSkyBlock &8| &cError&8: &eThe amount you specified is negative, it must be positive." + Short6: + Message: "&bSkyBlock &8| &cError&8: &eYou must specify an amount that does not contain a decimal." Invalid: Message: "&bSkyBlock &8| &cError&8: &eInvalid: /island bank []" Unlock: