diff --git a/FarmEventHandler.java b/FarmEventHandler.java index db0b928..b8af48b 100644 --- a/FarmEventHandler.java +++ b/FarmEventHandler.java @@ -11,7 +11,7 @@ public class FarmEventHandler implements CommandExecutor { GroupArray m_GroupArray; UserInfoArray m_UserInfoArray; - + UUID ZERO_UUID = new UUID(0,0); public FarmEventHandler(GroupArray GA, UserInfoArray UIA){ m_GroupArray = GA; m_UserInfoArray = UIA; @@ -24,21 +24,46 @@ public class FarmEventHandler implements CommandExecutor { 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); + if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){ + if(m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){ + m_UserInfoArray.setUserGroupUUID("Farm",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); + } + } + else{ + p.sendMessage("이미 존재하는 농장 이름"); + } } - p.sendMessage("농장 목록:"); - for (String Name: m_GroupArray.GetGroupNameList()){ - p.sendMessage(Name); + else{ + p.sendMessage("이미 농장을 소유중"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm")); } break; } case "가입":{ - p.sendMessage("가입 테스트"); + p.sendMessage("플레이어 UUID:"+p.getUniqueId()+" 농장 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm")); + p.sendMessage("ZERO UUID:"+ZERO_UUID); + if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){ + p.sendMessage("이미 가입한 농장이 존재"); + } + else{ + p.sendMessage("가입 완료"); + m_GroupArray.SignUpGroup("Farm",m_GroupArray.m_GroupNameList.get(args[1]),p.getUniqueId()); + p.sendMessage("농장 멤버 목록: "); + for (String Name: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(args[1]))){ + p.sendMessage(Name); + } + p.sendMessage("농장 목록:"); + for (String Name: m_GroupArray.GetGroupNameList()){ + p.sendMessage(Name); + } + } break; } case "초대":{ @@ -49,10 +74,29 @@ public class FarmEventHandler implements CommandExecutor { p.sendMessage("강퇴 테스트"); break; } + case "탈퇴": { + if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){ + m_GroupArray.ExpulsionGroupPlayer("Farm",m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Farm"),p.getUniqueId()); + } + else{ + p.sendMessage("가입한 농장이 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm")); + } + break; + } case "이름":{ p.sendMessage("현재 파티 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party"))); break; } + case "정보": { + for (String Name: m_GroupArray.GetGroupNameList()){ + p.sendMessage("농장 이름:"); + p.sendMessage(Name); + p.sendMessage("인원 목록"); + for (String Name2: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(Name))) { + p.sendMessage(Name2); + } + } + } } } return true; diff --git a/Group.java b/Group.java index 38f7b7e..f56be02 100644 --- a/Group.java +++ b/Group.java @@ -27,7 +27,7 @@ public class Group { 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)==uuid){ return true; diff --git a/GroupArray.java b/GroupArray.java index 71c3728..bd8086d 100644 --- a/GroupArray.java +++ b/GroupArray.java @@ -5,12 +5,12 @@ import org.bukkit.Bukkit; import java.util.*; public class GroupArray { - private static Map m_GroupArray = new HashMap(); + public static Map m_GroupArray = new HashMap(); - private static Map m_GroupNameList = new HashMap(); + public static Map m_GroupNameList = new HashMap(); UserInfoArray m_UserInfoArray; - + UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); public GroupArray(UserInfoArray m_UIA){ m_UserInfoArray = m_UIA; } @@ -23,7 +23,18 @@ public class GroupArray { return true; } } + public boolean CheckGroup(String GroupType, String Name){ + return m_GroupArray.containsKey(m_GroupNameList.get(Name)); + } + public static 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)){ @@ -55,10 +66,15 @@ public class GroupArray { } } - public boolean ExpulsionGroupPlayer(UUID GroupUUID, UUID PlayerUUID){ - if(GetGroupMembersName(GroupUUID).contains(PlayerUUID)) { + public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_GroupArray.get(GroupUUID).isMember(PlayerUUID)) { Group m_Group = m_GroupArray.get(GroupUUID); m_Group.Expulsion(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); + if(m_Group.isEmpty()==0){ + 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 }