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
+394 -115

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.BankSavePacket;
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.CustomGuiClosePacket;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiUnfocusedPacket;
@@ -110,6 +113,11 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new NpcClosePacket());
REQUEST_PACKET.registerPacket(new NpcDeletePacket());
// Cloner Packets
REQUEST_PACKET.registerPacket(new CloneListPacket());
REQUEST_PACKET.registerPacket(new SpawnMobPacket());
REQUEST_PACKET.registerPacket(new MobSpawnerPacket());
// Linked Packets
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
@@ -151,5 +151,5 @@ public enum EnumRequestPacket {
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");
else {
if (item != null) {
if (item.getItem() == CustomItems.mount)
mountPackets(type, in, player);
else if (item.getItem() == CustomItems.cloner)
if (item.getItem() == CustomItems.cloner)
clonePackets(type, in, player);
else if (item.getItem() == CustomItems.teleporter)
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 {
if (type == EnumPacketServer.ScriptGlobalGuiDataGet) {
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 {
if(type == EnumPacketServer.SpawnMob){
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){
if(type == EnumPacketServer.ClonePreSave){
boolean bo = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt()) != null;
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("NameExists", bo);
@@ -454,22 +382,6 @@ public class PacketHandlerServer{
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) {
int tab = buffer.readInt();
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
@@ -1,5 +1,9 @@
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.gui.GuiButton;
import net.minecraft.entity.Entity;
@@ -188,7 +192,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
private void showClones() {
if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneTagList, activeTab);
Client.sendData(EnumPacketServer.CloneList, activeTab);
PacketClient.sendClient(new CloneListPacket(activeTab));
return;
}
@@ -377,14 +381,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
String sel = scroll.getSelected();
if(sel == null)
return;
Client.sendData(EnumPacketServer.SpawnMob, true, posX, posY, posZ, sel, activeTab);
SpawnMobPacket.Server(posX, posY, posZ, sel, activeTab);
close();
}
else{
NBTTagCompound compound = getCompound();
if(compound == null)
return;
Client.sendData(EnumPacketServer.SpawnMob, false, posX, posY, posZ, compound);
SpawnMobPacket.Client(posX, posY, posZ, compound);
close();
}
}
@@ -393,14 +397,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
String sel = scroll.getSelected();
if(sel == null)
return;
Client.sendData(EnumPacketServer.MobSpawner, true, posX, posY, posZ, sel, activeTab);
MobSpawnerPacket.Server(posX, posY, posZ, sel, activeTab);
close();
}
else{
NBTTagCompound compound = getCompound();
if(compound == null)
return;
Client.sendData(EnumPacketServer.MobSpawner, false, posX, posY, posZ, compound);
MobSpawnerPacket.Client(posX, posY, posZ, compound);
close();
}
@@ -534,4 +538,4 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
}
}
}
}
@@ -1,6 +1,8 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.MountPacket;
import kamkeel.npcs.network.packets.request.clone.CloneListPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity;
@@ -117,7 +119,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
private void showClones() {
if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneList, activeTab);
PacketClient.sendClient(new CloneListPacket(activeTab));
return;
}
@@ -1,5 +1,7 @@
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.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
@@ -13,24 +15,24 @@ import java.util.ArrayList;
import java.util.List;
public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiData{
private GuiCustomScroll scroll;
private List<String> list;
private static String search = "";
public int activeTab = 1;
public boolean isServer = false;
public GuiNpcMobSpawnerSelector() {
super();
xSize = 256;
this.closeOnEsc = true;
setBackground("menubg.png");
}
public void initGui(){
super.initGui();
super.initGui();
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll.setSize(165, 188);
@@ -40,7 +42,7 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
scroll.guiLeft = guiLeft + 4;
scroll.guiTop = guiTop + 26;
addScroll(scroll);
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 165, 20, search));
addButton(new GuiNpcButton(0, guiLeft + 171, guiTop + 80, 80, 20, "gui.done"));
@@ -61,30 +63,30 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
addSideButton(new GuiMenuSideButton(33,guiLeft - 90, this.guiTop + 170, 45,22, "13"));
addSideButton(new GuiMenuSideButton(34,guiLeft - 45, this.guiTop + 191, 45,22, "14"));
addSideButton(new GuiMenuSideButton(35,guiLeft - 90, this.guiTop + 191, 45,22, "15"));
getSideButton(20 + activeTab).active = true;
showClones();
}
public String getSelected(){
return scroll.getSelected();
}
private void showClones() {
if(isServer){
Client.sendData(EnumPacketServer.CloneList, activeTab);
PacketClient.sendClient(new CloneListPacket(activeTab));
return;
}
ArrayList<String> list = new ArrayList<String>();
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeTab));
scroll.setList(getSearchList());
}
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(search.equals(getTextField(1).getText()))
return;
search = getTextField(1).getText().toLowerCase();
@@ -109,7 +111,7 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
compound.setString("ClonedName", sel);
return compound;
}
public void buttonEvent(GuiButton guibutton)
{
int id = guibutton.id;
@@ -139,11 +141,11 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
return nbttaglist;
}
@Override
public void save() {
// TODO Auto-generated method stub
}
@@ -3,7 +3,6 @@ package noppes.npcs.constants;
import noppes.npcs.CustomNpcsPermissions;
public enum EnumPacketServer {
SpawnMob(CustomNpcsPermissions.SPAWNER_MOB),
MobSpawner(CustomNpcsPermissions.SPAWNER_CREATE),
ClonePreSave(CustomNpcsPermissions.NPC_CLONE),