diff --git a/src/main/java/kamkeel/AnimationCommand.java b/src/main/java/kamkeel/AnimationCommand.java new file mode 100644 index 000000000..2326fe809 --- /dev/null +++ b/src/main/java/kamkeel/AnimationCommand.java @@ -0,0 +1,67 @@ +package kamkeel; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.monster.EntityEnderman; +import noppes.npcs.controllers.AnimationController; +import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.data.Animation; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerFactionData; + +import java.util.Arrays; +import java.util.List; + +public class AnimationCommand extends CommandKamkeelBase { + + public Animation selectedAnimation; + public List data; + + @Override + public String getCommandName() { + return "animation"; + } + + @Override + public String getDescription() { + return "Animation operations"; + } + + @Override + public String getUsage() { + return " "; + } + + @Override + public boolean runSubCommands(){ + return false; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + String playername = args[0]; + String animationName = args[1]; + + data = PlayerDataController.instance.getPlayersData(sender, playername); + if (data.isEmpty()) { + throw new CommandException("Unknown player: " + playername); + } + + selectedAnimation = AnimationController.getInstance().getAnimationFromName(animationName); + + if (selectedAnimation == null) { + throw new CommandException("Unknown animation: " + animationName); + } + + processSubCommand(sender, args[2], Arrays.copyOfRange(args, 3, args.length)); + } + + @SubCommand( + desc = "play animation", + usage = " play" + ) + public void play(ICommandSender sender, String[] args) throws CommandException { + + } +} diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index ef8d0e2c9..7eaa5d533 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -231,6 +231,7 @@ public class CustomNpcs { QuestController.instance.load(); ScriptController.HasStart = true; ServerCloneController.Instance = new ServerCloneController(); + ServerTagMapController.Instance = new ServerTagMapController(); } @EventHandler diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index aae75cd7a..9900676ac 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -28,6 +28,7 @@ import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.data.ITag; import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigMain; import noppes.npcs.config.ConfigScript; @@ -1000,7 +1001,7 @@ public class PacketHandlerServer{ Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else - warn(player,"tried todo something with the wrong tool, probably a hacker"); + warn(player,"WE 1 tried todo something with the wrong tool, probably a hacker"); } private void clonePackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { @@ -1077,33 +1078,25 @@ public class PacketHandlerServer{ } else if (type == EnumPacketServer.CloneTagList) { int tab = buffer.readInt(); - List cloneNames = ServerCloneController.Instance.getClones(tab); - NBTTagList cloneTags = new NBTTagList(); - for (String name : cloneNames) { - NBTTagCompound compound = ServerCloneController.Instance.getCloneData(null, name, tab); - if (compound.hasKey("TagUUIDs")) { - NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setString("Name",name); - - NBTTagList uuidList = compound.getTagList("TagUUIDs",8); - NBTTagList tags = new NBTTagList(); - for (int i = 0; i < uuidList.tagCount(); i++) { - String uuidString = uuidList.getStringTagAt(i); - NBTTagCompound tagNBT = new NBTTagCompound(); - TagController.getInstance().getTagFromUUID(UUID.fromString(uuidString)).writeNBT(tagNBT); - tags.appendTag(tagNBT); - } - tagCompound.setTag("Tags",tags); - cloneTags.appendTag(tagCompound); - } - } - + TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab); NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("CloneTags", cloneTags); + compound.setTag("CloneTags", tagMap.writeNBT()); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } + else if (type == EnumPacketServer.CloneAllTags) { + NBTTagCompound compound = new NBTTagCompound(); + HashSet validTags = TagController.getInstance().getAllTags(); + NBTTagList validTagList = new NBTTagList(); + for(Tag tag : validTags){ + NBTTagCompound tagCompound = new NBTTagCompound(); + tag.writeNBT(tagCompound); + validTagList.appendTag(tagCompound); + } + compound.setTag("AllTags", validTagList); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else - warn(player,"tried todo something with the wrong tool, probably a hacker"); + warn(player,"WE 2 tried todo something with the wrong tool, probably a hacker"); } private void warn(EntityPlayer player, String warning){ diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 352e36fec..60746591e 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -30,10 +30,7 @@ import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.*; import noppes.npcs.api.IWorld; import noppes.npcs.blocks.tiles.*; -import noppes.npcs.client.controllers.ClientCloneController; -import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.controllers.PresetController; -import noppes.npcs.client.controllers.ScriptSoundController; +import noppes.npcs.client.controllers.*; import noppes.npcs.client.fx.EntityElementalStaffFX; import noppes.npcs.client.fx.EntityEnderFX; import noppes.npcs.client.fx.EntityRainbowFX; @@ -145,6 +142,7 @@ public class ClientProxy extends CommonProxy { } ClientCloneController.Instance = new ClientCloneController(); + ClientTagMapController.Instance = new ClientTagMapController(); MinecraftForge.EVENT_BUS.register(new ClientEventHandler()); diff --git a/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java b/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java index b0cf6523d..10d190431 100644 --- a/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java +++ b/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java @@ -1,9 +1,15 @@ package noppes.npcs.client.controllers; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import noppes.npcs.CustomNpcs; import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.controllers.ServerTagMapController; +import noppes.npcs.controllers.data.TagMap; import java.io.File; +import java.util.HashSet; +import java.util.UUID; public class ClientCloneController extends ServerCloneController{ public static ClientCloneController Instance; @@ -15,4 +21,33 @@ public class ClientCloneController extends ServerCloneController{ dir.mkdir(); return dir; } + + @Override + public boolean addToTagMap(NBTTagCompound nbttagcompound, String name, int tab){ + HashSet tagUUIDs = new HashSet(); + if(nbttagcompound.hasKey("TagUUIDs")){ + NBTTagList nbtTagList = nbttagcompound.getTagList("TagUUIDs",8); + for (int i = 0; i < nbtTagList.tagCount(); i++) { + tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i))); + } + } + if(tagUUIDs.size() > 0){ + TagMap tagMap = ClientTagMapController.Instance.getTagMap(tab); + tagMap.putClone(name, tagUUIDs); + ClientTagMapController.Instance.saveTagMap(tagMap); + return true; + } + return false; + } + + @Override + public boolean removeFromTagMap(String name, int tab){ + TagMap tagMap = ClientTagMapController.Instance.getTagMap(tab); + if(tagMap.removeClone(name)){ + ClientTagMapController.Instance.saveTagMap(tagMap); + return true; + } + return false; + } + } diff --git a/src/main/java/noppes/npcs/client/controllers/ClientTagMapController.java b/src/main/java/noppes/npcs/client/controllers/ClientTagMapController.java new file mode 100644 index 000000000..9a2083745 --- /dev/null +++ b/src/main/java/noppes/npcs/client/controllers/ClientTagMapController.java @@ -0,0 +1,18 @@ +package noppes.npcs.client.controllers; + +import noppes.npcs.CustomNpcs; +import noppes.npcs.controllers.ServerTagMapController; + +import java.io.File; + +public class ClientTagMapController extends ServerTagMapController { + public static ClientTagMapController Instance; + + @Override + public File getDir(){ + File dir = new File(CustomNpcs.Dir,"clones"); + if(!dir.exists()) + dir.mkdir(); + return dir; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java index 504ce1fd7..693ce20c7 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java @@ -7,31 +7,40 @@ import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import noppes.npcs.client.Client; import noppes.npcs.client.controllers.ClientCloneController; +import noppes.npcs.client.controllers.ClientTagMapController; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Tag; +import noppes.npcs.controllers.data.TagMap; import java.lang.reflect.Modifier; import java.util.*; -public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGuiData,ISubGuiListener { - public static HashSet allTags = new HashSet<>(); - public static HashSet filter = new HashSet<>(); - public static boolean showNoTags = true; - public HashMap> tags = new HashMap<>(); +public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData { + public static HashMap tags = new HashMap<>(); + public static HashMap tagNames = new HashMap<>(); + public static HashSet tagFilters = new HashSet<>(); + public static byte displayTags = 0; + public static boolean ascending = true; + public TagMap tagMap; private final GuiCustomScrollCloner scroll = new GuiCustomScrollCloner(this,0); + private final GuiCustomScroll filterScroll = new GuiCustomScroll(this,1); + private int posX,posY,posZ; private List list; + private List tagList; private static int showingClones = 0; private static String search = ""; + private static String tagSearch = ""; private int activeTab = 1; @@ -45,7 +54,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu this.closeOnEsc = true; setBackground("menubg.png"); - Client.sendData(EnumPacketServer.TagsGet); + Client.sendData(EnumPacketServer.CloneAllTags, activeTab); } public void initGui() { @@ -57,9 +66,12 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu scroll.setSize(293, 188); scroll.guiLeft = guiLeft + 4; scroll.guiTop = guiTop + 26; - addScroll(scroll); - - addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 293, 20, search)); + filterScroll.clear(); + filterScroll.setSize(140, 166); + filterScroll.guiLeft = guiLeft + 4; + filterScroll.guiTop = guiTop + 19; + filterScroll.multipleSelection = true; + filterScroll.setSelectedList(tagFilters); GuiMenuTopButton button; addTopButton(button = new GuiMenuTopButton(3,guiLeft + 4, guiTop - 17, "spawner.clones")); @@ -68,44 +80,65 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu button.active = showingClones == 2; addTopButton(button = new GuiMenuTopButton(4, button, "spawner.entities")); button.active = showingClones == 1; + addTopButton(button = new GuiMenuTopButton(16, guiLeft + (xSize - 67), guiTop - 17, "gui.filters")); + button.active = showingClones == 3; + addTopButton(button = new GuiMenuTopButton(17, guiLeft + (xSize - 22), guiTop - 17, "X")); + if (showingClones < 3){ + addScroll(scroll); + addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 293, 20, search)); + addButton(new GuiNpcButton(1, guiLeft + 298, guiTop + 6, 52, 20, "item.monsterPlacer.name")); + addButton(new GuiNpcButton(2, guiLeft + 298, guiTop + 140, 52, 20, "spawner.mobspawner")); - addButton(new GuiNpcButton(1, guiLeft + 298, guiTop + 6, 52, 20, "item.monsterPlacer.name")); + if(showingClones == 0 || showingClones == 2){ - addButton(new GuiNpcButton(7, guiLeft + 298, guiTop + 78, 52, 20, "gui.filters")); - addButton(new GuiNpcButton(2, guiLeft + 298, guiTop + 100, 52, 20, "spawner.mobspawner")); + addSideButton(new GuiMenuSideButton(21,guiLeft - 70, this.guiTop + 2, 70,22, "1")); + addSideButton(new GuiMenuSideButton(22,guiLeft - 70, this.guiTop + 23, 70,22, "2")); + addSideButton(new GuiMenuSideButton(23,guiLeft - 70, this.guiTop + 44, 70,22, "3")); + addSideButton(new GuiMenuSideButton(24,guiLeft - 70, this.guiTop + 65, 70,22, "4")); + addSideButton(new GuiMenuSideButton(25,guiLeft - 70, this.guiTop + 86, 70,22, "5")); + addSideButton(new GuiMenuSideButton(26,guiLeft - 70, this.guiTop + 107, 35,22, "6")); + addSideButton(new GuiMenuSideButton(27,guiLeft - 35, this.guiTop + 107, 35,22, "7")); + addSideButton(new GuiMenuSideButton(28,guiLeft - 70, this.guiTop + 128, 35,22, "8")); + addSideButton(new GuiMenuSideButton(29,guiLeft - 35, this.guiTop + 128, 35,22, "9")); + addSideButton(new GuiMenuSideButton(30,guiLeft - 70, this.guiTop + 149, 35,22, "10")); + addSideButton(new GuiMenuSideButton(31,guiLeft - 35, this.guiTop + 149, 35,22, "11")); + addSideButton(new GuiMenuSideButton(32,guiLeft - 70, this.guiTop + 170, 35,22, "12")); + addSideButton(new GuiMenuSideButton(33,guiLeft - 35, this.guiTop + 170, 35,22, "13")); + addSideButton(new GuiMenuSideButton(34,guiLeft - 70, this.guiTop + 191, 35,22, "14")); + addSideButton(new GuiMenuSideButton(35,guiLeft - 35, this.guiTop + 191, 35,22, "15")); - if(showingClones == 0 || showingClones == 2){ + addButton(new GuiNpcButton(6, guiLeft + 298, guiTop + 190, 52, 20, "gui.remove")); - addSideButton(new GuiMenuSideButton(21,guiLeft - 70, this.guiTop + 2, 70,22, "1")); - addSideButton(new GuiMenuSideButton(22,guiLeft - 70, this.guiTop + 23, 70,22, "2")); - addSideButton(new GuiMenuSideButton(23,guiLeft - 70, this.guiTop + 44, 70,22, "3")); - addSideButton(new GuiMenuSideButton(24,guiLeft - 70, this.guiTop + 65, 70,22, "4")); - addSideButton(new GuiMenuSideButton(25,guiLeft - 70, this.guiTop + 86, 70,22, "5")); - addSideButton(new GuiMenuSideButton(26,guiLeft - 70, this.guiTop + 107, 35,22, "6")); - addSideButton(new GuiMenuSideButton(27,guiLeft - 35, this.guiTop + 107, 35,22, "7")); - addSideButton(new GuiMenuSideButton(28,guiLeft - 70, this.guiTop + 128, 35,22, "8")); - addSideButton(new GuiMenuSideButton(29,guiLeft - 35, this.guiTop + 128, 35,22, "9")); - addSideButton(new GuiMenuSideButton(30,guiLeft - 70, this.guiTop + 149, 35,22, "10")); - addSideButton(new GuiMenuSideButton(31,guiLeft - 35, this.guiTop + 149, 35,22, "11")); - addSideButton(new GuiMenuSideButton(32,guiLeft - 70, this.guiTop + 170, 35,22, "12")); - addSideButton(new GuiMenuSideButton(33,guiLeft - 35, this.guiTop + 170, 35,22, "13")); - addSideButton(new GuiMenuSideButton(34,guiLeft - 70, this.guiTop + 191, 35,22, "14")); - addSideButton(new GuiMenuSideButton(35,guiLeft - 35, this.guiTop + 191, 35,22, "15")); + getSideButton(20 + activeTab).active = true; + showClones(); + } + else { + showEntities(); + } + } else { + // Show Filters + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("menu.tags"), 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")); + getButton(12).width = 60; + getButton(12).height = 20; - // addButton(new GuiNpcButton(6, guiLeft + 298, guiTop + 190, 82, 20, "gui.remove")); - addButton(new GuiNpcButton(6, guiLeft + 298, guiTop + 190, 52, 20, "gui.remove")); - - getSideButton(20 + activeTab).active = true; - showClones(); - } - else{ - showEntities(); + showFilters(); } } + public int getShowingClones() {return showingClones; } + + public void showFilters(){ + filterScroll.setList(getTagList()); + } + private void showEntities() { Map data = EntityList.stringToClassMapping; ArrayList list = new ArrayList(); @@ -120,37 +153,116 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu } } this.list = list; - scroll.setList(getSearchList()); + scroll.setList(getSearchList(), ascending); } private void showClones() { - Client.sendData(EnumPacketServer.CloneTagList, activeTab); if(showingClones == 2){ + Client.sendData(EnumPacketServer.CloneTagList, activeTab); Client.sendData(EnumPacketServer.CloneList, activeTab); return; } ArrayList list = new ArrayList(); this.list = ClientCloneController.Instance.getClones(activeTab); - scroll.setList(getSearchList()); + this.tagMap = ClientTagMapController.Instance.getTagMap(activeTab); + scroll.setList(getSearchList(), ascending); } public void keyTyped(char c, int i) { super.keyTyped(c, i); + if(getTextField(1) != null){ + if(search.equals(getTextField(1).getText())) + return; + search = getTextField(1).getText().toLowerCase(); + scroll.setList(getSearchList(), ascending); + } + if(getTextField(2) != null){ + if(tagSearch.equals(getTextField(2).getText())) + return; + tagSearch = getTextField(2).getText().toLowerCase(); + filterScroll.setList(getTagList()); + } - if(search.equals(getTextField(1).getText())) - return; - search = getTextField(1).getText().toLowerCase(); - scroll.setList(getSearchList()); } + private List getSearchList(){ - if(search.isEmpty()) + 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); + } + return list; + } + // No Search // Yes Filters + else if(search.isEmpty() && tagFilters.size() > 0){ + 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){ + list.add(name); + } + } + } + return list; + } + // Yes Search // Yes Filters List list = new ArrayList(); for(String name : this.list){ - if(name.toLowerCase().contains(search)) + 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){ + list.add(name); + } + } + } + } + return list; + } + + private List getTagList(){ + if(this.tagList == null){ + this.tagList = new ArrayList(); + } + // No Search // No Filters - or - Entities + if(tagSearch.isEmpty()) + return new ArrayList(tagNames.keySet()); + // Yes Search // No Filters - or - Entities + + List list = new ArrayList(); + for(String name : this.tagList){ + if(name.toLowerCase().contains(tagSearch)) list.add(name); } return list; } + private NBTTagCompound getCompound(){ String sel = scroll.getSelected(); if(sel == null) @@ -220,6 +332,13 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu showingClones = 2; initGui(); } + if(id == 16){ + showingClones = 3; + initGui(); + } + if(id == 17){ + close(); + } if(id == 6){ if(scroll.getSelected() != null){ if(showingClones == 2){ @@ -231,8 +350,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu initGui(); } } - if (id == 7) { - setSubGui(new SubGuiNpcFilterTags()); + if (id == 11) { + tagFilters = new HashSet<>(); + filterScroll.setSelectedList(tagFilters); + initGui(); + } + if (id == 12) { + GuiNpcButton button = (GuiNpcButton) guibutton; + displayTags = (byte) button.getValue(); } if(id > 20){ activeTab = id - 20; @@ -240,57 +365,46 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGu } } - @Override - public void setData(Vector list, HashMap data) - { - allTags.addAll(list); - filter.addAll(allTags); - } - - @Override - public void setSelected(String selected) { - } - @Override public void save() { // TODO Auto-generated method stub - } + @Override public void setGuiData(NBTTagCompound compound) { if (compound.hasKey("CloneTags")) { - this.tags.clear(); - NBTTagList cloneTags = compound.getTagList("CloneTags", 10); - for (int i = 0; i < cloneTags.tagCount(); i++) { - NBTTagCompound tagCompound = cloneTags.getCompoundTagAt(i); - String name = tagCompound.getString("Name"); - - HashSet tagNames = new HashSet<>(); - NBTTagList tagList = tagCompound.getTagList("Tags", 10); - for (int j = 0; j < tagList.tagCount(); j++) { + this.tagMap = new TagMap(activeTab); + NBTTagCompound cloneTags = compound.getCompoundTag("CloneTags"); + this.tagMap.readNBT(cloneTags); + } + else if (compound.hasKey("AllTags")) { + NBTTagList validTags = compound.getTagList("AllTags", 10); + if(validTags != null){ + HashMap tagsUpdate = new HashMap<>(); + HashMap tagNamesUpdate = new HashMap<>(); + for(int j = 0; j < validTags.tagCount(); j++) + { + NBTTagCompound tagStructure = validTags.getCompoundTagAt(j); Tag tag = new Tag(); - tag.readNBT(tagList.getCompoundTagAt(j)); - tagNames.add(tag); + tag.readNBT(tagStructure); + tagsUpdate.put(tag.uuid, tag); + tagNamesUpdate.put(tag.name, tag.uuid); } - - this.tags.put(name, tagNames); + tags = tagsUpdate; + tagNames = tagNamesUpdate; + this.tagList = new ArrayList(tagNames.keySet()); + filterScroll.setList(getTagList()); } - } else { + } + else { NBTTagList nbtlist = compound.getTagList("List", 8); List list = new ArrayList(); for(int i = 0; i < nbtlist.tagCount(); i++){ list.add(nbtlist.getStringTagAt(i)); } this.list = list; - scroll.setList(getSearchList()); + scroll.setList(getSearchList(), ascending); } } - @Override - public void subGuiClosed(SubGuiInterface subgui) { - SubGuiNpcFilterTags filterGui = (SubGuiNpcFilterTags) subgui; - filter = filterGui.filterScroll.getSelectedList(); - showNoTags = filterGui.showNoTags; - initGui(); - } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcFilterTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcFilterTags.java deleted file mode 100644 index de2a1df84..000000000 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcFilterTags.java +++ /dev/null @@ -1,67 +0,0 @@ -package noppes.npcs.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.util.StatCollector; -import noppes.npcs.client.gui.util.GuiCustomScroll; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcLabel; -import noppes.npcs.client.gui.util.SubGuiInterface; - -import java.util.*; - -public class SubGuiNpcFilterTags extends SubGuiInterface -{ - ArrayList allTags = new ArrayList<>(); - HashSet filter; - public GuiCustomScroll filterScroll; - public boolean showNoTags; - - public SubGuiNpcFilterTags(){ - setBackground("menubg.png"); - xSize = 305; - ySize = 200; - closeOnEsc = true; - this.allTags.addAll(GuiNpcMobSpawner.allTags); - this.filter = GuiNpcMobSpawner.filter; - this.showNoTags = GuiNpcMobSpawner.showNoTags; - } - - public void initGui(){ - super.initGui(); - if(filterScroll == null){ - filterScroll = new GuiCustomScroll(this,0); - filterScroll.setSize(140, 180); - } - filterScroll.guiLeft = guiLeft + 4; - filterScroll.guiTop = guiTop + 14; - filterScroll.setList(this.allTags); - filterScroll.multipleSelection = true; - filterScroll.setSelectedList(this.filter); - this.addScroll(filterScroll); - - addButton(new GuiNpcButton(10, guiLeft + 150, guiTop + 20, 120, 20, "gui.selectAll")); - addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 120, 20, "gui.deselectAll")); - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.taglessEntries") + ":", guiLeft + 150, guiTop + 72)); - addButton(new GuiNpcButton(12, guiLeft + 240, guiTop + 65, new String[]{"display.show", "display.hide"}, showNoTags ? 0 : 1)); - getButton(12).width = 60; - getButton(12).height = 20; - - addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 175, 60, 20, "gui.done")); - } - - protected void actionPerformed(GuiButton guibutton){ - if (guibutton.id == 10) { - HashSet hashSet = new HashSet<>(this.allTags); - filterScroll.setSelectedList(hashSet); - } - if (guibutton.id == 11) { - filterScroll.setSelectedList(new HashSet<>()); - } - if (guibutton.id == 12) { - showNoTags = !showNoTags; - } - if (guibutton.id == 66) { - close(); - } - } -} diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java index f3e8a0013..045adf2ae 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java @@ -53,12 +53,12 @@ public class GuiNPCManageTags extends GuiNPCInterface2 implements IScrollData,IC String color = Integer.toHexString(tag.color); while(color.length() < 6) color = "0" + color; - addButton(new GuiNpcButton(10, guiLeft + 40, guiTop + 26, 60, 20, color)); - addLabel(new GuiNpcLabel(1,"gui.color", guiLeft + 8, guiTop + 31)); + addButton(new GuiNpcButton(10, guiLeft + 50, guiTop + 30, 60, 20, color)); + addLabel(new GuiNpcLabel(1,"gui.color", guiLeft + 8, guiTop + 35)); getButton(10).setTextColor(tag.color); - addLabel(new GuiNpcLabel(3,"tag.hidden", guiLeft + 8, guiTop + 75)); - this.addButton(new GuiNpcButton(3,guiLeft + 100, guiTop + 70, 45, 20, new String[]{"gui.no","gui.yes"},tag.hideTag?1:0)); + addLabel(new GuiNpcLabel(3,"faction.hidden", guiLeft + 8, guiTop + 59)); + this.addButton(new GuiNpcButton(3,guiLeft + 50, guiTop + 54, 60, 20, new String[]{"gui.no","gui.yes"},tag.hideTag?1:0)); } @Override 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 bcd34411a..295db8a2d 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -231,12 +231,24 @@ public class GuiCustomScroll extends GuiScreen // TODO Auto-generated method stub return selected >= 0; } - public void setList(List list){ + + public void setList(List list){ isSorted = true; Collections.sort(list, String.CASE_INSENSITIVE_ORDER); this.list = list; setSize(xSize,ySize); } + + public void setList(List list, boolean ascending){ + isSorted = true; + Collections.sort(list, String.CASE_INSENSITIVE_ORDER); + if(!ascending){ + Collections.reverse(list); + } + this.list = list; + setSize(xSize,ySize); + } + public void setUnsortedList(List list){ isSorted = false; this.list = list; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScrollCloner.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScrollCloner.java index d9addc3f3..36e50a69f 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScrollCloner.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScrollCloner.java @@ -5,6 +5,7 @@ import noppes.npcs.client.gui.GuiNpcMobSpawner; import noppes.npcs.controllers.data.Tag; import java.util.HashSet; +import java.util.UUID; public class GuiCustomScrollCloner extends GuiCustomScroll { private final GuiNpcMobSpawner parent; @@ -19,22 +20,6 @@ public class GuiCustomScrollCloner extends GuiCustomScroll { int l = 0; for(int i = 0; i < list.size(); i++) { - if (this.parent.tags.containsKey(list.get(i))) { - HashSet tags = this.parent.tags.get(list.get(i)); - boolean inFilter = false; - for (Tag tag : tags) { - if (GuiNpcMobSpawner.filter.contains(tag.name)) { - inFilter = true; - break; - } - } - if (!inFilter) { - continue; - } - } else if (!GuiNpcMobSpawner.showNoTags) { - continue; - } - int j = 4; int k = (14 * l + 4) - scrollY; l++; @@ -70,12 +55,19 @@ public class GuiCustomScrollCloner extends GuiCustomScroll { fontRendererObj.drawString(text, j, k, this.colors.getOrDefault(text, 0xffffff)); } - int tagStartX = j + fontRendererObj.getStringWidth(displayString) + 5; - if (this.parent.tags.containsKey(list.get(i))) { - for (Tag tag : this.parent.tags.get(list.get(i))) { - if (!tag.getIsHidden()) { - fontRendererObj.drawString("[" + tag.name + "]", tagStartX, k, tag.color); - tagStartX += fontRendererObj.getStringWidth("[" + tag.name + "]") + 2; + if((this.parent.getShowingClones() == 0 || this.parent.getShowingClones() == 2) && this.parent.tagMap != null){ + int tagStartX = j + fontRendererObj.getStringWidth(displayString) + 5; + if(GuiNpcMobSpawner.displayTags == 0 || GuiNpcMobSpawner.displayTags == 1){ + if (this.parent.tagMap.hasClone(list.get(i))) { + for (UUID tagUUID : this.parent.tagMap.getUUIDs(list.get(i))){ + Tag tag = this.parent.tags.get(tagUUID); + if(tag != null){ + if(GuiNpcMobSpawner.displayTags == 1 || !tag.getIsHidden()){ + fontRendererObj.drawString("[" + tag.name + "]", tagStartX, k, tag.color); + tagStartX += fontRendererObj.getStringWidth("[" + tag.name + "]") + 2; + } + } + } } } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 71d222a56..fdde8cf0c 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -33,7 +33,7 @@ public enum EnumPacketServer { RoleCompanionUpdate(CustomNpcsPermissions.NPC_ADVANCED, true), LinkedSet(CustomNpcsPermissions.NPC_ADVANCED, true), - ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, CloneTagList, + ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, CloneTagList, CloneAllTags, ScriptGlobalGuiDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), ScriptGlobalGuiDataGet(false), diff --git a/src/main/java/noppes/npcs/controllers/AnimationController.java b/src/main/java/noppes/npcs/controllers/AnimationController.java index 120574bf2..897402a35 100644 --- a/src/main/java/noppes/npcs/controllers/AnimationController.java +++ b/src/main/java/noppes/npcs/controllers/AnimationController.java @@ -5,6 +5,7 @@ import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAnimationHandler; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.controllers.data.Animation; +import noppes.npcs.controllers.data.Faction; import noppes.npcs.util.NBTJsonUtil; import java.io.File; @@ -20,6 +21,10 @@ public class AnimationController implements IAnimationHandler { load(); } + public static AnimationController getInstance(){ + return instance; + } + public void load(){ LogWriter.info("Loading animations..."); loadAnimations(); @@ -100,4 +105,24 @@ public class AnimationController implements IAnimationHandler { ArrayList animations = new ArrayList<>(this.animations.values()); return animations.toArray(new IAnimation[0]); } + + public Animation getAnimationFromName(String animation){ + for (Map.Entry entryAnimation : AnimationController.getInstance().animations.entrySet()){ + if (entryAnimation.getValue().name.equalsIgnoreCase(animation)){ + return entryAnimation.getValue(); + } + } + return null; + } + + public String[] getNames() { + String[] names = new String[animations.size()]; + int i = 0; + for(Animation animation : animations.values()){ + names[i] = animation.name.toLowerCase(); + i++; + } + return names; + } + } diff --git a/src/main/java/noppes/npcs/controllers/FactionController.java b/src/main/java/noppes/npcs/controllers/FactionController.java index 339362daa..6d1d68784 100644 --- a/src/main/java/noppes/npcs/controllers/FactionController.java +++ b/src/main/java/noppes/npcs/controllers/FactionController.java @@ -18,11 +18,11 @@ import java.util.zip.GZIPInputStream; public class FactionController implements IFactionHandler { public HashMap factions; - + private static FactionController instance; private int lastUsedID = 0; - + public FactionController(){ instance = this; factions = new HashMap(); @@ -32,9 +32,9 @@ public class FactionController implements IFactionHandler { factions.put(1,new Faction(1,"Neutral", 0xF2DD00, 1000)); factions.put(2,new Faction(2,"Aggressive", 0xDD0000, 0)); } - + } - + public static FactionController getInstance(){ return instance; } @@ -50,79 +50,79 @@ public class FactionController implements IFactionHandler { return; } try { - File file = new File(saveDir, "factions.dat"); - if(file.exists()){ - loadFactionsFile(file); - } + File file = new File(saveDir, "factions.dat"); + if(file.exists()){ + loadFactionsFile(file); + } } catch (Exception e) { try { - File file = new File(saveDir, "factions.dat_old"); - if(file.exists()){ - loadFactionsFile(file); - } - + File file = new File(saveDir, "factions.dat_old"); + if(file.exists()){ + loadFactionsFile(file); + } + } catch (Exception ee) { } } } private void loadFactionsFile(File file) throws IOException{ - DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))); + DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))); loadFactions(var1); var1.close(); } public void loadFactions(DataInputStream stream) throws IOException{ HashMap factions = new HashMap(); - NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream); - lastUsedID = nbttagcompound1.getInteger("lastID"); - NBTTagList list = nbttagcompound1.getTagList("NPCFactions", 10); + NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream); + lastUsedID = nbttagcompound1.getInteger("lastID"); + NBTTagList list = nbttagcompound1.getTagList("NPCFactions", 10); - if(list != null){ - for(int i = 0; i < list.tagCount(); i++) - { - NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); - Faction faction = new Faction(); - faction.readNBT(nbttagcompound); - factions.put(faction.id,faction); - } - } - this.factions = factions; + if(list != null){ + for(int i = 0; i < list.tagCount(); i++) + { + NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); + Faction faction = new Faction(); + faction.readNBT(nbttagcompound); + factions.put(faction.id,faction); + } + } + this.factions = factions; } public NBTTagCompound getNBT(){ - NBTTagList list = new NBTTagList(); - for(int slot : factions.keySet()){ - Faction faction = factions.get(slot); - NBTTagCompound nbtfactions = new NBTTagCompound(); - faction.writeNBT(nbtfactions); - list.appendTag(nbtfactions); - } - NBTTagCompound nbttagcompound = new NBTTagCompound(); - nbttagcompound.setInteger("lastID", lastUsedID); - nbttagcompound.setTag("NPCFactions", list); - return nbttagcompound; + NBTTagList list = new NBTTagList(); + for(int slot : factions.keySet()){ + Faction faction = factions.get(slot); + NBTTagCompound nbtfactions = new NBTTagCompound(); + faction.writeNBT(nbtfactions); + list.appendTag(nbtfactions); + } + NBTTagCompound nbttagcompound = new NBTTagCompound(); + nbttagcompound.setInteger("lastID", lastUsedID); + nbttagcompound.setTag("NPCFactions", list); + return nbttagcompound; } public void saveFactions(){ try { File saveDir = CustomNpcs.getWorldSaveDirectory(); - File file = new File(saveDir, "factions.dat_new"); - File file1 = new File(saveDir, "factions.dat_old"); - File file2 = new File(saveDir, "factions.dat"); - CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file)); - if(file1.exists()) - { - file1.delete(); - } - file2.renameTo(file1); - if(file2.exists()) - { - file2.delete(); - } - file.renameTo(file2); - if(file.exists()) - { - file.delete(); - } + File file = new File(saveDir, "factions.dat_new"); + File file1 = new File(saveDir, "factions.dat_old"); + File file2 = new File(saveDir, "factions.dat"); + CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file)); + if(file1.exists()) + { + file1.delete(); + } + file2.renameTo(file1); + if(file2.exists()) + { + file2.delete(); + } + file.renameTo(file2); + if(file.exists()) + { + file.delete(); + } } catch (Exception e) { LogWriter.except(e); } @@ -166,7 +166,7 @@ public class FactionController implements IFactionHandler { this.saveFaction(faction); return faction; } - + public int getUnusedId(){ if(lastUsedID == 0){ for(int catid : factions.keySet()) @@ -191,7 +191,7 @@ public class FactionController implements IFactionHandler { return null; } } - + public int getFirstFactionId() { return factions.keySet().iterator().next(); } @@ -206,22 +206,23 @@ public class FactionController implements IFactionHandler { return true; return false; } - public Faction getFactionFromName(String factioname){ - for (Map.Entryentryfaction:FactionController.getInstance().factions.entrySet()){ - if (entryfaction.getValue().name.equalsIgnoreCase(factioname)){ - return entryfaction.getValue(); - } - } - return null; - } - - public String[] getNames() { - String[] names = new String[factions.size()]; - int i = 0; - for(Faction faction : factions.values()){ - names[i] = faction.name.toLowerCase(); - i++; + + public Faction getFactionFromName(String factioname){ + for (Map.Entryentryfaction:FactionController.getInstance().factions.entrySet()){ + if (entryfaction.getValue().name.equalsIgnoreCase(factioname)){ + return entryfaction.getValue(); } - return names; } + return null; + } + + public String[] getNames() { + String[] names = new String[factions.size()]; + int i = 0; + for(Faction faction : factions.values()){ + names[i] = faction.name.toLowerCase(); + i++; + } + return names; + } } diff --git a/src/main/java/noppes/npcs/controllers/ServerCloneController.java b/src/main/java/noppes/npcs/controllers/ServerCloneController.java index e29d26ea1..6aa99088f 100644 --- a/src/main/java/noppes/npcs/controllers/ServerCloneController.java +++ b/src/main/java/noppes/npcs/controllers/ServerCloneController.java @@ -14,44 +14,42 @@ import noppes.npcs.api.IPos; import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.handler.ICloneHandler; +import noppes.npcs.controllers.data.TagMap; import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.util.NBTJsonUtil; import java.io.File; import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ServerCloneController implements ICloneHandler { public static ServerCloneController Instance; - + public ServerCloneController(){ loadClones(); } - + private void loadClones(){ try { File dir = new File(getDir(), ".."); - File file = new File(dir, "clonednpcs.dat"); - // System.out.println(file.getAbsolutePath()); - // System.out.println(file.exists()); - if(file.exists()){ - Map> clones = loadOldClones(file); - file.delete(); + File file = new File(dir, "clonednpcs.dat"); + // System.out.println(file.getAbsolutePath()); + // System.out.println(file.exists()); + if(file.exists()){ + Map> clones = loadOldClones(file); + file.delete(); file = new File(dir, "clonednpcs.dat_old"); if(file.exists()) file.delete(); - + for(int tab : clones.keySet()){ Map map = clones.get(tab); for(String name: map.keySet()){ saveClone(tab, name, map.get(name)); } } - } + } } catch (Exception e) { LogWriter.except(e); } @@ -63,40 +61,40 @@ public class ServerCloneController implements ICloneHandler { dir.mkdir(); return dir; } - + private Map> loadOldClones(File file) throws Exception{ Map> clones = new HashMap>(); - NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file)); - NBTTagList list = nbttagcompound1.getTagList("Data", 10); - if(list == null){ - return clones; - } - for(int i = 0; i < list.tagCount(); i++) - { - NBTTagCompound compound = list.getCompoundTagAt(i); - if(!compound.hasKey("ClonedTab")){ - compound.setInteger("ClonedTab", 1); - } - - Map tab = clones.get(compound.getInteger("ClonedTab")); - if(tab == null) - clones.put(compound.getInteger("ClonedTab"), tab = new HashMap()); - - String name = compound.getString("ClonedName"); - int number = 1; - while(tab.containsKey(name)){ - number++; - name = String.format("%s%s", compound.getString("ClonedName"), number); - } - compound.removeTag("ClonedName"); - compound.removeTag("ClonedTab"); - compound.removeTag("ClonedDate"); - cleanTags(compound); - tab.put(name, compound); - } + NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file)); + NBTTagList list = nbttagcompound1.getTagList("Data", 10); + if(list == null){ + return clones; + } + for(int i = 0; i < list.tagCount(); i++) + { + NBTTagCompound compound = list.getCompoundTagAt(i); + if(!compound.hasKey("ClonedTab")){ + compound.setInteger("ClonedTab", 1); + } + + Map tab = clones.get(compound.getInteger("ClonedTab")); + if(tab == null) + clones.put(compound.getInteger("ClonedTab"), tab = new HashMap()); + + String name = compound.getString("ClonedName"); + int number = 1; + while(tab.containsKey(name)){ + number++; + name = String.format("%s%s", compound.getString("ClonedName"), number); + } + compound.removeTag("ClonedName"); + compound.removeTag("ClonedTab"); + compound.removeTag("ClonedDate"); + cleanTags(compound); + tab.put(name, compound); + } return clones; } - + public NBTTagCompound getCloneData(ICommandSender player, String name, int tab) { File file = new File(new File(getDir(), tab + ""), name + ".json"); if(!file.exists()){ @@ -113,22 +111,23 @@ public class ServerCloneController implements ICloneHandler { } return null; } - + public void saveClone(int tab, String name, NBTTagCompound compound){ try { File dir = new File(getDir(), tab + ""); if(!dir.exists()) dir.mkdir(); String filename = name + ".json"; - - File file = new File(dir, filename + "_new"); - File file2 = new File(dir, filename); - - NBTJsonUtil.SaveFile(file, compound); - if(file2.exists()){ - file2.delete(); - } - file.renameTo(file2); + + File file = new File(dir, filename + "_new"); + File file2 = new File(dir, filename); + + NBTJsonUtil.SaveFile(file, compound); + if(file2.exists()){ + file2.delete(); + } + file.renameTo(file2); + addToTagMap(compound, name, tab); } catch (Exception e) { LogWriter.except(e); } @@ -144,27 +143,54 @@ public class ServerCloneController implements ICloneHandler { } return list; } - + public boolean removeClone(String name, int tab){ - File file = new File(new File(getDir(), tab + ""), name + ".json"); - if(!file.exists()) - return false; - file.delete(); - return true; + File file = new File(new File(getDir(), tab + ""), name + ".json"); + if(!file.exists()) + return false; + file.delete(); + removeFromTagMap(name, tab); + return true; } - + public String addClone(NBTTagCompound nbttagcompound, String name, int tab) { cleanTags(nbttagcompound); saveClone(tab, name, nbttagcompound); return name; } - + + public boolean addToTagMap(NBTTagCompound nbttagcompound, String name, int tab){ + HashSet tagUUIDs = new HashSet(); + if(nbttagcompound.hasKey("TagUUIDs")){ + NBTTagList nbtTagList = nbttagcompound.getTagList("TagUUIDs",8); + for (int i = 0; i < nbtTagList.tagCount(); i++) { + tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i))); + } + } + if(tagUUIDs.size() > 0){ + TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab); + tagMap.putClone(name, tagUUIDs); + ServerTagMapController.Instance.saveTagMap(tagMap); + return true; + } + return false; + } + + public boolean removeFromTagMap(String name, int tab){ + TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab); + if(tagMap.removeClone(name)){ + ServerTagMapController.Instance.saveTagMap(tagMap); + return true; + } + return false; + } + public void cleanTags(NBTTagCompound nbttagcompound){ if(nbttagcompound.hasKey("ItemGiverId")) nbttagcompound.setInteger("ItemGiverId", 0); if(nbttagcompound.hasKey("TransporterId")) nbttagcompound.setInteger("TransporterId", -1); - + nbttagcompound.removeTag("StartPosNew"); nbttagcompound.removeTag("StartPos"); nbttagcompound.removeTag("MovingPathNew"); @@ -187,7 +213,7 @@ public class ServerCloneController implements ICloneHandler { adv.setInteger("ItemGiverId", 0); nbttagcompound.setTag("TransformJob", adv); } - + if(nbttagcompound.hasKey("TransformAI")){ NBTTagCompound adv = nbttagcompound.getCompoundTag("TransformAI"); adv.removeTag("StartPosNew"); diff --git a/src/main/java/noppes/npcs/controllers/ServerTagMapController.java b/src/main/java/noppes/npcs/controllers/ServerTagMapController.java new file mode 100644 index 000000000..209def895 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/ServerTagMapController.java @@ -0,0 +1,89 @@ +package noppes.npcs.controllers; + +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; +import noppes.npcs.controllers.data.Faction; +import noppes.npcs.controllers.data.TagMap; + +import java.io.*; +import java.util.zip.GZIPInputStream; + +public class ServerTagMapController { + public static ServerTagMapController Instance; + public TagMap tagMap; + + public ServerTagMapController(){} + + public File getDir(){ + File dir = new File(CustomNpcs.getWorldSaveDirectory(), "clones"); + if(!dir.exists()) + dir.mkdir(); + return dir; + } + + public File getCloneTabDir(int tab){ + File dir = new File(getDir(), tab + ""); + if(!dir.exists()) + dir.mkdir(); + return dir; + } + + public TagMap getTagMap(int tab){ + this.tagMap = new TagMap(tab); + try { + File file = new File(getCloneTabDir(tab), "___tagmap.dat"); + if(file.exists()){ + loadTagMapFile(file); + } + } catch (Exception e) { + try { + File file = new File(getCloneTabDir(tab), "___tagmap.dat_old"); + if(file.exists()){ + loadTagMapFile(file); + } + } catch (Exception ignored) {} + } + return this.tagMap; + } + + private void loadTagMapFile(File file) throws IOException { + DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))); + loadTagMaps(var1); + var1.close(); + } + + public void loadTagMaps(DataInputStream stream) throws IOException{ + NBTTagCompound nbtCompound = CompressedStreamTools.read(stream); + this.tagMap.readNBT(nbtCompound); + } + + public void saveTagMap(TagMap tagMap){ + try { + File saveDir = getCloneTabDir(tagMap.cloneTab); + File file = new File(saveDir, "___tagmap.dat_new"); + File file1 = new File(saveDir, "___tagmap.dat_old"); + File file2 = new File(saveDir, "___tagmap.dat"); + CompressedStreamTools.writeCompressed(tagMap.writeNBT(), new FileOutputStream(file)); + if(file1.exists()) + { + file1.delete(); + } + file2.renameTo(file1); + if(file2.exists()) + { + file2.delete(); + } + file.renameTo(file2); + if(file.exists()) + { + file.delete(); + } + } catch (Exception e) { + LogWriter.except(e); + } + } + +} diff --git a/src/main/java/noppes/npcs/controllers/TagController.java b/src/main/java/noppes/npcs/controllers/TagController.java index 4915076b8..ac8d8176e 100644 --- a/src/main/java/noppes/npcs/controllers/TagController.java +++ b/src/main/java/noppes/npcs/controllers/TagController.java @@ -8,6 +8,8 @@ import noppes.npcs.LogWriter; import noppes.npcs.api.handler.ITagHandler; import noppes.npcs.api.handler.data.ITag; import noppes.npcs.controllers.data.Tag; +import noppes.npcs.controllers.data.TagMap; +import scala.Int; import java.io.*; import java.util.*; @@ -23,13 +25,12 @@ public class TagController implements ITagHandler { instance = this; tags = new HashMap(); loadTags(); - if(tags.isEmpty()){ - // TO-DO +// if(tags.isEmpty()){ +// // TO-DO // tags.put(0,new Faction(0,"Friendly", 0x00DD00, 2000)); // tags.put(1,new Faction(1,"Neutral", 0xF2DD00, 1000)); // tags.put(2,new Faction(2,"Aggressive", 0xDD0000, 0)); - } - +// } } public static TagController getInstance(){ return instance; @@ -66,6 +67,7 @@ public class TagController implements ITagHandler { public void loadTags(DataInputStream stream) throws IOException{ HashMap tags = new HashMap(); + HashMap tagUUIDs = new HashMap(); NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream); lastUsedID = nbttagcompound1.getInteger("lastID"); NBTTagList list = nbttagcompound1.getTagList("NPCTags", 10); @@ -77,6 +79,7 @@ public class TagController implements ITagHandler { Tag tag = new Tag(); tag.readNBT(nbttagcompound); tags.put(tag.id,tag); + tagUUIDs.put(tag.uuid, tag.id); } } this.tags = tags; @@ -187,14 +190,6 @@ public class TagController implements ITagHandler { } } - public int getFirstTagId() { - return tags.keySet().iterator().next(); - } - - public Tag getFirstTag() { - return tags.values().iterator().next(); - } - public boolean hasName(String newName) { if(newName.trim().isEmpty()) return true; @@ -213,6 +208,15 @@ public class TagController implements ITagHandler { return null; } + public Tag getTagFromUUID(UUID uuid){ + for (Map.Entry entryTag: TagController.getInstance().tags.entrySet()){ + if (entryTag.getValue().uuid.equals(uuid)) { + return entryTag.getValue(); + } + } + return null; + } + public String[] getNames() { String[] names = new String[tags.size()]; int i = 0; @@ -223,12 +227,7 @@ public class TagController implements ITagHandler { return names; } - public Tag getTagFromUUID(UUID uuid){ - for (Map.Entry entryTag: TagController.getInstance().tags.entrySet()){ - if (entryTag.getValue().uuid.equals(uuid)) { - return entryTag.getValue(); - } - } - return null; + public HashSet getAllTags(){ + return new HashSet(this.tags.values()); } } diff --git a/src/main/java/noppes/npcs/controllers/InnDoorData.java b/src/main/java/noppes/npcs/controllers/data/InnDoorData.java similarity index 69% rename from src/main/java/noppes/npcs/controllers/InnDoorData.java rename to src/main/java/noppes/npcs/controllers/data/InnDoorData.java index 07c653c3d..18397afc8 100644 --- a/src/main/java/noppes/npcs/controllers/InnDoorData.java +++ b/src/main/java/noppes/npcs/controllers/data/InnDoorData.java @@ -1,4 +1,4 @@ -package noppes.npcs.controllers; +package noppes.npcs.controllers.data; public class InnDoorData { public int x = 0; diff --git a/src/main/java/noppes/npcs/controllers/data/TagMap.java b/src/main/java/noppes/npcs/controllers/data/TagMap.java new file mode 100644 index 000000000..4a14706c9 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/TagMap.java @@ -0,0 +1,99 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; + +import java.util.*; + +public class TagMap { + public int cloneTab; + public HashMap> tagMap; + + public TagMap(int tab){ + this.cloneTab = tab; + this.tagMap = new HashMap>(); + } + + public void readNBT(NBTTagCompound compound){ + this.tagMap = new HashMap>(); + NBTTagList list = compound.getTagList("TagMap", 10); + if(list != null){ + for(int i = 0; i < list.tagCount(); i++) + { + NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); + String cloneName = nbttagcompound.getString("Clone"); + + HashSet uuids = new HashSet(); + NBTTagList nbtTagList = nbttagcompound.getTagList("TagUUIDs",8); + for (int j = 0; j < nbtTagList.tagCount(); j++) { + String uuid = nbtTagList.getStringTagAt(j); + if(!uuid.isEmpty()){ + uuids.add(UUID.fromString(uuid)); + } + } + tagMap.put(cloneName, uuids); + } + } + } + + public NBTTagCompound writeNBT(){ + NBTTagCompound nbt = new NBTTagCompound(); + NBTTagList cloneList = new NBTTagList(); + for(String key: tagMap.keySet()){ + HashSet uuidSet = tagMap.get(key); + if(uuidSet.size() > 0){ + NBTTagCompound cloneCompound = new NBTTagCompound(); + cloneCompound.setString("Clone", key); + NBTTagList nbtTagList = new NBTTagList(); + for (UUID uuid : uuidSet) { + nbtTagList.appendTag(new NBTTagString(uuid.toString())); + } + cloneCompound.setTag("TagUUIDs", nbtTagList); + cloneList.appendTag(cloneCompound); + } + } + nbt.setTag("TagMap", cloneList); + return nbt; + } + + public int getCloneTab() { + return this.cloneTab; + } + + public boolean hasClone(String cloneName) { + return tagMap.containsKey(cloneName); + } + + public HashSet getUUIDs(String cloneName) { + if(hasClone(cloneName)){ + return tagMap.get(cloneName); + } + return null; + } + + public boolean removeClone(String cloneName) { + return tagMap.remove(cloneName) != null; + } + + public void putClone(String cloneName, HashSet uuids) { + tagMap.put(cloneName, uuids); + } + + public boolean hasTag(String cloneName, UUID tag) { + HashSet uuids = getUUIDs(cloneName); + if(uuids == null){ + return false; + } + return uuids.contains(tag); + } + + public HashSet getAllUUIDs() { + HashSet uuids = new HashSet(); + for(HashSet uuids1 : tagMap.values()){ + uuids.addAll(uuids1); + } + return uuids; + } + +} diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index ce7a2f603..2d2c56aa0 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -291,6 +291,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(getHealth() <= 0){ clearActivePotions(); setBoolFlag(true, 8); + updateTasks(); + updateHitbox(); } setBoolFlag(this.getAttackTarget() != null, 4); setBoolFlag(!getNavigator().noPath(), 1); @@ -618,6 +620,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti clearTasks(tasks); clearTasks(targetTasks); + if(isKilled()) + return; + IEntitySelector attackEntitySelector = new NPCAttackSelector(this); this.targetTasks.addTask(0, new EntityAIClearTarget(this)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); @@ -1018,6 +1023,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti width = (width / 5f) * display.modelSize; height = (height / 5f) * display.modelSize; + if(isKilled() && stats.hideKilledBody) { + width = 0.00001f; + } + if(width / 2 > worldObj.MAX_ENTITY_RADIUS) { + worldObj.MAX_ENTITY_RADIUS = width / 2; + } + this.setPosition(posX, posY, posZ); } diff --git a/src/main/java/noppes/npcs/roles/RoleInnkeeper.java b/src/main/java/noppes/npcs/roles/RoleInnkeeper.java index 7e8bee8df..d910af254 100644 --- a/src/main/java/noppes/npcs/roles/RoleInnkeeper.java +++ b/src/main/java/noppes/npcs/roles/RoleInnkeeper.java @@ -5,7 +5,7 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ChatComponentTranslation; -import noppes.npcs.controllers.InnDoorData; +import noppes.npcs.controllers.data.InnDoorData; import noppes.npcs.entity.EntityNPCInterface; import java.util.HashMap; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 3c815bb39..d54d116e9 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -175,6 +175,7 @@ mailbox.setup=Setup mail display.model=Model display.show=Show display.hide=Hide +display.all=All display.showAttacking=Show when attacking display.size=Size display.texture=Texture