mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
Linked Packets
This commit is contained in:
1 parent
35da0f92f6
commit
b15d64bd09
9 files changed
+53
-51
No files matched your search
@@ -0,0 +1,8 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
public class PacketClient extends PacketHandler {
|
||||
|
||||
public static void sendClient(AbstractPacket packet){
|
||||
PacketHandler.Instance.sendToServer(packet);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,10 @@ import kamkeel.npcs.network.packets.data.gui.*;
|
||||
import kamkeel.npcs.network.packets.data.large.*;
|
||||
import kamkeel.npcs.network.packets.data.npc.*;
|
||||
import kamkeel.npcs.network.packets.data.script.*;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedAddPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedSetPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -22,11 +26,12 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class PacketHandler {
|
||||
public class PacketHandler {
|
||||
public static PacketHandler Instance;
|
||||
|
||||
// Channels
|
||||
@@ -53,6 +58,14 @@ public final class PacketHandler {
|
||||
this.registerDataPackets();
|
||||
}
|
||||
|
||||
public void registerRequestPackets(){
|
||||
// Linked Packets
|
||||
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedAddPacket());
|
||||
}
|
||||
|
||||
public void registerDataPackets(){
|
||||
// Client Packets
|
||||
DATA_PACKET.registerPacket(new AchievementPacket());
|
||||
@@ -159,6 +172,11 @@ public final class PacketHandler {
|
||||
}
|
||||
|
||||
if(side == Side.SERVER){
|
||||
if(abstractPacket.getChannel() == REQUEST_PACKET && ConfigMain.OpsOnly && !NoppesUtilServer.isOp(player)){
|
||||
LogWriter.error(String.format("%s tried to use CNPC+ without being an op", player.getCommandSenderName()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if permission is allowed
|
||||
if(abstractPacket.getPermission() != null && !CustomNpcsPermissions.hasPermission(player, abstractPacket.getPermission())){
|
||||
return;
|
||||
|
||||
@@ -22,8 +22,7 @@ import java.util.List;
|
||||
public final class LinkedGetAllPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedGetAll";
|
||||
|
||||
public LinkedGetAllPacket() {
|
||||
}
|
||||
public LinkedGetAllPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
|
||||
@@ -29,8 +29,7 @@ public final class LinkedRemovePacket extends AbstractPacket {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public LinkedRemovePacket() {
|
||||
}
|
||||
public LinkedRemovePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
|
||||
@@ -26,8 +26,7 @@ public final class LinkedSetPacket extends AbstractPacket {
|
||||
this.linkedName = linkedName;
|
||||
}
|
||||
|
||||
public LinkedSetPacket() {
|
||||
}
|
||||
public LinkedSetPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
|
||||
@@ -68,13 +68,7 @@ public class PacketHandlerServer{
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(type.needsNpc && npc == null){
|
||||
|
||||
}
|
||||
else if(type.hasPermission() && !CustomNpcsPermissions.hasPermission(player, type.permission)){
|
||||
//player doesnt have permission to do this
|
||||
}
|
||||
else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
|
||||
if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
|
||||
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
|
||||
else {
|
||||
if (item != null) {
|
||||
@@ -455,27 +449,7 @@ public class PacketHandlerServer{
|
||||
}
|
||||
|
||||
private void wandPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException{
|
||||
if(type == EnumPacketServer.LinkedRemove){
|
||||
LinkedNpcController.Instance.removeData(ByteBufUtils.readString(buffer));
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
for(LinkedData data : LinkedNpcController.Instance.list)
|
||||
list.add(data.name);
|
||||
ScrollListPacket.sendList((EntityPlayerMP)player, list);
|
||||
}
|
||||
else if(type == EnumPacketServer.LinkedGetAll){
|
||||
List<String> list = new ArrayList<String>();
|
||||
for(LinkedData data : LinkedNpcController.Instance.list)
|
||||
list.add(data.name);
|
||||
ScrollListPacket.sendList((EntityPlayerMP)player, list);
|
||||
if(npc != null)
|
||||
ScrollSelectedPacket.setSelectedList(player, npc.linkedName);
|
||||
}
|
||||
else if(type == EnumPacketServer.LinkedSet){
|
||||
npc.linkedName = ByteBufUtils.readString(buffer);
|
||||
LinkedNpcController.Instance.loadNpcData(npc);
|
||||
}
|
||||
else if(type == EnumPacketServer.BanksGet){
|
||||
if(type == EnumPacketServer.BanksGet){
|
||||
NoppesUtilServer.sendBankDataAll(player);
|
||||
}
|
||||
else if(type == EnumPacketServer.BankGet){
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedSetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import noppes.npcs.client.Client;
|
||||
@@ -15,21 +18,21 @@ import java.util.Vector;
|
||||
public class GuiNPCAdvancedLinkedNpc extends GuiNPCInterface2 implements IScrollData, ICustomScrollListener{
|
||||
private GuiCustomScroll scroll;
|
||||
private List<String> data = new ArrayList<String>();
|
||||
|
||||
|
||||
public static GuiScreen Instance;
|
||||
|
||||
|
||||
public GuiNPCAdvancedLinkedNpc(EntityNPCInterface npc){
|
||||
super(npc);
|
||||
Instance = this;
|
||||
Client.sendData(EnumPacketServer.LinkedGetAll);
|
||||
PacketClient.sendClient(new LinkedGetAllPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
|
||||
|
||||
this.addButton(new GuiNpcButton(1,guiLeft + 358, guiTop + 38, 58, 20, "gui.clear"));
|
||||
|
||||
|
||||
if(scroll == null){
|
||||
scroll = new GuiCustomScroll(this,0);
|
||||
scroll.setSize(143, 208);
|
||||
@@ -44,9 +47,9 @@ public class GuiNPCAdvancedLinkedNpc extends GuiNPCInterface2 implements IScroll
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button){
|
||||
if(button.id == 1){
|
||||
Client.sendData(EnumPacketServer.LinkedSet, "");
|
||||
PacketClient.sendClient(new LinkedSetPacket(""));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,13 +65,13 @@ public class GuiNPCAdvancedLinkedNpc extends GuiNPCInterface2 implements IScroll
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k,
|
||||
GuiCustomScroll guiCustomScroll) {
|
||||
Client.sendData(EnumPacketServer.LinkedSet, guiCustomScroll.getSelected());
|
||||
PacketClient.sendClient(new LinkedSetPacket(guiCustomScroll.getSelected()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedAddPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedRemovePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import noppes.npcs.client.Client;
|
||||
@@ -23,7 +27,7 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
|
||||
public GuiNPCManageLinkedNpc(EntityNPCInterface npc){
|
||||
super(npc);
|
||||
Instance = this;
|
||||
Client.sendData(EnumPacketServer.LinkedGetAll);
|
||||
PacketClient.sendClient(new LinkedGetAllPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +83,7 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
|
||||
}
|
||||
if(button.id == 2){
|
||||
if(scroll.hasSelected())
|
||||
Client.sendData(EnumPacketServer.LinkedRemove, scroll.getSelected());
|
||||
PacketClient.sendClient(new LinkedRemovePacket(scroll.getSelected()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,7 +91,7 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if(!((SubGuiEditText)subgui).cancelled){
|
||||
Client.sendData(EnumPacketServer.LinkedAdd, ((SubGuiEditText)subgui).text);
|
||||
PacketClient.sendClient(new LinkedAddPacket(((SubGuiEditText)subgui).text));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
|
||||
|
||||
public enum EnumPacketServer {
|
||||
NPCDelete(CustomNpcsPermissions.NPC_DELETE, true),
|
||||
@@ -33,7 +35,6 @@ public enum EnumPacketServer {
|
||||
RoleSave(CustomNpcsPermissions.NPC_ADVANCED, true), RoleGet(true),
|
||||
JobSpawnerAdd(CustomNpcsPermissions.NPC_ADVANCED, true), JobSpawnerRemove(CustomNpcsPermissions.NPC_ADVANCED, true),
|
||||
RoleCompanionUpdate(CustomNpcsPermissions.NPC_ADVANCED, true),
|
||||
LinkedSet(CustomNpcsPermissions.NPC_ADVANCED, true),
|
||||
|
||||
ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, CloneTagList, CloneAllTags, CloneAllTagsShort,
|
||||
|
||||
@@ -55,9 +56,6 @@ public enum EnumPacketServer {
|
||||
ScriptBlockDataSave(CustomNpcsPermissions.SCRIPT_BLOCK, false),
|
||||
ScriptBlockDataGet(false),
|
||||
|
||||
LinkedGetAll,
|
||||
LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED),
|
||||
|
||||
ScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true), ScriptDataGet(true),
|
||||
EventScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true), EventScriptDataGet(true),
|
||||
|
||||
|
||||
Reference in new issue
Block a user