ArrayEvent handler 생성

Command
poopki 3 years ago
parent c88d55d93f
commit 1b76db907b
  1. 2
      Account.java
  2. 5
      AccountArray.java
  3. 58
      AccountEventHandler.java
  4. 3
      User_DB.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;

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

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

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

Loading…
Cancel
Save