diff --git a/Account.java b/Array/Account.java similarity index 95% rename from Account.java rename to Array/Account.java index 8e929e7..949de09 100644 --- a/Account.java +++ b/Array/Account.java @@ -1,4 +1,4 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; public class Account { private int m_Balance; diff --git a/AccountArray.java b/Array/AccountArray.java similarity index 96% rename from AccountArray.java rename to Array/AccountArray.java index 8b5d951..742d25b 100644 --- a/AccountArray.java +++ b/Array/AccountArray.java @@ -1,4 +1,4 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; import java.util.HashMap; import java.util.Map; diff --git a/AccountEventHandler.java b/Array/AccountEventHandler.java similarity index 82% rename from AccountEventHandler.java rename to Array/AccountEventHandler.java index 281d44d..d8184be 100644 --- a/AccountEventHandler.java +++ b/Array/AccountEventHandler.java @@ -1,15 +1,20 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.UUID; public class AccountEventHandler implements CommandExecutor { AccountArray m_AccountArray; - public AccountEventHandler(AccountArray AA){ + UserInfoArray m_UserInfoArray; + public AccountEventHandler(AccountArray AA, UserInfoArray UIA){ m_AccountArray = AA; + m_UserInfoArray = UIA; } public static boolean isStringDouble(String s) { try { @@ -29,12 +34,13 @@ public class AccountEventHandler implements CommandExecutor { if (p.isOp()) { if (args.length > 1) { if (args[1] != null) { - Player op = Bukkit.getPlayer(args[1]); + UUID op = m_UserInfoArray.getUserUUID(args[1]); + if (op != null) { if (args.length > 2) { if (isStringDouble(args[2])) { - if(m_AccountArray.setAccountInfo(op.getUniqueId(), Long.parseLong(args[2]))){ - p.sendMessage(op.getName() + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다."); + if(m_AccountArray.setAccountInfo(m_UserInfoArray.getUserUUID(args[1]), Long.parseLong(args[2]))){ + p.sendMessage(args[1] + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다."); } else{ p.sendMessage("최대 금액 이상으로 설정할 수 없습니다."); } @@ -67,14 +73,15 @@ public class AccountEventHandler implements CommandExecutor { case "이체": { if (args.length > 1) { if(args.length > 2) { - Player op = Bukkit.getPlayer(args[1]); + UUID op = m_UserInfoArray.getUserUUID(args[1]); + p.sendMessage("이체"+args[1]+op); if (op != null) { if (isStringDouble(args[2])) { - if(p.getUniqueId() != op.getUniqueId()) { - switch(m_AccountArray.transfer(p.getUniqueId(), op.getUniqueId(), Long.parseLong(args[2]))) + if(p.getUniqueId() != op) { + switch(m_AccountArray.transfer(p.getUniqueId(), op, Long.parseLong(args[2]))) { case 1: { - p.sendMessage(op.getName() + "님에게 " + Integer.parseInt(args[2]) + "원을 이체하였습니다."); + p.sendMessage(args[1]+ "님에게 " + Integer.parseInt(args[2]) + "원을 이체하였습니다."); break; } case 2: { diff --git a/Array/Farm.java b/Array/Farm.java new file mode 100644 index 0000000..c9a4e2b --- /dev/null +++ b/Array/Farm.java @@ -0,0 +1,11 @@ +package org.poopki.duckdns.user_db.Array; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class Farm extends Group{ + public Farm(String Name, List uuid_list){ + super(Name, uuid_list); + } +} diff --git a/Array/FarmArray.java b/Array/FarmArray.java new file mode 100644 index 0000000..4437b2c --- /dev/null +++ b/Array/FarmArray.java @@ -0,0 +1,12 @@ +package org.poopki.duckdns.user_db.Array; + +import org.bukkit.Bukkit; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.*; + +public class FarmArray extends GroupArray{ + public FarmArray(UserInfoArray m_UIA){ + super(m_UIA, 10); + } +} diff --git a/FarmEventHandler.java b/Array/FarmEventHandler.java similarity index 99% rename from FarmEventHandler.java rename to Array/FarmEventHandler.java index 00aced6..0537669 100644 --- a/FarmEventHandler.java +++ b/Array/FarmEventHandler.java @@ -1,10 +1,11 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.UserInfoArray; import java.util.UUID; diff --git a/Group.java b/Array/Group.java similarity index 80% rename from Group.java rename to Array/Group.java index e2b1b88..c4fda08 100644 --- a/Group.java +++ b/Array/Group.java @@ -1,5 +1,6 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; +import java.util.Collections; import java.util.List; import java.util.ArrayList; import java.util.UUID; @@ -8,7 +9,7 @@ public class Group { private String m_Name; private List m_MemberList = new ArrayList<>(); UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_FARM_NUM = 13; + int MAX_FARM_NUM = 10; public Group(String Name, List uuid_list){ int index = 0; @@ -25,15 +26,19 @@ public class Group { public void Expulsion(UUID uuid){ m_MemberList.remove(uuid); - m_MemberList.add(ZERO_UUID); } public boolean isMember(UUID uuid){ return m_MemberList.contains(uuid); } - + public int getMemMaxNUM(){ + return MAX_FARM_NUM; + } public List getGroupMembers(){ return m_MemberList;} - + public int getMemNUM(){ + int num = m_MemberList.size(); + return num; + } public String getGroupName(){ return m_Name; } public int isEmpty(){return m_MemberList.size();} diff --git a/GroupArray.java b/Array/GroupArray.java similarity index 74% rename from GroupArray.java rename to Array/GroupArray.java index 0b26766..52beba6 100644 --- a/GroupArray.java +++ b/Array/GroupArray.java @@ -1,22 +1,26 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.UserInfoArray; import java.util.*; public class GroupArray { - public static Map m_GroupArray; - public static Map m_GroupNameList; + protected Map m_GroupArray; + protected Map m_GroupNameList; + public List m_DeleteQueue = new ArrayList<>(); UserInfoArray m_UserInfoArray; UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_GROUP_NUM = 13; + int MAX_GROUP_NUM = 10; - public GroupArray(UserInfoArray m_UIA){ + public GroupArray(UserInfoArray m_UIA, int num){ m_UserInfoArray = m_UIA; m_GroupArray = new HashMap(); m_GroupNameList = new HashMap(); + MAX_GROUP_NUM = num; } public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ @@ -25,9 +29,7 @@ public class GroupArray { } else{ List m_MemberList = new ArrayList<>(); m_MemberList.add(PlayerUUID); - for(int index=1; index temp = m_Group.getGroupMembers(); - if(temp.get(0).equals(ZERO_UUID)){ + int temp = m_GroupArray.get(GroupUUID).getMemNUM(); + + if(temp==0){ + m_GroupNameList.remove(m_Group.getGroupName()); m_GroupArray.remove(GroupUUID); - m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID)); + m_DeleteQueue.add(GroupUUID); + Bukkit.getPlayer(PlayerUUID).sendMessage(""+temp+" "+m_DeleteQueue); } return true; } else{ @@ -132,7 +137,10 @@ public class GroupArray { Group m_Group = m_GroupArray.get(GroupUUID); return m_Group.isMember(PlayerUUID); } - + public int GetGroupMemNUM(UUID GroupUUID){ + Group m_Group = m_GroupArray.get(GroupUUID); + return m_Group.getMemNUM(); + } public Set GetGroupNameList(){ return m_GroupNameList.keySet(); } @@ -146,11 +154,15 @@ public class GroupArray { Group m_Group = m_GroupArray.get(GroupUUID); return m_Group.getGroupName(); } - public static boolean isOffline(UUID uuid){ + public int GetGroupMemMaxNum(UUID GroupUUID){ + Group m_Group = m_GroupArray.get(GroupUUID); + return m_Group.getMemMaxNUM(); + } + public boolean isOffline(UUID uuid){ return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); } - public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ + public boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID); } private boolean isAvaliableGroup(UUID GroupUUID){ diff --git a/Array/GroupEventHandler.java b/Array/GroupEventHandler.java new file mode 100644 index 0000000..499bcab --- /dev/null +++ b/Array/GroupEventHandler.java @@ -0,0 +1,268 @@ +package org.poopki.duckdns.user_db.Array; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.UUID; + +public class GroupEventHandler implements CommandExecutor { + + GroupArray m_GroupArray; + UserInfoArray m_UserInfoArray; + AccountArray m_AccountArray; + UUID ZERO_UUID = new UUID(0,0); + + String m_GroupType; + String m_Type; + public GroupEventHandler(GroupArray GA, UserInfoArray UIA, AccountArray AA, String GroupType, String Type){ + m_GroupArray = GA; + m_UserInfoArray = UIA; + m_GroupType = GroupType; + m_Type=Type; + 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 "생성":{ + UUID tempUUID = UUID.randomUUID(); + if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){ + if(m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){ + m_UserInfoArray.setUserGroupUUID(m_Type,p.getUniqueId(), tempUUID); + m_AccountArray.putAccountInfo(tempUUID,0); + p.sendMessage(args[1]+m_GroupType+"이 생성되었습니다."); + p.sendMessage(m_GroupType+" 멤버 목록: "); + for (String Name: m_GroupArray.GetGroupMembersName(tempUUID)){ + p.sendMessage(Name); + } + p.sendMessage(m_GroupType+" 목록:"); + for (String Name: m_GroupArray.GetGroupNameList()){ + p.sendMessage(Name); + } + } + else{ + p.sendMessage("이미 존재하는 "+m_GroupType+" 이름입니다."); + } + } + else{ + p.sendMessage("이미"+m_GroupType+"을(를) 소유중입니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type)); + } + break; + } + case "가입":{ + p.sendMessage("플레이어 UUID:"+p.getUniqueId()+" 농장 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type)); + p.sendMessage("ZERO UUID:"+ZERO_UUID); + if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){ + p.sendMessage("이미 가입한 "+m_GroupType+"이(가) 존재합니다."); + } + else{ + p.sendMessage("가입 완료"); + m_GroupArray.SignUpGroup(m_Type,m_GroupArray.m_GroupNameList.get(args[1]),p.getUniqueId()); + p.sendMessage(m_GroupType+" 멤버 목록: "); + for (String Name: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(args[1]))){ + p.sendMessage(Name); + } + p.sendMessage(m_GroupType+" 목록:"); + for (String Name: m_GroupArray.GetGroupNameList()){ + p.sendMessage(Name); + } + } + break; + } + case "초대":{ + p.sendMessage("초대 테스트"); + break; + } + case "강퇴":{ + p.sendMessage("강퇴 테스트"); + if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){ + p.sendMessage("가입한 "+m_GroupType+"이(가) 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type)); + } + else{ + if(m_GroupArray.isOwner(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type), p.getUniqueId())){ + if (args.length > 1) { + Player op = Bukkit.getPlayer(args[1]); + if (op != null) { + if(m_GroupArray.isGroupMember(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type),op.getUniqueId())) { + m_GroupArray.ExpulsionGroupPlayer(m_Type, m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type), p.getUniqueId()); + } + else{ + p.sendMessage(m_GroupType+"에 가입되지 않은 유저입니다"); + } + } + else{ + p.sendMessage("잘못된 대상입니다."); + } + } + else{ + p.sendMessage("강퇴할 대상을 지정"); + } + } + else{ + p.sendMessage(m_GroupType+"주만 사용 가능한 명령어입니다."+ p.getUniqueId()); + } + } + break; + } + case "탈퇴": { + if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){ + p.sendMessage("가입한 "+m_GroupType+"이(가) 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type)); + } + else{ + p.sendMessage("탈퇴 플레이어 UUID:"+p.getUniqueId()+m_GroupType+" UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type)); + m_GroupArray.ExpulsionGroupPlayer(m_Type,m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),m_Type),p.getUniqueId()); + + } + break; + } + case "이름":{ + p.sendMessage("현재 "+m_GroupType+" 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party"))); + break; + } + case "정보": { + for (String Name: m_GroupArray.GetGroupNameList()){ + p.sendMessage(m_GroupType+" 이름:"); + p.sendMessage(Name); + p.sendMessage("인원 목록"); + for (String Name2: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(Name))) { + p.sendMessage(Name2); + } + p.sendMessage("계좌 잔액:"+m_AccountArray.getAccountInfo(m_GroupArray.m_GroupNameList.get(Name))); + } + } + case "계좌설정":{ + if (p.isOp()) { + if (args.length > 1) { + if (args[1] != null) { + UUID op = m_GroupArray.m_GroupNameList.get(args[1]); + if (op != null) { + if (args.length > 2) { + if (isStringDouble(args[2])) { + if(m_AccountArray.setAccountInfo(op, Long.parseLong(args[2]))){ + p.sendMessage(args[1] + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다."); + } else{ + p.sendMessage("최대 금액 이상으로 설정할 수 없습니다."); + } + } else { + p.sendMessage("설정 금액은 숫자만 가능합니다."); + } + } else { + p.sendMessage("설정 금액을 입력해주세요."); + } + } else { + p.sendMessage("잘못된 계좌입니다."); + } + } + }else{ + p.sendMessage("설정 대상이 지정되지 않았습니다."); + } + } else { + p.sendMessage("관리자만 실행 가능한 명령어입니다."); + } + break; + } + case "입금": { + if (args.length > 1) { + if(args.length > 2) { + UUID op = m_GroupArray.m_GroupNameList.get(args[1]); + if (op != null) { + if (isStringDouble(args[2])) { + if(p.getUniqueId() != op) { + switch(m_AccountArray.transfer(p.getUniqueId(), op, Long.parseLong(args[2]))) + { + case 1: { + p.sendMessage(args[1] + m_GroupType+"에 " + Integer.parseInt(args[2]) + "원을 이체하였습니다."); + break; + } + case 2: { + p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다."); + break; + } + case 3:{ + p.sendMessage("잔액이 부족합니다."); + break; + } + } + } else{ + p.sendMessage("자기 자신에게는 이체할 수 없습니다."); + } + } else { + p.sendMessage("이체 금액은 숫자만 가능합니다."); + } + } else { + p.sendMessage("잘못된 계좌입니다."); + } + } else { + p.sendMessage("이체 금액을 입력해주세요."); + } + } else { + p.sendMessage("이체 대상이 지정되지 않았습니다."); + } + break; + } + case "출금": { + if (args.length > 1) { + if(args.length > 2) { + UUID op = m_GroupArray.m_GroupNameList.get(args[1]); + if (op != null) { + if (isStringDouble(args[2])) { + if(p.getUniqueId() != op) { + switch(m_AccountArray.transfer(op,p.getUniqueId(), Long.parseLong(args[2]))) + { + case 1: { + p.sendMessage(args[1] + m_GroupType+"에서 " + Integer.parseInt(args[2]) + "원을 출금하였습니다."); + break; + } + case 2: { + p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다."); + break; + } + case 3:{ + p.sendMessage("잔액이 부족합니다."); + break; + } + } + } else{ + p.sendMessage("자기 자신에게는 이체할 수 없습니다."); + } + } else { + p.sendMessage("이체 금액은 숫자만 가능합니다."); + } + } else { + p.sendMessage("잘못된 계좌입니다."); + } + } else { + p.sendMessage("이체 금액을 입력해주세요."); + } + } else { + p.sendMessage("이체 대상이 지정되지 않았습니다."); + } + break; + } + case "잔액": { + p.sendMessage("==잔액: " + m_AccountArray.getAccountInfo(m_GroupArray.GetUUID(args[1]))+ "원=="); + break; + } + default: { + p.sendMessage("잘못된 명령어"); + } + } + } + return true; + } +} diff --git a/Array/Nation.java b/Array/Nation.java new file mode 100644 index 0000000..f341944 --- /dev/null +++ b/Array/Nation.java @@ -0,0 +1,11 @@ +package org.poopki.duckdns.user_db.Array; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class Nation extends Group{ + public Nation(String Name, List uuid_list){ + super(Name, uuid_list); + } +} diff --git a/Array/NationArray.java b/Array/NationArray.java new file mode 100644 index 0000000..339d6bc --- /dev/null +++ b/Array/NationArray.java @@ -0,0 +1,9 @@ +package org.poopki.duckdns.user_db.Array; + +import org.poopki.duckdns.user_db.UserInfoArray; + +public class NationArray extends GroupArray{ + public NationArray(UserInfoArray m_UIA){ + super(m_UIA, 50); + } +} diff --git a/NationEventHandler.java b/Array/NationEventHandler.java similarity index 99% rename from NationEventHandler.java rename to Array/NationEventHandler.java index 15c44e0..24c4b9f 100644 --- a/NationEventHandler.java +++ b/Array/NationEventHandler.java @@ -1,10 +1,11 @@ -package org.poopki.duckdns.user_db; +package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.UserInfoArray; import java.util.UUID; diff --git a/DB/DBUpdate.java b/DB/DBUpdate.java index fadd0c0..6345b47 100644 --- a/DB/DBUpdate.java +++ b/DB/DBUpdate.java @@ -1,11 +1,13 @@ package org.poopki.duckdns.user_db.DB; import org.poopki.duckdns.user_db.*; +import org.poopki.duckdns.user_db.Array.AccountArray; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; import java.sql.*; import java.util.ArrayList; import java.util.List; -import java.util.Set; import java.util.UUID; public class DBUpdate { @@ -115,7 +117,9 @@ public class DBUpdate { List m_MemberList = new ArrayList<>(); for(int index = 4; index m_MemberList = new ArrayList<>(); for(int index = 4; index m_MemberList = new ArrayList<>(); - UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_FARM_NUM = 13; - - public Farm(String Name, List uuid_list){ - int index = 0; - for(UUID key: uuid_list){ - m_MemberList.add(index,key); - index++; - } - m_Name = Name; - } - - public void SignUp(UUID uuid){ - m_MemberList.add((UUID)uuid); - } - - public void Expulsion(UUID uuid){ - m_MemberList.remove(uuid); - m_MemberList.add(ZERO_UUID); - } - - public boolean isMember(UUID uuid){ - return m_MemberList.contains(uuid); - } - - public List getGroupMembers(){ return m_MemberList;} - - - public String getGroupName(){ return m_Name; } - public int isEmpty(){return m_MemberList.size();} - public boolean isOwner(UUID uuid){ - if(m_MemberList.get(0).equals(uuid)){ - return true; - }else{ - return false; - } - } -} diff --git a/FarmArray.java b/FarmArray.java deleted file mode 100644 index a1a873e..0000000 --- a/FarmArray.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.poopki.duckdns.user_db; - -import org.bukkit.Bukkit; - -import java.util.*; - -public class FarmArray { - - - public static Map m_GroupArray; - public static Map m_GroupNameList; - UserInfoArray m_UserInfoArray; - UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_GROUP_NUM = 10; - - public FarmArray(UserInfoArray m_UIA){ - m_UserInfoArray = m_UIA; - m_GroupArray = new HashMap(); - m_GroupNameList = new HashMap(); - } - - public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ - if(m_GroupNameList.containsKey(Name)){ - return false; // Conflict - } else{ - List m_MemberList = new ArrayList<>(); - m_MemberList.add(PlayerUUID); - for(int index=1; index PlayerUUID){ - List m_MemberList = new ArrayList<>(); - - Iterator it = PlayerUUID.iterator(); - - while(it.hasNext()){ - m_MemberList.add(it.next()); - } - - for(int index=MAX_GROUP_NUM-PlayerUUID.size();index K getKey(Map map, V value) { - - for (K key : map.keySet()) { - if (value.equals(map.get(key))) { - return key; - } - } - return null; - } - public boolean DeleteGroup(UUID GroupUUID, String GroupType){ - if(m_GroupArray.containsKey(GroupUUID)){ - for(UUID key: GetGroupMembersUUID(GroupUUID)){ - m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0)); - } - - m_GroupNameList.remove(GetGroupName(GroupUUID)); - m_GroupArray.remove(GroupUUID); - return true; - } - else{ - return false; // Group is not exists. - } - - } - - public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ - if(m_GroupArray.containsKey(GroupUUID)){ - if(isOffline(PlayerUUID)){ - Farm m_Group = m_GroupArray.get(GroupUUID); - m_Group.SignUp(PlayerUUID); - m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); - return 1; // Success - }else{ - return 2; // Offline Player - } - } else{ - return 3; // Wrong Group - } - } - - public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ - if(m_GroupArray.get(GroupUUID).isMember(PlayerUUID)) { - Farm m_Group = m_GroupArray.get(GroupUUID); - m_Group.Expulsion(PlayerUUID); - m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); - List temp = m_Group.getGroupMembers(); - if(temp.get(0).equals(ZERO_UUID)){ - m_GroupArray.remove(GroupUUID); - m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID)); - } - return true; - } else{ - return false; // Wrong Player Name. FIXME{Need Checking function for a validate user name's } - /* Player op = Bukkit.getPlayer(args[1]); - if (op != null) { - */ - } - } - - public List GetGroupMembersName(UUID GroupUUID){ - List MembersName = new ArrayList<>(); - for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){ - try { - MembersName.add(Bukkit.getPlayer(key).getDisplayName()); - } - catch(NullPointerException e){ - - } - } - return MembersName; - } - public List GetGroupMembersUUID(UUID GroupUUID){ - return m_GroupArray.get(GroupUUID).getGroupMembers(); - } - public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ - Farm m_Group = m_GroupArray.get(GroupUUID); - return m_Group.isMember(PlayerUUID); - } - - public Set GetGroupNameList(){ - return m_GroupNameList.keySet(); - } - - public Set getKeySet(){ // 유저 목록 return - return m_GroupArray.keySet(); - } - - public Set getNameSet() { return m_GroupNameList.keySet(); } - public String GetGroupName(UUID GroupUUID){ - Farm m_Group = m_GroupArray.get(GroupUUID); - return m_Group.getGroupName(); - } - public static boolean isOffline(UUID uuid){ - return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); - } - - public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ - return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID); - } - private boolean isAvaliableGroup(UUID GroupUUID){ - return m_GroupArray.containsKey(GroupUUID); - } - -} diff --git a/GUI/BaseGUI.java b/GUI/BaseGUI.java new file mode 100644 index 0000000..a05da83 --- /dev/null +++ b/GUI/BaseGUI.java @@ -0,0 +1,107 @@ +package org.poopki.duckdns.user_db.GUI; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.poopki.duckdns.user_db.Array.AccountArray; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.UUID; + +public class BaseGUI implements Listener{ + private final Inventory inv; + UUID m_uuid; + ItemManager m_ItemManager= new ItemManager(); + AccountArray m_AA; + UserInfoArray m_UIA; + FarmArray m_FA; + NationArray m_NA; + public BaseGUI(AccountArray AA, UserInfoArray UIA, FarmArray FA, NationArray NA, UUID uuid, InventoryClickEvent e) { + m_uuid=uuid; + this.inv = Bukkit.createInventory(null,27,"TESTGUI"); + m_AA=AA; + m_UIA=UIA; + m_FA=FA; + m_NA=NA; + initItemSetting(); + } + + private void initItemSetting() { + + inv.setItem(0,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "User")); + inv.setItem(1,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "Nation")); + inv.setItem(2,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "Farm")); + + inv.setItem(9, m_ItemManager.btn1); + inv.setItem(18, m_ItemManager.btn2); + inv.setItem(10, m_ItemManager.btn3); + inv.setItem(19, m_ItemManager.btn4); + inv.setItem(11, m_ItemManager.btn5); + inv.setItem(20, m_ItemManager.btn6); + } + + public void open(Player player){ + player.openInventory(inv); + } + + public void inven(InventoryClickEvent e){ + Player p = (Player) e.getWhoClicked(); + Inventory m_inv = e.getClickedInventory(); + + if (e.getInventory() != m_inv) return; + + switch(e.getCurrentItem().getType()){ + case CANDLE: + e.setCancelled(true); + p.sendMessage("10000원 증가"); + m_AA.setAccountInfo(p.getUniqueId(), (long)m_AA.getAccountInfo(p.getUniqueId())+10000); + initItemSetting(); + p.openInventory(inv); + break; + case BEEF: + e.setCancelled(true); + p.sendMessage("10000원 감소"); + m_AA.setAccountInfo(p.getUniqueId(), (long)m_AA.getAccountInfo(p.getUniqueId())-10000); + initItemSetting(); + p.openInventory(inv); + break; + case TORCH: + e.setCancelled(true); + p.sendMessage("국가 10000원 증가"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Nation"))); + m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"))+10000); + initItemSetting(); + p.openInventory(inv); + break; + case GRASS: + e.setCancelled(true); + p.sendMessage("국가 10000원 감소"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Nation"))); + m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"))-10000); + initItemSetting(); + p.openInventory(inv); + break; + case DIAMOND: + e.setCancelled(true); + p.sendMessage("농장 10000원 증가"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Farm"))); + m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"))+10000); + initItemSetting(); + p.openInventory(inv); + break; + case IRON_INGOT: + e.setCancelled(true); + p.sendMessage("농장 10000원 감소"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Farm"))); + m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"))-10000); + initItemSetting(); + p.openInventory(inv); + break; + } + } +} diff --git a/GUI/ItemManager.java b/GUI/ItemManager.java new file mode 100644 index 0000000..ab302b8 --- /dev/null +++ b/GUI/ItemManager.java @@ -0,0 +1,59 @@ +package org.poopki.duckdns.user_db.GUI; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.poopki.duckdns.user_db.Array.AccountArray; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.Arrays; +import java.util.UUID; + +public class ItemManager { + UUID ZERO_UUID = new UUID(0,0); + public ItemStack btn1 = buildItem(Material.CANDLE, 1, ChatColor.AQUA +"지갑 10000원 증가", "", ChatColor.GREEN + "----"); + public ItemStack btn2 = buildItem(Material.BEEF, 1, ChatColor.AQUA +"지갑 10000원 감소", "", ChatColor.GREEN + "----"); + public ItemStack btn3 = buildItem(Material.TORCH, 1, ChatColor.AQUA +"국가 10000원 증가", "", ChatColor.GREEN + "----"); + public ItemStack btn4 = buildItem(Material.GRASS, 1, ChatColor.AQUA +"국가 10000원 감소", "", ChatColor.GREEN + "----"); + public ItemStack btn5 = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"농장 10000원 증가", "", ChatColor.GREEN + "----"); + public ItemStack btn6 = buildItem(Material.IRON_INGOT, 1, ChatColor.AQUA +"농장 10000원 증가", "", ChatColor.GREEN + "----"); + private static ItemStack buildItem(Material type, int amount, String displayName, String... lore) { + ItemStack stack = new ItemStack(type, amount); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(displayName); + meta.setLore(Arrays.asList(lore)); + stack.setItemMeta(meta); + return stack; + } + public ItemStack GetBalance(AccountArray AA, UserInfoArray UIA, FarmArray FA, NationArray NA, UUID m_uuid, String Type){ + + ItemStack dia = null; + switch (Type){ + case "User": + dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+UIA.getUserName(m_uuid), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(m_uuid)); + break; + case "Farm": + if(ZERO_UUID.equals(UIA.getUserGroupUUID(m_uuid, "Farm"))){ + dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"농장 없음", "잔액", ChatColor.GREEN + "----"); + }else{ + dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+FA.GetGroupName(UIA.getUserGroupUUID(m_uuid,"Farm")), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(UIA.getUserGroupUUID(m_uuid, "Farm"))); + } + break; + case "Nation": + if(ZERO_UUID.equals(UIA.getUserGroupUUID(m_uuid, "Nation"))){ + dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"국가 없음", "잔액", ChatColor.GREEN + "----"); + } + else{ + dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+NA.GetGroupName(UIA.getUserGroupUUID(m_uuid, "Nation")), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(UIA.getUserGroupUUID(m_uuid, "Nation"))); + } + + break; + } + return dia; + } + + +} \ No newline at end of file diff --git a/GUI/OpenInv.java b/GUI/OpenInv.java new file mode 100644 index 0000000..bae87e9 --- /dev/null +++ b/GUI/OpenInv.java @@ -0,0 +1,47 @@ +package org.poopki.duckdns.user_db.GUI; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.poopki.duckdns.user_db.Array.AccountArray; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +public class OpenInv implements Listener,CommandExecutor { + AccountArray m_AccountArray; + UserInfoArray m_UserInfoArray; + FarmArray m_FarmArray; + NationArray m_NationArray; + public OpenInv(AccountArray AA, UserInfoArray m_UIA, FarmArray FA, NationArray NA){ + m_UserInfoArray = m_UIA; + m_AccountArray = AA; + m_FarmArray = FA; + m_NationArray = NA; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(sender instanceof Player){ + Player player = (Player) sender; + player.sendMessage("이벤트 발생"); + BaseGUI inv = new BaseGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, ((Player) sender).getUniqueId(), null); + inv.open(player); + } + return false; + } + @EventHandler + public void inven2(InventoryClickEvent e){ + Player player = (Player) e.getWhoClicked();; + player.sendMessage("이벤트 발생"); + BaseGUI inv = new BaseGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, player.getUniqueId(), e); + inv.inven(e); + + } + + + +} diff --git a/GroupEventHandler.java b/GroupEventHandler.java deleted file mode 100644 index 5ac630c..0000000 --- a/GroupEventHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.poopki.duckdns.user_db; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.UUID; - -public class GroupEventHandler implements CommandExecutor { - - GroupArray m_GroupArray; - UserInfoArray m_UserInfoArray; - - public GroupEventHandler(GroupArray GA, UserInfoArray UIA){ - m_GroupArray = GA; - m_UserInfoArray = UIA; - } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player p = (Player) sender; - - if (args.length != 0) { - switch (args[0]) { - case "생성":{ - UUID tempUUID = UUID.randomUUID(); - m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId()); - m_UserInfoArray.setUserGroupUUID("Party",p.getUniqueId(), tempUUID); - p.sendMessage(args[1]+"파티가 생성되었습니다."); - p.sendMessage("멤버 목록: "); - for (String Name: m_GroupArray.GetGroupMembersName(tempUUID)){ - p.sendMessage(Name); - } - p.sendMessage("파티 목록:"); - for (String Name: m_GroupArray.GetGroupNameList()){ - p.sendMessage(Name); - } - break; - } - case "가입":{ - p.sendMessage("가입 테스트"); - break; - } - case "초대":{ - p.sendMessage("초대 테스트"); - break; - } - case "강퇴":{ - p.sendMessage("강퇴 테스트"); - break; - } - case "이름":{ - p.sendMessage("현재 파티 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party"))); - break; - } - } - } - return true; - } -} diff --git a/Invite/Invitation.java b/Invite/Invitation.java new file mode 100644 index 0000000..72b5184 --- /dev/null +++ b/Invite/Invitation.java @@ -0,0 +1,40 @@ +package org.poopki.duckdns.user_db.Invite; + +import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.UUID; + +public class Invitation { + protected long Time; + protected String Type; + + protected UUID uuid; + + protected Player sender; + protected Player receiver; + public Invitation(long Time, String Type, UUID uuid, Player sender, Player receiver){ + this.Time = Time; + this.Type = Type; + this.uuid = uuid; + this.sender = sender; + this.receiver = receiver; + } + + public long getTime(){ + return this.Time; + } + + public String getType(){ + return this.Type; + } + + public UUID getUUID(){ + return this.uuid; + } + public Player getSender(){return this.sender;} + public Player getReceiver(){ return this.receiver;} + +} diff --git a/Invite/InviteMaster.java b/Invite/InviteMaster.java new file mode 100644 index 0000000..b38bc34 --- /dev/null +++ b/Invite/InviteMaster.java @@ -0,0 +1,158 @@ +package org.poopki.duckdns.user_db.Invite; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.Array.FarmArray; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class InviteMaster implements CommandExecutor { + private static Map m_InviteQueue = new HashMap(); + UserInfoArray m_UserInfoArray; + FarmArray m_FarmArray; + NationArray m_NationArray; + + public InviteMaster(UserInfoArray UIA, FarmArray FA, NationArray NA){ + m_UserInfoArray = UIA; + m_FarmArray = FA; + m_NationArray = NA; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player)sender; + switch (args[0]) { + case "발송": { + if (args.length > 1) { + if (args.length > 2) { + UUID op = m_UserInfoArray.getUserUUID(args[2]); + if (op != null) { + if (p.getUniqueId().equals(op)) { + p.sendMessage("자기 자신에게 초대를 보낼 수 없습니다."); + } else { + sendInvite(p, Bukkit.getPlayer(args[2]), m_UserInfoArray, m_FarmArray, m_NationArray, args[1]); + } + } else { + p.sendMessage("잘못된 대상입니다."); + } + } else { + p.sendMessage("초대 대상을 입력해주세요."); + } + } else { + p.sendMessage("국가/농장이 지정되지 않았습니다."); + } + break; + } + case "응답": { + if (args.length > 1) { + if (args.length > 2) { + switch (args[2]) { + case "수락": + replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, args[1], true); + p.sendMessage("수락하였습니다."); + break; + case "거절": + replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, args[1], false); + p.sendMessage("거절하였습니다."); + break; + default: + p.sendMessage("/초대 응답 국가|농장 수락|거절"); + } + + } else { + p.sendMessage("초대 대상을 입력해주세요."); + } + } else { + p.sendMessage("국가/농장이 지정되지 않았습니다."); + } + break; + } + } + return true; + } + public boolean sendInvite(Player sender, Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, String Type){ + if(!isExpired(receiver.getUniqueId())){ + sender.sendMessage("응답 대기중"); + return false; + } + + switch (Type){ + case "농장": + if(FA.GetGroupMemNUM(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))>FA.GetGroupMemMaxNum(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))){ + sender.sendMessage("인원이 초과되었습니다."); + return false; + } + else{ + m_InviteQueue.put(receiver.getUniqueId(), new Invitation(System.currentTimeMillis(), "Farm", UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"), sender, receiver)); + receiver.sendMessage(sender.getDisplayName()+"님의 "+FA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))+"에 초대되었습니다."); + receiver.sendMessage("제한시간(5분)내 /농장 수락 혹은 /농장 거절 입력해주시기 바랍니다."); + } + break; + case "국가": + if(NA.GetGroupMemNUM(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))>NA.GetGroupMemMaxNum(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))){ + sender.sendMessage("인원이 초과되었습니다."); + return false; + } + else{ + m_InviteQueue.put(receiver.getUniqueId(), new Invitation(System.currentTimeMillis(), "Nation", UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"), sender, receiver)); + receiver.sendMessage(sender.getDisplayName()+"님의 "+NA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))+"에 초대되었습니다."); + receiver.sendMessage("제한시간(5분)내 /국가 수락 혹은 /국가 거절 입력해주시기 바랍니다."+receiver.getUniqueId()); + } + break; + } + return true; + } + + public boolean replyInvite(Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, String Type, boolean accept){ + Player sender = m_InviteQueue.get(receiver.getUniqueId()).getSender(); + if(isExpired(receiver.getUniqueId())){ + m_InviteQueue.remove(receiver.getUniqueId()); + receiver.sendMessage("수신 받은 초대가 없거나, 초대가 만료되었습니다."); + return false; + } + + if(!accept){ + sender.sendMessage("초대를 거절하였습니다."); + receiver.sendMessage("초대를 거절하였습니다."); + m_InviteQueue.remove(receiver.getUniqueId()); + return false; + } + switch (Type){ + case "농장": + if(FA.GetGroupMemNUM(m_InviteQueue.get(sender.getUniqueId()).getUUID())>FA.GetGroupMemMaxNum(m_InviteQueue.get(sender.getUniqueId()).getUUID())){ + sender.sendMessage("인원이 초과되었습니다."); + receiver.sendMessage("인원이 초과되었습니다.."); + m_InviteQueue.remove(receiver.getUniqueId()); + return false; + } + else{ + FA.SignUpGroup("Farm", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), m_InviteQueue.get(receiver.getUniqueId()).getReceiver().getUniqueId()); + m_InviteQueue.remove(receiver.getUniqueId()); + } + break; + case "국가": + if(NA.GetGroupMemNUM(m_InviteQueue.get(sender.getUniqueId()).getUUID())>NA.GetGroupMemMaxNum(m_InviteQueue.get(sender.getUniqueId()).getUUID())){ + sender.sendMessage("인원이 초과되었습니다."); + receiver.sendMessage("인원이 초과되었습니다."); + m_InviteQueue.remove(receiver.getUniqueId()); + return false; + } + else{ + receiver.sendMessage("가입되었습니다."+m_InviteQueue.get(receiver.getUniqueId()).getUUID()+ " "+ m_InviteQueue.get(receiver.getUniqueId()).getReceiver()); + NA.SignUpGroup("Nation", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), m_InviteQueue.get(receiver.getUniqueId()).getReceiver().getUniqueId()); + m_InviteQueue.remove(receiver.getUniqueId()); + } + break; + } + return true; + } + private boolean isExpired(UUID uuid){ + return !m_InviteQueue.containsKey(uuid) || (System.currentTimeMillis() - m_InviteQueue.get(uuid).getTime()) >= 300000L; + } +} diff --git a/Nation.java b/Nation.java deleted file mode 100644 index fb9c00b..0000000 --- a/Nation.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.poopki.duckdns.user_db; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class Nation { - private String m_Name; - private List m_MemberList = new ArrayList<>(); - UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_FARM_NUM = 13; - - public Nation(String Name, List uuid_list){ - int index = 0; - for(UUID key: uuid_list){ - m_MemberList.add(index,key); - index++; - } - m_Name = Name; - } - - public void SignUp(UUID uuid){ - m_MemberList.add((UUID)uuid); - } - - public void Expulsion(UUID uuid){ - m_MemberList.remove(uuid); - m_MemberList.add(ZERO_UUID); - } - - public boolean isMember(UUID uuid){ - return m_MemberList.contains(uuid); - } - - public List getGroupMembers(){ return m_MemberList;} - - - public String getGroupName(){ return m_Name; } - public int isEmpty(){return m_MemberList.size();} - public boolean isOwner(UUID uuid){ - if(m_MemberList.get(0).equals(uuid)){ - return true; - }else{ - return false; - } - } -} diff --git a/NationArray.java b/NationArray.java deleted file mode 100644 index d2b8603..0000000 --- a/NationArray.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.poopki.duckdns.user_db; - -import org.bukkit.Bukkit; - -import java.util.*; - -public class NationArray { - - - public static Map m_GroupArray; - public static Map m_GroupNameList; - UserInfoArray m_UserInfoArray; - UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); - int MAX_GROUP_NUM = 13; - - public NationArray(UserInfoArray m_UIA){ - m_UserInfoArray = m_UIA; - m_GroupArray = new HashMap(); - m_GroupNameList = new HashMap(); - } - - public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ - if(m_GroupNameList.containsKey(Name)){ - return false; // Conflict - } else{ - List m_MemberList = new ArrayList<>(); - m_MemberList.add(PlayerUUID); - for(int index=1; index PlayerUUID){ - List m_MemberList = new ArrayList<>(); - - Iterator it = PlayerUUID.iterator(); - - while(it.hasNext()){ - m_MemberList.add(it.next()); - } - - for(int index=MAX_GROUP_NUM-PlayerUUID.size();index K getKey(Map map, V value) { - - for (K key : map.keySet()) { - if (value.equals(map.get(key))) { - return key; - } - } - return null; - } - public boolean DeleteGroup(UUID GroupUUID, String GroupType){ - if(m_GroupArray.containsKey(GroupUUID)){ - for(UUID key: GetGroupMembersUUID(GroupUUID)){ - m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0)); - } - - m_GroupNameList.remove(GetGroupName(GroupUUID)); - m_GroupArray.remove(GroupUUID); - return true; - } - else{ - return false; // Group is not exists. - } - - } - - public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ - if(m_GroupArray.containsKey(GroupUUID)){ - if(isOffline(PlayerUUID)){ - Nation m_Group = m_GroupArray.get(GroupUUID); - m_Group.SignUp(PlayerUUID); - m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); - return 1; // Success - }else{ - return 2; // Offline Player - } - } else{ - return 3; // Wrong Group - } - } - - public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ - if(m_GroupArray.get(GroupUUID).isMember(PlayerUUID)) { - Nation m_Group = m_GroupArray.get(GroupUUID); - m_Group.Expulsion(PlayerUUID); - m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); - List temp = m_Group.getGroupMembers(); - if(temp.get(0).equals(ZERO_UUID)){ - m_GroupArray.remove(GroupUUID); - m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID)); - } - return true; - } else{ - return false; // Wrong Player Name. FIXME{Need Checking function for a validate user name's } - /* Player op = Bukkit.getPlayer(args[1]); - if (op != null) { - */ - } - } - - public List GetGroupMembersName(UUID GroupUUID){ - List MembersName = new ArrayList<>(); - for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){ - try { - MembersName.add(Bukkit.getPlayer(key).getDisplayName()); - } - catch(NullPointerException e){ - - } - } - return MembersName; - } - public List GetGroupMembersUUID(UUID GroupUUID){ - return m_GroupArray.get(GroupUUID).getGroupMembers(); - } - public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ - Nation m_Group = m_GroupArray.get(GroupUUID); - return m_Group.isMember(PlayerUUID); - } - - public Set GetGroupNameList(){ - return m_GroupNameList.keySet(); - } - - public Set getKeySet(){ // 유저 목록 return - return m_GroupArray.keySet(); - } - - public Set getNameSet() { return m_GroupNameList.keySet(); } - public String GetGroupName(UUID GroupUUID){ - Nation m_Group = m_GroupArray.get(GroupUUID); - return m_Group.getGroupName(); - } - public static boolean isOffline(UUID uuid){ - return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); - } - - public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ - return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID); - } - private boolean isAvaliableGroup(UUID GroupUUID){ - return m_GroupArray.containsKey(GroupUUID); - } - -} diff --git a/SquadEventHandler.java b/SquadEventHandler.java index c2d4e04..b689cb6 100644 --- a/SquadEventHandler.java +++ b/SquadEventHandler.java @@ -4,6 +4,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.poopki.duckdns.user_db.Array.GroupArray; import java.util.UUID; diff --git a/UserInfoArray.java b/UserInfoArray.java index fa2be12..35609f6 100644 --- a/UserInfoArray.java +++ b/UserInfoArray.java @@ -7,7 +7,7 @@ import java.util.UUID; public class UserInfoArray { private static Map m_UserInfoArray = new HashMap(); - + private static Map m_UserNameUUID = new HashMap(); public String getUserName(UUID uuid){ // 유저 이름 return return m_UserInfoArray.get(uuid).getUserName(); } @@ -21,13 +21,16 @@ public class UserInfoArray { public UUID getUserGroupUUID(UUID PlayerUUID, String GroupType){ return m_UserInfoArray.get(PlayerUUID).GetGroupUUID(GroupType); } - + public UUID getUserUUID(String Name){ + return m_UserNameUUID.get(Name); + } public void setUserGroupUUID(String GroupType, UUID PlayerUUID, UUID GroupUUID){ m_UserInfoArray.get(PlayerUUID).SetGroupUUID(GroupType,GroupUUID); } public void putUserInfo(UUID uuid,String Name, UUID Nation, UUID Squad, UUID Farm, UUID Party) { // UserInfoArray entry 입력 m_UserInfoArray.put(uuid, new UserInfo(uuid,Name, Nation, Squad, Farm, Party)); + m_UserNameUUID.put(Name, uuid); } } \ No newline at end of file diff --git a/UserJoin.java b/UserJoin.java index d3d2a4f..7730581 100644 --- a/UserJoin.java +++ b/UserJoin.java @@ -3,6 +3,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import org.poopki.duckdns.user_db.Array.AccountArray; import java.util.UUID; diff --git a/User_DB.java b/User_DB.java index 526ee5e..a765c0d 100644 --- a/User_DB.java +++ b/User_DB.java @@ -2,8 +2,10 @@ package org.poopki.duckdns.user_db; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import org.poopki.duckdns.user_db.Array.*; import org.poopki.duckdns.user_db.DB.*; - +import org.poopki.duckdns.user_db.GUI.*; +import org.poopki.duckdns.user_db.Invite.*; import java.sql.SQLException; @@ -13,8 +15,8 @@ public final class User_DB extends JavaPlugin implements Listener { UserInfoArray m_InfoArrayInstance = new UserInfoArray(); // UserInfo 저장하는 Array instance 생성 FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance); NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance); - DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_AccountArrayInstance, m_FarmArrayInstance, m_NationArrayInstance); + @Override public void onEnable() { // Plugin startup logic @@ -24,11 +26,15 @@ public final class User_DB extends JavaPlugin implements Listener { } catch (SQLException e) { throw new RuntimeException(e); } - getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance)); + getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance,m_InfoArrayInstance)); getCommand("농장").setExecutor(new FarmEventHandler(m_FarmArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance)); getCommand("국가").setExecutor(new NationEventHandler(m_NationArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance)); - + getCommand("opitem").setExecutor(new OpenInv(m_AccountArrayInstance, m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance)); + getCommand("초대").setExecutor(new InviteMaster(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance)); getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_AccountArrayInstance),this); + getServer().getPluginManager().registerEvents(new OpenInv(m_AccountArrayInstance, m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance), this); + + }