You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.3 KiB
103 lines
3.3 KiB
package org.poopki.duckdns.user_db; |
|
|
|
import org.bukkit.Bukkit; |
|
|
|
import java.util.*; |
|
|
|
public class GroupArray { |
|
private static Map<UUID, Group> m_GroupArray = new HashMap<UUID, Group>(); |
|
|
|
private static Map<String, UUID> m_GroupNameList = new HashMap<String, UUID>(); |
|
|
|
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, String GroupType){ |
|
if(m_GroupArray.containsKey(GroupUUID)){ |
|
for(UUID key: GetGroupMembersUUID(GroupUUID)){ |
|
m_UserInfoArray.setUserPartyUUID(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)){ |
|
Group m_Group = m_GroupArray.get(GroupUUID); |
|
m_Group.SignUp(PlayerUUID); |
|
m_UserInfoArray.setUserPartyUUID(GroupType,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<String> GetGroupMembersName(UUID GroupUUID){ |
|
List<String> MembersName = new ArrayList<>(); |
|
for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){ |
|
MembersName.add(Bukkit.getPlayer(key).getDisplayName()); |
|
} |
|
return MembersName; |
|
} |
|
public List<UUID> 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<String> 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); |
|
} |
|
|
|
}
|
|
|