Merge remote-tracking branch 'upstream/packet' into packet

This commit is contained in:
somehussar committed 2025-02-03 03:23:54 +01:00
commit a2a3d94de6
10 files changed
+378 -99

No files matched your search

@@ -24,6 +24,9 @@ import kamkeel.npcs.network.packets.request.bank.BankGetPacket;
import kamkeel.npcs.network.packets.request.bank.BankRemovePacket; import kamkeel.npcs.network.packets.request.bank.BankRemovePacket;
import kamkeel.npcs.network.packets.request.bank.BankSavePacket; import kamkeel.npcs.network.packets.request.bank.BankSavePacket;
import kamkeel.npcs.network.packets.request.bank.BanksGetPacket; import kamkeel.npcs.network.packets.request.bank.BanksGetPacket;
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.customgui.CustomGuiButtonPacket; import kamkeel.npcs.network.packets.request.customgui.CustomGuiButtonPacket;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiClosePacket; import kamkeel.npcs.network.packets.request.customgui.CustomGuiClosePacket;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiUnfocusedPacket; import kamkeel.npcs.network.packets.request.customgui.CustomGuiUnfocusedPacket;
@@ -110,6 +113,11 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new NpcClosePacket()); REQUEST_PACKET.registerPacket(new NpcClosePacket());
REQUEST_PACKET.registerPacket(new NpcDeletePacket()); REQUEST_PACKET.registerPacket(new NpcDeletePacket());
// Cloner Packets
REQUEST_PACKET.registerPacket(new CloneListPacket());
REQUEST_PACKET.registerPacket(new SpawnMobPacket());
REQUEST_PACKET.registerPacket(new MobSpawnerPacket());
// Linked Packets // Linked Packets
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket()); REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
REQUEST_PACKET.registerPacket(new LinkedRemovePacket()); REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
@@ -151,5 +151,5 @@ public enum EnumRequestPacket {
TraderMarketSave, TraderMarketSave,
ServerUpdateSkinOverlays CloneList, ServerUpdateSkinOverlays
} }
@@ -0,0 +1,82 @@
package kamkeel.npcs.network.packets.request.clone;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class CloneListPacket extends AbstractPacket {
public static String packetName = "Request|CloneList";
private int tab;
public CloneListPacket(int tab) {
this.tab = tab;
}
public CloneListPacket() {}
@Override
public Enum getType() {
return EnumRequestPacket.CloneList;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(tab);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.MOUNTER, EnumItemPacketType.CLONER))
return;
int id = in.readInt();
Entity entity = player.worldObj.getEntityByID(id);
if (!(entity instanceof EntityNPCInterface))
return;
NBTTagList list = new NBTTagList();
int tab = in.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);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
@@ -0,0 +1,130 @@
package kamkeel.npcs.network.packets.request.clone;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public class MobSpawnerPacket extends AbstractPacket {
public static final String packetName = "Player|MobSpawner";
private Action type;
private int posX;
private int posY;
private int posz;
private String selectedName;
private int tab;
private NBTTagCompound compound;
public MobSpawnerPacket() {}
public MobSpawnerPacket(Action type, int posX, int posY, int posz, String selectedName, int tab) {
this.type = type;
this.posX = posX;
this.posY = posY;
this.posz = posz;
this.selectedName = selectedName;
this.tab = tab;
}
public MobSpawnerPacket(Action type, int posX, int posY, int posz, NBTTagCompound compound) {
this.type = type;
this.posX = posX;
this.posY = posY;
this.posz = posz;
this.compound = compound;
}
public static MobSpawnerPacket Server(int x, int y, int z, String name, int tab) {
return new MobSpawnerPacket(Action.Server, x, y, z, name, tab);
}
public static MobSpawnerPacket Client(int x, int y, int z, NBTTagCompound compound) {
return new MobSpawnerPacket(Action.Client, x, y, z, compound);
}
@Override
public Enum getType() {
return EnumRequestPacket.MobSpawner;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.SPAWNER_CREATE;
}
@Override
@SideOnly(Side.CLIENT)
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
out.writeInt(posX);
out.writeInt(posY);
out.writeInt(posz);
if (type == Action.Server) {
ByteBufUtils.writeString(out, this.selectedName);
out.writeInt(this.tab);
} else {
ByteBufUtils.writeNBT(out, this.compound);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.CLONER))
return;
Action requestedAction = Action.values()[in.readInt()];
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
NBTTagCompound compound;
if(requestedAction == Action.Server)
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(in), in.readInt());
else
compound = ByteBufUtils.readNBT(in);
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
return;
}
if(compound != null)
NoppesUtilServer.createMobSpawner(x, y, z, compound, player);
}
private enum Action {
Server,
Client,
}
}
@@ -0,0 +1,140 @@
package kamkeel.npcs.network.packets.request.clone;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public class SpawnMobPacket extends AbstractPacket {
public static final String packetName = "Player|SpawnMob";
private Action type;
private int posX;
private int posY;
private int posz;
private String selectedName;
private int tab;
private NBTTagCompound compound;
public SpawnMobPacket() {}
public SpawnMobPacket(Action type, int posX, int posY, int posz, String selectedName, int tab) {
this.type = type;
this.posX = posX;
this.posY = posY;
this.posz = posz;
this.selectedName = selectedName;
this.tab = tab;
}
public SpawnMobPacket(Action type, int posX, int posY, int posz, NBTTagCompound compound) {
this.type = type;
this.posX = posX;
this.posY = posY;
this.posz = posz;
this.compound = compound;
}
public static SpawnMobPacket Server(int x, int y, int z, String name, int tab) {
return new SpawnMobPacket(Action.Server, x, y, z, name, tab);
}
public static SpawnMobPacket Client(int x, int y, int z, NBTTagCompound compound) {
return new SpawnMobPacket(Action.Client, x, y, z, compound);
}
@Override
public Enum getType() {
return EnumRequestPacket.SpawnMob;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.SPAWNER_MOB;
}
@Override
@SideOnly(Side.CLIENT)
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
out.writeInt(posX);
out.writeInt(posY);
out.writeInt(posz);
if (type == Action.Server) {
ByteBufUtils.writeString(out, this.selectedName);
out.writeInt(this.tab);
} else {
ByteBufUtils.writeNBT(out, this.compound);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.CLONER))
return;
Action requestedAction = Action.values()[in.readInt()];
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
NBTTagCompound compound;
if(requestedAction == Action.Server)
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(in), in.readInt());
else
compound = ByteBufUtils.readNBT(in);
if(compound == null)
return;
Entity entity = NoppesUtilServer.spawnClone(compound, x, y, z, player.worldObj);
if(entity == null){
player.addChatMessage(new ChatComponentText("Failed to create an entity out of your clone"));
return;
}
if (entity instanceof EntityNPCInterface && !ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.script.setEnabled(false);
}
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
LogWriter.script(String.format("[%s] (Player) %s SPAWNED ENTITY %s", "CLONER", player.getCommandSenderName(), entity));
}
}
private enum Action {
Server,
Client,
}
}
@@ -72,9 +72,7 @@ public class PacketHandlerServer{
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker"); warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
else { else {
if (item != null) { if (item != null) {
if (item.getItem() == CustomItems.mount) if (item.getItem() == CustomItems.cloner)
mountPackets(type, in, player);
else if (item.getItem() == CustomItems.cloner)
clonePackets(type, in, player); clonePackets(type, in, player);
else if (item.getItem() == CustomItems.teleporter) else if (item.getItem() == CustomItems.teleporter)
featherPackets(type, in, player); featherPackets(type, in, player);
@@ -145,10 +143,6 @@ public class PacketHandlerServer{
} }
} }
private void isGuiOpenPacket(ByteBuf buffer, EntityPlayerMP player) throws IOException {
NoppesUtilServer.isGUIOpen(buffer, player);
}
private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if (type == EnumPacketServer.ScriptGlobalGuiDataGet) { if (type == EnumPacketServer.ScriptGlobalGuiDataGet) {
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
@@ -349,74 +343,8 @@ public class PacketHandlerServer{
} }
} }
private void mountPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException{
if(type == EnumPacketServer.CloneList){
NBTTagList list = new NBTTagList();
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);
GuiDataPacket.sendGuiData(player, compound);
}
else
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 { private void clonePackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.SpawnMob){ if(type == EnumPacketServer.ClonePreSave){
boolean server = buffer.readBoolean();
int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
NBTTagCompound compound;
if(server)
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(buffer), buffer.readInt());
else
compound = ByteBufUtils.readNBT(buffer);
if(compound == null)
return;
Entity entity = NoppesUtilServer.spawnClone(compound, x, y, z, player.worldObj);
if(entity == null){
player.addChatMessage(new ChatComponentText("Failed to create an entity out of your clone"));
return;
}
if (entity instanceof EntityNPCInterface && !ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.script.setEnabled(false);
}
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
LogWriter.script(String.format("[%s] (Player) %s SPAWNED ENTITY %s", "CLONER", player.getCommandSenderName(), entity));
}
}
else if(type == EnumPacketServer.MobSpawner){
boolean server = buffer.readBoolean();
int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
NBTTagCompound compound;
if(server)
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(buffer), buffer.readInt());
else
compound = ByteBufUtils.readNBT(buffer);
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
return;
}
if(compound != null)
NoppesUtilServer.createMobSpawner(x, y, z, compound, player);
}
else if(type == EnumPacketServer.ClonePreSave){
boolean bo = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt()) != null; boolean bo = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt()) != null;
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("NameExists", bo); compound.setBoolean("NameExists", bo);
@@ -454,22 +382,6 @@ public class PacketHandlerServer{
GuiDataPacket.sendGuiData(player, compound); GuiDataPacket.sendGuiData(player, compound);
} }
else if(type == EnumPacketServer.CloneList){
NBTTagList list = new NBTTagList();
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);
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneTagList) { else if (type == EnumPacketServer.CloneTagList) {
int tab = buffer.readInt(); int tab = buffer.readInt();
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab); TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
@@ -1,5 +1,9 @@
package noppes.npcs.client.gui; 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 net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -188,7 +192,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
private void showClones() { private void showClones() {
if(showingClones == 2){ if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneTagList, activeTab); Client.sendData(EnumPacketServer.CloneTagList, activeTab);
Client.sendData(EnumPacketServer.CloneList, activeTab); PacketClient.sendClient(new CloneListPacket(activeTab));
return; return;
} }
@@ -377,14 +381,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
String sel = scroll.getSelected(); String sel = scroll.getSelected();
if(sel == null) if(sel == null)
return; return;
Client.sendData(EnumPacketServer.SpawnMob, true, posX, posY, posZ, sel, activeTab); SpawnMobPacket.Server(posX, posY, posZ, sel, activeTab);
close(); close();
} }
else{ else{
NBTTagCompound compound = getCompound(); NBTTagCompound compound = getCompound();
if(compound == null) if(compound == null)
return; return;
Client.sendData(EnumPacketServer.SpawnMob, false, posX, posY, posZ, compound); SpawnMobPacket.Client(posX, posY, posZ, compound);
close(); close();
} }
} }
@@ -393,14 +397,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
String sel = scroll.getSelected(); String sel = scroll.getSelected();
if(sel == null) if(sel == null)
return; return;
Client.sendData(EnumPacketServer.MobSpawner, true, posX, posY, posZ, sel, activeTab); MobSpawnerPacket.Server(posX, posY, posZ, sel, activeTab);
close(); close();
} }
else{ else{
NBTTagCompound compound = getCompound(); NBTTagCompound compound = getCompound();
if(compound == null) if(compound == null)
return; return;
Client.sendData(EnumPacketServer.MobSpawner, false, posX, posY, posZ, compound); MobSpawnerPacket.Client(posX, posY, posZ, compound);
close(); close();
} }
@@ -1,6 +1,8 @@
package noppes.npcs.client.gui; package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.MountPacket; import kamkeel.npcs.network.packets.request.MountPacket;
import kamkeel.npcs.network.packets.request.clone.CloneListPacket;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -117,7 +119,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
private void showClones() { private void showClones() {
if(showingClones == 2){ if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneList, activeTab); PacketClient.sendClient(new CloneListPacket(activeTab));
return; return;
} }
@@ -1,5 +1,7 @@
package noppes.npcs.client.gui; package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.clone.CloneListPacket;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble; import net.minecraft.nbt.NBTTagDouble;
@@ -72,7 +74,7 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
private void showClones() { private void showClones() {
if(isServer){ if(isServer){
Client.sendData(EnumPacketServer.CloneList, activeTab); PacketClient.sendClient(new CloneListPacket(activeTab));
return; return;
} }
@@ -3,7 +3,6 @@ package noppes.npcs.constants;
import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.CustomNpcsPermissions;
public enum EnumPacketServer { public enum EnumPacketServer {
SpawnMob(CustomNpcsPermissions.SPAWNER_MOB),
MobSpawner(CustomNpcsPermissions.SPAWNER_CREATE), MobSpawner(CustomNpcsPermissions.SPAWNER_CREATE),
ClonePreSave(CustomNpcsPermissions.NPC_CLONE), ClonePreSave(CustomNpcsPermissions.NPC_CLONE),