package org.poopki.duckdns.user_db.TechTree; import dev.lone.itemsadder.api.CustomStack; 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.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.Array.SquadArray; import org.poopki.duckdns.user_db.UserInfoArray; import java.util.ArrayList; import java.util.List; 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); ArrayList 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--; } }