Cloner Packets

This commit is contained in:
Kam committed 2025-02-02 22:31:39 -05:00
1 parent c5329a1c63
commit 9841d158ff
12 files changed
+449 -98

No files matched your search

@@ -72,9 +72,7 @@ public class PacketHandlerServer{
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
else {
if (item != null) {
if (item.getItem() == CustomItems.cloner)
clonePackets(type, in, player);
else if (item.getItem() == CustomItems.teleporter)
if (item.getItem() == CustomItems.teleporter)
featherPackets(type, in, player);
else if (ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
if (type == EnumPacketServer.EventScriptDataGet || type == EnumPacketServer.EventScriptDataSave)
@@ -343,78 +341,6 @@ public class PacketHandlerServer{
}
}
private void clonePackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.ClonePreSave){
boolean bo = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt()) != null;
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("NameExists", bo);
GuiDataPacket.sendGuiData(player, compound);
}
else if(type == EnumPacketServer.CloneSave){
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
if(data.cloned == null)
return;
String name = ByteBufUtils.readString(buffer);
int tab = buffer.readInt();
NBTTagCompound tagExtra = ByteBufUtils.readNBT(buffer);
NBTTagCompound tagCompound = ByteBufUtils.readNBT(buffer);
NBTTagList tagList = tagCompound.getTagList("TagUUIDs", 8);
data.cloned.setTag("TagUUIDs", tagList);
ServerCloneController.Instance.addClone(data.cloned, name, tab, tagExtra);
}
else if(type == EnumPacketServer.CloneRemove){
int tab = buffer.readInt();
ServerCloneController.Instance.removeClone(ByteBufUtils.readString(buffer), tab);
NBTTagList list = new NBTTagList();
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);
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneTagList) {
int tab = buffer.readInt();
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("CloneTags", tagMap.writeNBT());
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneAllTags) {
NBTTagCompound compound = new NBTTagCompound();
HashSet<Tag> 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);
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneAllTagsShort) {
NBTTagCompound compound = new NBTTagCompound();
HashSet<Tag> validTags = TagController.getInstance().getAllTags();
NBTTagList validTagList = new NBTTagList();
for(Tag tag : validTags){
NBTTagCompound tagCompound = new NBTTagCompound();
tag.writeShortNBT(tagCompound);
validTagList.appendTag(tagCompound);
}
compound.setTag("ShortTags", validTagList);
GuiDataPacket.sendGuiData(player, compound);
}
}
private void warn(EntityPlayer player, String warning){
MinecraftServer.getServer().logWarning(player.getCommandSenderName() + ": " + warning);
}
@@ -1,9 +1,7 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.clone.CloneListPacket;
import kamkeel.npcs.network.packets.request.clone.MobSpawnerPacket;
import kamkeel.npcs.network.packets.request.clone.SpawnMobPacket;
import kamkeel.npcs.network.packets.request.clone.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity;
@@ -66,7 +64,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
this.closeOnEsc = true;
setBackground("menubg.png");
Client.sendData(EnumPacketServer.CloneAllTags, activeTab);
PacketClient.sendClient(new CloneAllTagsPacket());
}
public void initGui()
{
@@ -191,7 +189,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
}
private void showClones() {
if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneTagList, activeTab);
PacketClient.sendClient(new CloneTagListPacket(activeTab));
PacketClient.sendClient(new CloneListPacket(activeTab));
return;
}
@@ -431,7 +429,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
if(id == 6){
if(scroll.getSelected() != null){
if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneRemove, activeTab, scroll.getSelected());
PacketClient.sendClient(new CloneRemovePacket(activeTab, scroll.getSelected()));
return;
}
ClientCloneController.Instance.removeClone(scroll.getSelected(), activeTab);
@@ -1,5 +1,10 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.request.clone.CloneAllTagsShortPacket;
import kamkeel.npcs.network.packets.request.clone.ClonePreSavePacket;
import kamkeel.npcs.network.packets.request.clone.CloneSavePacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiYesNo;
@@ -58,7 +63,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
addTagUUIDs = new HashSet<>();
}
if(isNPC){
Client.sendData(EnumPacketServer.CloneAllTagsShort);
PacketClient.sendClient(new CloneAllTagsShortPacket());
}
}
@@ -102,7 +107,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
confirmClicked(true, 0);
}
else
Client.sendData(EnumPacketServer.ClonePreSave, name, tab);
PacketClient.sendClient(new ClonePreSavePacket(name, tab));
}
if(id == 1){
close();
@@ -145,7 +150,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
if(isNPC){
compounder.setTag("TagUUIDs", tagsCompound);
}
Client.sendData(EnumPacketServer.CloneSave, name, tab, extraTags, compounder);
PacketClient.sendClient(new CloneSavePacket(name, tab, extraTags, compounder));
}
close();
@@ -3,16 +3,6 @@ package noppes.npcs.constants;
import noppes.npcs.CustomNpcsPermissions;
public enum EnumPacketServer {
MobSpawner(CustomNpcsPermissions.SPAWNER_CREATE),
ClonePreSave(CustomNpcsPermissions.NPC_CLONE),
CloneSave(CustomNpcsPermissions.NPC_CLONE),
CloneRemove(CustomNpcsPermissions.NPC_CLONE),
CloneList,
CloneTagList,
CloneAllTags,
CloneAllTagsShort,
ScriptGlobalGuiDataSave(CustomNpcsPermissions.SCRIPT_GLOBAL, false),
ScriptGlobalGuiDataGet(false),