parent
6037d17087
commit
8295f06691
12 changed files with 1048 additions and 54 deletions
@ -0,0 +1,47 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
public class Farm { |
||||
private String m_Name; |
||||
private List<UUID> 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> 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<UUID> 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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
|
||||
import java.util.*; |
||||
|
||||
public class FarmArray { |
||||
|
||||
|
||||
public static Map<UUID, Farm> m_GroupArray; |
||||
public static Map<String, UUID> m_GroupNameList; |
||||
UserInfoArray m_UserInfoArray; |
||||
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); |
||||
int MAX_GROUP_NUM = 13; |
||||
|
||||
public FarmArray(UserInfoArray m_UIA){ |
||||
m_UserInfoArray = m_UIA; |
||||
m_GroupArray = new HashMap<UUID, Farm>(); |
||||
m_GroupNameList = new HashMap<String, UUID>(); |
||||
} |
||||
|
||||
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ |
||||
if(m_GroupNameList.containsKey(Name)){ |
||||
return false; // Conflict
|
||||
} else{ |
||||
List<UUID> m_MemberList = new ArrayList<>(); |
||||
m_MemberList.add(PlayerUUID); |
||||
for(int index=1; index<MAX_GROUP_NUM;index++){ |
||||
m_MemberList.add(index,ZERO_UUID); |
||||
} |
||||
m_GroupArray.put(GroupUUID, new Farm(Name, m_MemberList)); |
||||
m_GroupNameList.put(Name, GroupUUID); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public boolean PutGroup(UUID GroupUUID, String Name,List<UUID> PlayerUUID){ |
||||
List<UUID> m_MemberList = new ArrayList<>(); |
||||
|
||||
Iterator <UUID> it = PlayerUUID.iterator(); |
||||
|
||||
while(it.hasNext()){ |
||||
m_MemberList.add(it.next()); |
||||
} |
||||
|
||||
for(int index=MAX_GROUP_NUM-PlayerUUID.size();index<MAX_GROUP_NUM;index++){ |
||||
m_MemberList.add(ZERO_UUID); |
||||
} |
||||
m_GroupArray.put(GroupUUID, new Farm(Name, m_MemberList)); |
||||
m_GroupNameList.put(Name,GroupUUID); |
||||
return true; |
||||
} |
||||
public UUID GetUUID(String name){ |
||||
return m_GroupNameList.get(name); |
||||
} |
||||
public boolean CheckGroup(String GroupType, String Name){ |
||||
return m_GroupArray.containsKey(m_GroupNameList.get(Name)); |
||||
} |
||||
public static <K, V> K getKey(Map<K, V> 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<UUID> 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<String> GetGroupMembersName(UUID GroupUUID){ |
||||
List<String> 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<UUID> 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<String> GetGroupNameList(){ |
||||
return m_GroupNameList.keySet(); |
||||
} |
||||
|
||||
public Set<UUID> getKeySet(){ // 유저 목록 return
|
||||
return m_GroupArray.keySet(); |
||||
} |
||||
|
||||
public Set<String> 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); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
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<UUID> 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> 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<UUID> 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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
|
||||
import java.util.*; |
||||
|
||||
public class NationArray { |
||||
|
||||
|
||||
public static Map<UUID, Nation> m_GroupArray; |
||||
public static Map<String, UUID> 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<UUID, Nation>(); |
||||
m_GroupNameList = new HashMap<String, UUID>(); |
||||
} |
||||
|
||||
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ |
||||
if(m_GroupNameList.containsKey(Name)){ |
||||
return false; // Conflict
|
||||
} else{ |
||||
List<UUID> m_MemberList = new ArrayList<>(); |
||||
m_MemberList.add(PlayerUUID); |
||||
for(int index=1; index<MAX_GROUP_NUM;index++){ |
||||
m_MemberList.add(index,ZERO_UUID); |
||||
} |
||||
m_GroupArray.put(GroupUUID, new Nation(Name, m_MemberList)); |
||||
m_GroupNameList.put(Name, GroupUUID); |
||||
return true; |
||||
} |
||||
} |
||||
public UUID GetUUID(String name){ |
||||
return m_GroupNameList.get(name); |
||||
} |
||||
public boolean PutGroup(UUID GroupUUID, String Name,List<UUID> PlayerUUID){ |
||||
List<UUID> m_MemberList = new ArrayList<>(); |
||||
|
||||
Iterator <UUID> it = PlayerUUID.iterator(); |
||||
|
||||
while(it.hasNext()){ |
||||
m_MemberList.add(it.next()); |
||||
} |
||||
|
||||
for(int index=MAX_GROUP_NUM-PlayerUUID.size();index<MAX_GROUP_NUM;index++){ |
||||
m_MemberList.add(ZERO_UUID); |
||||
} |
||||
m_GroupArray.put(GroupUUID, new Nation(Name, m_MemberList)); |
||||
m_GroupNameList.put(Name,GroupUUID); |
||||
return true; |
||||
} |
||||
|
||||
public boolean CheckGroup(String GroupType, String Name){ |
||||
return m_GroupArray.containsKey(m_GroupNameList.get(Name)); |
||||
} |
||||
public static <K, V> K getKey(Map<K, V> 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<UUID> 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<String> GetGroupMembersName(UUID GroupUUID){ |
||||
List<String> 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<UUID> 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<String> GetGroupNameList(){ |
||||
return m_GroupNameList.keySet(); |
||||
} |
||||
|
||||
public Set<UUID> getKeySet(){ // 유저 목록 return
|
||||
return m_GroupArray.keySet(); |
||||
} |
||||
|
||||
public Set<String> 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); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue