mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 01:29:05 +00:00
Merge remote-tracking branch 'upstream/packet' into packet
This commit is contained in:
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,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user