diff --git a/DB/DBUpdate.java b/DB/DBUpdate.java index 5864372..195878f 100644 --- a/DB/DBUpdate.java +++ b/DB/DBUpdate.java @@ -73,9 +73,10 @@ public class DBUpdate { while(rs.next()){ m_InfoArrayInstance.putUserInfo(UUID.fromString(rs.getString(1)), rs.getString(2), - Integer.parseInt(rs.getString(3)), - Integer.parseInt(rs.getString(4)), - Integer.parseInt(rs.getString(5))); + UUID.fromString(rs.getString(3)), + UUID.fromString(rs.getString(4)), + UUID.fromString(rs.getString(5)), + new UUID(0,0)); m_AccountArray.putAccountInfo(UUID.fromString(rs.getString(1)),Integer.parseInt(rs.getString(6))); } diff --git a/GroupArray.java b/GroupArray.java new file mode 100644 index 0000000..bcd27ec --- /dev/null +++ b/GroupArray.java @@ -0,0 +1,103 @@ +package org.poopki.duckdns.user_db; + +import org.bukkit.Bukkit; + +import java.util.*; + +public class GroupArray { + private static Map m_GroupArray = new HashMap(); + + private static Map m_GroupNameList = new HashMap(); + + UserInfoArray m_UserInfoArray; + + public GroupArray(UserInfoArray m_UIA){ + m_UserInfoArray = m_UIA; + } + public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ + if(m_GroupNameList.containsKey(Name)){ + return false; // Conflict + } else{ + m_GroupArray.put(GroupUUID, new Group(Name, PlayerUUID)); + m_GroupNameList.put(Name, GroupUUID); + return true; + } + } + + public boolean DeleteGroup(UUID GroupUUID){ + if(m_GroupArray.containsKey(GroupUUID)){ + for(UUID key: GetGroupMembersUUID(GroupUUID)){ + m_UserInfoArray.setUserPartyUUID(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(UUID GroupUUID, UUID PlayerUUID){ + if(m_GroupArray.containsKey(GroupUUID)){ + if(isOffline(PlayerUUID)){ + Group m_Group = m_GroupArray.get(GroupUUID); + m_Group.SignUp(PlayerUUID); + m_UserInfoArray.setUserPartyUUID(PlayerUUID,GroupUUID); + return 1; // Success + }else{ + return 2; // Offline Player + } + } else{ + return 3; // Wrong Group + } + } + + public boolean ExpulsionGroupPlayer(UUID GroupUUID, UUID PlayerUUID){ + if(GetGroupMembersName(GroupUUID).contains(PlayerUUID)) { + Group m_Group = m_GroupArray.get(GroupUUID); + m_Group.Expulsion(PlayerUUID); + 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()){ + MembersName.add(Bukkit.getPlayer(key).getDisplayName()); + } + return MembersName; + } + public List GetGroupMembersUUID(UUID GroupUUID){ + return m_GroupArray.get(GroupUUID).getGroupMembers(); + } + public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ + Group m_Group = m_GroupArray.get(GroupUUID); + return m_Group.isMember(PlayerUUID); + } + + public Set GetGroupNameList(){ + return m_GroupNameList.keySet(); + } + + + public String GetGroupName(UUID GroupUUID){ + Group 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); + } + + private boolean isAvaliableGroup(UUID GroupUUID){ + return m_GroupArray.containsKey(GroupUUID); + } + +} diff --git a/UserInfo.java b/UserInfo.java index 7519067..e1e8abc 100644 --- a/UserInfo.java +++ b/UserInfo.java @@ -1,40 +1,29 @@ package org.poopki.duckdns.user_db; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class UserInfo extends Status { private UUID m_UUID; private String m_Name; - private static Map m_status = new HashMap(); - - private int m_Nation; - private int m_Squad; - private int m_Farm; - - private UUID m_Party; - - public UserInfo(UUID uuid, String Name, int Nation, int Squad, int Farm){ //UserInfo 초기화 + private static Map m_GroupUUID = new HashMap(); + public UserInfo(UUID uuid, String Name, UUID Nation, UUID Squad, UUID Farm, UUID Party){ //UserInfo 초기화 super(100,100,1,10,10,10,10); m_UUID = uuid; m_Name = Name; - m_Nation = Nation; - m_Squad = Squad; - m_Farm = Farm; - } - public void JoinNation(int Nation) { m_Nation = Nation; } - public void JoinSquad(int Squad) { m_Squad = Squad; } - public void JoinFarm(int Farm) { m_Farm = Farm; } + m_GroupUUID.put("Nation", Nation); + m_GroupUUID.put("Squad", Squad); + m_GroupUUID.put("Farm", Farm); + m_GroupUUID.put("Party", Party); + } + public void SetGroupUUID(String GroupType, UUID m_UUID){ m_GroupUUID.put(GroupType, m_UUID); } + public UUID GetGroupUUID(String GroupType){ return m_GroupUUID.get(GroupType); } public String getUserName(){ return m_Name; } public UUID getUserUUID(){ return m_UUID; } - public UUID getPartyUUID(){ return m_Party; } - public void setPartyUUID(UUID uuid){ m_Party = uuid; } } diff --git a/UserInfoArray.java b/UserInfoArray.java index dafa328..bcbd0fa 100644 --- a/UserInfoArray.java +++ b/UserInfoArray.java @@ -17,15 +17,17 @@ public class UserInfoArray { public Set getKeySet(){ // 유저 목록 return return m_UserInfoArray.keySet(); } - public UUID getUserPartyUUID(UUID uuid){ - return m_UserInfoArray.get(uuid).getPartyUUID(); + + public UUID getUserPartyUUID(UUID PlayerUUID, String GroupType){ + return m_UserInfoArray.get(PlayerUUID).GetGroupUUID(GroupType); } - public void setUserPartyUUID(UUID PlayerUUID, UUID PartyUUID){ - m_UserInfoArray.get(PlayerUUID).setPartyUUID(PartyUUID); + public void setUserPartyUUID(String GroupType, UUID PlayerUUID, UUID PartyUUID){ + m_UserInfoArray.get(PlayerUUID).SetGroupUUID(GroupType,PartyUUID); } - public void putUserInfo(UUID uuid,String Name, int Nation, int Squad, int Farm) { // UserInfoArray entry 입력 - m_UserInfoArray.put(uuid, new UserInfo(uuid,Name, Nation, Squad, Farm)); + + 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)); } } \ No newline at end of file diff --git a/UserJoin.java b/UserJoin.java index ed9b4a4..d3d2a4f 100644 --- a/UserJoin.java +++ b/UserJoin.java @@ -4,6 +4,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +import java.util.UUID; + public class UserJoin implements Listener { private UserInfoArray m_InfoArrayInstance; private AccountArray m_AccountArray; @@ -15,7 +17,7 @@ public class UserJoin implements Listener { public void PlayerLogin(PlayerJoinEvent e) { Player p = e.getPlayer(); if(!m_InfoArrayInstance.checkNewUser(p.getUniqueId())){ //새로운 user인 경우 array에 등록 - m_InfoArrayInstance.putUserInfo(p.getUniqueId(), p.getName(), 0, 0, 0); + m_InfoArrayInstance.putUserInfo(p.getUniqueId(), p.getName(), new UUID(0,0), new UUID(0,0), new UUID(0,0), new UUID(0,0)); m_AccountArray.putAccountInfo(p.getUniqueId(), 0); } }