diff --git a/Account.java b/Account.java index 47c45d2..40ff105 100644 --- a/Account.java +++ b/Account.java @@ -6,7 +6,7 @@ public class Account { public Account(int Balance){ // Account Balance 초기화 m_Balance = Balance; } - + public void setBalance(int Amount){ m_Balance = Amount;} public int getBalance(){ return m_Balance; } //잔액 return public void credit(int Amount){ // 입금 m_Balance +=Amount; diff --git a/AccountArray.java b/AccountArray.java index 8084591..111b4b6 100644 --- a/AccountArray.java +++ b/AccountArray.java @@ -24,4 +24,9 @@ public class AccountArray { public void putAccountInfo(UUID uuid, int Amount) { //AccountArray 생성 m_AccountArray.put(uuid, new Account(Amount)); } + + public void setAccountInfo(UUID uuid, int Amount) { + Account m_Account = m_AccountArray.get(uuid); + m_Account.setBalance(Amount); + } } diff --git a/AccountEventHandler.java b/AccountEventHandler.java new file mode 100644 index 0000000..fa4e551 --- /dev/null +++ b/AccountEventHandler.java @@ -0,0 +1,58 @@ +package org.poopki.duckdns.user_db; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class AccountEventHandler implements CommandExecutor { + AccountArray m_AccountArray; + public AccountEventHandler(AccountArray AA){ + m_AccountArray = AA; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + + if (args.length != 0) { + switch (args[0]) { + case "계좌설정": { + if (p.isOp()) { + if (args[1] != null) { + Player op = Bukkit.getPlayer(args[1]); + p.sendMessage("계좌 UUID: " + op.getUniqueId()); + if (op != null) { + m_AccountArray.setAccountInfo(op.getUniqueId(), Integer.parseInt(args[2])); + } else { + p.sendMessage("잘못된 계좌입니다."); + } + } + } else { + p.sendMessage("OP만 실행 가능한 명령어"); + } + } + case "잔액": { + p.sendMessage("잔액: " + m_AccountArray.getAccountInfo(p.getUniqueId()) + "원"); + } + case "이체": { + if (args[1] != null) { + Player op = Bukkit.getPlayer(args[1]); + if (op != null) { + m_AccountArray.transfer(p.getUniqueId(), op.getUniqueId(), Integer.parseInt(args[2])); + } else { + p.sendMessage("잘못된 계좌입니다."); + } + } else { + p.sendMessage("대상이 지정되지 않음"); + } + } + default: { + p.sendMessage("잘못된 명령어"); + } + } + + } + return false; + } +} diff --git a/User_DB.java b/User_DB.java index 9c38e24..6bdbed9 100644 --- a/User_DB.java +++ b/User_DB.java @@ -24,8 +24,9 @@ public final class User_DB extends JavaPlugin implements Listener { } catch (SQLException e) { throw new RuntimeException(e); } - + getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance)); getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_AccountArrayInstance),this); + } @Override