Bank & money stuff $$$

This commit is contained in:
Esophose 2019-03-10 15:44:30 -06:00
parent ac2a92fb4a
commit f1ad953644
7 changed files with 117 additions and 54 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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));

View File

@ -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];

View File

@ -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.

View File

@ -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 [<Deposit|Withdraw|Balance>]"
Unlock: