mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-27 04:35:46 +01:00
New Bank GUI
This commit is contained in:
parent
5526fbc3c5
commit
6800bc6b47
@ -1,9 +1,14 @@
|
||||
package com.songoda.skyblock.bank;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.NumberUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,17 +16,14 @@ import org.bukkit.entity.Player;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class BankManager {
|
||||
private static BankManager instance;
|
||||
|
||||
public static BankManager getInstance() {return instance == null ? instance = new BankManager() : instance;}
|
||||
|
||||
private HashMap<UUID, List<Transaction>> log;
|
||||
private final HashMap<UUID, List<Transaction>> log;
|
||||
|
||||
public FileConfiguration lang;
|
||||
|
||||
@ -101,4 +103,83 @@ public class BankManager {
|
||||
public List<Transaction> getTransactionList(UUID uuid) {
|
||||
return log.get(uuid);
|
||||
}
|
||||
|
||||
public BankResponse deposit(Player player, Island island, double amt, boolean admin) {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
// Make sure the amount is positive
|
||||
if (amt <= 0) {
|
||||
return BankResponse.NEGATIVE_AMOUNT;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return BankResponse.DECIMALS_NOT_ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!admin) {
|
||||
if (!EconomyManager.hasBalance(player, amt)) {
|
||||
return BankResponse.NOT_ENOUGH_MONEY;
|
||||
}
|
||||
|
||||
EconomyManager.withdrawBalance(player, amt);
|
||||
}
|
||||
|
||||
island.addToBank(amt);
|
||||
Transaction t = new Transaction();
|
||||
t.player = player;
|
||||
t.amount = (float) amt;
|
||||
t.timestamp = Calendar.getInstance().getTime();
|
||||
t.action = Transaction.Type.DEPOSIT;
|
||||
t.visibility = admin ? Transaction.Visibility.ADMIN : Transaction.Visibility.USER;
|
||||
this.addTransaction(player, t);
|
||||
return BankResponse.SUCCESS;
|
||||
}
|
||||
|
||||
public BankResponse withdraw(Player player, Island island, double amt, boolean admin) {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
// Make sure the amount is positive
|
||||
if (amt <= 0) {
|
||||
return BankResponse.NEGATIVE_AMOUNT;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return BankResponse.DECIMALS_NOT_ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!admin){
|
||||
if (amt > island.getBankBalance()) {
|
||||
return BankResponse.NOT_ENOUGH_MONEY;
|
||||
}
|
||||
|
||||
EconomyManager.deposit(player, amt);
|
||||
}
|
||||
|
||||
island.removeFromBank(amt);
|
||||
Transaction t = new Transaction();
|
||||
t.player = player;
|
||||
t.amount = (float) amt;
|
||||
t.timestamp = Calendar.getInstance().getTime();
|
||||
t.action = Transaction.Type.WITHDRAW;
|
||||
t.visibility = admin ? Transaction.Visibility.ADMIN : Transaction.Visibility.USER;
|
||||
this.addTransaction(player, t);
|
||||
return BankResponse.SUCCESS;
|
||||
}
|
||||
|
||||
public enum BankResponse{
|
||||
NOT_ENOUGH_MONEY,
|
||||
DECIMALS_NOT_ALLOWED,
|
||||
NEGATIVE_AMOUNT,
|
||||
SUCCESS
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.skyblock.bank;
|
||||
|
||||
import com.songoda.skyblock.menus.Ownership;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Date;
|
||||
@ -7,7 +8,18 @@ import java.util.Date;
|
||||
public class Transaction {
|
||||
|
||||
public OfflinePlayer player;
|
||||
public float ammount;
|
||||
public float amount;
|
||||
public Date timestamp;
|
||||
public Type action;
|
||||
public Visibility visibility;
|
||||
|
||||
public enum Type {
|
||||
WITHDRAW,
|
||||
DEPOSIT
|
||||
}
|
||||
|
||||
public enum Visibility {
|
||||
ADMIN,
|
||||
USER
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.songoda.skyblock.bank;
|
||||
|
||||
public enum Type {
|
||||
WITHDRAW,
|
||||
DEPOSIT
|
||||
}
|
@ -4,10 +4,13 @@ import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.gui.bank.GuiBank;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.player.OfflinePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -15,15 +18,16 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminBank extends SubCommand {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
@ -33,28 +37,21 @@ public class AdminBank extends SubCommand {
|
||||
|
||||
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Bank.Enable")) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Disabled.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.admin.Bank.Short01.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
skyblock.getGuiManager().showGUI(player, new GuiBank(skyblock, island, null, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (island == null && args.length <2) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.admin.Bank.NullIsland.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "balance":
|
||||
if (args.length <2) {
|
||||
messageManager.sendMessage(player, Objects.requireNonNull(configLoad.getString("Command.Island.Admin.Bank.Balance.Message")).replace("%player%", args[1]).replace("%bal%", "" + EconomyManager.formatEconomy(EconomyManager.getBalance(Bukkit.getOfflinePlayer(args[1])))));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message").replace("%player%", args[1]).replace("%bal%", "" + EconomyManager.formatEconomy(EconomyManager.getBalance(Bukkit.getOfflinePlayer(args[1])))));
|
||||
}else {
|
||||
messageManager.sendMessage(player, Objects.requireNonNull(configLoad.getString("Command.Island.Admin.Bank.Balance.Message")).replace("%player%", args[1]).replace("%bal%", "" + EconomyManager.formatEconomy(EconomyManager.getBalance(Bukkit.getOfflinePlayer(island.getOwnerUUID())))));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Balance.Message").replace("%player%", args[1]).replace("%bal%", "" + EconomyManager.formatEconomy(EconomyManager.getBalance(Bukkit.getOfflinePlayer(island.getOwnerUUID())))));
|
||||
}
|
||||
return;
|
||||
case "deposit":
|
||||
@ -62,7 +59,7 @@ public class AdminBank extends SubCommand {
|
||||
islandManager.getIslandByPlayer(Bukkit.getOfflinePlayer(Objects.requireNonNull(Bukkit.getPlayer(args[1])).getUniqueId())).addToBank(Double.parseDouble(args[2]));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.SuccesDeposit.Message").replace("%player%",args[1]).replace("%ammount%",EconomyManager.formatEconomy(Double.parseDouble(args[2]))));
|
||||
}else {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.admin.Bank.ByConsole.Message"));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
}
|
||||
return;
|
||||
case "withdraw":
|
||||
@ -70,12 +67,33 @@ public class AdminBank extends SubCommand {
|
||||
islandManager.getIslandByPlayer(Bukkit.getOfflinePlayer(Bukkit.getPlayer(args[1]).getUniqueId())).removeFromBank(Double.parseDouble(args[2]));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.SuccesWithdraw.Message").replace("%player%",args[1]).replace("%ammount%",EconomyManager.formatEconomy(Double.parseDouble(args[2]))));
|
||||
}else {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.admin.Bank.ByConsole.Message"));
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
}
|
||||
return;
|
||||
case "open":
|
||||
if(args.length == 2){
|
||||
Player targetPlayer = Bukkit.getServer().getPlayer(args[1]);
|
||||
UUID islandOwnerUUID;
|
||||
|
||||
if (targetPlayer == null) {
|
||||
OfflinePlayer targetPlayerOffline = new OfflinePlayer(args[1]);
|
||||
islandOwnerUUID = targetPlayerOffline.getOwner();
|
||||
} else {
|
||||
islandOwnerUUID = playerDataManager.getPlayerData(targetPlayer).getOwner();
|
||||
}
|
||||
|
||||
island = islandManager.getIsland(Bukkit.getOfflinePlayer(islandOwnerUUID));
|
||||
}
|
||||
if (island != null){
|
||||
skyblock.getGuiManager().showGUI(player, new GuiBank(skyblock, island, null, true));
|
||||
} else {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.NullIsland.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
configLoad.getString("Command.Island.admin.Bank.Unexpected.Message");
|
||||
return;
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Admin.Bank.Unexpected.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +119,7 @@ public class AdminBank extends SubCommand {
|
||||
islandManager.getIslandByPlayer(Bukkit.getOfflinePlayer(Bukkit.getPlayer(args[1]).getUniqueId())).addToBank(Double.parseDouble(args[2]));
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.SuccesDeposit.Message").replace("%player%",args[1]).replace("%ammount%",EconomyManager.formatEconomy(Double.parseDouble(args[2]))));
|
||||
}else {
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.admin.Bank.ByConsole.Message"));
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
}
|
||||
return;
|
||||
case "withdraw":
|
||||
@ -109,12 +127,11 @@ public class AdminBank extends SubCommand {
|
||||
islandManager.getIslandByPlayer(Bukkit.getOfflinePlayer(Bukkit.getPlayer(args[1]).getUniqueId())).removeFromBank(Double.parseDouble(args[2]));
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.SuccesWithdraw.Message").replace("%player%",args[1]).replace("%ammount%",EconomyManager.formatEconomy(Double.parseDouble(args[2]))));
|
||||
}else {
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.admin.Bank.ByConsole.Message"));
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
}
|
||||
return;
|
||||
default:
|
||||
configLoad.getString("Command.Island.admin.Bank.Unexpected.Message");
|
||||
return;
|
||||
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Bank.Unexpected.Message"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,14 @@
|
||||
package com.songoda.skyblock.command.commands.island;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.gui.bank.GuiBank;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import com.songoda.skyblock.menus.Bank;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.NumberUtil;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -23,8 +20,8 @@ public class BankCommand extends SubCommand {
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
@ -36,7 +33,16 @@ public class BankCommand extends SubCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
Bank.getInstance().open(player);
|
||||
Island island;
|
||||
island = islandManager.getIsland(player);
|
||||
|
||||
if (island == null) {
|
||||
skyblock.getSoundManager().playSound(player, CompatibleSound.BLOCK_GLASS_BREAK.getSound(), 1.0F, 1.0F);
|
||||
skyblock.getMessageManager().sendMessage(player, configLoad.getString("Command.Bank.Unknown"));
|
||||
return;
|
||||
}
|
||||
|
||||
skyblock.getGuiManager().showGUI(player, new GuiBank(skyblock, island, null, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,77 +2,205 @@ package com.songoda.skyblock.gui.bank;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.gui.AnvilGui;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.bank.BankManager;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.gui.GuiSignatureEditor;
|
||||
import com.songoda.skyblock.gui.GuiWelcomeEditor;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandMessage;
|
||||
import com.songoda.skyblock.island.IslandPermission;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.permission.BasicPermission;
|
||||
import com.songoda.skyblock.permission.PermissionManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.NumberUtil;
|
||||
import com.songoda.skyblock.visit.Visit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiBank extends Gui {
|
||||
private final SkyBlock plugin;
|
||||
private final BankManager bankManager;
|
||||
private final PermissionManager permissionManager;
|
||||
private final Island island;
|
||||
private final FileConfiguration languageLoad;
|
||||
private final FileManager.Config config;
|
||||
private final FileConfiguration config;
|
||||
private final Gui returnGui;
|
||||
private final boolean admin;
|
||||
|
||||
public GuiBank(SkyBlock plugin, Island island, Gui returnGui) {
|
||||
super(6, returnGui);
|
||||
this.plugin = plugin;
|
||||
public GuiBank(SkyBlock plugin, Island island, Gui returnGui, boolean admin) {
|
||||
super(2, returnGui);
|
||||
this.plugin = plugin;;
|
||||
this.bankManager = plugin.getBankManager();
|
||||
this.permissionManager = plugin.getPermissionManager();
|
||||
this.island = island;
|
||||
this.returnGui = returnGui;
|
||||
this.admin = admin;
|
||||
this.languageLoad = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
this.config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml"));
|
||||
setTitle(TextUtils.formatText(languageLoad.getString("Menu.Settings.Title"))); // TODO Title
|
||||
setDefaultItem(null);
|
||||
this.config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration();
|
||||
setDefaultItem(CompatibleMaterial.BLACK_STAINED_GLASS_PANE.getItem());
|
||||
setTitle(TextUtils.formatText("Bank"));
|
||||
paint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(GuiManager manager, Player player) {
|
||||
updateItem(13, // Balance
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Balance.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Balance.Lore")
|
||||
.replace("%balance", String.valueOf(island.getBankBalance()))));
|
||||
super.onOpen(manager, player);
|
||||
}
|
||||
|
||||
public void paint() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
setDefaultItem(CompatibleMaterial.BLACK_STAINED_GLASS_PANE.getItem());
|
||||
setActionForRange(0, 0, 1, 8, null);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, // Exit
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
event.player.closeInventory();
|
||||
});
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, // Exit
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
event.player.closeInventory();
|
||||
});
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, // Transaction log
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
guiManager.showGUI(event.player, new GuiBankTransaction(plugin, island, this));
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Log.Displayname"))), (event) -> {
|
||||
guiManager.showGUI(event.player, new GuiBankTransaction(plugin, island, this, admin));
|
||||
});
|
||||
|
||||
setButton(10, GuiUtils.createButtonItem(CompatibleMaterial.RED_DYE, // Deposit
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Deposit.Displayname"))), (event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setAction((e -> {
|
||||
MessageManager messageManager = plugin.getMessageManager();
|
||||
|
||||
double amount;
|
||||
try {
|
||||
amount = Double.parseDouble(gui.getInputText().trim());
|
||||
} catch (NumberFormatException e1) {
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short4.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
return;
|
||||
}
|
||||
BankManager.BankResponse response = bankManager.deposit(e.player, island, amount, admin);
|
||||
|
||||
switch(response){
|
||||
case NOT_ENOUGH_MONEY:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short2.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case DECIMALS_NOT_ALLOWED:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short6.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case NEGATIVE_AMOUNT:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short5.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case SUCCESS:
|
||||
CompatibleSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(e.player);
|
||||
messageManager.sendMessage(e.player, Objects.requireNonNull(languageLoad.getString("Command.Island.Bank.Deposit.Message")).replace(
|
||||
"%amount%", NumberUtil.formatNumberByDecimal(amount)));
|
||||
break;
|
||||
}
|
||||
|
||||
e.player.closeInventory();
|
||||
// paint();
|
||||
guiManager.showGUI(event.player, this);
|
||||
}));
|
||||
|
||||
ItemStack input = CompatibleMaterial.PAPER.getItem();
|
||||
ItemMeta im = input.getItemMeta();
|
||||
if(im != null){
|
||||
im.setDisplayName(TextUtils.formatText(languageLoad.getString("Menu.Bank.Words.Amount")));
|
||||
input.setItemMeta(im);
|
||||
}
|
||||
|
||||
gui.setInput(input);
|
||||
gui.setTitle(TextUtils.formatText(languageLoad.getString("Menu.Bank.Words.Deposit")));
|
||||
guiManager.showGUI(event.player, gui);
|
||||
}));
|
||||
|
||||
setItem(13, GuiUtils.createButtonItem(CompatibleMaterial.GOLD_INGOT, // Balance
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))));
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Balance.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Balance.Lore")
|
||||
.replace("%balance", String.valueOf(island.getBankBalance())))));
|
||||
|
||||
setButton(16, GuiUtils.createButtonItem(CompatibleMaterial.GREEN_DYE, // WithDraw
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Withdraw.Displayname"))), (event) -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setAction((e -> {
|
||||
MessageManager messageManager = plugin.getMessageManager();
|
||||
|
||||
double amount;
|
||||
try {
|
||||
amount = Double.parseDouble(gui.getInputText().trim());
|
||||
} catch (NumberFormatException e1) {
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short4.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
BankManager.BankResponse response = bankManager.withdraw(e.player, island, amount, admin);
|
||||
|
||||
switch(response){
|
||||
case NOT_ENOUGH_MONEY:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short2.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case DECIMALS_NOT_ALLOWED:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short6.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case NEGATIVE_AMOUNT:
|
||||
messageManager.sendMessage(e.player, languageLoad.getString("Command.Island.Bank.Short5.Message"));
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(e.player);
|
||||
break;
|
||||
case SUCCESS:
|
||||
CompatibleSound.ENTITY_EXPERIENCE_ORB_PICKUP.play(e.player);
|
||||
messageManager.sendMessage(e.player, Objects.requireNonNull(languageLoad.getString("Command.Island.Bank.Withdraw.Message")).replace(
|
||||
"%amount%", NumberUtil.formatNumberByDecimal(amount)));
|
||||
break;
|
||||
}
|
||||
|
||||
e.player.closeInventory();
|
||||
// paint();
|
||||
guiManager.showGUI(event.player, this);
|
||||
}));
|
||||
|
||||
ItemStack input = CompatibleMaterial.PAPER.getItem();
|
||||
ItemMeta im = input.getItemMeta();
|
||||
if(im != null){
|
||||
im.setDisplayName(TextUtils.formatText(languageLoad.getString("Menu.Bank.Words.Amount")));
|
||||
input.setItemMeta(im);
|
||||
}
|
||||
|
||||
gui.setInput(input);
|
||||
gui.setTitle(TextUtils.formatText(languageLoad.getString("Menu.Bank.Words.Withdraw")));
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,11 @@ import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiBankTransaction extends Gui {
|
||||
@ -24,14 +27,16 @@ public class GuiBankTransaction extends Gui {
|
||||
private final Gui returnGui;
|
||||
private final int transactions;
|
||||
private final List<Transaction> transactionList;
|
||||
private final boolean admin;
|
||||
|
||||
public GuiBankTransaction(SkyBlock plugin, Island island, Gui returnGui) {
|
||||
public GuiBankTransaction(SkyBlock plugin, Island island, Gui returnGui, boolean admin) {
|
||||
super(returnGui);
|
||||
this.plugin = plugin;
|
||||
this.bankManager = plugin.getBankManager();
|
||||
this.transactionList = bankManager.getTransactions(island.getOwnerUUID());
|
||||
this.transactions = this.transactionList.size();
|
||||
this.returnGui = returnGui;
|
||||
this.admin = admin;
|
||||
this.languageLoad = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
this.config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml"));
|
||||
@ -41,10 +46,10 @@ public class GuiBankTransaction extends Gui {
|
||||
} else if(transactions > 4*9){
|
||||
setRows(6);
|
||||
} else {
|
||||
setRows(transactions%9+1);
|
||||
setRows((int) (Math.ceil((double) transactions / 9d)+1));
|
||||
}
|
||||
|
||||
setTitle(TextUtils.formatText(languageLoad.getString("Menu.Settings.Title"))); // TODO Title
|
||||
setTitle(TextUtils.formatText(languageLoad.getString("Menu.Bank.Transactions.Title")));
|
||||
setDefaultItem(null);
|
||||
paint();
|
||||
}
|
||||
@ -55,19 +60,28 @@ public class GuiBankTransaction extends Gui {
|
||||
setActionForRange(0, 0, 1, 8, null);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, // Exit
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, // Exit
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
|
||||
setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING, // Info
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"))));
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Transactions.Info.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Transactions.Info.Lore")
|
||||
.replace("%totalTransactions", String.valueOf(transactions)))));
|
||||
|
||||
if(transactions > 0){
|
||||
this.pages = (int) Math.max(1, Math.ceil((double) transactions / 36d));
|
||||
|
||||
if (page != 1)
|
||||
setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Last.Displayname"))),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Last.Displayname"))),
|
||||
(event) -> {
|
||||
page--;
|
||||
paint();
|
||||
@ -75,13 +89,13 @@ public class GuiBankTransaction extends Gui {
|
||||
|
||||
if (page != pages)
|
||||
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Next.Displayname"))),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Next.Displayname"))),
|
||||
(event) -> {
|
||||
page++;
|
||||
paint();
|
||||
});
|
||||
|
||||
for (int i = 9; i < 45; i++) { // TODO dynamic dimension!
|
||||
for (int i = 9; i < ((getRows()-1)*9)+9; i++) { // TODO check dynamic dimension!
|
||||
int current = ((page - 1) * 36) - 9;
|
||||
if (current + i >= transactions) {
|
||||
setItem(i, null);
|
||||
@ -91,17 +105,69 @@ public class GuiBankTransaction extends Gui {
|
||||
if (transaction == null) continue;
|
||||
|
||||
ItemStack is = null;
|
||||
ItemMeta im;
|
||||
String name = "";
|
||||
SimpleDateFormat formatDate = new SimpleDateFormat(languageLoad.getString("Menu.Bank.Item.Transactions.DateTimeFormat", "dd/MM/yyyy HH:mm:ss"));
|
||||
switch(transaction.action){
|
||||
case WITHDRAW:
|
||||
is = CompatibleMaterial.GREEN_DYE.getItem();
|
||||
is = CompatibleMaterial.RED_DYE.getItem();
|
||||
im = is.getItemMeta();
|
||||
if(im != null){
|
||||
|
||||
im.setDisplayName(TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Transactions.Withdraw.DisplayName")
|
||||
.replace("%dateTime", formatDate.format(transaction.timestamp))));
|
||||
List<String> lore = new ArrayList<>();
|
||||
switch (transaction.visibility){
|
||||
case ADMIN:
|
||||
name = languageLoad.getString("Menu.Bank.Word.Admin");
|
||||
if(admin){
|
||||
name += " " + transaction.player.getName();
|
||||
}
|
||||
break;
|
||||
case USER:
|
||||
name = transaction.player.getName();
|
||||
break;
|
||||
}
|
||||
lore.add(TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Transactions.Withdraw.Format")
|
||||
.replace("%playerName", name)
|
||||
.replace("%amount", String.valueOf(transaction.amount))));
|
||||
im.setLore(lore);
|
||||
is.setItemMeta(im);
|
||||
}
|
||||
break;
|
||||
case DEPOSIT:
|
||||
is = CompatibleMaterial.RED_DYE.getItem();
|
||||
is = CompatibleMaterial.GREEN_DYE.getItem();
|
||||
im = is.getItemMeta();
|
||||
if(im != null){
|
||||
|
||||
im.setDisplayName(TextUtils.formatText(languageLoad.getString("Menu.Bank.Item.Transactions.Deposit.DisplayName")
|
||||
.replace("%dateTime", formatDate.format(transaction.timestamp))));
|
||||
List<String> lore = new ArrayList<>();
|
||||
switch (transaction.visibility){
|
||||
case ADMIN:
|
||||
name = languageLoad.getString("Menu.Bank.Word.Admin");
|
||||
if(admin){
|
||||
name += transaction.player.getName();
|
||||
}
|
||||
break;
|
||||
case USER:
|
||||
name = transaction.player.getName();
|
||||
break;
|
||||
}
|
||||
lore.add(TextUtils.formatText(languageLoad.getString("Menu.Bank.Transactions.Deposit.Format")
|
||||
.replace("%playerName", name)
|
||||
.replace("%amount", String.valueOf(transaction.amount))));
|
||||
im.setLore(lore);
|
||||
is.setItemMeta(im);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO set item meta
|
||||
setItem(i, is);
|
||||
}
|
||||
} else {
|
||||
setItem(31, CompatibleMaterial.BARRIER.getItem());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,326 +0,0 @@
|
||||
package com.songoda.skyblock.menus;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.gui.AnvilGui;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.core.input.ChatPrompt;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.bank.BankManager;
|
||||
import com.songoda.skyblock.bank.Transaction;
|
||||
import com.songoda.skyblock.bank.Type;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.generator.GeneratorMaterial;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.AbstractAnvilGUI;
|
||||
import com.songoda.skyblock.utils.NumberUtil;
|
||||
import com.songoda.skyblock.utils.item.MenuClickRegistry;
|
||||
import com.songoda.skyblock.utils.item.nInventoryUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Bank {
|
||||
|
||||
private static Bank instance;
|
||||
|
||||
private BankManager bankManager;
|
||||
|
||||
private IslandManager islandManager;
|
||||
|
||||
public static Bank getInstance() {
|
||||
return instance == null ? instance = new Bank() : instance;
|
||||
}
|
||||
|
||||
public Bank() {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
bankManager = BankManager.getInstance();
|
||||
MenuClickRegistry.getInstance().register((executors) -> {
|
||||
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Exit.Displayname", CompatibleMaterial.OAK_FENCE_GATE), (inst, player, e) -> {
|
||||
inst.getSoundManager().playSound(player, CompatibleSound.BLOCK_GLASS_BREAK.getSound(), 1.0F, 1.0F);
|
||||
|
||||
e.setWillClose(true);
|
||||
e.setWillDestroy(false);
|
||||
});
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Barrier.Displayname", CompatibleMaterial.BLACK_STAINED_GLASS_PANE), (inst, player, e) -> {
|
||||
inst.getSoundManager().playSound(player, CompatibleSound.BLOCK_GLASS_BREAK.getSound(), 1.0F, 1.0F);
|
||||
|
||||
e.setWillClose(false);
|
||||
e.setWillDestroy(false);
|
||||
});
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Deposit.Displayname", CompatibleMaterial.DIRT), (inst, player, e) -> {
|
||||
inst.getSoundManager().playSound(player, CompatibleSound.ENTITY_BAT_TAKEOFF.getSound(), 1.0F, 1.0F);
|
||||
//Deposit money
|
||||
Island island = islandManager.getIsland(player);
|
||||
if (island != null) {
|
||||
SelectInputMethod.getInstance().open(player, "Deposit", (action) -> {
|
||||
if (action == InputMethodSelectlistener.InputMethod.CANCELED) {
|
||||
Bukkit.getScheduler().runTask(skyblock, () ->
|
||||
this.open(player));
|
||||
} else if (action == InputMethodSelectlistener.InputMethod.ALL) {
|
||||
deposit(player, island, EconomyManager.getBalance(Bukkit.getOfflinePlayer(player.getUniqueId())));
|
||||
} else {
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event1 -> {
|
||||
if (event1.getSlot() == AbstractAnvilGUI.AnvilSlot.OUTPUT) {
|
||||
if (!(player.hasPermission("fabledskyblock.island.bank") // TODO check correct permissions - Fabrimat
|
||||
|| player.hasPermission("fabledskyblock.*"))) {
|
||||
messageManager.sendMessage(player, "No permission"); // TODO language.yml - Fabrimat
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(),
|
||||
1.0F, 1.0F);
|
||||
} else if (!event1.getName().replace(" ", "")
|
||||
.matches("^[a-zA-Z0-9|.]+$")) {
|
||||
messageManager.sendMessage(player, "Invalid characters"); // TODO language.yml - Fabrimat
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(),
|
||||
1.0F, 1.0F);
|
||||
} else if (!event1.getName().matches("-?\\d+(?:\\.\\d+)?")) {
|
||||
messageManager.sendMessage(player, "Only numbers allowed"); // TODO language.yml - Fabrimat
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(),
|
||||
1.0F, 1.0F);
|
||||
} else {
|
||||
double amount;
|
||||
|
||||
try {
|
||||
amount = Double.parseDouble(event1.getName());
|
||||
} catch (NumberFormatException e1) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short4.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
deposit(player, island, amount);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
Bukkit.getServer().getScheduler()
|
||||
.runTaskLater(skyblock, () -> open(player), 1L);
|
||||
}
|
||||
|
||||
event1.setWillClose(true);
|
||||
event1.setWillDestroy(true);
|
||||
} else {
|
||||
event1.setWillClose(false);
|
||||
event1.setWillDestroy(false);
|
||||
}
|
||||
});
|
||||
|
||||
ItemStack is = CompatibleMaterial.NAME_TAG.getItem();
|
||||
ItemMeta im = is.getItemMeta();
|
||||
im.setDisplayName("Amount"); // TODO language.yml - Fabrimat
|
||||
is.setItemMeta(im);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, is);
|
||||
gui.open();
|
||||
// ---
|
||||
/*ChatPrompt.showPrompt(skyblock, player, (event) -> {
|
||||
if (event.getMessage().equals(""))
|
||||
return;
|
||||
|
||||
double amount;
|
||||
try {
|
||||
amount = Double.parseDouble(event.getMessage());
|
||||
} catch (NumberFormatException e1) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short4.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
deposit(player, island, amount);
|
||||
});*/
|
||||
}
|
||||
});
|
||||
}
|
||||
e.setWillClose(true);
|
||||
e.setCancelled(false);
|
||||
});
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Withdraw.Displayname", CompatibleMaterial.GLISTERING_MELON_SLICE), (inst, player, e) -> {
|
||||
inst.getSoundManager().playSound(player, CompatibleSound.ENTITY_BAT_TAKEOFF.getSound(), 1.0F, 1.0F);
|
||||
//Withdraw money
|
||||
Island island;
|
||||
island = islandManager.getIsland(player);
|
||||
if (island != null) {
|
||||
SelectInputMethod.getInstance().open(player, "Withdraw", (action) -> {
|
||||
if (action == InputMethodSelectlistener.InputMethod.CANCELED) {
|
||||
Bukkit.getScheduler().runTask(skyblock, () -> {
|
||||
this.open(player);
|
||||
});
|
||||
} else if (action == InputMethodSelectlistener.InputMethod.ALL) {
|
||||
withdraw(player, island, island.getBankBalance());
|
||||
} else {
|
||||
ChatPrompt.showPrompt(skyblock, player, (event) -> {
|
||||
if (event.getMessage().equals(""))
|
||||
return;
|
||||
double amount = 0;
|
||||
try {
|
||||
amount = Double.parseDouble(event.getMessage());
|
||||
} catch (NumberFormatException e1) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short4.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
}
|
||||
withdraw(player, island, amount);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
e.setWillClose(true);
|
||||
e.setCancelled(false);
|
||||
});
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Log.Displayname", CompatibleMaterial.BOOK), (inst, player, e) -> {
|
||||
inst.getSoundManager().playSound(player, CompatibleSound.BLOCK_GLASS_BREAK.getSound(), 1.0F, 1.0F);
|
||||
e.setWillClose(false);
|
||||
e.setWillDestroy(false);
|
||||
});
|
||||
executors.put(MenuClickRegistry.RegistryKey.fromLanguageFile("Menu.Bank.Item.Balance.Displayname", CompatibleMaterial.STICK), (inst, player, e) -> {
|
||||
e.setWillClose(false);
|
||||
e.setWillDestroy(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
Island island;
|
||||
island = islandManager.getIsland(player);
|
||||
|
||||
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
nInventoryUtil nInv = new nInventoryUtil(player, event -> MenuClickRegistry.getInstance().dispatch(player, event));
|
||||
|
||||
if (island == null) {
|
||||
skyblock.getSoundManager().playSound(player, CompatibleSound.BLOCK_GLASS_BREAK.getSound(), 1.0F, 1.0F);
|
||||
skyblock.getMessageManager().sendMessage(player, configLoad.getString("Command.Bank.Unknown"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Glass panes barriers
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.BLACK_STAINED_GLASS_PANE.getItem(), configLoad.getString("Menu.Bank.Item.Barrier.Displayname"), null, null, null, null), 0, 2, 5, 8,
|
||||
1, 2, 3, 5, 6, 7, 9, 11, 12, 14, 15, 17);
|
||||
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.OAK_FENCE_GATE.getItem(), configLoad.getString("Menu.Bank.Item.Exit.Displayname"),
|
||||
configLoad.getStringList("Menu.Bank.Item.Exit.Lore"), null, null, null), 0, 8);
|
||||
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.BOOK.getItem(), configLoad.getString("Menu.Bank.Item.Log.Displayname"),
|
||||
bankManager.getTransactions(player), null, null, null), 4);
|
||||
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.DIRT.getItem(), configLoad.getString("Menu.Bank.Item.Deposit.Displayname"),
|
||||
configLoad.getStringList("Menu.Bank.Item.Deposit.Lore"), null, null, null), 10);
|
||||
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.GLISTERING_MELON_SLICE.getItem(), configLoad.getString("Menu.Bank.Item.Withdraw.Displayname"),
|
||||
configLoad.getStringList("Menu.Bank.Item.Withdraw.Lore"), null, null, null), 16);
|
||||
|
||||
nInv.addItem(nInv.createItem(CompatibleMaterial.STICK.getItem(), configLoad.getString("Menu.Bank.Item.Balance.Displayname"),
|
||||
BankManager.getInstance().getBalanceLore(player), null, null, null), 13);
|
||||
|
||||
|
||||
nInv.setTitle(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(configLoad.getString("Menu.Bank.Title"))));
|
||||
nInv.setRows(2);
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(skyblock, nInv::open);
|
||||
}
|
||||
|
||||
private void deposit(Player player, Island island, double amt) {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
// Make sure the amount is positive
|
||||
if (amt <= 0) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short5.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 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, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EconomyManager.hasBalance(player, amt)) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyManager.withdrawBalance(player, amt);
|
||||
island.addToBank(amt);
|
||||
Transaction t = new Transaction();
|
||||
t.player = player;
|
||||
t.ammount = (float) amt;
|
||||
t.timestamp = Calendar.getInstance().getTime();
|
||||
t.action = Type.DEPOSIT;
|
||||
bankManager.addTransaction(player, t);
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Deposit.Message").replace(
|
||||
"%amount%", NumberUtil.formatNumberByDecimal(amt)));
|
||||
}
|
||||
|
||||
private void withdraw(Player player, Island island, double amt) {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
FileManager.Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
// Make sure the amount is positive
|
||||
if (amt <= 0) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short5.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 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, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (amt > island.getBankBalance()) {
|
||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short2.Message"));
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyManager.deposit(player, amt);
|
||||
island.removeFromBank(amt);
|
||||
Transaction t = new Transaction();
|
||||
t.player = player;
|
||||
t.ammount = (float) amt;
|
||||
t.timestamp = Calendar.getInstance().getTime();
|
||||
t.action = Type.WITHDRAW;
|
||||
bankManager.addTransaction(player, t);
|
||||
messageManager.sendMessage(player, Objects.requireNonNull(configLoad.getString("Command.Island.Bank.Withdraw.Message")).replace(
|
||||
"%amount%", NumberUtil.formatNumberByDecimal(amt)));
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ package com.songoda.skyblock.playerdata;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.bank.BankManager;
|
||||
import com.songoda.skyblock.bank.Transaction;
|
||||
import com.songoda.skyblock.bank.Type;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.confirmation.Confirmation;
|
||||
import com.songoda.skyblock.menus.MenuType;
|
||||
@ -59,12 +58,18 @@ public class PlayerData {
|
||||
FileConfiguration configLoad = getConfig().getFileConfiguration();
|
||||
for (int i = 0;i< configLoad.getInt("Bank.Transactions.Size");i++) {
|
||||
Transaction t = new Transaction();
|
||||
t.action = Type.valueOf(configLoad.getString("Bank.Transactions."+i+".Action"));
|
||||
t.ammount = Float.parseFloat(Objects.requireNonNull(configLoad.getString("Bank.Transactions." + i + ".Amount")));
|
||||
t.action = Transaction.Type.valueOf(configLoad.getString("Bank.Transactions."+i+".Action"));
|
||||
t.amount = Float.parseFloat(Objects.requireNonNull(configLoad.getString("Bank.Transactions." + i + ".Amount")));
|
||||
t.player = Bukkit.getOfflinePlayer(UUID.fromString(Objects.requireNonNull(configLoad.getString("Bank.Transactions." + i + ".Player"))));
|
||||
Date d = new Date();
|
||||
d.setTime(configLoad.getLong("Bank.Transactions."+i+".Date"));
|
||||
t.timestamp = d;
|
||||
String visibility = configLoad.getString("Bank.Transactions."+i+".Visibility");
|
||||
if(visibility != null){
|
||||
t.visibility = Transaction.Visibility.valueOf(visibility);
|
||||
} else {
|
||||
t.visibility = Transaction.Visibility.USER; // Defaulting this as it's a new field
|
||||
}
|
||||
transactions.add(t);
|
||||
}
|
||||
}
|
||||
@ -264,9 +269,10 @@ public class PlayerData {
|
||||
for (int i = 0; i < transactions.size(); i++) {
|
||||
Transaction t = transactions.get(i);
|
||||
configLoad.set("Bank.Transactions." + i + ".Action", t.action.name());
|
||||
configLoad.set("Bank.Transactions." + i + ".Amount", t.ammount);
|
||||
configLoad.set("Bank.Transactions." + i + ".Amount", t.amount);
|
||||
configLoad.set("Bank.Transactions." + i + ".Player", t.player.getUniqueId().toString());
|
||||
configLoad.set("Bank.Transactions." + i + ".Date", t.timestamp.getTime());
|
||||
configLoad.set("Bank.Transactions." + i + ".Visibility", t.visibility.name());
|
||||
}
|
||||
}else {
|
||||
configLoad.set("Bank.Transactions.Size", 0);
|
||||
|
@ -3198,21 +3198,43 @@ Menu:
|
||||
Title: 'Bank'
|
||||
Item:
|
||||
Exit:
|
||||
Displayname: 'Exit'
|
||||
Lore: 'Exits the Menu'
|
||||
Displayname: '&cExit'
|
||||
Lore: '&7Exits the Menu'
|
||||
Barrier:
|
||||
Displayname: '&cBank'
|
||||
Log:
|
||||
Displayname: 'Transaction Log'
|
||||
Empty: 'Looks like you haven''t got transactions'
|
||||
Displayname: '&fTransaction Log'
|
||||
Empty: '&7Looks like you haven''t got transactions'
|
||||
Deposit:
|
||||
Displayname: 'Deposit'
|
||||
Lore: 'Click to deposit your money. Everything or a custom ammount.'
|
||||
Displayname: '&fDeposit'
|
||||
Lore: '&7Click to deposit your money. Everything or a custom amount.'
|
||||
Withdraw:
|
||||
Displayname: 'Withdraw'
|
||||
Lore: 'Click to withdraw your money. Everything or a custom ammount.'
|
||||
Displayname: '&fWithdraw'
|
||||
Lore: '&7Click to withdraw your money. Everything or a custom amount.'
|
||||
Balance:
|
||||
Displayname: 'Balance'
|
||||
Displayname: '&fBalance'
|
||||
Lore: '&7Bank balance: &6$%balance'
|
||||
Next:
|
||||
Displayname: '&aNext Page'
|
||||
Last:
|
||||
Displayname: '&aPrevious Page'
|
||||
Transactions:
|
||||
Info:
|
||||
Displayname: '&fInfo'
|
||||
Lore: '&7Total transactions: %totalTransactions'
|
||||
Title: 'Transactions'
|
||||
Withdraw:
|
||||
DisplayName: '&c%dateTime'
|
||||
Format: '&7 %playerName withdrawn %amount'
|
||||
Deposit:
|
||||
DisplayName: '&a%dateTime'
|
||||
Format: '&7 %playerName deposited %amount'
|
||||
Admin: '&cAdmin&7'
|
||||
DateTimeFormat: 'dd/MM/yyyy HH:mm:ss'
|
||||
Words:
|
||||
Withdraw: 'Withdraw'
|
||||
Deposit: 'Deposit'
|
||||
Amount: 'Amount'
|
||||
Input:
|
||||
Title: 'Select amount.'
|
||||
Item:
|
||||
|
Loading…
Reference in New Issue
Block a user