From 36b0fec006172dbafc758519a0920b2215ff7865 Mon Sep 17 00:00:00 2001 From: poopki Date: Thu, 21 Sep 2023 17:54:17 +0900 Subject: [PATCH] 20230921 --- Array/Account.java | 14 +- Array/AccountArray.java | 4 +- Array/FarmArray.java | 175 +++++++++++++++- Array/Group.java | 93 +-------- Array/GroupArray.java | 9 +- Array/Nation.java | 132 +++++------- Array/NationArray.java | 187 ++++++++++++++++- Array/NationEventHandler.java | 4 +- Array/SquadArray.java | 178 +++++++++++++++- {GUI => Bank}/AccountGUI.java | 13 +- {GUI => Bank}/AccountGUIEvent.java | 19 +- Bank/Digit.java | 4 + DB/DBUpdate.java | 280 +++++++++----------------- GUI/BaseGUI.java | 44 ---- GUI/Digit.java | 4 - GUI/ItemManager.java | 4 +- GUI/OpenInv.java | 21 +- GUI/TechGUIEvent.java | 64 ------ GUI/TechStat.java | 101 ---------- {GUI => InfoGUI}/ScoreboardEvent.java | 4 +- Research/Research.java | 102 ++++++++++ Research/ResearchGUIEvent.java | 45 +++++ {GUI => TechTree}/TechGUI.java | 49 +---- TechTree/TechGUIEvent.java | 237 ++++++++++++++++++++++ TechTree/TechStat.java | 22 ++ UserJoin.java | 11 +- User_DB.java | 36 +++- WorldGuard/WG.java | 77 +++++++ WorldGuard/WGRegionExample.java | 36 ++++ WorldGuard/WgCommand.java | 89 ++++++++ 30 files changed, 1386 insertions(+), 672 deletions(-) rename {GUI => Bank}/AccountGUI.java (96%) rename {GUI => Bank}/AccountGUIEvent.java (73%) create mode 100644 Bank/Digit.java delete mode 100644 GUI/Digit.java delete mode 100644 GUI/TechGUIEvent.java delete mode 100644 GUI/TechStat.java rename {GUI => InfoGUI}/ScoreboardEvent.java (97%) create mode 100644 Research/Research.java create mode 100644 Research/ResearchGUIEvent.java rename {GUI => TechTree}/TechGUI.java (67%) create mode 100644 TechTree/TechGUIEvent.java create mode 100644 TechTree/TechStat.java create mode 100644 WorldGuard/WG.java create mode 100644 WorldGuard/WGRegionExample.java create mode 100644 WorldGuard/WgCommand.java diff --git a/Array/Account.java b/Array/Account.java index 949de09..99b8791 100644 --- a/Array/Account.java +++ b/Array/Account.java @@ -6,9 +6,9 @@ public class Account { public Account(int Balance){ // Account Balance 초기화 m_Balance = Balance; } - public boolean setBalance(Long Amount){ - if(Amount= Amount){ - m_Balance -= Amount.intValue(); + if(m_Balance >= Amount){ // 잔고가 MAX_BALANCE 이하일경우 + m_Balance -= Amount.intValue(); // Amount만큼 현재 잔고에서 빼기 return true; } return false; diff --git a/Array/AccountArray.java b/Array/AccountArray.java index 742d25b..85d5fb5 100644 --- a/Array/AccountArray.java +++ b/Array/AccountArray.java @@ -1,12 +1,14 @@ package org.poopki.duckdns.user_db.Array; +import org.bukkit.plugin.Plugin; + import java.util.HashMap; import java.util.Map; import java.util.UUID; public class AccountArray { private static Map m_AccountArray = new HashMap(); - + Plugin plugin; public int transfer(UUID Src, UUID Des, Long Amount){ // 송금 method Account m_Src = m_AccountArray.get(Src); Account m_Des = m_AccountArray.get(Des); diff --git a/Array/FarmArray.java b/Array/FarmArray.java index 4437b2c..bd9539a 100644 --- a/Array/FarmArray.java +++ b/Array/FarmArray.java @@ -1,12 +1,181 @@ package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.poopki.duckdns.user_db.UserInfoArray; import java.util.*; -public class FarmArray extends GroupArray{ - public FarmArray(UserInfoArray m_UIA){ - super(m_UIA, 10); +public class FarmArray { + + + public Map m_FarmArray; + protected Map m_GroupNameList; + public List m_DeleteQueue = new ArrayList<>(); + UserInfoArray m_UserInfoArray; + UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); + int MAX_GROUP_NUM = 10; + Plugin plugin; + public FarmArray(UserInfoArray m_UIA, int num, Plugin plugin){ + m_UserInfoArray = m_UIA; + m_FarmArray = new HashMap(); + m_GroupNameList = new HashMap(); + MAX_GROUP_NUM = num; + this.plugin = plugin; + } + + public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ + if(m_GroupNameList.containsKey(Name)){ + return false; // Conflict + } else{ + List m_MemberList = new ArrayList<>(); + m_MemberList.add(PlayerUUID); + + m_FarmArray.put(GroupUUID, new Farm(Name, m_MemberList)); + m_GroupNameList.put(Name, GroupUUID); + return true; + } + } + + public void SetGroupTechTree(UUID GroupUUID, String TechName, Integer set){ + m_FarmArray.get(GroupUUID).SetTechTree(TechName,set); + + } + + public int GetGroupTechTree(UUID GroupUUID, String TechName){ + return m_FarmArray.get(GroupUUID).GetTechTree(TechName); + } + + public boolean PutGroup(UUID GroupUUID, String Name,List PlayerUUID){ + List m_MemberList = new ArrayList<>(); + + Iterator it = PlayerUUID.iterator(); + + while(it.hasNext()){ + m_MemberList.add(it.next()); + } + + m_FarmArray.put(GroupUUID, new Farm(Name, m_MemberList)); + m_GroupNameList.put(Name,GroupUUID); + return true; + } + + public boolean CheckGroup(String GroupType, String Name){ + return m_FarmArray.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 UUID GetUUID(String name){ + return m_GroupNameList.get(name); } + + public boolean DeleteGroup(UUID GroupUUID, String GroupType){ + if(m_FarmArray.containsKey(GroupUUID)){ + for(UUID key: GetGroupMembersUUID(GroupUUID)){ + m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0)); + } + + m_GroupNameList.remove(GetGroupName(GroupUUID)); + m_FarmArray.remove(GroupUUID); + return true; + } + else{ + return false; // Group is not exists. + } + + } + + public String SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_FarmArray.containsKey(GroupUUID) && m_UserInfoArray.getUserGroupUUID(PlayerUUID, GroupType).equals(ZERO_UUID)){ + Group m_Group = m_FarmArray.get(GroupUUID); + m_Group.SignUp(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); + return ""; + } else{ + return "다른 그룹에 가입되어있습니다."; // Wrong Group + } + } + + public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_FarmArray.get(GroupUUID).isMember(PlayerUUID)) { + Group m_Group = m_FarmArray.get(GroupUUID); + m_Group.Expulsion(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); + int temp = m_FarmArray.get(GroupUUID).getMemNUM(); + + if(temp==0){ + m_GroupNameList.remove(m_Group.getGroupName()); + m_FarmArray.remove(GroupUUID); + m_DeleteQueue.add(GroupUUID); + Bukkit.getPlayer(PlayerUUID).sendMessage(""+temp+" "+m_DeleteQueue); + } + 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_FarmArray.get(GroupUUID).getGroupMembers()){ + try { + MembersName.add(Bukkit.getPlayer(key).getDisplayName()); + } + catch(NullPointerException e){ + + } + } + return MembersName; + } + public List GetGroupMembersUUID(UUID GroupUUID){ + return m_FarmArray.get(GroupUUID).getGroupMembers(); + } + public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ + Group m_Group = m_FarmArray.get(GroupUUID); + return m_Group.isMember(PlayerUUID); + } + public int GetGroupMemNUM(UUID GroupUUID){ + Group m_Group = m_FarmArray.get(GroupUUID); + return m_Group.getMemNUM(); + } + public Set GetGroupNameList(){ + return m_GroupNameList.keySet(); + } + + public Set getKeySet(){ // 유저 목록 return + return m_FarmArray.keySet(); + } + + public Set getNameSet() { return m_GroupNameList.keySet(); } + public String GetGroupName(UUID GroupUUID){ + Group m_Group = m_FarmArray.get(GroupUUID); + return m_Group.getGroupName(); + } + public int GetGroupMemMaxNum(UUID GroupUUID){ + Group m_Group = m_FarmArray.get(GroupUUID); + return m_Group.getMemMaxNUM(); + } + public boolean isOffline(UUID uuid){ + return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); + } + + public boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ + return m_FarmArray.get(GroupUUID).isOwner(PlayerUUID); + } + private boolean isAvaliableGroup(UUID GroupUUID){ + return m_FarmArray.containsKey(GroupUUID); + } + } diff --git a/Array/Group.java b/Array/Group.java index 4ffd8eb..587db04 100644 --- a/Array/Group.java +++ b/Array/Group.java @@ -1,14 +1,18 @@ package org.poopki.duckdns.user_db.Array; +import org.bukkit.inventory.Inventory; +import org.poopki.duckdns.user_db.Research.Research; + import java.util.*; public class Group { - private String m_Name; - private List m_MemberList = new ArrayList<>(); - public List TechList = Arrays.asList("agriculture","pottery","animal_husbandry","archery","mining","sailing","calendar","writing","trapping","wheel","masonry","bronze","optics","horseback","mathematics","construction","philosophy","drama","currency","engineering","iron_working","theology","civil_service","guilds","metal_casting","compass","education","chivalry","machinery","physics","steel","astronomy","acoustics","banking","printing_press","gunpowder","navigation","architecture","economics","metallurgy","chemistry","archaeology","scientific_theory","industrialization","rifling","military_science","fertilizer","biology","electricity","steam_power","dynamite","refrigeration","radio","flight","railroad","plastics","electronics","ballistics","combustion","penicillin","atomic_theory","radar","combined_arms","ecology","nuclear_fission","rocketry","computers","telecommunications","mobile_tactics","advanced_ballistics","satellites","robotics","lasers","the_internet","globalization","particle_physics","nuclear_fusion","nanotechnology","stealth"); + public String m_Name; + public List m_MemberList = new ArrayList<>(); + public List m_ResearchArray = new ArrayList(); public Map m_TechStat = new HashMap(); UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); int MAX_FARM_NUM = 10; + Inventory research_tab; public Group(String Name, List uuid_list){ int index = 0; @@ -16,7 +20,6 @@ public class Group { m_MemberList.add(index,key); index++; } - InitTechTree(); m_Name = Name; } @@ -50,86 +53,8 @@ public class Group { } } - public void InitTechTree(){ - m_TechStat.put("agriculture",0); - m_TechStat.put("pottery",0); - m_TechStat.put("animal_husbandry",0); - m_TechStat.put("archery",0); - m_TechStat.put("mining",0); - m_TechStat.put("sailing",0); - m_TechStat.put("calendar",0); - m_TechStat.put("writing",0); - m_TechStat.put("trapping",0); - m_TechStat.put("wheel",0); - m_TechStat.put("masonry",0); - m_TechStat.put("bronze",0); - m_TechStat.put("optics",0); - m_TechStat.put("horseback",0); - m_TechStat.put("mathematics",0); - m_TechStat.put("construction",0); - m_TechStat.put("philosophy",0); - m_TechStat.put("drama",0); - m_TechStat.put("currency",0); - m_TechStat.put("engineering",0); - m_TechStat.put("iron_working",0); - m_TechStat.put("theology",0); - m_TechStat.put("civil_service",0); - m_TechStat.put("guilds",0); - m_TechStat.put("metal_casting",0); - m_TechStat.put("compass",0); - m_TechStat.put("education",0); - m_TechStat.put("chivalry",0); - m_TechStat.put("machinery",0); - m_TechStat.put("physics",0); - m_TechStat.put("steel",0); - m_TechStat.put("astronomy",0); - m_TechStat.put("acoustics",0); - m_TechStat.put("banking",0); - m_TechStat.put("printing_press",0); - m_TechStat.put("gunpowder",0); - m_TechStat.put("navigation",0); - m_TechStat.put("architecture",0); - m_TechStat.put("economics",0); - m_TechStat.put("metallurgy",0); - m_TechStat.put("chemistry",0); - m_TechStat.put("archaeology",0); - m_TechStat.put("scientific_theory",0); - m_TechStat.put("industrialization",0); - m_TechStat.put("rifling",0); - m_TechStat.put("military_science",0); - m_TechStat.put("fertilizer",0); - m_TechStat.put("biology",0); - m_TechStat.put("electricity",0); - m_TechStat.put("steam_power",0); - m_TechStat.put("dynamite",0); - m_TechStat.put("refrigeration",0); - m_TechStat.put("radio",0); - m_TechStat.put("flight",0); - m_TechStat.put("railroad",0); - m_TechStat.put("plastics",0); - m_TechStat.put("electronics",0); - m_TechStat.put("ballistics",0); - m_TechStat.put("combustion",0); - m_TechStat.put("penicillin",0); - m_TechStat.put("atomic_theory",0); - m_TechStat.put("radar",0); - m_TechStat.put("combined_arms",0); - m_TechStat.put("ecology",0); - m_TechStat.put("nuclear_fission",0); - m_TechStat.put("rocketry",0); - m_TechStat.put("computers",0); - m_TechStat.put("telecommunications",0); - m_TechStat.put("mobile_tactics",0); - m_TechStat.put("advanced_ballistics",0); - m_TechStat.put("satellites",0); - m_TechStat.put("robotics",0); - m_TechStat.put("lasers",0); - m_TechStat.put("the_internet",0); - m_TechStat.put("globalization",0); - m_TechStat.put("particle_physics",0); - m_TechStat.put("nuclear_fusion",0); - m_TechStat.put("nanotechnology",0); - m_TechStat.put("stealth",0); + public void InitTechTree(String A, Integer B){ + m_TechStat.put(A,B); } public void SetTechTree(String TechName, Integer set){ m_TechStat.replace(TechName,set); diff --git a/Array/GroupArray.java b/Array/GroupArray.java index bbbeaad..f1928d9 100644 --- a/Array/GroupArray.java +++ b/Array/GroupArray.java @@ -2,6 +2,7 @@ package org.poopki.duckdns.user_db.Array; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.poopki.duckdns.user_db.UserInfoArray; import java.util.*; @@ -15,12 +16,13 @@ public class GroupArray { UserInfoArray m_UserInfoArray; UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); int MAX_GROUP_NUM = 10; - - public GroupArray(UserInfoArray m_UIA, int num){ + Plugin plugin; + public GroupArray(UserInfoArray m_UIA, int num, Plugin plugin){ m_UserInfoArray = m_UIA; m_GroupArray = new HashMap(); m_GroupNameList = new HashMap(); MAX_GROUP_NUM = num; + this.plugin = plugin; } public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ @@ -36,9 +38,6 @@ public class GroupArray { } } - public void InitGroupTechTree(UUID GroupUUID){ - m_GroupArray.get(GroupUUID).InitTechTree(); - } public void SetGroupTechTree(UUID GroupUUID, String TechName, Integer set){ m_GroupArray.get(GroupUUID).SetTechTree(TechName,set); diff --git a/Array/Nation.java b/Array/Nation.java index 5e15c15..f38d3d4 100644 --- a/Array/Nation.java +++ b/Array/Nation.java @@ -1,93 +1,57 @@ package org.poopki.duckdns.user_db.Array; +import dev.lone.itemsadder.api.CustomStack; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.poopki.duckdns.user_db.Research.Research; + import java.util.*; public class Nation extends Group{ - public Nation(String Name, List uuid_list){ + + String[] techtree = {"agriculture","pottery","animal_husbandry","archery","mining","sailing","calendar","writing","trapping","wheel","masonry","bronze","optics","horseback","mathematics","construction","philosophy","drama","currency","engineering","iron_working","theology","civil_service","guilds","metal_casting","compass","education","chivalry","machinery","physics","steel","astronomy","acoustics","banking","printing_press","gunpowder","navigation","architecture","economics","metallurgy","chemistry","archaeology","scientific_theory","industrialization","rifling","military_science","fertilizer","biology","electricity","steam_power","dynamite","refrigeration","radio","flight","railroad","plastics","electronics","ballistics","combustion","penicillin","atomic_theory","radar","combined_arms","ecology","nuclear_fission","rocketry","computers","telecommunications","mobile_tactics","advanced_ballistics","satellites","robotics","lasers","the_internet","globalization","particle_physics","nuclear_fusion","nanotechnology","stealth"}; + + + public Nation(String Name, List uuid_list, Plugin plugin){ super(Name, uuid_list); - } - private Map m_TechStat = new HashMap(); - public void InitTechTree(){ - m_TechStat.put("agriculture",0); - m_TechStat.put("pottery",0); - m_TechStat.put("animal_husbandry",0); - m_TechStat.put("archery",0); - m_TechStat.put("mining",0); - m_TechStat.put("sailing",0); - m_TechStat.put("calendar",0); - m_TechStat.put("writing",0); - m_TechStat.put("trapping",0); - m_TechStat.put("wheel",0); - m_TechStat.put("masonry",0); - m_TechStat.put("bronze",0); - m_TechStat.put("optics",0); - m_TechStat.put("horseback",0); - m_TechStat.put("mathematics",0); - m_TechStat.put("construction",0); - m_TechStat.put("philosophy",0); - m_TechStat.put("drama",0); - m_TechStat.put("currency",0); - m_TechStat.put("engineering",0); - m_TechStat.put("iron_working",0); - m_TechStat.put("theology",0); - m_TechStat.put("civil_service",0); - m_TechStat.put("guilds",0); - m_TechStat.put("metal_casting",0); - m_TechStat.put("compass",0); - m_TechStat.put("education",0); - m_TechStat.put("chivalry",0); - m_TechStat.put("machinery",0); - m_TechStat.put("physics",0); - m_TechStat.put("steel",0); - m_TechStat.put("astronomy",0); - m_TechStat.put("acoustics",0); - m_TechStat.put("banking",0); - m_TechStat.put("printing_press",0); - m_TechStat.put("gunpowder",0); - m_TechStat.put("navigation",0); - m_TechStat.put("architecture",0); - m_TechStat.put("economics",0); - m_TechStat.put("metallurgy",0); - m_TechStat.put("chemistry",0); - m_TechStat.put("archaeology",0); - m_TechStat.put("scientific_theory",0); - m_TechStat.put("industrialization",0); - m_TechStat.put("rifling",0); - m_TechStat.put("military_science",0); - m_TechStat.put("fertilizer",0); - m_TechStat.put("biology",0); - m_TechStat.put("electricity",0); - m_TechStat.put("steam_power",0); - m_TechStat.put("dynamite",0); - m_TechStat.put("refrigeration",0); - m_TechStat.put("radio",0); - m_TechStat.put("flight",0); - m_TechStat.put("railroad",0); - m_TechStat.put("plastics",0); - m_TechStat.put("electronics",0); - m_TechStat.put("ballistics",0); - m_TechStat.put("combustion",0); - m_TechStat.put("penicillin",0); - m_TechStat.put("atomic_theory",0); - m_TechStat.put("radar",0); - m_TechStat.put("combined_arms",0); - m_TechStat.put("ecology",0); - m_TechStat.put("nuclear_fission",0); - m_TechStat.put("rocketry",0); - m_TechStat.put("computers",0); - m_TechStat.put("telecommunications",0); - m_TechStat.put("mobile_tactics",0); - m_TechStat.put("advanced_ballistics",0); - m_TechStat.put("satellites",0); - m_TechStat.put("robotics",0); - m_TechStat.put("lasers",0); - m_TechStat.put("the_internet",0); - m_TechStat.put("globalization",0); - m_TechStat.put("particle_physics",0); - m_TechStat.put("nuclear_fusion",0); - m_TechStat.put("nanotechnology",0); - m_TechStat.put("stealth",0); - } + for(int i = 0; i<3; i++){ + m_ResearchArray.add(new Research("연구 테스트",plugin, m_MemberList)); + //연구 프로그레스바 등록 + } + //Init 테크트리 + for(String Key: techtree){ + InitTechTree(Key,0); + } + new BukkitRunnable(){ + @Override + public void run(){ + for(Research key:m_ResearchArray){ + for(UUID uuid: Nation.super.getGroupMembers()){ + if(Bukkit.getPlayer(uuid)!=null){ + key.tech1_progressbar.addPlayer(Bukkit.getPlayer(uuid)); + } + } + } + } + }.runTaskTimer(plugin,0,20); + } + public void InitResearchItem(){ + //System.out.println(CustomStack.getInstance("research:materials-book").getDisplayName()); + ArrayList InitStack = new ArrayList(); + InitStack.add(CustomStack.getInstance("research:materials-book").getItemStack()); + InitStack.add(CustomStack.getInstance("research:materials-crystal").getItemStack()); + InitStack.add(CustomStack.getInstance("research:materials-god_pot").getItemStack()); + m_ResearchArray.get(0).SetMaterials(InitStack); // 0-> 고대 연구 아이템 설정 + } + public void AddShowResearchProgressBar(Integer index, Player player){ + m_ResearchArray.get(index).tech1_progressbar.addPlayer(player); + } + public void ShowResearchProgressBar(Integer index, boolean toggle){ + m_ResearchArray.get(index).tech1_progressbar.setVisible(toggle); + } } diff --git a/Array/NationArray.java b/Array/NationArray.java index 518fe83..d42b33c 100644 --- a/Array/NationArray.java +++ b/Array/NationArray.java @@ -1,9 +1,190 @@ package org.poopki.duckdns.user_db.Array; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; import org.poopki.duckdns.user_db.UserInfoArray; -public class NationArray extends GroupArray{ - public NationArray(UserInfoArray m_UIA){ - super(m_UIA, 50); + +import java.util.*; + +public class NationArray { + + + public Map m_NationArray; + protected Map m_GroupNameList; + public List m_DeleteQueue = new ArrayList<>(); + UserInfoArray m_UserInfoArray; + UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); + int MAX_GROUP_NUM = 10; + Plugin plugin; + public NationArray(UserInfoArray m_UIA, int num, Plugin plugin){ + m_UserInfoArray = m_UIA; + m_NationArray = new HashMap(); + m_GroupNameList = new HashMap(); + MAX_GROUP_NUM = num; + this.plugin = plugin; + + } + public Inventory getGroupTechInv(Player player, Integer index){ + return m_NationArray.get(m_UserInfoArray.getUserGroupUUID(player.getUniqueId(),"Nation")).m_ResearchArray.get(index).getInventory(); + } + public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ + if(m_GroupNameList.containsKey(Name)){ + return false; // Conflict + } else{ + List m_MemberList = new ArrayList<>(); + m_MemberList.add(PlayerUUID); + + m_NationArray.put(GroupUUID, new Nation(Name, m_MemberList, plugin)); + m_GroupNameList.put(Name, GroupUUID); + return true; + } + } +/* + public void InitGroupTechTree(UUID GroupUUID){ + m_NationArray.get(GroupUUID).InitTechTree(); + } + + */ + public void SetGroupTechTree(UUID GroupUUID, String TechName, Integer set){ + m_NationArray.get(GroupUUID).SetTechTree(TechName,set); + + } + + public int GetGroupTechTree(UUID GroupUUID, String TechName){ + return m_NationArray.get(GroupUUID).GetTechTree(TechName); + } + + public boolean PutGroup(UUID GroupUUID, String Name,List PlayerUUID){ + List m_MemberList = new ArrayList<>(); + + Iterator it = PlayerUUID.iterator(); + + while(it.hasNext()){ + m_MemberList.add(it.next()); + } + + m_NationArray.put(GroupUUID, new Nation(Name, m_MemberList, plugin)); + m_GroupNameList.put(Name,GroupUUID); + return true; + } + + public boolean CheckGroup(String GroupType, String Name){ + return m_NationArray.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 UUID GetUUID(String name){ + return m_GroupNameList.get(name); + } + + public boolean DeleteGroup(UUID GroupUUID, String GroupType){ + if(m_NationArray.containsKey(GroupUUID)){ + for(UUID key: GetGroupMembersUUID(GroupUUID)){ + m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0)); + } + + m_GroupNameList.remove(GetGroupName(GroupUUID)); + m_NationArray.remove(GroupUUID); + return true; + } + else{ + return false; // Group is not exists. + } + + } + + public String SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_NationArray.containsKey(GroupUUID) && m_UserInfoArray.getUserGroupUUID(PlayerUUID, GroupType).equals(ZERO_UUID)){ + Group m_Group = m_NationArray.get(GroupUUID); + m_Group.SignUp(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); + return ""; + } else{ + return "다른 그룹에 가입되어있습니다."; // Wrong Group + } + } + + public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_NationArray.get(GroupUUID).isMember(PlayerUUID)) { + Group m_Group = m_NationArray.get(GroupUUID); + m_Group.Expulsion(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); + int temp = m_NationArray.get(GroupUUID).getMemNUM(); + + if(temp==0){ + m_GroupNameList.remove(m_Group.getGroupName()); + m_NationArray.remove(GroupUUID); + m_DeleteQueue.add(GroupUUID); + Bukkit.getPlayer(PlayerUUID).sendMessage(""+temp+" "+m_DeleteQueue); + } + 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_NationArray.get(GroupUUID).getGroupMembers()){ + try { + MembersName.add(Bukkit.getPlayer(key).getDisplayName()); + } + catch(NullPointerException e){ + + } + } + return MembersName; + } + public List GetGroupMembersUUID(UUID GroupUUID){ + return m_NationArray.get(GroupUUID).getGroupMembers(); + } + public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ + Group m_Group = m_NationArray.get(GroupUUID); + return m_Group.isMember(PlayerUUID); + } + public int GetGroupMemNUM(UUID GroupUUID){ + Group m_Group = m_NationArray.get(GroupUUID); + return m_Group.getMemNUM(); + } + public Set GetGroupNameList(){ + return m_GroupNameList.keySet(); + } + + public Set getKeySet(){ // 유저 목록 return + return m_NationArray.keySet(); + } + + public Set getNameSet() { return m_GroupNameList.keySet(); } + public String GetGroupName(UUID GroupUUID){ + Group m_Group = m_NationArray.get(GroupUUID); + return m_Group.getGroupName(); + } + public int GetGroupMemMaxNum(UUID GroupUUID){ + Group m_Group = m_NationArray.get(GroupUUID); + return m_Group.getMemMaxNUM(); + } + public boolean isOffline(UUID uuid){ + return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); + } + + public boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ + return m_NationArray.get(GroupUUID).isOwner(PlayerUUID); + } + private boolean isAvaliableGroup(UUID GroupUUID){ + return m_NationArray.containsKey(GroupUUID); } } diff --git a/Array/NationEventHandler.java b/Array/NationEventHandler.java index da50e8c..f03599c 100644 --- a/Array/NationEventHandler.java +++ b/Array/NationEventHandler.java @@ -6,7 +6,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.poopki.duckdns.user_db.UserInfoArray; - +import org.poopki.duckdns.user_db.Research.*; import java.util.UUID; public class NationEventHandler implements CommandExecutor { @@ -49,11 +49,11 @@ public class NationEventHandler implements CommandExecutor { m_UserInfoArray.setUserGroupUUID("Nation",p.getUniqueId(), tempUUID); m_AccountArray.putAccountInfo(tempUUID,0); - for (UUID key: m_UserInfoArray.getKeySet()){ p.sendMessage("------------"+p.getUniqueId()); p.sendMessage(""+m_UserInfoArray.getUserGroupUUID(key,"Nation")); } + p.sendMessage(args[1]+"국가이 생성되었습니다."+m_NationArray.GetGroupTechTree(tempUUID,"agriculture")); p.sendMessage("국가 멤버 목록: "); diff --git a/Array/SquadArray.java b/Array/SquadArray.java index 32a72cb..0649899 100644 --- a/Array/SquadArray.java +++ b/Array/SquadArray.java @@ -1,9 +1,181 @@ package org.poopki.duckdns.user_db.Array; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.poopki.duckdns.user_db.UserInfoArray; -public class SquadArray extends GroupArray{ - public SquadArray(UserInfoArray m_UIA){ - super(m_UIA, 8); +import java.util.*; + +public class SquadArray { + + + public Map m_SquadArray; + protected Map m_GroupNameList; + public List m_DeleteQueue = new ArrayList<>(); + UserInfoArray m_UserInfoArray; + UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); + int MAX_GROUP_NUM = 10; + Plugin plugin; + public SquadArray(UserInfoArray m_UIA, int num, Plugin plugin){ + m_UserInfoArray = m_UIA; + m_SquadArray = new HashMap(); + m_GroupNameList = new HashMap(); + MAX_GROUP_NUM = num; + this.plugin = plugin; + } + + public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ + if(m_GroupNameList.containsKey(Name)){ + return false; // Conflict + } else{ + List m_MemberList = new ArrayList<>(); + m_MemberList.add(PlayerUUID); + + m_SquadArray.put(GroupUUID, new Squad(Name, m_MemberList)); + m_GroupNameList.put(Name, GroupUUID); + return true; + } + } + + public void SetGroupTechTree(UUID GroupUUID, String TechName, Integer set){ + m_SquadArray.get(GroupUUID).SetTechTree(TechName,set); + + } + + public int GetGroupTechTree(UUID GroupUUID, String TechName){ + return m_SquadArray.get(GroupUUID).GetTechTree(TechName); + } + + public boolean PutGroup(UUID GroupUUID, String Name,List PlayerUUID){ + List m_MemberList = new ArrayList<>(); + + Iterator it = PlayerUUID.iterator(); + + while(it.hasNext()){ + m_MemberList.add(it.next()); + } + + m_SquadArray.put(GroupUUID, new Squad(Name, m_MemberList)); + m_GroupNameList.put(Name,GroupUUID); + return true; + } + + public boolean CheckGroup(String GroupType, String Name){ + return m_SquadArray.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 UUID GetUUID(String name){ + return m_GroupNameList.get(name); + } + + public boolean DeleteGroup(UUID GroupUUID, String GroupType){ + if(m_SquadArray.containsKey(GroupUUID)){ + for(UUID key: GetGroupMembersUUID(GroupUUID)){ + m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0)); + } + + m_GroupNameList.remove(GetGroupName(GroupUUID)); + m_SquadArray.remove(GroupUUID); + return true; + } + else{ + return false; // Group is not exists. + } + + } + + public String SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_SquadArray.containsKey(GroupUUID) && m_UserInfoArray.getUserGroupUUID(PlayerUUID, GroupType).equals(ZERO_UUID)){ + Group m_Group = m_SquadArray.get(GroupUUID); + m_Group.SignUp(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); + return ""; + } else{ + return "다른 그룹에 가입되어있습니다."; // Wrong Group + } + } + + public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ + if(m_SquadArray.get(GroupUUID).isMember(PlayerUUID)) { + Group m_Group = m_SquadArray.get(GroupUUID); + m_Group.Expulsion(PlayerUUID); + m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); + int temp = m_SquadArray.get(GroupUUID).getMemNUM(); + + if(temp==0){ + m_GroupNameList.remove(m_Group.getGroupName()); + m_SquadArray.remove(GroupUUID); + m_DeleteQueue.add(GroupUUID); + Bukkit.getPlayer(PlayerUUID).sendMessage(""+temp+" "+m_DeleteQueue); + } + 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_SquadArray.get(GroupUUID).getGroupMembers()){ + try { + MembersName.add(Bukkit.getPlayer(key).getDisplayName()); + } + catch(NullPointerException e){ + + } + } + return MembersName; + } + public List GetGroupMembersUUID(UUID GroupUUID){ + return m_SquadArray.get(GroupUUID).getGroupMembers(); + } + public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){ + Group m_Group = m_SquadArray.get(GroupUUID); + return m_Group.isMember(PlayerUUID); } + public int GetGroupMemNUM(UUID GroupUUID){ + Group m_Group = m_SquadArray.get(GroupUUID); + return m_Group.getMemNUM(); + } + public Set GetGroupNameList(){ + return m_GroupNameList.keySet(); + } + + public Set getKeySet(){ // 유저 목록 return + return m_SquadArray.keySet(); + } + + public Set getNameSet() { return m_GroupNameList.keySet(); } + public String GetGroupName(UUID GroupUUID){ + Group m_Group = m_SquadArray.get(GroupUUID); + return m_Group.getGroupName(); + } + public int GetGroupMemMaxNum(UUID GroupUUID){ + Group m_Group = m_SquadArray.get(GroupUUID); + return m_Group.getMemMaxNUM(); + } + public boolean isOffline(UUID uuid){ + return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); + } + + public boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ + return m_SquadArray.get(GroupUUID).isOwner(PlayerUUID); + } + private boolean isAvaliableGroup(UUID GroupUUID){ + return m_SquadArray.containsKey(GroupUUID); + } + } diff --git a/GUI/AccountGUI.java b/Bank/AccountGUI.java similarity index 96% rename from GUI/AccountGUI.java rename to Bank/AccountGUI.java index b95e8f5..87a262d 100644 --- a/GUI/AccountGUI.java +++ b/Bank/AccountGUI.java @@ -1,6 +1,6 @@ -package org.poopki.duckdns.user_db.GUI; +package org.poopki.duckdns.user_db.Bank; -import dev.lone.itemsadder.api.CustomStack; +import dev.lone.itemsadder.api.CustomStack;; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -11,6 +11,7 @@ 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.Array.SquadArray; +import org.poopki.duckdns.user_db.GUI.ItemManager; import org.poopki.duckdns.user_db.UserInfoArray; import org.bukkit.inventory.ItemStack; import java.util.UUID; @@ -80,16 +81,16 @@ public class AccountGUI implements Listener{ Inventory m_inv = e.getClickedInventory(); if (e.getInventory() != m_inv) return; - +/* switch(e.getCurrentItem().getType()){ - case CANDLE: + case TORCH: 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: + case TORCH: e.setCancelled(true); p.sendMessage("10000원 감소"); m_AA.setAccountInfo(p.getUniqueId(), (long)m_AA.getAccountInfo(p.getUniqueId())-10000); @@ -125,5 +126,7 @@ public class AccountGUI implements Listener{ p.openInventory(inv); break; } + + */ } } diff --git a/GUI/AccountGUIEvent.java b/Bank/AccountGUIEvent.java similarity index 73% rename from GUI/AccountGUIEvent.java rename to Bank/AccountGUIEvent.java index d063aef..1489a29 100644 --- a/GUI/AccountGUIEvent.java +++ b/Bank/AccountGUIEvent.java @@ -1,4 +1,4 @@ -package org.poopki.duckdns.user_db.GUI; +package org.poopki.duckdns.user_db.Bank; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -37,12 +37,19 @@ public class AccountGUIEvent implements Listener,CommandExecutor { return false; } @EventHandler - public void inven2(InventoryClickEvent e){ + public boolean inven_Bank(InventoryClickEvent e){ Player player = (Player) e.getWhoClicked();; - player.sendMessage("이벤트 발생"); - AccountGUI inv = new AccountGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); - inv.inven(e); - + String name = e.getView().getTitle(); + player.sendMessage("이벤트 발생B"); + if(name.equals(":offset_-8::bank_main:")){ + if(e.getCurrentItem()!=null){ + e.setCancelled(true); + AccountGUI inv = new AccountGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.inven(e); + return true; + } + } + return false; } diff --git a/Bank/Digit.java b/Bank/Digit.java new file mode 100644 index 0000000..8f6f3e4 --- /dev/null +++ b/Bank/Digit.java @@ -0,0 +1,4 @@ +package org.poopki.duckdns.user_db.Bank; + +public class Digit { +} diff --git a/DB/DBUpdate.java b/DB/DBUpdate.java index f5a55da..46a2d7f 100644 --- a/DB/DBUpdate.java +++ b/DB/DBUpdate.java @@ -154,6 +154,7 @@ public class DBUpdate { m_NationArray.PutGroup(UUID.fromString(rs.getString(1)), rs.getString(2), m_MemberList); + m_AccountArray.putAccountInfo(UUID.fromString(rs.getString(1)),Integer.parseInt(rs.getString(3))); } @@ -183,7 +184,7 @@ public class DBUpdate { while(rs.next()){ Integer index=2; if(rs.getString(index) != null){ - for(String TechName: m_NationArray.m_GroupArray.get(UUID.fromString(rs.getString(1))).TechList){ + for(String TechName: m_NationArray.m_NationArray.get(UUID.fromString(rs.getString(1))).m_TechStat.keySet()){ m_NationArray.SetGroupTechTree(UUID.fromString(rs.getString(1)),TechName, Integer.parseInt(rs.getString(index))); index++; } @@ -203,6 +204,8 @@ public class DBUpdate { } } + + // try { Class.forName("org.mariadb.jdbc.Driver"); @@ -262,10 +265,10 @@ public class DBUpdate { pstmt.setString(6, String.valueOf(m_AccountArray.getAccountInfo(key))); int cnt = pstmt.executeUpdate(); if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); + System.out.println("[DB] 유저 데이터 입력 실패"); } else{ - System.out.println("데이터 입력 성공"); + System.out.println("[DB] 유저 데이터 입력 성공"); } } @@ -282,60 +285,20 @@ public class DBUpdate { conn.close(); } } + UpdateFarmInfo(); + UpdateNationInfo(); + UpdateSquadInfo(); - // Update Farm Info - try{ - Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - - for (UUID key : m_FarmArray.getKeySet()) { - - String sql = "REPLACE INTO Farm VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"; - pstmt = conn.prepareStatement(sql); - pstmt.setString(1, String.valueOf(key.toString())); - pstmt.setString(2, String.valueOf(m_FarmArray.GetGroupName(key))); - pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key))); - int index = 4; - for (UUID MemUUID : m_FarmArray.GetGroupMembersUUID(key)){ - pstmt.setString(index, String.valueOf(MemUUID.toString())); - index++; - } - for(; index<=MAX_FARM_NUM;index++){ - pstmt.setString(index, null); - } - - int cnt = pstmt.executeUpdate(); - if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); - } - else{ - System.out.println("데이터 입력 성공"); - } - - } - } - catch(ClassNotFoundException e){ - e.printStackTrace(); - } - catch(SQLException e){ - System.err.println("에러 내용 :" + e.getMessage()); - System.out.println("DB Connection fail"); - } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } try{ Class.forName("org.mariadb.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key: m_FarmArray.m_DeleteQueue){ - String sql = "DELETE FROM Farm WHERE FARM_UUID=?"; + for (UUID key: m_NationArray.m_DeleteQueue){ + String sql = "DELETE FROM TechTree WHERE UUID=?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, String.valueOf(key.toString())); int cnt = pstmt.executeUpdate(); - m_FarmArray.m_DeleteQueue.remove(key); + m_NationArray.m_DeleteQueue.remove(key); } } catch(ClassNotFoundException e){ @@ -350,40 +313,28 @@ public class DBUpdate { conn.close(); } } - - // Update nation Info try{ Class.forName("org.mariadb.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key: m_NationArray.m_DeleteQueue){ - String sql = "DELETE FROM Nation WHERE NATION_UUID (?)"; - pstmt = conn.prepareStatement(sql); - pstmt.setString(1, String.valueOf(key.toString())); - int cnt = pstmt.executeUpdate(); - m_NationArray.m_DeleteQueue.remove(key); - } + for (UUID key : m_NationArray.getKeySet()) { - String sql = "REPLACE INTO Nation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"; + String sql = "REPLACE INTO TechTree VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); + int index = 2; + pstmt.setString(1, String.valueOf(key.toString())); - pstmt.setString(2, String.valueOf(m_NationArray.GetGroupName(key))); - pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key))); - int index = 4; - for (UUID MemUUID : m_NationArray.GetGroupMembersUUID(key)){ - pstmt.setString(index, String.valueOf(MemUUID.toString())); + for (String Name : m_NationArray.m_NationArray.get(key).m_TechStat.keySet()){ + pstmt.setString(index, String.valueOf(m_NationArray.m_NationArray.get(key).GetTechTree(Name))); index++; } - for(; index<=MAX_FARM_NUM;index++){ - pstmt.setString(index, null); - } int cnt = pstmt.executeUpdate(); if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); + System.out.println("[DB] 국가 데이터 입력 실패"); } else{ - System.out.println("데이터 입력 성공"); + System.out.println("[DB] 국가 데이터 입력 성공"); } } @@ -400,15 +351,22 @@ public class DBUpdate { conn.close(); } } + + } + + public void UpdateFarmInfo(){ try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key: m_NationArray.m_DeleteQueue){ - String sql = "DELETE FROM Nation WHERE NATION_UUID=?"; - pstmt = conn.prepareStatement(sql); + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); + for (UUID key: m_FarmArray.m_DeleteQueue){ + String sql = "DELETE FROM Farm WHERE Farm_UUID=?"; + PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, String.valueOf(key.toString())); int cnt = pstmt.executeUpdate(); - + m_FarmArray.m_DeleteQueue.remove(key); + } + if( conn != null && !conn.isClosed()){ + conn.close(); } } catch(ClassNotFoundException e){ @@ -418,40 +376,33 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key : m_SquadArray.getKeySet()) { - - String sql = "REPLACE INTO Squad VALUES (?,?,?,?,?,?,?,?,?,?,?)"; - pstmt = conn.prepareStatement(sql); - pstmt.setString(1, String.valueOf(key.toString())); - pstmt.setString(2, String.valueOf(m_SquadArray.GetGroupName(key))); - pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key))); - int index = 4; - for (UUID MemUUID : m_SquadArray.GetGroupMembersUUID(key)){ - pstmt.setString(index, String.valueOf(MemUUID.toString())); + for (UUID key : m_FarmArray.getKeySet()) { + String sql = "REPLACE INTO Farm SET "; + String sql_A = "FARM_UUID='"+String.valueOf(key.toString())+"', NAME='"+String.valueOf(m_FarmArray.GetGroupName(key))+"', Account='"+String.valueOf(m_AccountArray.getAccountInfo(key))+"',"; + String sql_B = ""; + int index=1; + for (UUID MemUUID : m_FarmArray.GetGroupMembersUUID(key)){ + sql_B = sql_B + "MEMBER"+String.valueOf(index)+"_UUID='"+String.valueOf(MemUUID.toString())+"',"; index++; } - for(; index<=11;index++){ - pstmt.setString(index, null); - } - + sql_B = sql_B.substring(0,sql_B.length()-1); + sql = sql+sql_A+sql_B; + PreparedStatement pstmt = conn.prepareStatement(sql); int cnt = pstmt.executeUpdate(); if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); + System.out.println("[DB] 분대 데이터 입력 실패"); } else{ - System.out.println("데이터 입력 성공"); + System.out.println("[DB] 분대 데이터 입력 성공"); } - + } + if( conn != null && !conn.isClosed()){ + conn.close(); } } catch(ClassNotFoundException e){ @@ -461,21 +412,20 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } - + } + public void UpdateNationInfo(){ try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key: m_SquadArray.m_DeleteQueue){ - String sql = "DELETE FROM Squad WHERE Squad_UUID=?"; - pstmt = conn.prepareStatement(sql); + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); + for (UUID key: m_NationArray.m_DeleteQueue){ + String sql = "DELETE FROM Nation WHERE Nation_UUID=?"; + PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, String.valueOf(key.toString())); int cnt = pstmt.executeUpdate(); - m_SquadArray.m_DeleteQueue.remove(key); + m_NationArray.m_DeleteQueue.remove(key); + } + if( conn != null && !conn.isClosed()){ + conn.close(); } } catch(ClassNotFoundException e){ @@ -485,40 +435,33 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - - for (UUID key : m_SquadArray.getKeySet()) { + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - String sql = "REPLACE INTO Squad VALUES (?,?,?,?,?,?,?,?,?,?,?)"; - pstmt = conn.prepareStatement(sql); - pstmt.setString(1, String.valueOf(key.toString())); - pstmt.setString(2, String.valueOf(m_SquadArray.GetGroupName(key))); - pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key))); - int index = 4; - for (UUID MemUUID : m_SquadArray.GetGroupMembersUUID(key)){ - pstmt.setString(index, String.valueOf(MemUUID.toString())); + for (UUID key : m_NationArray.getKeySet()) { + String sql = "REPLACE INTO Nation SET "; + String sql_A = "NATION_UUID='"+String.valueOf(key.toString())+"', NAME='"+String.valueOf(m_NationArray.GetGroupName(key))+"', Account='"+String.valueOf(m_AccountArray.getAccountInfo(key))+"',"; + String sql_B = ""; + int index=1; + for (UUID MemUUID : m_NationArray.GetGroupMembersUUID(key)){ + sql_B = sql_B + "MEMBER"+String.valueOf(index)+"_UUID='"+String.valueOf(MemUUID.toString())+"',"; index++; } - for(; index<=11;index++){ - pstmt.setString(index, null); - } - + sql_B = sql_B.substring(0,sql_B.length()-1); + sql = sql+sql_A+sql_B; + PreparedStatement pstmt = conn.prepareStatement(sql); int cnt = pstmt.executeUpdate(); if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); + System.out.println("[DB] 분대 데이터 입력 실패"); } else{ - System.out.println("데이터 입력 성공"); + System.out.println("[DB] 분대 데이터 입력 성공"); } - + } + if( conn != null && !conn.isClosed()){ + conn.close(); } } catch(ClassNotFoundException e){ @@ -528,22 +471,21 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } - + } + public void UpdateSquadInfo(){ try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); for (UUID key: m_SquadArray.m_DeleteQueue){ String sql = "DELETE FROM Squad WHERE Squad_UUID=?"; - pstmt = conn.prepareStatement(sql); + PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, String.valueOf(key.toString())); int cnt = pstmt.executeUpdate(); m_SquadArray.m_DeleteQueue.remove(key); } + if( conn != null && !conn.isClosed()){ + conn.close(); + } } catch(ClassNotFoundException e){ e.printStackTrace(); @@ -552,64 +494,35 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } - //Update Tech try{ Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - - for (UUID key : m_NationArray.getKeySet()) { - - String sql = "REPLACE INTO TechTree VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - pstmt = conn.prepareStatement(sql); - int index = 2; + Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - pstmt.setString(1, String.valueOf(key.toString())); - for (String Name : m_NationArray.m_GroupArray.get(key).TechList){ - System.out.println(Name+String.valueOf(m_NationArray.m_GroupArray.get(key).GetTechTree(Name))); - pstmt.setString(index, String.valueOf(m_NationArray.m_GroupArray.get(key).GetTechTree(Name))); + for (UUID key : m_SquadArray.getKeySet()) { + String sql = "REPLACE INTO Squad SET "; + String sql_A = "Squad_UUID='"+String.valueOf(key.toString())+"', NAME='"+String.valueOf(m_SquadArray.GetGroupName(key))+"', Account='"+String.valueOf(m_AccountArray.getAccountInfo(key))+"',"; + String sql_B = ""; + int index=1; + for (UUID MemUUID : m_SquadArray.GetGroupMembersUUID(key)){ + sql_B = sql_B + "MEMBER"+String.valueOf(index)+"_UUID='"+String.valueOf(MemUUID.toString())+"',"; index++; } - + sql_B = sql_B.substring(0,sql_B.length()-1); + sql = sql+sql_A+sql_B; + PreparedStatement pstmt = conn.prepareStatement(sql); int cnt = pstmt.executeUpdate(); if( cnt == 0 ){ - System.out.println("데이터 입력 실패"); + System.out.println("[DB] 분대 데이터 입력 실패"); } else{ - System.out.println("데이터 입력 성공"); + System.out.println("[DB] 분대 데이터 입력 성공"); } - } - } - catch(ClassNotFoundException e){ - e.printStackTrace(); - } - catch(SQLException e){ - System.err.println("에러 내용 :" + e.getMessage()); - System.out.println("DB Connection fail"); - } - finally { if( conn != null && !conn.isClosed()){ conn.close(); } } - - try{ - Class.forName("org.mariadb.jdbc.Driver"); - conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); - for (UUID key: m_NationArray.m_DeleteQueue){ - String sql = "DELETE FROM TechTree WHERE UUID=?"; - pstmt = conn.prepareStatement(sql); - pstmt.setString(1, String.valueOf(key.toString())); - int cnt = pstmt.executeUpdate(); - m_NationArray.m_DeleteQueue.remove(key); - } - } catch(ClassNotFoundException e){ e.printStackTrace(); } @@ -617,10 +530,5 @@ public class DBUpdate { System.err.println("에러 내용 :" + e.getMessage()); System.out.println("DB Connection fail"); } - finally { - if( conn != null && !conn.isClosed()){ - conn.close(); - } - } } } \ No newline at end of file diff --git a/GUI/BaseGUI.java b/GUI/BaseGUI.java index a085eae..202040b 100644 --- a/GUI/BaseGUI.java +++ b/GUI/BaseGUI.java @@ -62,49 +62,5 @@ public class BaseGUI implements Listener{ 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; - } } } diff --git a/GUI/Digit.java b/GUI/Digit.java deleted file mode 100644 index 21c77f7..0000000 --- a/GUI/Digit.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.poopki.duckdns.user_db.GUI; - -public class Digit { -} diff --git a/GUI/ItemManager.java b/GUI/ItemManager.java index 8d162b8..f747589 100644 --- a/GUI/ItemManager.java +++ b/GUI/ItemManager.java @@ -15,8 +15,8 @@ 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 btn1 = buildItem(Material.TORCH, 1, ChatColor.AQUA +"지갑 10000원 증가", "", ChatColor.GREEN + "----"); + public ItemStack btn2 = buildItem(Material.TORCH, 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 + "----"); diff --git a/GUI/OpenInv.java b/GUI/OpenInv.java index 6512e8f..1204373 100644 --- a/GUI/OpenInv.java +++ b/GUI/OpenInv.java @@ -1,5 +1,6 @@ package org.poopki.duckdns.user_db.GUI; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -37,13 +38,17 @@ public class OpenInv implements Listener,CommandExecutor { 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, m_SquadArray, player.getUniqueId(), e); - inv.inven(e); + public boolean inven_TEST(InventoryClickEvent e){ + Player player = (Player) e.getWhoClicked(); + String name = e.getView().getTitle(); + if(name.equals("TESTGUI")){ + if(e.getCurrentItem()!=null){ + e.setCancelled(true); + BaseGUI inv = new BaseGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.inven(e); + return true; + } + } + return false; } - - - } diff --git a/GUI/TechGUIEvent.java b/GUI/TechGUIEvent.java deleted file mode 100644 index 173a22c..0000000 --- a/GUI/TechGUIEvent.java +++ /dev/null @@ -1,64 +0,0 @@ -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.Array.SquadArray; -import org.poopki.duckdns.user_db.UserInfoArray; - -import java.util.UUID; - - -public class TechGUIEvent implements Listener,CommandExecutor { - AccountArray m_AccountArray; - UserInfoArray m_UserInfoArray; - FarmArray m_FarmArray; - NationArray m_NationArray; - SquadArray m_SquadArray; - UUID ZERO_UUID = new UUID(0,0); - public TechGUIEvent(UserInfoArray m_UIA, FarmArray FA, NationArray NA, SquadArray SA, AccountArray AA){ - m_UserInfoArray = m_UIA; - m_AccountArray = AA; - m_FarmArray = FA; - m_NationArray = NA; - m_SquadArray = SA; - } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(sender instanceof Player){ - if(ZERO_UUID.equals(m_UserInfoArray.getUserGroupUUID(((Player) sender).getUniqueId(), "Nation"))){ - Player player = (Player) sender; - player.sendMessage("국가에 소속된 유저만 사용이 가능"); - } - else{ - Player player = (Player) sender; - player.sendMessage("TECH: "+player.getUniqueId()); - player.sendMessage("TECH: "+m_UserInfoArray.getUserGroupUUID(player.getUniqueId(),"Nation")); - player.sendMessage("TECH: "+m_NationArray.GetGroupTechTree(m_UserInfoArray.getUserGroupUUID(player.getUniqueId(),"Nation"),"agriculture")); - - TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray,player.getUniqueId(), null); - - inv.open(player); - } - } - return false; - } - @EventHandler - public void inven2(InventoryClickEvent e){ - Player player = (Player) e.getWhoClicked();; - player.sendMessage("이벤트 발생"); - TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); - inv.inven(e); - - } - - - -} diff --git a/GUI/TechStat.java b/GUI/TechStat.java deleted file mode 100644 index fef2080..0000000 --- a/GUI/TechStat.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.poopki.duckdns.user_db.GUI; - -import org.poopki.duckdns.user_db.UserInfo; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class TechStat { - private Map m_TechStat = new HashMap(); - - public void InitTechTree(){ - m_TechStat.put("agriculture",0); - m_TechStat.put("pottery",0); - m_TechStat.put("animal_husbandry",0); - m_TechStat.put("archery",0); - m_TechStat.put("mining",0); - m_TechStat.put("sailing",0); - m_TechStat.put("calendar",0); - m_TechStat.put("writing",0); - m_TechStat.put("trapping",0); - m_TechStat.put("wheel",0); - m_TechStat.put("masonry",0); - m_TechStat.put("bronze",0); - m_TechStat.put("optics",0); - m_TechStat.put("horseback",0); - m_TechStat.put("mathematics",0); - m_TechStat.put("construction",0); - m_TechStat.put("philosophy",0); - m_TechStat.put("drama",0); - m_TechStat.put("currency",0); - m_TechStat.put("engineering",0); - m_TechStat.put("iron_working",0); - m_TechStat.put("theology",0); - m_TechStat.put("civil_service",0); - m_TechStat.put("guilds",0); - m_TechStat.put("metal_casting",0); - m_TechStat.put("compass",0); - m_TechStat.put("education",0); - m_TechStat.put("chivalry",0); - m_TechStat.put("machinery",0); - m_TechStat.put("physics",0); - m_TechStat.put("steel",0); - m_TechStat.put("astronomy",0); - m_TechStat.put("acoustics",0); - m_TechStat.put("banking",0); - m_TechStat.put("printing_press",0); - m_TechStat.put("gunpowder",0); - m_TechStat.put("navigation",0); - m_TechStat.put("architecture",0); - m_TechStat.put("economics",0); - m_TechStat.put("metallurgy",0); - m_TechStat.put("chemistry",0); - m_TechStat.put("archaeology",0); - m_TechStat.put("scientific_theory",0); - m_TechStat.put("industrialization",0); - m_TechStat.put("rifling",0); - m_TechStat.put("military_science",0); - m_TechStat.put("fertilizer",0); - m_TechStat.put("biology",0); - m_TechStat.put("electricity",0); - m_TechStat.put("steam_power",0); - m_TechStat.put("dynamite",0); - m_TechStat.put("refrigeration",0); - m_TechStat.put("radio",0); - m_TechStat.put("flight",0); - m_TechStat.put("railroad",0); - m_TechStat.put("plastics",0); - m_TechStat.put("electronics",0); - m_TechStat.put("ballistics",0); - m_TechStat.put("combustion",0); - m_TechStat.put("penicillin",0); - m_TechStat.put("atomic_theory",0); - m_TechStat.put("radar",0); - m_TechStat.put("combined_arms",0); - m_TechStat.put("ecology",0); - m_TechStat.put("nuclear_fission",0); - m_TechStat.put("rocketry",0); - m_TechStat.put("computers",0); - m_TechStat.put("telecommunications",0); - m_TechStat.put("mobile_tactics",0); - m_TechStat.put("advanced_ballistics",0); - m_TechStat.put("satellites",0); - m_TechStat.put("robotics",0); - m_TechStat.put("lasers",0); - m_TechStat.put("the_internet",0); - m_TechStat.put("globalization",0); - m_TechStat.put("particle_physics",0); - m_TechStat.put("nuclear_fusion",0); - m_TechStat.put("nanotechnology",0); - m_TechStat.put("stealth",0); - } - - public void EnableTechTree(String TechName){ - m_TechStat.replace(TechName,1); - } - - public int GetTachTree(String TechName){ - return m_TechStat.get(TechName); - } -} diff --git a/GUI/ScoreboardEvent.java b/InfoGUI/ScoreboardEvent.java similarity index 97% rename from GUI/ScoreboardEvent.java rename to InfoGUI/ScoreboardEvent.java index a37ca4e..14bc8b5 100644 --- a/GUI/ScoreboardEvent.java +++ b/InfoGUI/ScoreboardEvent.java @@ -1,4 +1,4 @@ -package org.poopki.duckdns.user_db.GUI; +package org.poopki.duckdns.user_db.InfoGUI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -33,7 +33,7 @@ public class ScoreboardEvent { manager = Bukkit.getScoreboardManager(); scoreboard = manager.getNewScoreboard(); - Objective score_obj = scoreboard.registerNewObjective("Scoreboard","dummy","계좌"); + Objective score_obj = scoreboard.registerNewObjective("Scoreboard","dummy"); score_obj.setDisplaySlot(DisplaySlot.SIDEBAR); Score score = score_obj.getScore(ChatColor.BLUE + "==-=-=-=-=-=-=="); diff --git a/Research/Research.java b/Research/Research.java new file mode 100644 index 0000000..aea6066 --- /dev/null +++ b/Research/Research.java @@ -0,0 +1,102 @@ +package org.poopki.duckdns.user_db.Research; + +import dev.lone.itemsadder.api.CustomStack; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.boss.*; +import org.poopki.duckdns.user_db.Array.Account; +import org.poopki.duckdns.user_db.Array.NationArray; +import org.poopki.duckdns.user_db.UserInfoArray; + +import java.sql.SQLException; +import java.util.*; + +public class Research { + public Inventory research_tab; + public String m_title; + public Double m_progress=0.0; + public ArrayList m_material = new ArrayList(); + public BossBar tech1_progressbar; + public Integer research_point=0; + public Research(String title, Plugin plugin, ListMemberList) { + research_tab = Bukkit.createInventory(null, 54, title); + tech1_progressbar = Bukkit.createBossBar(m_title, BarColor.BLUE,BarStyle.SOLID); + new BukkitRunnable(){ + @Override + public void run(){ + if(CheckItem()){ + if(1<=m_progress) { + research_point = research_point+1; + m_progress = 0.0; + for(UUID key: MemberList){ + if(Bukkit.getPlayer(key) != null){ + Bukkit.getPlayer(key).sendMessage("국가의 연구가 완료되었습니다."); + } + } + }else{ + System.out.println(m_progress); + m_progress = m_progress + 0.2; + } + } + tech1_progressbar.setProgress(m_progress); + for(Player p: tech1_progressbar.getPlayers()){ + + } + + } + }.runTaskTimer(plugin,0,20); + } + public void SetMaterials(ArrayList m_material){ + for(ItemStack Key: m_material){ + this.m_material.add(Key); + } + } + + + public Inventory getInventory(){ + return research_tab; + } + private boolean CheckItem() { + if(0 PrevTech = new ArrayList(); + public TechGUIEvent(UserInfoArray m_UIA, FarmArray FA, NationArray NA, SquadArray SA, AccountArray AA){ + m_UserInfoArray = m_UIA; + m_AccountArray = AA; + m_FarmArray = FA; + m_NationArray = NA; + m_SquadArray = SA; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(sender instanceof Player){ + if(ZERO_UUID.equals(m_UserInfoArray.getUserGroupUUID(((Player) sender).getUniqueId(), "Nation"))){ + Player player = (Player) sender; + player.sendMessage("국가에 소속된 유저만 사용이 가능"); + } + else{ + Player player = (Player) sender; + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray,player.getUniqueId(), null); + inv.open(player); + } + } + return false; + } + @EventHandler + public boolean inven_Tech(InventoryClickEvent e){ + Player player = (Player) e.getWhoClicked();; + String name = e.getView().getTitle(); + if(name.equals(":offset_-8::ancient_era:")){ + if(CheckClickItem(e.getCurrentItem(),"techtree:agriculture_0")){ + e.setCancelled(true); + if(CheckPoint(player,0, "Nation")){ + SelectTech(player, "Nation", "agriculture", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:pottery_0")){ + e.setCancelled(true); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "pottery", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:mining_0")){ + e.setCancelled(true); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "mining", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:archery_0")){ + e.setCancelled(true); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "archery", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:animal_husbandry_0")){ + e.setCancelled(true); + PrevTech.add("pottery"); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "animal_husbandry", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:writing_0")){ + e.setCancelled(true); + PrevTech.add("pottery"); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "writing", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:masonry_0")){ + e.setCancelled(true); + PrevTech.add("archery"); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "masonry", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + if(CheckClickItem(e.getCurrentItem(),"techtree:bronze_0")){ + e.setCancelled(true); + PrevTech.add("mining"); + PrevTech.add("agriculture"); + if(CheckPoint(player,0, "Nation")){ + if(CheckTechTree(player,"Nation",PrevTech)){ + SelectTech(player, "Nation", "bronze", 0); + player.sendMessage("국가 테크를 선택하였습니다."); + } + else{ + player.sendMessage("이전 테크를 선택하지 않았습니다."); + } + } + else{ + player.sendMessage("테크 포인트가 부족합니다."); + } + PrevTech.clear(); + TechGUI inv = new TechGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, m_SquadArray, player.getUniqueId(), e); + inv.open(player); + return true; + } + } + return false; + } + public boolean CheckClickItem(ItemStack ClickedItem, String Name){ + return ClickedItem.getItemMeta().getDisplayName().equals(CustomStack.getInstance(Name).getItemStack().getItemMeta().getDisplayName()); + } + public boolean CheckPoint(Player p, Integer page, String Type){ + return !m_NationArray.m_NationArray.get(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),Type)).m_ResearchArray.get(page).research_point.equals(0); + } + public boolean CheckTechTree(Player p, String Type, ArrayList PrevTech){ + for(String key: PrevTech){ + if(m_NationArray.m_NationArray.get(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),Type)).GetTechTree(key)==0){ + return false; + } + } + return true; + } + + public void SelectTech(Player p, String Type, String TechName, Integer page){ + m_NationArray.m_NationArray.get(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),Type)).SetTechTree(TechName, 1); + m_NationArray.m_NationArray.get(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),Type)).m_ResearchArray.get(page).research_point--; + } +} diff --git a/TechTree/TechStat.java b/TechTree/TechStat.java new file mode 100644 index 0000000..88f3af6 --- /dev/null +++ b/TechTree/TechStat.java @@ -0,0 +1,22 @@ +package org.poopki.duckdns.user_db.TechTree; + +import org.poopki.duckdns.user_db.UserInfo; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class TechStat { + private Map m_TechStat = new HashMap(); + + public void InitTechTree(String A, Integer B){ + m_TechStat.put(A,B); + } + public void SetTechTree(String TechName, Integer set){ + m_TechStat.replace(TechName,set); + } + + public int GetTechTree(String TechName){ + return m_TechStat.get(TechName); + } +} diff --git a/UserJoin.java b/UserJoin.java index d59e6d7..7b79679 100644 --- a/UserJoin.java +++ b/UserJoin.java @@ -1,13 +1,11 @@ package org.poopki.duckdns.user_db; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.scoreboard.*; import org.poopki.duckdns.user_db.Array.*; -import org.poopki.duckdns.user_db.GUI.ScoreboardEvent; +import org.poopki.duckdns.user_db.InfoGUI.ScoreboardEvent; import java.util.UUID; @@ -17,7 +15,7 @@ public class UserJoin implements Listener { private FarmArray m_FarmArray; private NationArray m_NationArray; private SquadArray m_SquadArray; - + UUID ZERO_UUID = new UUID(0,0); private ScoreboardEvent m_ScoreboardEventHandler; UserJoin(UserInfoArray m_UIA, FarmArray FA, NationArray NA, SquadArray SA, AccountArray AA, ScoreboardEvent SE){ m_AccountArray = AA; @@ -35,6 +33,11 @@ public class UserJoin implements Listener { m_AccountArray.putAccountInfo(p.getUniqueId(), 0); } m_ScoreboardEventHandler.ScoreboardUpdate(p); + if(!m_InfoArrayInstance.getUserGroupUUID(p.getUniqueId(),"Nation").equals(ZERO_UUID)){ + m_NationArray.m_NationArray.get(m_InfoArrayInstance.getUserGroupUUID(p.getUniqueId(),"Nation")).AddShowResearchProgressBar(0, p); + m_NationArray.m_NationArray.get(m_InfoArrayInstance.getUserGroupUUID(p.getUniqueId(),"Nation")).AddShowResearchProgressBar(1, p); + m_NationArray.m_NationArray.get(m_InfoArrayInstance.getUserGroupUUID(p.getUniqueId(),"Nation")).AddShowResearchProgressBar(2, p); + } } diff --git a/User_DB.java b/User_DB.java index 0101dc3..16ed251 100644 --- a/User_DB.java +++ b/User_DB.java @@ -1,29 +1,37 @@ package org.poopki.duckdns.user_db; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.RegionContainer; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scoreboard.*; import org.poopki.duckdns.user_db.Array.*; +import org.poopki.duckdns.user_db.Bank.AccountGUIEvent; import org.poopki.duckdns.user_db.DB.*; import org.poopki.duckdns.user_db.GUI.*; +import org.poopki.duckdns.user_db.InfoGUI.ScoreboardEvent; import org.poopki.duckdns.user_db.Invite.*; +import org.poopki.duckdns.user_db.TechTree.TechGUIEvent; +import org.poopki.duckdns.user_db.Research.*; +import org.poopki.duckdns.user_db.WorldGuard.*; + import java.sql.SQLException; -import java.util.UUID; public final class User_DB extends JavaPlugin implements Listener { AccountArray m_AccountArrayInstance = new AccountArray(); UserInfoArray m_InfoArrayInstance = new UserInfoArray(); // UserInfo 저장하는 Array instance 생성 - FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance); - NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance); - SquadArray m_SquadArrayInstance = new SquadArray(m_InfoArrayInstance); + FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance, 10,this); + NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance,50,this); + SquadArray m_SquadArrayInstance = new SquadArray(m_InfoArrayInstance,4,this); ScoreboardEvent m_ScoreboardEventHandler = new ScoreboardEvent(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance); DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance); - + final WgCommand wgCommand = new WgCommand(); @Override public void onEnable() { // Plugin startup logic @@ -41,10 +49,18 @@ public final class User_DB extends JavaPlugin implements Listener { getCommand("은행").setExecutor(new AccountGUIEvent(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance)); getCommand("테크").setExecutor(new TechGUIEvent(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance)); getCommand("초대").setExecutor(new InviteMaster(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance)); + getCommand("연구").setExecutor(new ResearchGUIEvent(m_InfoArrayInstance, m_NationArrayInstance)); + getCommand("wge").setExecutor(wgCommand); + getCommand("wge").setTabCompleter(wgCommand); getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance, m_ScoreboardEventHandler), this); getServer().getPluginManager().registerEvents(new OpenInv( m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance), this); + getServer().getPluginManager().registerEvents(new AccountGUIEvent(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance), this); + getServer().getPluginManager().registerEvents(new TechGUIEvent(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance, m_SquadArrayInstance, m_AccountArrayInstance), this); + //getServer().getPluginManager().registerEvents(new WgCommand(), this); + getServer().getPluginManager().registerEvents(new WGRegionExample(), this); + getCommand("지역").setExecutor(new WG(this)); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { @Override @@ -52,8 +68,14 @@ public final class User_DB extends JavaPlugin implements Listener { for(Player p : Bukkit.getOnlinePlayers()) { m_ScoreboardEventHandler.ScoreboardUpdate(p); } + try{ + Database_backup.UpdateDB(); + } catch (SQLException e){ + throw new RuntimeException(e); + } } },0,20L); + } @Override public void onDisable() { diff --git a/WorldGuard/WG.java b/WorldGuard/WG.java new file mode 100644 index 0000000..ea77f39 --- /dev/null +++ b/WorldGuard/WG.java @@ -0,0 +1,77 @@ +package org.poopki.duckdns.user_db.WorldGuard; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.managers.storage.StorageException; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class WG implements CommandExecutor { + public WorldGuardPlugin worldGuardPlugin; + private RegionManager rm; + private ProtectedRegion pr; + + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + + public WG(Plugin plugin){ + worldGuardPlugin =getWorldGuard(plugin); + + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + LocalPlayer pl= WorldGuardPlugin.inst().wrapPlayer(p); + this.rm = container.get(pl.getWorld()); + if (args.length != 0) { + switch (args[0]) { + case "지상":{ + // [1]: radius, [2]-[4]: center point axys(x, y, z) + Integer radius = Integer.parseInt(args[1]); + BlockVector3 min = BlockVector3.at(Integer.parseInt(args[2])-radius/2, Integer.parseInt(args[3])-10, Integer.parseInt(args[4])+radius/2); + BlockVector3 max = BlockVector3.at(Integer.parseInt(args[2])+radius/2, Integer.parseInt(args[3])+50, Integer.parseInt(args[4])-radius/2); + ProtectedRegion region = new ProtectedCuboidRegion(args[5], min, max); + this.rm.addRegion(region); + break; + } + case "지하":{ + Integer radius = Integer.parseInt(args[1]); + BlockVector3 min = BlockVector3.at(Integer.parseInt(args[2])-radius/2, Integer.parseInt(args[3])-11, Integer.parseInt(args[4])+radius/2); + BlockVector3 max = BlockVector3.at(Integer.parseInt(args[2])+radius/2, Integer.parseInt(args[3])-100, Integer.parseInt(args[4])-radius/2); + ProtectedRegion region = new ProtectedCuboidRegion(args[5], min, max); + this.rm.addRegion(region); + break; + } + } + } + try { + this.rm.save(); + } catch (StorageException e) { + e.printStackTrace(); + p.sendMessage("region-save-error"); + return false; + } + return true; + } + public WorldGuardPlugin getWorldGuard(Plugin plugin){ + Plugin WGPlugin = plugin.getServer().getPluginManager().getPlugin("WorldGuard"); + if(WGPlugin == null || !(WGPlugin instanceof WorldGuardPlugin)){ + return null; + } + return (WorldGuardPlugin) WGPlugin; + } + public void save() throws StorageException { + this.rm.addRegion(pr); + this.rm.save(); + } +} diff --git a/WorldGuard/WGRegionExample.java b/WorldGuard/WGRegionExample.java new file mode 100644 index 0000000..42851be --- /dev/null +++ b/WorldGuard/WGRegionExample.java @@ -0,0 +1,36 @@ +package org.poopki.duckdns.user_db.WorldGuard; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import de.netzkronehd.wgregionevents.events.RegionEnterEvent; +import de.netzkronehd.wgregionevents.events.RegionEnteredEvent; +import de.netzkronehd.wgregionevents.events.RegionLeaveEvent; +import de.netzkronehd.wgregionevents.events.RegionLeftEvent; + +public class WGRegionExample implements Listener { + + public static final String PREFIX = "§8[§aWGE-Example§8]§7 "; + + @EventHandler + public void onRegionEnter(RegionEnterEvent e) { + e.getPlayer().sendMessage(PREFIX+"You are entering§e "+e.getRegion().getId()+"§7."); + } + + @EventHandler + public void onRegionEntered(RegionEnteredEvent e) { + e.getPlayer().sendMessage(PREFIX+"You entered§e "+e.getRegion().getId()+"§7."); + } + + @EventHandler + public void onRegionLeave(RegionLeaveEvent e) { + e.getPlayer().sendMessage(PREFIX+"You are leaving§e "+e.getRegion().getId()+"§7."); + } + + @EventHandler + public void onRegionLeft(RegionLeftEvent e) { + e.getPlayer().sendMessage(PREFIX+"You left§e "+e.getRegion().getId()+"§7."); + } + +} \ No newline at end of file diff --git a/WorldGuard/WgCommand.java b/WorldGuard/WgCommand.java new file mode 100644 index 0000000..a6631c2 --- /dev/null +++ b/WorldGuard/WgCommand.java @@ -0,0 +1,89 @@ +package org.poopki.duckdns.user_db.WorldGuard; + +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import de.netzkronehd.wgregionevents.api.SimpleWorldGuardAPI; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class WgCommand implements CommandExecutor, TabExecutor { + + private final SimpleWorldGuardAPI simpleWorldGuardAPI; + + public WgCommand() { + simpleWorldGuardAPI = new SimpleWorldGuardAPI(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(args.length == 2) { + if(args[0].equals("playersinregion")) { + final List players = simpleWorldGuardAPI.getPlayersInRegion(args[1]); + final StringBuilder sb = new StringBuilder(WGRegionExample.PREFIX+"Player: "); + for(Player player : players) { + sb.append(player.getName()).append(", "); + } + + sender.sendMessage(sb.toString()); + return true; + } else if(args[0].equalsIgnoreCase("regions")) { + final Player p = Bukkit.getPlayer(args[1]); + if(p != null) { + final StringBuilder sb = new StringBuilder(WGRegionExample.PREFIX+"Regions: "); + for (ProtectedRegion region : simpleWorldGuardAPI.getRegions(p.getLocation())) { + sb.append(region.getId()).append("§7, "); + } + + sender.sendMessage(sb.toString()); + } else sender.sendMessage(WGRegionExample.PREFIX+"That player is offline."); + + return true; + } + } + sendHelp(sender); + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + final List tabs = new ArrayList<>(); + if(args.length == 1) { + args[0] = args[0].toLowerCase(); + + if("regions".startsWith(args[0])) tabs.add("regions"); + if("playersinregion".startsWith(args[0])) tabs.add("playersinregion"); + + } else if(args.length == 2) { + if(args[0].equalsIgnoreCase("regions")) { + args[1] = args[1].toLowerCase(); + for (Player player : Bukkit.getOnlinePlayers()) { + if(player.getName().toLowerCase().startsWith(args[1])) { + tabs.add(player.getName()); + } + } + } else if(args[0].equalsIgnoreCase("playersinregion")) { + args[1] = args[1].toLowerCase(); + for(ProtectedRegion pr : simpleWorldGuardAPI.getRegions().values()) { + if(pr.getId().toLowerCase().startsWith(args[1])) { + tabs.add(pr.getId()); + } + } + } + } + return tabs; + } + + private void sendHelp(CommandSender s) { + s.sendMessage(WGRegionExample.PREFIX+"Wrong usage, please use:"); + s.sendMessage("§e/wge playersinregion§8 <§eRegion§8>"); + s.sendMessage("§e/wge regions§8 <§ePlayer§8>"); + + } + +} \ No newline at end of file