diff --git a/AccountArray.java b/AccountArray.java index 111b4b6..a0fb005 100644 --- a/AccountArray.java +++ b/AccountArray.java @@ -7,13 +7,15 @@ import java.util.UUID; public class AccountArray { private static Map m_AccountArray = new HashMap(); - public void transfer(UUID Src, UUID Des, int Amount){ // 송금 method + public boolean transfer(UUID Src, UUID Des, int Amount){ // 송금 method Account m_Src = m_AccountArray.get(Src); Account m_Des = m_AccountArray.get(Des); if(m_Src.withdraw(Amount)){ //인출 성공시 입금 m_Des.credit(Amount); + return true; } + return false; } public int getAccountInfo(UUID uuid) { // DB backup시 account 정보 접근 method diff --git a/AccountEventHandler.java b/AccountEventHandler.java index fa4e551..0f7f06e 100644 --- a/AccountEventHandler.java +++ b/AccountEventHandler.java @@ -11,19 +11,37 @@ public class AccountEventHandler implements CommandExecutor { public AccountEventHandler(AccountArray AA){ m_AccountArray = AA; } + public static boolean isStringDouble(String s) { + try { + Double.parseDouble(s); + return true; + } catch (NumberFormatException e) { + return false; + } + } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Player p = (Player) sender; if (args.length != 0) { switch (args[0]) { - case "계좌설정": { + 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])); + try{ + if(isStringDouble(args[2])){ + m_AccountArray.setAccountInfo(op.getUniqueId(), Integer.parseInt(args[2])); + p.sendMessage(op.getName()+"님의 잔액을"+Integer.parseInt(args[2])+"원으로 설정하였습니다."); + } + else { + p.sendMessage("설정 금액은 숫자만 가능합니다."); + } + } catch(Exception e){ + p.sendMessage("설정 대상의 닉네임을 모두 작성해야합니다."); + } + } else { p.sendMessage("잘못된 계좌입니다."); } @@ -31,21 +49,36 @@ public class AccountEventHandler implements CommandExecutor { } else { p.sendMessage("OP만 실행 가능한 명령어"); } + break; } case "잔액": { p.sendMessage("잔액: " + m_AccountArray.getAccountInfo(p.getUniqueId()) + "원"); + break; } case "이체": { - if (args[1] != null) { + if (args.length > 1) { Player op = Bukkit.getPlayer(args[1]); if (op != null) { - m_AccountArray.transfer(p.getUniqueId(), op.getUniqueId(), Integer.parseInt(args[2])); + if(isStringDouble(args[2])){ + try{ + boolean temp = m_AccountArray.transfer(p.getUniqueId(), op.getUniqueId(), Integer.parseInt(args[2])); + if(temp) + p.sendMessage(op.getName()+"님 에게 "+Integer.parseInt(args[2])+"원을 이체하였습니다."); + else + p.sendMessage("잔액이 부족합니다."); + }catch (Exception e){ + p.sendMessage("이체 대상의 닉네임을 모두 작성해야합니다."); + } + } + else + p.sendMessage("이체 금액은 숫자만 가능합니다."); } else { p.sendMessage("잘못된 계좌입니다."); } } else { - p.sendMessage("대상이 지정되지 않음"); + p.sendMessage("이체 대상이 지정되지 않았습니다."); } + break; } default: { p.sendMessage("잘못된 명령어"); @@ -53,6 +86,9 @@ public class AccountEventHandler implements CommandExecutor { } } + else{ + p.sendMessage("명령어를 입력하세요(잔액 | 이체)"); + } return false; } } diff --git a/Command.java b/Command.java deleted file mode 100644 index c411370..0000000 --- a/Command.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.poopki.duckdns.user_db; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -public class Command implements CommandExecutor { -}