parent
de6b3de02f
commit
d464d5a77d
27 changed files with 874 additions and 534 deletions
@ -1,4 +1,4 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
package org.poopki.duckdns.user_db.Array; |
||||
|
||||
public class Account { |
||||
private int m_Balance; |
@ -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; |
@ -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> uuid_list){ |
||||
super(Name, uuid_list); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
|
@ -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; |
||||
} |
||||
} |
@ -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> uuid_list){ |
||||
super(Name, uuid_list); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
|
@ -1,47 +0,0 @@ |
||||
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; |
||||
} |
||||
} |
||||
} |
@ -1,162 +0,0 @@ |
||||
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 = 10; |
||||
|
||||
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,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; |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
|
||||
|
||||
} |
@ -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); |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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;} |
||||
|
||||
} |
@ -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<UUID, Invitation> m_InviteQueue = new HashMap<UUID, Invitation>(); |
||||
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; |
||||
} |
||||
} |
@ -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<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; |
||||
} |
||||
} |
||||
} |
@ -1,162 +0,0 @@ |
||||
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