diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index b52f9a4c6..c1457e39a 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -985,12 +985,17 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.CloneList){ NBTTagList list = new NBTTagList(); - - for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) + int tab = buffer.readInt(); + for(String name : ServerCloneController.Instance.getClones(tab)) list.appendTag(new NBTTagString(name)); + NBTTagList listDate = new NBTTagList(); + for(String name : ServerCloneController.Instance.getClonesDate(tab)) + listDate.appendTag(new NBTTagString(name)); + NBTTagCompound compound = new NBTTagCompound(); compound.setTag("List", list); + compound.setTag("ListDate", listDate); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } @@ -1054,19 +1059,29 @@ public class PacketHandlerServer{ for(String name : ServerCloneController.Instance.getClones(tab)) list.appendTag(new NBTTagString(name)); + NBTTagList listDate = new NBTTagList(); + for(String name : ServerCloneController.Instance.getClonesDate(tab)) + listDate.appendTag(new NBTTagString(name)); + NBTTagCompound compound = new NBTTagCompound(); compound.setTag("List", list); + compound.setTag("ListDate", listDate); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if(type == EnumPacketServer.CloneList){ NBTTagList list = new NBTTagList(); - - for(String name : ServerCloneController.Instance.getClones(buffer.readInt())) + int tab = buffer.readInt(); + for(String name : ServerCloneController.Instance.getClones(tab)) list.appendTag(new NBTTagString(name)); + NBTTagList listDate = new NBTTagList(); + for(String name : ServerCloneController.Instance.getClonesDate(tab)) + listDate.appendTag(new NBTTagString(name)); + NBTTagCompound compound = new NBTTagCompound(); compound.setTag("List", list); + compound.setTag("ListDate", listDate); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java index 693ce20c7..ec65abc7e 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java @@ -25,7 +25,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { public static HashMap tagNames = new HashMap<>(); public static HashSet tagFilters = new HashSet<>(); public static byte displayTags = 0; - public static boolean ascending = true; + + // 0 - Any, 1 - All, 2 - Not Any, 3 - Not All + public static byte filterCondition = 0; + + public static byte ascending = 0; + + // 0 - By Name, 1 - By Date + public static byte sortType = 0; public TagMap tagMap; @@ -118,17 +125,38 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { } } else { // Show Filters - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("menu.tags"), guiLeft + 7, guiTop + 7)); + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.tagFilters"), guiLeft + 7, guiTop + 7)); addScroll(filterScroll); addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 190, 140, 20, tagSearch)); - addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("display.visible") + ":", guiLeft + 150, guiTop + 27)); - addButton(new GuiNpcButton(12, guiLeft + 190, guiTop + 20, new String[]{"display.show", "display.all", "display.hide"}, displayTags)); - addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 100, 20, "gui.deselectAll")); + addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("cloner.tagVisibility"), guiLeft + 150, guiTop + 27)); + addButton(new GuiNpcButton(12, guiLeft + 215, guiTop + 20, new String[]{"display.show", "display.all", "display.hide"}, displayTags)); - getButton(12).width = 60; + addLabel(new GuiNpcLabel(3, StatCollector.translateToLocal("filter.contains"), guiLeft + 150, guiTop + 50)); + addButton(new GuiNpcButton(13, guiLeft + 215, guiTop + 43, new String[]{"filter.any", "filter.all", "filter.notany", "filter.notall"}, filterCondition)); + + addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 66, 130, 20, "gui.deselectAll")); + + + addLabel(new GuiNpcLabel(4, StatCollector.translateToLocal("cloner.order"), guiLeft + 150, guiTop + 112)); + addButton(new GuiNpcButton(14, guiLeft + 215, guiTop + 105, new String[]{"cloner.ascending", "cloner.descending"}, ascending)); + + addLabel(new GuiNpcLabel(5, StatCollector.translateToLocal("cloner.type"), guiLeft + 150, guiTop + 135)); + addButton(new GuiNpcButton(15, guiLeft + 215, guiTop + 128, new String[]{"cloner.name", "cloner.date"}, sortType)); + + + getButton(12).width = 65; getButton(12).height = 20; + getButton(13).width = 65; + getButton(13).height = 20; + + getButton(14).width = 65; + getButton(14).height = 20; + + getButton(15).width = 65; + getButton(15).height = 20; + showFilters(); } } @@ -153,7 +181,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { } } this.list = list; - scroll.setList(getSearchList(), ascending); + scroll.setList(getSearchList(), ascending == 0, sortType == 0); } private void showClones() { if(showingClones == 2){ @@ -161,10 +189,16 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { Client.sendData(EnumPacketServer.CloneList, activeTab); return; } - ArrayList list = new ArrayList(); - this.list = ClientCloneController.Instance.getClones(activeTab); + + if(sortType == 0){ + this.list = ClientCloneController.Instance.getClones(activeTab); + } + else { + this.list = ClientCloneController.Instance.getClonesDate(activeTab); + } + this.tagMap = ClientTagMapController.Instance.getTagMap(activeTab); - scroll.setList(getSearchList(), ascending); + scroll.setList(getSearchList(), ascending == 0, sortType == 0); } public void keyTyped(char c, int i) { @@ -173,7 +207,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { if(search.equals(getTextField(1).getText())) return; search = getTextField(1).getText().toLowerCase(); - scroll.setList(getSearchList(), ascending); + scroll.setList(getSearchList(), ascending == 0, sortType == 0); } if(getTextField(2) != null){ if(tagSearch.equals(getTextField(2).getText())) @@ -188,56 +222,45 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { if(this.list == null){ this.list = new ArrayList(); } - // No Search // No Filters - or - Entities - if(search.isEmpty() && (tagFilters.size() == 0 || showingClones == 1)) - return new ArrayList(list); - // Yes Search // No Filters - or - Entities - else if(!search.isEmpty() && (tagFilters.size() == 0 || showingClones == 1)){ - List list = new ArrayList(); - for(String name : this.list){ - if(name.toLowerCase().contains(search)) - list.add(name); + + // No Filters - or - Entities + if(tagFilters.size() == 0 || showingClones == 1){ + // No Search + if(search.isEmpty()) + return new ArrayList(this.list); + // Yes Search + else { + List list = new ArrayList(); + for(String name : this.list){ + if(name.toLowerCase().contains(search)) + list.add(name); + } + return list; } - return list; } - // No Search // Yes Filters - else if(search.isEmpty() && tagFilters.size() > 0){ + + //////////////////////// + //// WITH FILTERS + + // No Search + if(search.isEmpty()){ List list = new ArrayList(); for(String name : this.list){ if(tagMap.hasClone(name)){ - boolean hasAll = true; - for(String tagName : tagFilters){ - UUID tagUUID = tagNames.get(tagName); - if(tagUUID != null){ - if(!tagMap.hasTag(name, tagUUID)){ - hasAll = false; - break; - } - } - } - if(hasAll){ + if(meetsCondition(name)){ list.add(name); } } } return list; } - // Yes Search // Yes Filters + + // Yes Search List list = new ArrayList(); for(String name : this.list){ if(name.toLowerCase().contains(search)) { if(tagMap.hasClone(name)){ - boolean hasAll = true; - for(String tagName : tagFilters){ - UUID tagUUID = tagNames.get(tagName); - if(tagUUID != null){ - if(!tagMap.hasTag(name, tagUUID)){ - hasAll = false; - break; - } - } - } - if(hasAll){ + if(meetsCondition(name)){ list.add(name); } } @@ -246,6 +269,40 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { return list; } + private boolean meetsCondition(String name){ + if(tagMap == null){ + return true; + } + boolean conditionMet = true; + boolean allRequirement = filterCondition == 1 || filterCondition == 3; + + for(String tagName : tagFilters){ + UUID tagUUID = tagNames.get(tagName); + if(tagUUID != null) { + boolean hasTag = tagMap.hasTag(name, tagUUID); + if (!allRequirement) { + if (!hasTag && filterCondition == 0) { + conditionMet = false; + break; + } else if (hasTag && filterCondition == 2) { + conditionMet = false; + break; + } + } else { + if (!hasTag && filterCondition == 1) { + conditionMet = false; + break; + } else if (hasTag && filterCondition == 3) { + conditionMet = false; + break; + } + } + } + } + + return conditionMet; + } + private List getTagList(){ if(this.tagList == null){ this.tagList = new ArrayList(); @@ -359,6 +416,18 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { GuiNpcButton button = (GuiNpcButton) guibutton; displayTags = (byte) button.getValue(); } + if (id == 13) { + GuiNpcButton button = (GuiNpcButton) guibutton; + filterCondition = (byte) button.getValue(); + } + if (id == 14) { + GuiNpcButton button = (GuiNpcButton) guibutton; + ascending = (byte) button.getValue(); + } + if (id == 15) { + GuiNpcButton button = (GuiNpcButton) guibutton; + sortType = (byte) button.getValue(); + } if(id > 20){ activeTab = id - 20; initGui(); @@ -397,13 +466,22 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { } } else { - NBTTagList nbtlist = compound.getTagList("List", 8); List list = new ArrayList(); - for(int i = 0; i < nbtlist.tagCount(); i++){ - list.add(nbtlist.getStringTagAt(i)); + if(sortType == 1){ + NBTTagList nbtlist = compound.getTagList("ListDate", 8); + for(int i = 0; i < nbtlist.tagCount(); i++){ + list.add(nbtlist.getStringTagAt(i)); + } } + else { + NBTTagList nbtlist = compound.getTagList("List", 8); + for(int i = 0; i < nbtlist.tagCount(); i++){ + list.add(nbtlist.getStringTagAt(i)); + } + } + this.list = list; - scroll.setList(getSearchList(), ascending); + scroll.setList(getSearchList(), ascending == 0, sortType == 0); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java index e5a4cf1a6..3fd43958e 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java @@ -13,8 +13,8 @@ import java.util.HashSet; public class SubGuiClonerQuickTags extends SubGuiInterface { public GuiNpcMobSpawnerAdd parent; - ArrayList allTags = new ArrayList<>(); - HashSet filter; + public ArrayList allTags = new ArrayList<>(); + public HashSet filter; public GuiCustomScroll filterScroll; public SubGuiClonerQuickTags(GuiNpcMobSpawnerAdd par){ diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 295db8a2d..cf61ca36c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -239,9 +239,11 @@ public class GuiCustomScroll extends GuiScreen setSize(xSize,ySize); } - public void setList(List list, boolean ascending){ + public void setList(List list, boolean ascending, boolean caseOrder){ isSorted = true; - Collections.sort(list, String.CASE_INSENSITIVE_ORDER); + if(caseOrder){ + Collections.sort(list, String.CASE_INSENSITIVE_ORDER); + } if(!ascending){ Collections.reverse(list); } diff --git a/src/main/java/noppes/npcs/controllers/ServerCloneController.java b/src/main/java/noppes/npcs/controllers/ServerCloneController.java index 6aa99088f..7413bffa3 100644 --- a/src/main/java/noppes/npcs/controllers/ServerCloneController.java +++ b/src/main/java/noppes/npcs/controllers/ServerCloneController.java @@ -18,6 +18,7 @@ import noppes.npcs.controllers.data.TagMap; import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.util.NBTJsonUtil; +import org.lwjgl.Sys; import java.io.File; import java.io.FileInputStream; @@ -144,6 +145,27 @@ public class ServerCloneController implements ICloneHandler { return list; } + public List getClonesDate(int tab){ + List list = new ArrayList(); + File dir = new File(getDir(), tab + ""); + if(!dir.exists() || !dir.isDirectory()) + return list; + File[] files = dir.listFiles(); + Arrays.sort(files, new Comparator(){ + public int compare(File f1, File f2) + { + return Long.compare(f1.lastModified(), f2.lastModified()); + } + }); + + for(File file : files){ + String fileName = file.getName(); + if(fileName.endsWith(".json")) + list.add(fileName.substring(0, fileName.length() - 5)); + } + return list; + } + public boolean removeClone(String name, int tab){ File file = new File(new File(getDir(), tab + ""), name + ".json"); if(!file.exists()) diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 5bdae4e21..73d1cddaa 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -129,6 +129,11 @@ gui.selectAll=Select All gui.deselectAll=Deselect All scale.shared=Shared +filter.contains=Contains +filter.any=Any +filter.all=All +filter.notany=Not Any +filter.notall=Not All remote.title=Nearby NPCs remote.reset=Reset @@ -401,8 +406,16 @@ menu.role=Role menu.animations=Animations menu.tags=Tags +cloner.tagFilters=Tag Filters +cloner.tagVisibility=Tag Visibility cloner.wandTags=Wand Tags cloner.npcTags=NPC Tags +cloner.order=Sort Order +cloner.ascending=Ascending +cloner.descending=Descending +cloner.type=Sort Type +cloner.name=Name +cloner.date=Date tags.allTags=All Tags tags.selectedTags=Selected Tags