ArrayEvent handler - minor bug clear

Command
poopki 3 years ago
parent 1b76db907b
commit bdebf993bd
  1. 4
      AccountArray.java
  2. 48
      AccountEventHandler.java
  3. 10
      Command.java

@ -7,13 +7,15 @@ import java.util.UUID;
public class AccountArray { public class AccountArray {
private static Map<UUID, Account> m_AccountArray = new HashMap<UUID, Account>(); private static Map<UUID, Account> m_AccountArray = new HashMap<UUID, Account>();
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_Src = m_AccountArray.get(Src);
Account m_Des = m_AccountArray.get(Des); Account m_Des = m_AccountArray.get(Des);
if(m_Src.withdraw(Amount)){ //인출 성공시 입금 if(m_Src.withdraw(Amount)){ //인출 성공시 입금
m_Des.credit(Amount); m_Des.credit(Amount);
return true;
} }
return false;
} }
public int getAccountInfo(UUID uuid) { // DB backup시 account 정보 접근 method public int getAccountInfo(UUID uuid) { // DB backup시 account 정보 접근 method

@ -11,19 +11,37 @@ public class AccountEventHandler implements CommandExecutor {
public AccountEventHandler(AccountArray AA){ public AccountEventHandler(AccountArray AA){
m_AccountArray = AA; m_AccountArray = AA;
} }
public static boolean isStringDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length != 0) { if (args.length != 0) {
switch (args[0]) { switch (args[0]) {
case "계좌설정": { case "설정": {
if (p.isOp()) { if (p.isOp()) {
if (args[1] != null) { if (args[1] != null) {
Player op = Bukkit.getPlayer(args[1]); Player op = Bukkit.getPlayer(args[1]);
p.sendMessage("계좌 UUID: " + op.getUniqueId());
if (op != null) { 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 { } else {
p.sendMessage("잘못된 계좌입니다."); p.sendMessage("잘못된 계좌입니다.");
} }
@ -31,21 +49,36 @@ public class AccountEventHandler implements CommandExecutor {
} else { } else {
p.sendMessage("OP만 실행 가능한 명령어"); p.sendMessage("OP만 실행 가능한 명령어");
} }
break;
} }
case "잔액": { case "잔액": {
p.sendMessage("잔액: " + m_AccountArray.getAccountInfo(p.getUniqueId()) + "원"); p.sendMessage("잔액: " + m_AccountArray.getAccountInfo(p.getUniqueId()) + "원");
break;
} }
case "이체": { case "이체": {
if (args[1] != null) { if (args.length > 1) {
Player op = Bukkit.getPlayer(args[1]); Player op = Bukkit.getPlayer(args[1]);
if (op != null) { 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 { } else {
p.sendMessage("잘못된 계좌입니다."); p.sendMessage("잘못된 계좌입니다.");
} }
} else { } else {
p.sendMessage("대상이 지정되지 않음"); p.sendMessage("이체 대상이 지정되지 않았습니다.");
} }
break;
} }
default: { default: {
p.sendMessage("잘못된 명령어"); p.sendMessage("잘못된 명령어");
@ -53,6 +86,9 @@ public class AccountEventHandler implements CommandExecutor {
} }
} }
else{
p.sendMessage("명령어를 입력하세요(잔액 | 이체)");
}
return false; return false;
} }
} }

@ -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 {
}
Loading…
Cancel
Save