Merge remote-tracking branch 'refs/remotes/origin/packet' into animation-events-2

# Conflicts:
#	src/api
#	src/main/java/noppes/npcs/CommonProxy.java
#	src/main/java/noppes/npcs/ServerEventsHandler.java
#	src/main/java/noppes/npcs/client/PacketHandlerClient.java
#	src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java
#	src/main/java/noppes/npcs/controllers/data/AnimationData.java
This commit is contained in:
luisc committed 2025-02-11 16:53:36 -06:00
commit 00af353e65
602 files changed
+29702 -6562

No files matched your search

+2 -2
View File
@@ -172,7 +172,7 @@ public class CmdClone extends ChMcLogger {
entity.setPosition(posX + 0.5, posY + 1, posZ + 0.5);
if(entity instanceof EntityNPCInterface){
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
npc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
if(newname != null && !newname.isEmpty())
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
}
@@ -274,7 +274,7 @@ public class CmdClone extends ChMcLogger {
entity.setPosition(posX + 0.5 + x, yy + 1, posZ + 0.5 + z);
if(entity instanceof EntityNPCInterface){
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ai.startPos = new int[]{xx, yy, zz};
npc.ais.startPos = new int[]{xx, yy, zz};
if(newname != null && !newname.isEmpty())
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
}
+4 -3
View File
@@ -5,15 +5,16 @@ import foxz.commandhelper.annotations.Command;
import foxz.commandhelper.annotations.SubCommand;
import foxz.commandhelper.permissions.OpOnly;
import foxz.commandhelper.permissions.PlayerOnly;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumConfigOperation;
import kamkeel.npcs.network.packets.data.ConfigCommandPacket;
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.block.BlockVine;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.ChunkController;
import java.util.Arrays;
@@ -207,6 +208,6 @@ public class CmdConfig extends ChMcLogger {
for(int i = 0; i < args.length; i++){
font += " " + args[i];
}
Server.sendData((EntityPlayerMP)this.pcParam, EnumPacketClient.CONFIG, 0, font.trim(), size);
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)this.pcParam);
}
}
+1 -1
View File
@@ -5,12 +5,12 @@ import foxz.commandhelper.annotations.Command;
import foxz.commandhelper.annotations.SubCommand;
import foxz.commandhelper.permissions.OpOnly;
import foxz.commandhelper.permissions.ParamCheck;
import kamkeel.npcs.controllers.SyncController;
import net.minecraft.command.CommandBase;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
import noppes.npcs.controllers.data.PlayerData;
+2 -2
View File
@@ -50,7 +50,7 @@ public class CmdNpc extends ChMcLogger {
posZ = CommandBase.func_110666_a(pcParam, selectedNpc.posZ, args[2]);
}
selectedNpc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
selectedNpc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
}
@SubCommand(
@@ -144,7 +144,7 @@ public class CmdNpc extends ChMcLogger {
if(args.length > 0)
npc.display.name = args[0];
npc.setPositionAndRotation(player.posX, player.posY, player.posZ, player.cameraYaw, player.cameraPitch);
npc.ai.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
npc.ais.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
pw.spawnEntityInWorld(npc);
npc.setHealth(npc.getMaxHealth());
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
+5 -5
View File
@@ -5,11 +5,11 @@ import foxz.commandhelper.annotations.Command;
import foxz.commandhelper.annotations.SubCommand;
import foxz.commandhelper.permissions.OpOnly;
import foxz.commandhelper.permissions.ParamCheck;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.QuestData;
@@ -58,8 +58,8 @@ public class CmdQuest extends ChMcLogger{
playerdata.questData.activeQuests.put(questid, questdata);
playerdata.save();
if(playerdata.player != null){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
}
playerdata.updateClient = true;
}
@@ -1,7 +1,7 @@
package kamkeel.addon;
package kamkeel.npcs.addon;
import kamkeel.addon.client.DBCClient;
import kamkeel.addon.client.GeckoAddonClient;
import kamkeel.npcs.addon.client.DBCClient;
import kamkeel.npcs.addon.client.GeckoAddonClient;
public class AddonManager {
public static AddonManager Instance;
@@ -1,6 +1,5 @@
package kamkeel.addon;
package kamkeel.npcs.addon;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -1,4 +1,4 @@
package kamkeel.addon;
package kamkeel.npcs.addon;
import net.minecraft.entity.EntityLivingBase;
@@ -17,4 +17,4 @@ public class GeckoAddon {
public void geckoCopyData(EntityLivingBase copied, EntityLivingBase entity){}
}
}
@@ -1,15 +1,10 @@
package kamkeel.addon.client;
package kamkeel.npcs.addon.client;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
import noppes.npcs.client.gui.model.GuiCreationScreen;
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.model.ModelMPM;
import noppes.npcs.entity.EntityNPCInterface;
public class DBCClient {
@@ -1,4 +1,4 @@
package kamkeel.addon.client;
package kamkeel.npcs.addon.client;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.EntityLivingBase;
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -1,8 +1,7 @@
package kamkeel.command;
package kamkeel.npcs.command;
import foxz.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
@@ -180,9 +179,9 @@ public class CloneCommand extends CommandKamkeelBase {
return;
}
try{
posX = CommandBase.func_110666_a(sender, posX, par[0]);
posY = CommandBase.func_110665_a(sender, posY, par[1].trim(), 0, 0);
posZ = CommandBase.func_110666_a(sender, posZ, par[2]);
posX = func_110666_a(sender, posX, par[0]);
posY = func_110665_a(sender, posY, par[1].trim(), 0, 0);
posZ = func_110666_a(sender, posZ, par[2]);
} catch(NumberFormatException ex){
sendError(sender, "Location should be in numbers");
return;
@@ -204,7 +203,7 @@ public class CloneCommand extends CommandKamkeelBase {
entity.setPosition(posX + 0.5, posY + 1, posZ + 0.5);
if(entity instanceof EntityNPCInterface){
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
npc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
if(newname != null && !newname.isEmpty())
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
}
@@ -272,9 +271,9 @@ public class CloneCommand extends CommandKamkeelBase {
return;
}
try{
posX = CommandBase.func_110666_a(sender, posX, par[0]);
posY = CommandBase.func_110665_a(sender, posY, par[1].trim(), 0, 0);
posZ = CommandBase.func_110666_a(sender, posZ, par[2]);
posX = func_110666_a(sender, posX, par[0]);
posY = func_110665_a(sender, posY, par[1].trim(), 0, 0);
posZ = func_110666_a(sender, posZ, par[2]);
} catch(NumberFormatException ex){
sendError(sender, "Location should be in numbers");
return;
@@ -310,7 +309,7 @@ public class CloneCommand extends CommandKamkeelBase {
entity.setPosition(posX + 0.5 + x, yy + 1, posZ + 0.5 + z);
if(entity instanceof EntityNPCInterface){
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ai.startPos = new int[]{xx, yy, zz};
npc.ais.startPos = new int[]{xx, yy, zz};
if(newname != null && !newname.isEmpty())
npc.display.name = newname.replaceAll("%", " "); // like name, newname must use % in place of space to keep a logical way
}
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@@ -46,7 +46,7 @@ public class CommandKamkeel extends CommandBase{
@Override
public String getCommandName() {
return "kamkeel";
return "kamkeel/npcs";
}
@Override
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@@ -1,6 +1,9 @@
package kamkeel.command;
package kamkeel.npcs.command;
import foxz.utils.Market;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumConfigOperation;
import kamkeel.npcs.network.packets.data.ConfigCommandPacket;
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
@@ -10,9 +13,7 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.ChunkController;
import noppes.npcs.controllers.PlayerDataController;
@@ -291,8 +292,7 @@ public class ConfigCommand extends CommandKamkeelBase {
for(int i = 0; i < args.length; i++){
font += " " + args[i];
}
Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size);
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)sender);
}
}
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -1,5 +1,6 @@
package kamkeel.command;
package kamkeel.npcs.command;
import kamkeel.npcs.controllers.SyncController;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -10,7 +11,6 @@ import noppes.npcs.constants.EnumAvailabilityDialog;
import noppes.npcs.constants.EnumAvailabilityQuest;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Availability;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
@@ -0,0 +1,139 @@
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.CustomEffect;
import noppes.npcs.controllers.data.PlayerData;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class EffectCommand extends CommandKamkeelBase {
@Override
public String getDescription() {
return "Custom Effect operations";
}
@Override
public String getCommandName() {
return "effect";
}
// info all
@SubCommand(desc = "Lists all effects")
public void infoAll(ICommandSender sender, String[] args) throws CommandException {
// TODO: FIX EFFECT COMMAND
// Set<Map.Entry<Integer, StatusEffect>> effects = DBCEffectController.getInstance().standardEffects.entrySet();
// Set<Map.Entry<Integer, CustomEffect>> customEffects = DBCEffectController.getInstance().customEffects.entrySet();
//
// if (effects.isEmpty() && customEffects.isEmpty()) {
// sendError(sender, "No effects found.");
// return;
// }
//
// sendResult(sender, "--------------------");
//
// for (Map.Entry<Integer, StatusEffect> entry : effects) {
// sendResult(sender, String.format("\u00a7b%2$s \u00a77(ID%3$s: %1$s)", entry.getKey(), entry.getValue().getName(), entry.getValue().isCustom() ? " - CUSTOM" : " "));
// }
// for (Map.Entry<Integer, CustomEffect> entry : customEffects) {
// sendResult(sender, String.format("\u00a7b%2$s \u00a77(ID%3$s: %1$s)", entry.getKey(), entry.getValue().getName(), entry.getValue().isCustom() ? " - CUSTOM" : " "));
// }
//
// sendResult(sender, "--------------------");
}
@SubCommand(desc = "Gives a effect to a player", usage = "<player> <time> <effectName>")
public void give(ICommandSender sender, String[] args) throws CommandException {
// String playername = args[0];
// int time = Integer.parseInt(args[1]);
// String name = "";
// for (int i = 2; i < args.length; i++) {
// name += args[i] + (i != args.length - 1 ? " " : "");
// }
//
// List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
// if (data.isEmpty()) {
// sendError(sender, "Unknown player: " + playername);
// return;
// }
//
// StatusEffect statusEffect = DBCEffectController.getInstance().get(name);
// if (statusEffect == null) {
// sendError(sender, "Unknown effect: " + name);
// return;
// }
//
// for (PlayerData playerdata : data) {
// DBCEffectController.getInstance().applyEffect(playerdata.player, statusEffect.getID(), time);
// sendResult(sender, String.format("%s §agiven to §7'§b%s§7'", statusEffect.getName(), playerdata.playername));
// if (sender != playerdata.player) {
// sendResult(playerdata.player, String.format("§Effect §7%s §aadded.", statusEffect.getName()));
// }
// }
}
@SubCommand(desc = "Removes a effect from a player", usage = "<player> <effectName>")
public void remove(ICommandSender sender, String[] args) throws CommandException {
// String playername = args[0];
// String name = "";
// for (int i = 1; i < args.length; i++) {
// name += args[i] + (i != args.length - 1 ? " " : "");
// }
//
// List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
// if (data.isEmpty()) {
// sendError(sender, "Unknown player: " + playername);
// return;
// }
//
// StatusEffect statusEffect = DBCEffectController.getInstance().get(name);
// if (statusEffect == null) {
// sendError(sender, "Unknown effect: " + name);
// return;
// }
//
// for (PlayerData playerData : data) {
// DBCEffectController.getInstance().removeEffect(playerData.player, statusEffect.getID(), DBCPlayerEvent.EffectEvent.ExpirationType.REMOVED);
// sendResult(sender, String.format("Effect %s removed from %s", statusEffect.getName(), playerData.playername));
// }
}
@SubCommand(desc = "Gives a effect to a player", usage = "<player> <time> <effectId>")
public void giveId(ICommandSender sender, String[] args) throws CommandException {
// String playername = args[0];
// int time = Integer.parseInt(args[1]);
//
// List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
// if (data.isEmpty()) {
// sendError(sender, "Unknown player: " + playername);
// return;
// }
//
// for (PlayerData playerdata : data) {
// int statusEffectId = Integer.parseInt(args[2]);
// DBCEffectController.getInstance().applyEffect(playerdata.player, statusEffectId, time);
// sendResult(sender, String.format("Effect %d given to %s", statusEffectId, playerdata.playername));
// }
}
@SubCommand(desc = "Removes a effect from a player", usage = "<player> <effectId>")
public void removeId(ICommandSender sender, String[] args) throws CommandException {
// String playername = args[0];
// List<PlayerData> data = PlayerDataController.Instance.getPlayersData(sender, playername);
// if (data.isEmpty()) {
// sendError(sender, "Unknown player: " + playername);
// return;
// }
//
// for (PlayerData playerData : data) {
// int statusEffectId = Integer.parseInt(args[1]);
// DBCEffectController.getInstance().removeEffect(playerData.player, statusEffectId, DBCPlayerEvent.EffectEvent.ExpirationType.REMOVED);
// sendResult(sender, String.format("Effect %d removed from %s", statusEffectId, playerData.playername));
// }
}
}
@@ -1,6 +1,5 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import noppes.npcs.controllers.FactionController;
@@ -153,7 +152,7 @@ public class FactionCommand extends CommandKamkeelBase {
@Override
public List addTabCompletionOptions(ICommandSender par1, String[] args) {
if(args.length == 3){
return CommandBase.getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
return getListOfStringsMatchingLastWord(args, new String[]{"add", "subtract", "set", "reset", "drop", "create"});
}
return null;
}
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@@ -93,7 +93,7 @@ public class NpcCommand extends CommandKamkeelBase {
posZ = CommandBase.func_110666_a(sender, selectedNpc.posZ, args[2]);
}
selectedNpc.ai.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
selectedNpc.ais.startPos = new int[]{MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)};
sendResult(sender, String.format("Set NPC \u00A7e%s\u00A77 Home to \u00A7b[%.1f] [%.1f] [%.1f]\u00A77", selectedNpc.display.name, posX, posY, posZ));
}
@@ -199,7 +199,7 @@ public class NpcCommand extends CommandKamkeelBase {
if(args.length > 0)
npc.display.name = args[0];
npc.setPositionAndRotation(player.posX, player.posY, player.posZ, player.cameraYaw, player.cameraPitch);
npc.ai.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
npc.ais.startPos = new int[]{MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ)};
pw.spawnEntityInWorld(npc);
npc.setHealth(npc.getMaxHealth());
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@@ -1,10 +1,10 @@
package kamkeel.command;
package kamkeel.npcs.command;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.QuestController;
@@ -93,8 +93,8 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
if(playerdata.player != null){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.completed", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.completed", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.completed", ": ", quest.title);
}
count++;
}
@@ -185,8 +185,8 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
count++;
if(playerdata.player != null && questData.sendAlerts){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
}
}
}
@@ -1,19 +1,17 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import noppes.npcs.Server;
import noppes.npcs.api.handler.data.IQuestObjective;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestCompletion;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.Quest;
@@ -67,8 +65,8 @@ public class QuestCommand extends CommandKamkeelBase {
playerdata.questData.activeQuests.put(questid, questdata);
playerdata.save();
if(playerdata.player != null && questdata.sendAlerts){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.newquest", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.newquest", ": ", quest.title);
}
playerdata.updateClient = true;
sendResult(sender, String.format("Started Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
@@ -113,8 +111,8 @@ public class QuestCommand extends CommandKamkeelBase {
playerdata.save();
if(playerdata.player != null){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.completed", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.completed", ": ", quest.title);
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title);
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerdata.player, "quest.completed", ": ", quest.title);
}
playerdata.updateClient = true;
sendResult(sender, String.format("Finished Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
@@ -192,7 +190,7 @@ public class QuestCommand extends CommandKamkeelBase {
usage = "<player> <quest> [objective] [value]"
)
public void objective(ICommandSender sender, String[] args) throws CommandException {
EntityPlayer player = CommandBase.getPlayer(sender, args[0]);
EntityPlayer player = getPlayer(sender, args[0]);
int questid;
try {
questid = Integer.parseInt(args[1]);
@@ -1,4 +1,4 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.ICommandSender;
import noppes.npcs.controllers.ScriptController;
@@ -1,6 +1,5 @@
package kamkeel.command;
package kamkeel.npcs.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
@@ -134,6 +133,6 @@ public class SlayCommand extends CommandKamkeelBase {
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args){
return CommandBase.getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
return getListOfStringsMatchingLastWord(args, SlayMap.keySet().toArray(new String[SlayMap.size()]));
}
}
@@ -0,0 +1,70 @@
package kamkeel.npcs.command.profile;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentTranslation;
import java.lang.reflect.Method;
import java.util.Map.Entry;
public class CommandHelpProfile extends CommandProfileBase {
private CommandProfile parent;
public CommandHelpProfile(CommandProfile parent){
this.parent = parent;
}
@Override
public String getCommandName() {
return "help";
}
@Override
public String getDescription() {
return "help [command]";
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if(args.length == 0){
sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------");
for(Entry<String, CommandProfileBase> entry : parent.map.entrySet()){
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getCommandUsage(sender));
}
return;
}
CommandProfileBase command = parent.getCommand(args);
if(command == null){
sendError(sender, "Unknown command " + args[0]);
return;
}
if(command.subcommands.isEmpty()){
sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender)));
return;
}
Method m = null;
if(args.length > 1){
m = command.subcommands.get(args[1].toLowerCase());
}
if(m == null){
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------");
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
for(Entry<String, Method> entry : command.subcommands.entrySet()){
sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc()));
}
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + CommandProfile.getCommandPermission(command.getCommandName())));
}
else{
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------");
SubCommand sc = m.getAnnotation(SubCommand.class);
sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc()));
if(!sc.usage().isEmpty())
sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage()));
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1])));
}
}
}
@@ -0,0 +1,141 @@
package kamkeel.npcs.command.profile;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.scripted.CustomNPCsException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommandProfile extends CommandBase {
public Map<String, CommandProfileBase> map = new HashMap<String, CommandProfileBase>();
public CommandHelpProfile help = new CommandHelpProfile(this);
public String[] alias = {"profile"};
public CommandProfile(){
registerCommand(help);
registerCommand(new CommandProfileChange());
}
public void registerCommand(CommandProfileBase command){
String name = command.getCommandName().toLowerCase();
if(map.containsKey(name))
throw new CustomNPCsException("Already a subcommand with the name: " + name);
map.put(name, command);
}
@Override
public String getCommandName() {
return "profile";
}
@Override
public List getCommandAliases()
{
return Arrays.asList(alias);
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "Use as /profile subcommand";
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if(args.length == 0){
help.processCommand(sender, args);
return;
}
CommandProfileBase command = getCommand(args);
if(command == null)
throw new CommandException("Unknown command " + args[0]);
args = Arrays.copyOfRange(args, 1, args.length);
if(command.subcommands.isEmpty() || !command.runSubCommands()){
if(!canSendCommand(sender, command))
throw new CommandException("You are not allowed to use this command: " + command);
command.canRun(sender, command.getUsage(), args);
command.processCommand(sender, args);
return;
}
if(args.length == 0){
help.processCommand(sender, new String[]{command.getCommandName()});
return;
}
command.processSubCommand(sender, args[0], Arrays.copyOfRange(args, 1, args.length));
}
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args){
if(args.length == 1)
return CommandBase.getListOfStringsMatchingLastWord(args, map.keySet().toArray(new String[map.size()]));
CommandProfileBase command = getCommand(args);
if(command == null)
return null;
if(args.length == 2 && command.runSubCommands())
return getListOfStringsMatchingLastWord(args, command.subcommands.keySet().toArray(new String[command.subcommands.keySet().size()]));
String[] useArgs = command.getUsage().split(" ");
if(command.runSubCommands()) {
Method m = command.subcommands.get(args[1].toLowerCase());
if(m != null) {
useArgs = m.getAnnotation(CommandProfileBase.SubCommand.class).usage().split(" ");
}
}
if(args.length <= useArgs.length + 2) {
if(args.length - 3 >= 0){
String usage = useArgs[args.length - 3];
if(usage.equals("<player>") || usage.equals("[player]")) {
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
}
}
}
return command.addTabCompletionOptions(sender, Arrays.copyOfRange(args, 1, args.length));
}
public CommandProfileBase getCommand(String[] args){
if(args.length == 0)
return null;
return map.get(args[0].toLowerCase());
}
@Override
public int getRequiredPermissionLevel(){
return 0;
}
public static String getCommandPermission(String command){
return "profile.kamkeel." + command.toLowerCase();
}
public static String getUniversalPermission(){
return "profile.kamkeel.*";
}
public static boolean canSendCommand(ICommandSender sender, CommandProfileBase command){
if(sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getUniversalPermission())){
return true;
}
if(sender.canCommandSenderUseCommand(command.getRequiredPermissionLevel(), getCommandPermission(command.getCommandName()))){
return true;
}
if(sender instanceof EntityPlayer){
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getCommandPermission(command.getCommandName()));
}
return false;
}
}
@@ -0,0 +1,148 @@
package kamkeel.npcs.command.profile;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import noppes.npcs.CustomNpcsPermissions;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class CommandProfileBase extends CommandBase{
public Map<String, Method> subcommands = new HashMap<String, Method>();
public CommandProfileBase(){
for (Method m : this.getClass().getDeclaredMethods()) {
SubCommand sc = m.getAnnotation(SubCommand.class);
if (sc != null) {
String name = sc.name();
if (name.equals(""))
name = m.getName();
subcommands.put(name.toLowerCase(), m);
}
}
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
}
@Override
public String getCommandUsage(ICommandSender sender) {
return getDescription();
}
public abstract String getDescription();
/**
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
*/
public String getUsage(){
return "";
}
public boolean runSubCommands(){
return !subcommands.isEmpty();
}
protected static void sendMessage(ICommandSender sender, String message, Object... obs) {
sender.addChatMessage(new ChatComponentTranslation(message, obs));
}
protected static void sendResult(ICommandSender sender, String message, Object... obs) {
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs));
}
protected static void sendError(ICommandSender sender, String message, Object... obs) {
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs));
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SubCommand {
String name() default "";
/**
* @return Should return a string in the format of <arg> <arg2> <arg3> [arg4] where <> is a required parameter and [] optional
*/
String usage() default "";
String desc();
int permission() default 2;
}
public void processSubCommand(ICommandSender sender, String command, String[] args) throws CommandException {
Method m = subcommands.get(command.toLowerCase());
if(m == null)
throw new CommandException("Unknown subcommand " + command);
SubCommand sc = m.getAnnotation(SubCommand.class);
if(!canSendCommand(sender, sc, command))
throw new CommandException("You are not allowed to use this command: " + command);
canRun(sender, sc.usage(), args);
try {
m.invoke(this, sender, args);
} catch (Exception e) {
e.printStackTrace();
}
}
public void canRun(ICommandSender sender, String usage, String[] args) throws CommandException{
String[] np = usage.split(" ");
List<String> required = new ArrayList<String>();
for(int i = 0; i < np.length; i++){
String command = np[i];
if(command.startsWith("<")){
required.add(command);
}
if(command.equals("<player>") && args.length > i){
CommandBase.getPlayer(sender, args[i]); //throws PlayerNotFoundException if no player is found
}
}
if (args.length < required.size()) {
throw new CommandException("Missing parameter: " + required.get(args.length));
}
}
public int getRequiredPermissionLevel(){
return 2;
}
public String getSubCommandPermission(String subCommand){
return "profile.kamkeel." + getCommandName().toLowerCase() + "." + subCommand.toLowerCase();
}
public String getSubUniversalPermission(){
return "profile.kamkeel." + getCommandName().toLowerCase() + "*";
}
public boolean canSendCommand(ICommandSender sender, SubCommand command, String subCommand){
if(sender.canCommandSenderUseCommand(command.permission(), getSubUniversalPermission())){
return true;
}
if(sender.canCommandSenderUseCommand(command.permission(), getSubCommandPermission(subCommand))){
return true;
}
if(sender instanceof EntityPlayer){
return CustomNpcsPermissions.hasCustomPermission((EntityPlayer) sender, getSubCommandPermission(subCommand));
}
return false;
}
}
@@ -0,0 +1,61 @@
package kamkeel.npcs.command.profile;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.data.Profile;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
public class CommandProfileChange extends CommandProfileBase {
@Override
public String getCommandName() {
return "change";
}
@Override
public String getDescription() {
return "change profiles";
}
@Override
public String getUsage() {
return "<number>";
}
@Override
public boolean runSubCommands(){
return false;
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if(!(sender instanceof EntityPlayer)){
sendError(sender, "This command can only be sent by a player");
return;
}
int slotID;
try {
slotID = Integer.parseInt(args[0]);
} catch (NumberFormatException ex) {
sendError(sender, "Slot ID must be a number: " + args[1]);
return;
}
// TODO: Check if the player has permission to switch to this slot
EntityPlayerMP player = (EntityPlayerMP) sender;
Profile profile = ProfileController.activeProfiles.get(player.getUniqueID());
if(profile == null){
sendError(sender, "Could not find a valid profile file");
return;
}
ProfileController.changePlayerSlot(player, slotID);
// TODO: Add Cooldown to successful operation
sendResult(sender, String.format("Switched to Slot \u00A7b%d\u00A77", slotID));
}
}
@@ -0,0 +1,176 @@
package kamkeel.npcs.controllers;
import kamkeel.npcs.controllers.data.IProfileData;
import kamkeel.npcs.controllers.data.Profile;
import kamkeel.npcs.controllers.data.Slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.util.CustomNPCsThreader;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.UUID;
public class ProfileController {
public static HashMap<String, IProfileData> profileTypes;
public static HashMap<UUID, Profile> activeProfiles;
public static String profile_directory = "profiles";
public ProfileController(){
profileTypes = new HashMap<>();
activeProfiles = new HashMap<>();
}
/**
* Register during ServerStartEvent()
*
* @param type - IProfile Type to always Save/Load
* @return true/false if profile was successfully added
*/
public static boolean registerProfileType(IProfileData type){
if(profileTypes.containsKey(type.getTagName()))
return false;
profileTypes.put(type.getTagName(), type);
return true;
}
public static File getProfileDir(){
try{
File file = new File(CustomNpcs.getWorldSaveDirectory(), profile_directory);
if(!file.exists())
file.mkdir();
return file;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static synchronized void login(EntityPlayer player){
if(player == null)
return;
Profile profile;
if(activeProfiles.containsKey(player.getUniqueID())){
profile = activeProfiles.get(player.getUniqueID());
profile.player = player;
} else {
NBTTagCompound profileCompound = load(player);
profile = new Profile(player, profileCompound);
activeProfiles.put(player.getUniqueID(), profile);
}
}
public static synchronized NBTTagCompound load(EntityPlayer player) {
File saveDir = getProfileDir();
String filename = player.getUniqueID().toString();
filename += ".dat";
try {
File file = new File(saveDir, filename);
if(file.exists()){
return NBTJsonUtil.loadNBTData(file);
}
} catch (Exception e) {
LogWriter.error("Error loading profile file: " + filename, e);
}
return new NBTTagCompound();
}
public static synchronized void save(EntityPlayer player, Profile profile) {
CustomNPCsThreader.customNPCThread.execute(() -> {
final NBTTagCompound compound = profile.writeToNBT();
final String filename = player.getUniqueID() + ".dat";
try {
File saveDir = getProfileDir();
File file = new File(saveDir, filename + "_new");
File file1 = new File(saveDir, filename);
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file));
if(file1.exists()){
file1.delete();
}
file.renameTo(file1);
} catch (Exception e) {
LogWriter.except(e);
}
});
}
public static void changeSlot(EntityPlayer player, int slotNumber){
if(!activeProfiles.containsKey(player.getUniqueID()))
return;
Profile profile = activeProfiles.get(player.getUniqueID());
if(profile.currentID == slotNumber)
return;
// Saves Current Slot Data
saveSlotData(player);
// Sets Player to New Slot
changePlayerSlot(player, slotNumber);
// Save Slot File
save(player, profile);
}
public static void saveSlotData(EntityPlayer player){
if(!activeProfiles.containsKey(player.getUniqueID()))
return;
NBTTagCompound dataCompound;
Slot slot;
Profile profile = activeProfiles.get(player.getUniqueID());
if(!profile.slots.isEmpty() && profile.slots.containsKey(profile.currentID)){
slot = profile.slots.get(profile.currentID);
dataCompound = (NBTTagCompound) slot.getCompound().copy();
} else {
slot = new Slot(profile.currentID, "Slot " + profile.currentID);
dataCompound = new NBTTagCompound();
slot.setCompound(dataCompound);
}
for(IProfileData profileData : profileTypes.values()){
NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy();
dataCompound.setTag(profileData.getTagName(), cloned);
}
slot.setCompound(dataCompound);
}
public static void changePlayerSlot(EntityPlayer player, int id){
if(!activeProfiles.containsKey(player.getUniqueID()))
return;
NBTTagCompound slotCompound;
Slot slot;
Profile profile = activeProfiles.get(player.getUniqueID());
if(!profile.slots.isEmpty() && profile.slots.containsKey(id)){
slot = profile.slots.get(id);
slotCompound = (NBTTagCompound) slot.getCompound().copy();
} else {
slot = new Slot(id, "Slot " + id);
slotCompound = new NBTTagCompound();
slot.setCompound(slotCompound);
}
slot.setLastLoaded(System.currentTimeMillis());
profile.slots.put(id, slot);
for(IProfileData profileData : profileTypes.values()){
profileData.setNBT(player, slotCompound.getCompoundTag(profileData.getTagName()));
profileData.save(player);
}
profile.currentID = id;
}
}
@@ -0,0 +1,582 @@
package kamkeel.npcs.controllers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.addon.DBCAddon;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
import kamkeel.npcs.network.packets.data.large.SyncPacket;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.*;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SyncController {
public static void syncPlayer(EntityPlayerMP player){
// 1) Factions
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.FACTION,
EnumSyncAction.RELOAD,
-1,
factionsNBT()
), player);
// 2) Dialog Categories
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.DIALOG_CATEGORY,
EnumSyncAction.RELOAD,
-1,
dialogCategoriesNBT()
), player);
// 3) Quest Categories
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.QUEST_CATEGORY,
EnumSyncAction.RELOAD,
-1,
questCategoriesNBT()
), player);
// 4) Workbench Recipes
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
workbenchNBT()
), player);
// 5) Carpentry Recipes
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
carpentryNBT()
), player);
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.ANVIL_RECIPES,
EnumSyncAction.RELOAD,
-1,
anvilNBT()
), player);
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.CUSTOM_EFFECTS,
EnumSyncAction.RELOAD,
-1,
customEffectsNBT()
), player);
DBCAddon.instance.syncPlayer(player);
syncPlayerData(player, false);
}
public static NBTTagCompound workbenchNBT(){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(RecipeCarpentry recipe : controller.globalRecipes.values()){
list.appendTag(recipe.writeNBT());
}
compound.setTag("recipes", list);
return compound;
}
public static NBTTagCompound carpentryNBT(){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(RecipeCarpentry recipe : controller.carpentryRecipes.values()){
list.appendTag(recipe.writeNBT());
}
compound.setTag("recipes", list);
return compound;
}
public static NBTTagCompound anvilNBT(){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(RecipeAnvil recipe : controller.anvilRecipes.values()){
list.appendTag(recipe.writeNBT());
}
compound.setTag("recipes", list);
return compound;
}
public static NBTTagCompound factionsNBT(){
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(Faction faction : FactionController.getInstance().factions.values()){
NBTTagCompound factioNBT = new NBTTagCompound();
faction.writeNBT(factioNBT);
list.appendTag(factioNBT);
}
compound.setTag("Factions", list);
return compound;
}
public static NBTTagCompound dialogCategoriesNBT(){
NBTTagCompound compound = new NBTTagCompound();
NBTTagList categoryList = new NBTTagList();
for(DialogCategory category : DialogController.Instance.categories.values()){
NBTTagCompound questCompound = new NBTTagCompound();
NBTTagList dialogList = new NBTTagList();
for(int dialogID : category.dialogs.keySet()){
Dialog quest = category.dialogs.get(dialogID);
dialogList.appendTag(quest.writeToNBT(new NBTTagCompound()));
}
questCompound.setTag("Data", dialogList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
categoryList.appendTag(questCompound);
}
compound.setTag("DialogCategories", categoryList);
return compound;
}
public static NBTTagCompound questCategoriesNBT(){
NBTTagCompound compound = new NBTTagCompound();
NBTTagList categoryList = new NBTTagList();
for(QuestCategory category : QuestController.Instance.categories.values()){
NBTTagCompound questCompound = new NBTTagCompound();;
NBTTagList questList = new NBTTagList();
for(int questID : category.quests.keySet()){
Quest quest = category.quests.get(questID);
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
}
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
categoryList.appendTag(questCompound);
}
compound.setTag("QuestCategories", categoryList);
return compound;
}
public static NBTTagCompound customEffectsNBT(){
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for (CustomEffect effect : CustomEffectController.getInstance().customEffects.values()) {
list.appendTag(effect.writeToNBT(false));
}
compound.setTag("Data", list);
return compound;
}
public static void syncPlayerData(EntityPlayerMP player, boolean update){
PlayerData data = PlayerData.get(player);
if(data != null){
if(update){
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.PLAYERDATA,
EnumSyncAction.UPDATE,
-1,
data.getSyncNBT())
, player);
} else {
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.PLAYERDATA,
EnumSyncAction.RELOAD,
-1,
data.getSyncNBTFull()), player);
}
}
}
public static void syncRemove(EnumSyncType enumSyncType, int id){
PacketHandler.Instance.sendToAll(new SyncPacket(
enumSyncType,
EnumSyncAction.REMOVE,
id,
new NBTTagCompound()
));
}
public static void syncAllDialogs() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.DIALOG_CATEGORY,
EnumSyncAction.RELOAD,
-1,
dialogCategoriesNBT()
));
}
public static void syncAllQuests() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.QUEST_CATEGORY,
EnumSyncAction.RELOAD,
-1,
questCategoriesNBT()
));
}
public static void syncAllWorkbenchRecipes() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
workbenchNBT()
));
}
public static void syncAllCarpentryRecipes() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
carpentryNBT()
));
}
public static void syncAllAnvilRecipes() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.ANVIL_RECIPES,
EnumSyncAction.RELOAD,
-1,
anvilNBT()
));
}
public static void syncAllCustomEffects() {
PacketHandler.Instance.sendToAll(new SyncPacket(
EnumSyncType.CUSTOM_EFFECTS,
EnumSyncAction.RELOAD,
-1,
customEffectsNBT()
));
}
@SideOnly(Side.CLIENT)
public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) {
switch (enumSyncType){
case FACTION: {
NBTTagList list = fullCompound.getTagList("Factions", 10);
for (int i = 0; i < list.tagCount(); i++) {
Faction faction = new Faction();
faction.readNBT(list.getCompoundTagAt(i));
FactionController.getInstance().factionsSync.put(faction.id, faction);
}
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
break;
}
case DIALOG_CATEGORY: {
if(!fullCompound.hasNoTags()){
NBTTagList categories = fullCompound.getTagList("DialogCategories", 10);
for(int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) {
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
if(categoryCompound.hasNoTags())
continue;
DialogCategory category = new DialogCategory();
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
NBTTagList dialogList = categoryCompound.getTagList("Data", 10);
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
category = DialogController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < dialogList.tagCount(); i++)
{
Dialog dialog = new Dialog();
dialog.readNBT(dialogList.getCompoundTagAt(i));
dialog.category = category;
category.dialogs.put(dialog.id, dialog);
}
DialogController.Instance.categoriesSync.put(category.id, category);
}
}
HashMap<Integer, Dialog> dialogs = new HashMap<Integer, Dialog>();
for(DialogCategory category : DialogController.Instance.categoriesSync.values()){
for(Dialog dialog : category.dialogs.values()){
dialogs.put(dialog.id, dialog);
}
}
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
DialogController.Instance.dialogs = dialogs;
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
break;
}
case QUEST_CATEGORY: {
if(!fullCompound.hasNoTags()){
NBTTagList categories = fullCompound.getTagList("QuestCategories", 10);
for(int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) {
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
if(categoryCompound.hasNoTags())
continue;
QuestCategory category = new QuestCategory();
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
NBTTagList questList = categoryCompound.getTagList("Data", 10);
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
category = QuestController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < questList.tagCount(); i++)
{
Quest quest = new Quest();
quest.readNBT(questList.getCompoundTagAt(i));
quest.category = category;
category.quests.put(quest.id, quest);
}
QuestController.Instance.categoriesSync.put(category.id, category);
}
}
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
for(QuestCategory category : QuestController.Instance.categoriesSync.values()){
for(Quest quest : category.quests.values()){
quests.put(quest.id, quest);
}
}
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
QuestController.Instance.quests = quests;
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
break;
}
case PLAYERDATA: {
ClientCacheHandler.playerData.setSyncNBTFull(fullCompound);
break;
}
case WORKBENCH_RECIPES: {
NBTTagList list = fullCompound.getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
break;
}
case CARPENTRY_RECIPES: {
NBTTagList list = fullCompound.getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
break;
}
case ANVIL_RECIPES: {
NBTTagList list = fullCompound.getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeAnvil recipe = RecipeAnvil.read(list.getCompoundTagAt(i));
RecipeController.syncAnvilRecipes.put(recipe.id, recipe);
}
RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes;
RecipeController.syncAnvilRecipes = new HashMap<Integer, RecipeAnvil>();
break;
}
case CUSTOM_EFFECTS: {
NBTTagList list = fullCompound.getTagList("Data", 10);
for (int i = 0; i < list.tagCount(); i++) {
CustomEffect effect = new CustomEffect();
effect.readFromNBT(list.getCompoundTagAt(i));
ClientCacheHandler.getImageData(effect.icon);
CustomEffectController.getInstance().customEffectsSync.put(effect.id, effect);
}
CustomEffectController.getInstance().customEffects = CustomEffectController.getInstance().customEffectsSync;
CustomEffectController.getInstance().customEffectsSync = new HashMap<>();
break;
}
}
}
/**
* Update Related Tasks
*/
@SideOnly(Side.CLIENT)
public static void clientUpdate(EnumSyncType enumSyncType, int category_id, NBTTagCompound compound) {
switch (enumSyncType){
case FACTION: {
Faction faction = new Faction();
faction.readNBT(compound);
FactionController.getInstance().factions.put(faction.id, faction);
break;
}
case DIALOG: {
DialogCategory category = DialogController.Instance.categories.get(category_id);
Dialog dialog = new Dialog();
dialog.category = category;
dialog.readNBT(compound);
DialogController.Instance.dialogs.put(dialog.id, dialog);
category.dialogs.put(dialog.id, dialog);
break;
}
case QUEST: {
QuestCategory category = QuestController.Instance.categories.get(category_id);
Quest quest = new Quest();
quest.category = category;
quest.readNBT(compound);
QuestController.Instance.quests.put(quest.id, quest);
category.quests.put(quest.id, quest);
break;
}
case QUEST_CATEGORY: {
QuestCategory category = new QuestCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
category = QuestController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Quest quest = new Quest();
quest.readNBT(list.getCompoundTagAt(i));
quest.category = category;
category.quests.put(quest.id, quest);
}
QuestController.Instance.categories.put(category.id, category);
break;
}
case DIALOG_CATEGORY: {
DialogCategory category = new DialogCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
category = DialogController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Dialog dialog = new Dialog();
dialog.readNBT(list.getCompoundTagAt(i));
dialog.category = category;
category.dialogs.put(dialog.id, dialog);
}
DialogController.Instance.categories.put(category.id, category);
break;
}
case PLAYERDATA: {
ClientCacheHandler.playerData.setSyncNBT(compound);
break;
}
case CUSTOM_EFFECTS: {
CustomEffect effect = new CustomEffect();
effect.readFromNBT(compound);
ClientCacheHandler.getImageData(effect.icon);
CustomEffectController.Instance.customEffects.put(effect.id, effect);
break;
}
}
}
public static void syncUpdate(EnumSyncType type, int cat, NBTTagCompound compound) {
PacketHandler.Instance.sendToAll(new SyncPacket(
type,
EnumSyncAction.UPDATE,
cat,
compound
));
}
public static NBTTagCompound updateQuestCat(QuestCategory questCategory) {
NBTTagCompound questCompound = new NBTTagCompound();
NBTTagList questList = new NBTTagList();
for(int questID : questCategory.quests.keySet()){
Quest quest = questCategory.quests.get(questID);
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
}
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
return questCompound;
}
public static NBTTagCompound updateDialogCat(DialogCategory dialogCategory) {
NBTTagCompound dialogCompound = new NBTTagCompound();
NBTTagList dialogList = new NBTTagList();
for(int questID : dialogCategory.dialogs.keySet()){
Dialog dialog = dialogCategory.dialogs.get(questID);
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
}
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
return dialogCompound;
}
@SideOnly(Side.CLIENT)
public static void clientSyncRemove(EnumSyncType enumSyncType, int id) {
switch (enumSyncType){
case FACTION:
FactionController.getInstance().factions.remove(id);
break;
case DIALOG:
Dialog dialog = DialogController.Instance.dialogs.remove(id);
if(dialog != null) {
dialog.category.dialogs.remove(id);
}
break;
case DIALOG_CATEGORY:
DialogCategory dialogCategory = DialogController.Instance.categories.remove(id);
if(dialogCategory != null) {
DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.dialogs.keySet());
}
break;
case QUEST:
Quest quest = QuestController.Instance.quests.remove(id);
if(quest != null) {
quest.category.quests.remove(id);
}
break;
case QUEST_CATEGORY:
QuestCategory questCategory = QuestController.Instance.categories.remove(id);
if(questCategory != null) {
QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet());
}
break;
case MAGIC:
break;
case CUSTOM_EFFECTS:
CustomEffectController.Instance.customEffects.remove(id);
break;
}
}
public static void syncEffects(EntityPlayerMP playerMP){
ConcurrentHashMap<EffectKey, PlayerEffect> playerEffects = CustomEffectController.getInstance().getPlayerEffects(playerMP);
PlayerData playerData = PlayerData.get(playerMP);
playerData.effectData.setEffects(playerEffects);
NBTTagCompound compound = playerData.getPlayerEffects();
PacketHandler.Instance.sendToPlayer(new SyncEffectPacket(compound), playerMP);
}
@SideOnly(Side.CLIENT)
public static void clientSyncEffects(NBTTagCompound compound) {
PlayerData playerData = PlayerData.get(Minecraft.getMinecraft().thePlayer);
if(playerData != null){
playerData.setPlayerEffects(compound);
}
}
}
@@ -0,0 +1,39 @@
package kamkeel.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.data.PlayerData;
public class CNPCData implements IProfileData {
@Override
public String getTagName() {
return "CustomNPC+";
}
@Override
public NBTTagCompound getCurrentNBT(EntityPlayer player) {
PlayerData customNPCData = PlayerData.get(player);
return customNPCData.getNBT();
}
@Override
public void save(EntityPlayer player) {
PlayerData customNPCData = PlayerData.get(player);
customNPCData.save();
}
@Override
public void setNBT(EntityPlayer player, NBTTagCompound replace) {
PlayerData customNPCData = PlayerData.get(player);
if(replace.hasNoTags()){
PlayerData newData = new PlayerData();
newData.player = player;
customNPCData.setNBT((NBTTagCompound) newData.getNBT().copy());
}
else {
customNPCData.setNBT(replace);
}
customNPCData.updateClient = true;
}
}
@@ -0,0 +1,29 @@
package kamkeel.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
public interface IProfileData {
/**
* Do not use the tag: - Name, lastLoaded, ID
*
* @return The Save Tag utilized in the Profile
*/
public String getTagName();
/**
* @return NBTTagCompound of their Current Data for a given Entity Player
*/
public NBTTagCompound getCurrentNBT(EntityPlayer player);
/**
* Called immediately after setNBT() Replaces existing NBT
*/
public void save(EntityPlayer player);
/**
* Replaces their Current Data operation when changing Profiles
*/
public void setNBT(EntityPlayer player, NBTTagCompound replace);
}
@@ -0,0 +1,57 @@
package kamkeel.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import java.util.HashMap;
import java.util.Set;
public class Profile {
public EntityPlayer player;
public int currentID;
public HashMap<Integer, Slot> slots = new HashMap<>();
public Profile(EntityPlayer player, NBTTagCompound compound){
this.player = player;
if(compound.hasKey("CurrentID")){
this.currentID = compound.getInteger("CurrentID");
} else {
this.currentID = 1;
}
if (compound.hasKey("Slots")) {
// Load Slots
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
for (String key : (Set<String>) slotsCompound.func_150296_c()) {
int slotID = Integer.parseInt(key);
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
Slot slot = Slot.fromNBT(slotID, slotNBT);
slots.put(slotID, slot);
}
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound fullCompound = new NBTTagCompound();
if(this.player != null)
fullCompound.setString("Name", player.getCommandSenderName());
fullCompound.setInteger("CurrentID", currentID);
if(!slots.isEmpty()){
NBTTagCompound slotsCompound = new NBTTagCompound();
for (HashMap.Entry<Integer, Slot> entry : slots.entrySet()) {
int id = entry.getKey();
Slot slot = entry.getValue();
slot.setId(id);
NBTTagCompound slotTag = slot.toNBT();
slotsCompound.setTag(String.valueOf(id), slotTag);
}
fullCompound.setTag("Slots", slotsCompound);
}
return fullCompound;
}
}
@@ -0,0 +1,70 @@
package kamkeel.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
public class Slot {
private int id;
private String name;
private long lastLoaded;
private NBTTagCompound compound;
public Slot(int id, String name) {
this.id = id;
this.name = name;
}
public Slot(int id, String name, NBTTagCompound compound, long last) {
this.id = id;
this.name = name;
this.compound = compound;
this.lastLoaded = last;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getLastLoaded() {
return lastLoaded;
}
public void setLastLoaded(long lastLoaded) {
this.lastLoaded = lastLoaded;
}
public NBTTagCompound getCompound() {
return compound;
}
public void setCompound(NBTTagCompound compound) {
this.compound = compound;
}
public NBTTagCompound toNBT() {
NBTTagCompound slotNBT = new NBTTagCompound();
slotNBT.setString("Name", name);
slotNBT.setLong("LastLoaded", lastLoaded);
slotNBT.setTag("Data", compound);
return slotNBT;
}
public static Slot fromNBT(int id, NBTTagCompound slotNBT) {
String name = slotNBT.getString("Name");
long lastLoaded = slotNBT.getLong("LastLoaded");
NBTTagCompound compound = slotNBT.getCompoundTag("Data");
return new Slot(id, name, compound, lastLoaded);
}
}
@@ -1,4 +1,4 @@
package kamkeel.developer;
package kamkeel.npcs.developer;
import java.util.HashSet;
import java.util.UUID;
@@ -0,0 +1,61 @@
package kamkeel.npcs.network;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public abstract class AbstractPacket {
public EntityNPCInterface npc;
public FMLProxyPacket generatePacket() {
PacketChannel packetChannel = getChannel();
ByteBuf buf = Unpooled.buffer();
try {
buf.writeInt(packetChannel.getChannelType().ordinal());
buf.writeInt(getType().ordinal());
sendData(buf);
return new FMLProxyPacket(buf, packetChannel.getChannelName());
} catch (Exception e) {
// For debugging, you might want to log it
e.printStackTrace();
}
return null;
}
public List<FMLProxyPacket> generatePackets() {
FMLProxyPacket single = generatePacket();
if (single == null) {
return Collections.emptyList();
}
return Collections.singletonList(single);
}
public abstract Enum getType();
public abstract PacketChannel getChannel();
public CustomNpcsPermissions.Permission getPermission(){
return null;
}
public boolean needsNPC(){
return false;
}
public void setNPC(EntityNPCInterface npc){
this.npc = npc;
}
public abstract void sendData(ByteBuf out) throws IOException;
//"player" on the server side is the client who sent this packet
//"player" on the client side is the client player
public abstract void receiveData(ByteBuf in, EntityPlayer player) throws IOException;
}
@@ -0,0 +1,162 @@
package kamkeel.npcs.network;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.LogWriter;
import org.lwjgl.Sys;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public abstract class LargeAbstractPacket extends AbstractPacket {
private static final Map<UUID, PacketStorage> packetChunks = new ConcurrentHashMap<>();
private static final int CHUNK_SIZE = 10000;
/**
* Create multiple FMLProxyPacket objects, each containing up to CHUNK_SIZE bytes.
*/
@Override
public List<FMLProxyPacket> generatePackets() {
List<FMLProxyPacket> packets = new ArrayList<>();
PacketChannel packetChannel = getChannel();
byte[] fullData;
try {
fullData = getData();
} catch (IOException e) {
e.printStackTrace();
return packets;
}
int totalSize = fullData.length;
UUID packetId = UUID.randomUUID();
// Break data into CHUNK_SIZE chunks
for (int offset = 0; offset < totalSize; offset += CHUNK_SIZE) {
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
ByteBuf chunkBuf = Unpooled.buffer();
chunkBuf.writeInt(packetChannel.getChannelType().ordinal());
chunkBuf.writeInt(getType().ordinal());
chunkBuf.writeLong(packetId.getMostSignificantBits());
chunkBuf.writeLong(packetId.getLeastSignificantBits());
chunkBuf.writeInt(totalSize);
chunkBuf.writeInt(offset);
chunkBuf.writeInt((totalSize + CHUNK_SIZE - 1) / CHUNK_SIZE);
chunkBuf.writeBytes(fullData, offset, chunkSize);
FMLProxyPacket proxyPacket = new FMLProxyPacket(chunkBuf, packetChannel.getChannelName());
packets.add(proxyPacket);
}
return packets;
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
UUID packetId = null;
PacketStorage storage = null;
ByteBuf chunk = null;
ByteBuf completeData = null;
try {
// Read UUID from the buffer
long mostSigBits = in.readLong();
long leastSigBits = in.readLong();
packetId = new UUID(mostSigBits, leastSigBits);
// Read packet metadata
int totalSize = in.readInt();
int offset = in.readInt();
int totalChunks = in.readInt(); // Debugging info
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
// Basic validation to ensure the chunk won't overwrite out of bounds
if (chunkSize <= 0 || offset < 0 || (offset + chunkSize) > totalSize) {
throw new IndexOutOfBoundsException("Invalid chunk size/offset: chunkSize="
+ chunkSize + ", offset=" + offset + ", totalSize=" + totalSize);
}
// Read the exact chunk data
chunk = in.readBytes(chunkSize);
// Store the received chunk in a PacketStorage
storage = packetChunks.computeIfAbsent(packetId, k -> new PacketStorage(Unpooled.buffer(totalSize), 0, totalSize));
// Write this chunk into the buffer at the correct offset
storage.data.setBytes(offset, chunk);
storage.receivedSoFar += chunkSize;
// If we've received all bytes, finalize
if (storage.receivedSoFar >= totalSize) {
packetChunks.remove(packetId);
completeData = storage.data.copy(0, totalSize);
try {
handleCompleteData(completeData, player);
} finally {
completeData.release();
}
storage.data.release();
}
} catch (Exception e) {
// Log the exception with contextual information
LogWriter.error("Error in receiveData for packetId " + (packetId != null ? packetId.toString() : "null") + ": " + e.getMessage());
e.printStackTrace();
// If storage was created but the packet is incomplete, release storage.data
if (storage != null && storage.receivedSoFar < storage.totalSize) {
storage.data.release();
if (packetId != null) {
packetChunks.remove(packetId);
}
}
throw e; // Rethrow the exception after logging
} finally {
// Ensure that 'chunk' is released if it was allocated
if (chunk != null && chunk.refCnt() > 0) {
chunk.release();
}
// Ensure that 'completeData' is released if it was created and not yet released
if (completeData != null && completeData.refCnt() > 0) {
completeData.release();
}
}
}
protected abstract byte[] getData() throws IOException;
protected abstract void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException;
@Override
public final FMLProxyPacket generatePacket() {return null;}
@Override
public void sendData(ByteBuf out) throws IOException {}
/**
* Simple storage class to keep track of partial data and how many bytes we've received so far.
*/
private static class PacketStorage {
final ByteBuf data;
int receivedSoFar;
final int totalSize;
PacketStorage(ByteBuf data, int receivedSoFar, int totalSize) {
this.data = data;
this.receivedSoFar = receivedSoFar;
this.totalSize = totalSize;
}
}
}
@@ -0,0 +1,43 @@
package kamkeel.npcs.network;
import kamkeel.npcs.network.enums.EnumChannelType;
import java.util.Hashtable;
import java.util.Map;
public class PacketChannel {
private String channelName;
private EnumChannelType channelType;
public Map<Integer, AbstractPacket> packets = new Hashtable<>();
public PacketChannel(String channelName, EnumChannelType channelType) {
this.channelName = channelName;
this.channelType = channelType;
}
public String getChannelName() {
return channelName;
}
public void setChannelName(String channelName) {
this.channelName = channelName;
}
public EnumChannelType getChannelType() {
return channelType;
}
public void setChannelType(EnumChannelType channelType) {
this.channelType = channelType;
}
public void registerPacket(AbstractPacket packet) {
if(packets.containsKey(packet.getType().ordinal())){
System.out.println("Packet ID: " + packet.getType().ordinal() + " is already registered in " + this.channelName);
return;
}
this.packets.put(packet.getType().ordinal(), packet);
}
}
@@ -0,0 +1,8 @@
package kamkeel.npcs.network;
public class PacketClient extends PacketHandler {
public static void sendClient(AbstractPacket packet){
PacketHandler.Instance.sendToServer(packet);
}
}
@@ -0,0 +1,554 @@
package kamkeel.npcs.network;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.enums.EnumChannelType;
import kamkeel.npcs.network.packets.data.*;
import kamkeel.npcs.network.packets.data.gui.*;
import kamkeel.npcs.network.packets.data.gui.IsGuiOpenPacket;
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.player.*;
import kamkeel.npcs.network.packets.request.*;
import kamkeel.npcs.network.packets.request.animation.*;
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.*;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiButtonPacket;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiClosePacket;
import kamkeel.npcs.network.packets.request.customgui.CustomGuiUnfocusedPacket;
import kamkeel.npcs.network.packets.request.customgui.CustomScrollClickPacket;
import kamkeel.npcs.network.packets.request.dialog.*;
import kamkeel.npcs.network.packets.request.effects.EffectGetPacket;
import kamkeel.npcs.network.packets.request.effects.EffectRemovePacket;
import kamkeel.npcs.network.packets.request.effects.EffectSavePacket;
import kamkeel.npcs.network.packets.request.effects.EffectsGetPacket;
import kamkeel.npcs.network.packets.request.faction.*;
import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket;
import kamkeel.npcs.network.packets.request.jobs.JobGetPacket;
import kamkeel.npcs.network.packets.request.jobs.JobSavePacket;
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket;
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerRemovePacket;
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 kamkeel.npcs.network.packets.request.mainmenu.*;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetAllPacket;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetPacket;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnRemovePacket;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnSavePacket;
import kamkeel.npcs.network.packets.request.npc.*;
import kamkeel.npcs.network.packets.request.party.*;
import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket;
import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket;
import kamkeel.npcs.network.packets.request.quest.*;
import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket;
import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket;
import kamkeel.npcs.network.packets.request.recipe.RecipeSavePacket;
import kamkeel.npcs.network.packets.request.recipe.RecipesGetPacket;
import kamkeel.npcs.network.packets.request.role.RoleCompanionUpdatePacket;
import kamkeel.npcs.network.packets.request.role.RoleGetPacket;
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
import kamkeel.npcs.network.packets.request.script.*;
import kamkeel.npcs.network.packets.request.script.item.ItemScriptErrorPacket;
import kamkeel.npcs.network.packets.request.script.item.ItemScriptPacket;
import kamkeel.npcs.network.packets.request.tags.*;
import kamkeel.npcs.network.packets.request.transform.TransformGetPacket;
import kamkeel.npcs.network.packets.request.transform.TransformLoadPacket;
import kamkeel.npcs.network.packets.request.transform.TransformSavePacket;
import kamkeel.npcs.network.packets.request.transport.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
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 class PacketHandler {
public static PacketHandler Instance;
// Channels
public Map<EnumChannelType, FMLEventChannel> channels = new Hashtable<>();
// Client to Server
public static final PacketChannel REQUEST_PACKET = new PacketChannel("CNPC+|Req", EnumChannelType.REQUEST);
// Client to Server - Typically information
public static final PacketChannel PLAYER_PACKET = new PacketChannel("CNPC+|Player", EnumChannelType.PLAYER);
// Server to Client
public static final PacketChannel DATA_PACKET = new PacketChannel("CNPC+|Data", EnumChannelType.DATA);
public static final List<PacketChannel> packetChannels = new ArrayList<>();
public PacketHandler() {
// Register Channels
packetChannels.add(REQUEST_PACKET);
packetChannels.add(PLAYER_PACKET);
packetChannels.add(DATA_PACKET);
this.registerDataPackets();
this.registerRequestPackets();
this.registerPlayerPackets();
}
public void registerRequestPackets(){
// NPC Packets
REQUEST_PACKET.registerPacket(new NpcClosePacket());
REQUEST_PACKET.registerPacket(new NpcDeletePacket());
// Script Packets
REQUEST_PACKET.registerPacket(new BlockScriptPacket());
REQUEST_PACKET.registerPacket(new EventScriptPacket());
REQUEST_PACKET.registerPacket(new ForgeScriptPacket());
REQUEST_PACKET.registerPacket(new GlobalNPCScriptPacket());
REQUEST_PACKET.registerPacket(new ItemScriptPacket());
REQUEST_PACKET.registerPacket(new ItemScriptErrorPacket());
REQUEST_PACKET.registerPacket(new NPCScriptPacket());
REQUEST_PACKET.registerPacket(new PlayerScriptPacket());
REQUEST_PACKET.registerPacket(new ScriptInfoPacket());
REQUEST_PACKET.registerPacket(new EffectScriptPacket());
// Cloner Packets
REQUEST_PACKET.registerPacket(new CloneListPacket());
REQUEST_PACKET.registerPacket(new SpawnMobPacket());
REQUEST_PACKET.registerPacket(new MobSpawnerPacket());
REQUEST_PACKET.registerPacket(new ClonePreSavePacket());
REQUEST_PACKET.registerPacket(new CloneSavePacket());
REQUEST_PACKET.registerPacket(new CloneRemovePacket());
REQUEST_PACKET.registerPacket(new CloneTagListPacket());
REQUEST_PACKET.registerPacket(new CloneAllTagsPacket());
REQUEST_PACKET.registerPacket(new CloneAllTagsShortPacket());
// Linked Packets
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
REQUEST_PACKET.registerPacket(new LinkedSetPacket());
REQUEST_PACKET.registerPacket(new LinkedAddPacket());
// Bank Packets
REQUEST_PACKET.registerPacket(new BanksGetPacket());
REQUEST_PACKET.registerPacket(new BankGetPacket());
REQUEST_PACKET.registerPacket(new BankRemovePacket());
REQUEST_PACKET.registerPacket(new BankSavePacket());
// Recipe Packets
REQUEST_PACKET.registerPacket(new RecipesGetPacket());
REQUEST_PACKET.registerPacket(new RecipeGetPacket());
REQUEST_PACKET.registerPacket(new RecipeRemovePacket());
REQUEST_PACKET.registerPacket(new RecipeSavePacket());
// Natural Spawn Packets
REQUEST_PACKET.registerPacket(new NaturalSpawnGetAllPacket());
REQUEST_PACKET.registerPacket(new NaturalSpawnGetPacket());
REQUEST_PACKET.registerPacket(new NaturalSpawnSavePacket());
REQUEST_PACKET.registerPacket(new NaturalSpawnRemovePacket());
// Dialog Category Packets
REQUEST_PACKET.registerPacket(new DialogCategorySavePacket());
REQUEST_PACKET.registerPacket(new DialogCategoryRemovePacket());
REQUEST_PACKET.registerPacket(new DialogCategoryGetPacket());
REQUEST_PACKET.registerPacket(new DialogCategoriesGetPacket());
// Dialog Packets
REQUEST_PACKET.registerPacket(new DialogSavePacket());
REQUEST_PACKET.registerPacket(new DialogRemovePacket());
REQUEST_PACKET.registerPacket(new DialogsGetPacket());
REQUEST_PACKET.registerPacket(new DialogGetPacket());
REQUEST_PACKET.registerPacket(new DialogNpcGetPacket());
REQUEST_PACKET.registerPacket(new DialogNpcSetPacket());
REQUEST_PACKET.registerPacket(new DialogNpcRemovePacket());
// Quest Category Packets
REQUEST_PACKET.registerPacket(new QuestCategorySavePacket());
REQUEST_PACKET.registerPacket(new QuestCategoryRemovePacket());
REQUEST_PACKET.registerPacket(new QuestCategoryGetPacket());
REQUEST_PACKET.registerPacket(new QuestCategoriesGetPacket());
// Quest Packets
REQUEST_PACKET.registerPacket(new QuestOpenGuiPacket());
REQUEST_PACKET.registerPacket(new QuestSavePacket());
REQUEST_PACKET.registerPacket(new QuestRemovePacket());
REQUEST_PACKET.registerPacket(new QuestDialogGetTitlePacket());
REQUEST_PACKET.registerPacket(new QuestLogToServerPacket());
REQUEST_PACKET.registerPacket(new QuestUntrackPacket());
REQUEST_PACKET.registerPacket(new QuestGetPacket());
REQUEST_PACKET.registerPacket(new QuestsGetPacket());
// Faction Packets
REQUEST_PACKET.registerPacket(new FactionSavePacket());
REQUEST_PACKET.registerPacket(new FactionRemovePacket());
REQUEST_PACKET.registerPacket(new FactionSetPacket());
REQUEST_PACKET.registerPacket(new FactionGetPacket());
REQUEST_PACKET.registerPacket(new FactionsGetPacket());
// Tag Packets
REQUEST_PACKET.registerPacket(new TagsGetPacket());
REQUEST_PACKET.registerPacket(new TagGetPacket());
REQUEST_PACKET.registerPacket(new TagsNpcGetPacket());
REQUEST_PACKET.registerPacket(new TagSetPacket());
REQUEST_PACKET.registerPacket(new TagSavePacket());
REQUEST_PACKET.registerPacket(new TagRemovePacket());
// PlayerData Packets
REQUEST_PACKET.registerPacket(new PlayerDataGetPacket());
REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket());
REQUEST_PACKET.registerPacket(new PlayerDataMapRegenPacket());
// Main Menu Packets
REQUEST_PACKET.registerPacket(new MainmenuDisplayGetPacket());
REQUEST_PACKET.registerPacket(new MainmenuDisplaySavePacket());
REQUEST_PACKET.registerPacket(new MainmenuStatsGetPacket());
REQUEST_PACKET.registerPacket(new MainmenuStatsSavePacket());
REQUEST_PACKET.registerPacket(new MainmenuAIGetPacket());
REQUEST_PACKET.registerPacket(new MainmenuAISavePacket());
REQUEST_PACKET.registerPacket(new MainmenuAdvancedGetPacket());
REQUEST_PACKET.registerPacket(new MainmenuAdvancedSavePacket());
REQUEST_PACKET.registerPacket(new MainmenuAdvancedMarkDataPacket());
REQUEST_PACKET.registerPacket(new MainmenuInvGetPacket());
REQUEST_PACKET.registerPacket(new MainmenuInvSavePacket());
// Transport Packets
REQUEST_PACKET.registerPacket(new TransportCategoriesGetPacket());
REQUEST_PACKET.registerPacket(new TransportCategorySavePacket());
REQUEST_PACKET.registerPacket(new TransportCategoryRemovePacket());
REQUEST_PACKET.registerPacket(new TransportRemovePacket());
REQUEST_PACKET.registerPacket(new TransportsGetPacket());
REQUEST_PACKET.registerPacket(new TransportSavePacket());
REQUEST_PACKET.registerPacket(new TransportGetLocationPacket());
// Remote Packets Packets
REQUEST_PACKET.registerPacket(new RemoteMainMenuPacket());
REQUEST_PACKET.registerPacket(new RemoteGlobalMenuPacket());
REQUEST_PACKET.registerPacket(new RemoteDeletePacket());
REQUEST_PACKET.registerPacket(new RemoteNpcsGetPacket());
REQUEST_PACKET.registerPacket(new RemoteFreezeGetPacket());
REQUEST_PACKET.registerPacket(new RemoteFreezePacket());
REQUEST_PACKET.registerPacket(new RemoteResetPacket());
REQUEST_PACKET.registerPacket(new RemoteTpToNpcPacket());
// CustomGUI Packets
REQUEST_PACKET.registerPacket(new CustomGuiButtonPacket());
REQUEST_PACKET.registerPacket(new CustomGuiClosePacket());
REQUEST_PACKET.registerPacket(new CustomGuiUnfocusedPacket());
REQUEST_PACKET.registerPacket(new CustomScrollClickPacket());
// Job Packets
REQUEST_PACKET.registerPacket(new JobGetPacket());
REQUEST_PACKET.registerPacket(new JobSavePacket());
REQUEST_PACKET.registerPacket(new JobSpawnerAddPacket());
REQUEST_PACKET.registerPacket(new JobSpawnerRemovePacket());
// Role Packets
REQUEST_PACKET.registerPacket(new RoleCompanionUpdatePacket());
REQUEST_PACKET.registerPacket(new RoleSavePacket());
REQUEST_PACKET.registerPacket(new RoleGetPacket());
// Transform Packets
REQUEST_PACKET.registerPacket(new TransformSavePacket());
REQUEST_PACKET.registerPacket(new TransformGetPacket());
REQUEST_PACKET.registerPacket(new TransformLoadPacket());
// Trader Packets
REQUEST_PACKET.registerPacket(new TraderMarketSavePacket());
// Party Packets
REQUEST_PACKET.registerPacket(new PartySavePacket());
REQUEST_PACKET.registerPacket(new PartyInfoPacket());
REQUEST_PACKET.registerPacket(new PartyDisbandPacket());
REQUEST_PACKET.registerPacket(new PartySetLeaderPacket());
REQUEST_PACKET.registerPacket(new PartyKickPacket());
REQUEST_PACKET.registerPacket(new PartyLeavePacket());
REQUEST_PACKET.registerPacket(new PartySetQuestPacket());
REQUEST_PACKET.registerPacket(new PartyInvitePacket());
REQUEST_PACKET.registerPacket(new PartyAcceptInvitePacket());
REQUEST_PACKET.registerPacket(new PartyIgnoreInvitePacket());
REQUEST_PACKET.registerPacket(new PartyLogToServerPacket());
// Animation Packets
REQUEST_PACKET.registerPacket(new AnimationsGetPacket());
REQUEST_PACKET.registerPacket(new AnimationGetPacket());
REQUEST_PACKET.registerPacket(new AnimationRemovePacket());
REQUEST_PACKET.registerPacket(new AnimationSavePacket());
REQUEST_PACKET.registerPacket(new AnimationCachePacket());
// Moving Path
REQUEST_PACKET.registerPacket(new MovingPathSavePacket());
REQUEST_PACKET.registerPacket(new MovingPathGetPacket());
// Custom Effect Packets
REQUEST_PACKET.registerPacket(new EffectGetPacket());
REQUEST_PACKET.registerPacket(new EffectsGetPacket());
REQUEST_PACKET.registerPacket(new EffectSavePacket());
REQUEST_PACKET.registerPacket(new EffectRemovePacket());
// Other Packets
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
REQUEST_PACKET.registerPacket(new DimensionsGetPacket());
REQUEST_PACKET.registerPacket(new MerchantUpdatePacket());
REQUEST_PACKET.registerPacket(new ModelDataSavePacket());
REQUEST_PACKET.registerPacket(new MailOpenSetupPacket());
REQUEST_PACKET.registerPacket(new TileEntityGetPacket());
REQUEST_PACKET.registerPacket(new TileEntitySavePacket());
REQUEST_PACKET.registerPacket(new MountPacket());
REQUEST_PACKET.registerPacket(new DimensionTeleportPacket());
}
public void registerDataPackets(){
// Data Packets
DATA_PACKET.registerPacket(new AchievementPacket());
DATA_PACKET.registerPacket(new ChatAlertPacket());
DATA_PACKET.registerPacket(new ChatBubblePacket());
DATA_PACKET.registerPacket(new ConfigCommandPacket());
DATA_PACKET.registerPacket(new DisableMouseInputPacket());
DATA_PACKET.registerPacket(new MarkDataPacket());
DATA_PACKET.registerPacket(new OverlayQuestTrackingPacket());
DATA_PACKET.registerPacket(new ParticlePacket());
DATA_PACKET.registerPacket(new PlayerUpdateSkinOverlaysPacket());
DATA_PACKET.registerPacket(new QuestCompletionPacket());
DATA_PACKET.registerPacket(new ScrollSelectedPacket());
DATA_PACKET.registerPacket(new SoundManagementPacket());
DATA_PACKET.registerPacket(new SwingPlayerArmPacket());
DATA_PACKET.registerPacket(new UpdateAnimationsPacket());
DATA_PACKET.registerPacket(new VillagerListPacket());
// Data | GUI Packets
DATA_PACKET.registerPacket(new GuiClosePacket());
DATA_PACKET.registerPacket(new GuiOpenPacket());
DATA_PACKET.registerPacket(new GuiErrorPacket());
DATA_PACKET.registerPacket(new GuiRedstonePacket());
DATA_PACKET.registerPacket(new GuiTeleporterPacket());
DATA_PACKET.registerPacket(new GuiWaypointPacket());
DATA_PACKET.registerPacket(new IsGuiOpenPacket());
DATA_PACKET.registerPacket(new GuiOpenBookPacket());
// Data | NPC Packets
DATA_PACKET.registerPacket(new DeleteNpcPacket());
DATA_PACKET.registerPacket(new EditNpcPacket());
DATA_PACKET.registerPacket(new UpdateNpcPacket());
DATA_PACKET.registerPacket(new DialogPacket());
DATA_PACKET.registerPacket(new RolePacket());
DATA_PACKET.registerPacket(new WeaponNpcPacket());
// Data | Script Packets
DATA_PACKET.registerPacket(new ScriptedParticlePacket());
DATA_PACKET.registerPacket(new ScriptOverlayClosePacket());
DATA_PACKET.registerPacket(new ScriptOverlayDataPacket());
// Data | Large Packets
DATA_PACKET.registerPacket(new ClonerPacket());
DATA_PACKET.registerPacket(new ScrollGroupPacket());
DATA_PACKET.registerPacket(new ScrollDataPacket());
DATA_PACKET.registerPacket(new ScrollListPacket());
DATA_PACKET.registerPacket(new SyncPacket());
DATA_PACKET.registerPacket(new SyncEffectPacket());
DATA_PACKET.registerPacket(new GuiDataPacket());
DATA_PACKET.registerPacket(new PartyDataPacket());
}
public void registerPlayerPackets() {
PLAYER_PACKET.registerPacket(new FollowerPacket());
PLAYER_PACKET.registerPacket(new TransportPacket());
PLAYER_PACKET.registerPacket(new BankActionPacket());
PLAYER_PACKET.registerPacket(new DialogSelectPacket());
PLAYER_PACKET.registerPacket(new CheckPlayerValue());
PLAYER_PACKET.registerPacket(new MailActionPacket());
PLAYER_PACKET.registerPacket(new MailActionPacket.MailSendPacket());
PLAYER_PACKET.registerPacket(new SaveSignPacket());
PLAYER_PACKET.registerPacket(new SaveBookPacket());
PLAYER_PACKET.registerPacket(new CompanionActionPacket());
PLAYER_PACKET.registerPacket(new GetNPCRole());
PLAYER_PACKET.registerPacket(new InputDevicePacket());
PLAYER_PACKET.registerPacket(new ScreenSizePacket());
}
public void registerChannels() {
for (PacketChannel channel : packetChannels) {
FMLEventChannel eventChannel =
NetworkRegistry.INSTANCE.newEventDrivenChannel(channel.getChannelName());
eventChannel.register(this);
channels.put(channel.getChannelType(), eventChannel);
}
}
public PacketChannel getPacketChannel(EnumChannelType type) {
return packetChannels.stream()
.filter(channel -> channel.getChannelType() == type)
.findFirst()
.orElse(null);
}
public FMLEventChannel getEventChannel(AbstractPacket abstractPacket){
PacketChannel packetChannel = getPacketChannel(abstractPacket.getChannel().getChannelType());
if (packetChannel == null) {
return null;
}
return channels.get(packetChannel.getChannelType());
}
@SubscribeEvent
public void onServerPacket(FMLNetworkEvent.ServerCustomPacketEvent event) {
handlePacket(event.packet, ((NetHandlerPlayServer) event.handler).playerEntity, Side.SERVER);
}
@SubscribeEvent
public void onClientPacket(FMLNetworkEvent.ClientCustomPacketEvent event) {
handlePacket(event.packet, CustomNpcs.proxy.getPlayer(), Side.CLIENT);
}
private void handlePacket(FMLProxyPacket packet, EntityPlayer player, Side side) {
ByteBuf buf = packet.payload();
try {
int packetTypeOrdinal = buf.readInt();
EnumChannelType packetType = EnumChannelType.values()[packetTypeOrdinal];
PacketChannel packetChannel = getPacketChannel(packetType);
if (packetChannel == null) {
LogWriter.error("Error: Packet channel is null for packet type: " + packetType);
return;
}
int packetId = buf.readInt();
AbstractPacket abstractPacket = packetChannel.packets.get(packetId);
if (abstractPacket == null) {
LogWriter.error("Error: Abstract packet is null for packet ID: " + packetId);
return;
}
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;
}
// Check for required NPC
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(abstractPacket.needsNPC() && npc == null){
return;
}
abstractPacket.setNPC(npc);
}
// Let the packet parse the rest
abstractPacket.receiveData(buf, player);
} catch (IndexOutOfBoundsException e) {
LogWriter.error("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
LogWriter.error("Error: Exception in handlePacket: " + e.getMessage());
e.printStackTrace();
}
}
/**
* Sends every FMLProxyPacket produced by packet.generatePackets()
*/
private void sendAllPackets(AbstractPacket packet, SendAction action) {
// get all generated FMLProxyPacket objects (could be 1 for normal, or many for large)
List<FMLProxyPacket> proxyPackets = packet.generatePackets();
if (proxyPackets.isEmpty()) {
LogWriter.error("Warning: No packets generated for " + packet.getClass().getName());
}
for (FMLProxyPacket proxy : proxyPackets) {
action.send(proxy);
}
}
// ------------------------------------------------------------------------
// Public API methods for sending
public void sendToPlayer(AbstractPacket packet, EntityPlayerMP player) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendAllPackets(packet, p -> eventChannel.sendTo(p, player));
}
public void sendToServer(AbstractPacket packet) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendAllPackets(packet, eventChannel::sendToServer);
}
public void sendToAll(AbstractPacket packet) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendAllPackets(packet, eventChannel::sendToAll);
}
public void sendToDimension(AbstractPacket packet, final int dimensionId) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendAllPackets(packet, p -> eventChannel.sendToDimension(p, dimensionId));
}
public void sendTracking(AbstractPacket packet, final Entity entity) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
final NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
sendAllPackets(packet, p -> eventChannel.sendToAllAround(p, point));
}
// Simple functional interface to unify the "send" action
private interface SendAction {
void send(FMLProxyPacket proxy);
}
}
@@ -0,0 +1,232 @@
package kamkeel.npcs.network;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomItems;
import noppes.npcs.LogWriter;
import noppes.npcs.NBTTags;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.IScriptHandler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
public class PacketUtil {
public static boolean verifyItemPacket(EnumItemPacketType type, EntityPlayer player) {
if (player == null)
return false;
ItemStack item = player.inventory.getCurrentItem();
if (item == null) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without an item, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
switch (type) {
case WAND:
if (item.getItem() != CustomItems.wand) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Wand, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case MOUNTER:
if (item.getItem() != CustomItems.mount) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Mounter, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case CLONER:
if (item.getItem() != CustomItems.cloner) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Cloner, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case TELEPORTER:
if (item.getItem() != CustomItems.teleporter) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Teleporter, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case SCRIPTER:
if (item.getItem() != CustomItems.scripter) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Scripter, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case PATHER:
if (item.getItem() != CustomItems.moving) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case BLOCK:
if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint)
|| item.getItem() == Item.getItemFromBlock(CustomItems.border)
|| item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a valid Block, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
}
return true;
}
/**
* New method that accepts multiple EnumItemPacketTypes.
* It returns true if any one of the provided types is valid.
* If none are valid, a merged error message is logged.
*/
public static boolean verifyItemPacket(EntityPlayer player, EnumItemPacketType... types) {
if (player == null)
return false;
ItemStack item = player.inventory.getCurrentItem();
if (item == null) {
LogWriter.error(String.format("%s attempted to utilize a Packet without an item. Expected one of: %s, they could be a hacker",
player.getCommandSenderName(), getExpectedItemNames(types)));
return false;
}
for (EnumItemPacketType type : types) {
if (isValidItemForType(item, type)) {
return true;
}
}
// None passed; log one merged error message listing all expected items.
LogWriter.error(String.format("%s attempted to utilize a Packet without a valid item. Expected one of: %s, they could be a hacker",
player.getCommandSenderName(), getExpectedItemNames(types)));
return false;
}
private static boolean isValidItemForType(ItemStack item, EnumItemPacketType type) {
if(item == null || item.getItem() == null)
return false;
switch (type) {
case WAND:
return item.getItem() == CustomItems.wand;
case MOUNTER:
return item.getItem() == CustomItems.mount;
case CLONER:
return item.getItem() == CustomItems.cloner;
case TELEPORTER:
return item.getItem() == CustomItems.teleporter;
case SCRIPTER:
return item.getItem() == CustomItems.scripter;
case PATHER:
return item.getItem() == CustomItems.moving;
case BLOCK:
// For BLOCK, the item is valid as long as it is NOT one of these blocks.
return !(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint)
|| item.getItem() == Item.getItemFromBlock(CustomItems.border)
|| item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock));
default:
return false;
}
}
/**
* Builds a comma‐separated list of expected item names for the given types.
*/
private static String getExpectedItemNames(EnumItemPacketType... types) {
Set<String> expectedNames = new LinkedHashSet<>();
for (EnumItemPacketType type : types) {
expectedNames.add(getExpectedItemName(type));
}
return String.join(", ", expectedNames);
}
/**
* Returns the expected item name for the given EnumItemPacketType.
*/
private static String getExpectedItemName(EnumItemPacketType type) {
switch (type) {
case WAND:
return "Wand";
case MOUNTER:
return "Mounter";
case CLONER:
return "Cloner";
case TELEPORTER:
return "Teleporter";
case SCRIPTER:
return "Scripter";
case PATHER:
return "Pather";
case BLOCK:
return "valid Block";
default:
return type.toString();
}
}
public static void getScripts(IScriptHandler data, EntityPlayerMP player) {
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("ScriptEnabled", data.getEnabled());
compound.setString("ScriptLanguage", data.getLanguage());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(data.getConsoleText()));
GuiDataPacket.sendGuiData(player, compound);
List<ScriptContainer> containers = data.getScripts();
for (int i = 0; i < containers.size(); i++) {
ScriptContainer container = containers.get(i);
NBTTagCompound tabCompound = new NBTTagCompound();
tabCompound.setInteger("Tab",i);
tabCompound.setTag("Script",container.writeToNBT(new NBTTagCompound()));
tabCompound.setInteger("TotalScripts",containers.size());
GuiDataPacket.sendGuiData(player, tabCompound);
}
}
public static void saveScripts(IScriptHandler data, ByteBuf buffer) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
data.getScripts().clear();
}
if (tab >= 0) {
if (data.getScripts().size() > totalScripts) {
data.setScripts(data.getScripts().subList(0,totalScripts));
} else while (data.getScripts().size() < totalScripts) {
data.getScripts().add(new ScriptContainer(data));
}
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
ScriptContainer script = new ScriptContainer(data);
script.readFromNBT(tabCompound);
data.getScripts().set(tab,script);
} else {
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
data.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(data.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
data.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
data.setLanguage("ECMAScript");
}
}
data.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
}
@@ -0,0 +1,8 @@
package kamkeel.npcs.network.enums;
public enum EnumChannelType {
REQUEST,
PLAYER,
DATA,
INFO
}
@@ -0,0 +1,5 @@
package kamkeel.npcs.network.enums;
public enum EnumConfigOperation {
FONT,
}
@@ -0,0 +1,60 @@
package kamkeel.npcs.network.enums;
// Packets to the Client
public enum EnumDataPacket {
// Synchronization
SYNC,
SYNC_EFFECTS,
CONFIG_COMMAND,
// Messages
CHAT_ALERT,
ACHIEVEMENT,
CHATBUBBLE,
SOUND,
DIALOG,
QUEST_COMPLETION,
// NPC
EDIT_NPC,
UPDATE_NPC,
ROLE_NPC,
DELETE_NPC,
CLONE_NPC,
WEAPON_NPC,
// Data
SCROLL_LIST,
SCROLL_DATA,
SCROLL_GROUP,
SCROLL_SELECTED,
PARTY_DATA,
// GUI
GUI_OPEN,
GUI_REDSTONE,
GUI_WAYPOINT,
GUI_TELEPORTER,
GUI_BOOK,
GUI_DATA,
GUI_ERROR,
GUI_CLOSE,
ISGUIOPEN,
// Visual
SCRIPTED_PARTICLE,
PARTICLE,
PLAYER_UPDATE_SKIN_OVERLAYS,
UPDATE_ANIMATIONS,
SCRIPT_OVERLAY_DATA,
SCRIPT_OVERLAY_CLOSE,
OVERLAY_QUEST_TRACKING,
MARK_DATA,
// Other
VILLAGER_LIST,
SWING_PLAYER_ARM,
DISABLE_MOUSE_INPUT,
LOGIN,
}
@@ -0,0 +1,11 @@
package kamkeel.npcs.network.enums;
public enum EnumItemPacketType {
WAND,
MOUNTER,
CLONER,
TELEPORTER,
SCRIPTER,
PATHER,
BLOCK
}
@@ -0,0 +1,17 @@
package kamkeel.npcs.network.enums;
public enum EnumPlayerPacket {
FollowerAction,
Transport,
BankAction,
DialogSelect,
GetPlayerValue,
MailBoxAction,
MailSend,
SaveSign,
SaveBook,
CompanionAction,
GetRole,
InputDevice,
ScreenSize
}
@@ -0,0 +1,180 @@
package kamkeel.npcs.network.enums;
public enum EnumRequestPacket {
NPCDelete,
RemoteMainMenu,
RemoteGlobalMenu,
NpcClose,
RemoteDelete,
RemoteFreeze,
RemoteFreezeGet,
RemoteReset,
SpawnMob,
MobSpawner,
DimensionsGet,
MainmenuAISave,
MainmenuAIGet,
MainmenuInvSave,
MainmenuInvGet,
MainmenuStatsSave,
MainmenuStatsGet,
MainmenuDisplaySave,
MainmenuDisplayGet,
ModelDataSave,
MainmenuAdvancedSave,
MainmenuAdvancedGet,
MainmenuAdvancedMarkData,
DialogNpcSet,
DialogNpcRemove,
DialogNpcGet,
DialogCategorySave,
DialogCategoriesGet,
DialogCategoryRemove,
DialogCategoryGet,
DialogSave,
DialogsGet,
DialogGet,
DialogRemove,
TransportSave,
TransportCategoriesGet,
TransportCategorySave,
TransportCategoryRemove,
TransportRemove,
TransportGetLocation,
TransportsGet,
FactionSet,
FactionSave,
FactionsGet,
FactionGet,
FactionRemove,
TagSet,
TagSave,
TagsGet,
TagGet,
NpcTagsGet,
TagRemove,
QuestUntrack,
QuestLogToServer,
QuestCategorySave,
QuestCategoriesGet,
QuestRemove,
QuestCategoryRemove,
QuestRewardSave,
QuestSave,
QuestsGetFromQuest,
QuestsGet,
QuestDialogGetTitle,
QuestOpenGui,
QuestGet,
RecipeSave,
RecipeRemove,
RecipesGet,
RecipeGet,
NaturalSpawnSave,
NaturalSpawnGet,
NaturalSpawnRemove,
NaturalSpawnGetAll,
MerchantUpdate,
MountPacket,
MovingPathSave,
MovingPathGet,
AnimationsGet,
AnimationGet,
AnimationRemove,
AnimationSave,
RemoteNpcsGet,
RemoteTpToNpc,
TileEntitySave,
TileEntityGet,
Gui,
IsGuiOpen,
CacheAnimation,
CustomGuiButton,
CustomGuiScrollClick,
CustomGuiClose,
CustomGuiUnfocused,
PartyLogToServer,
PartySave,
PartyInfo,
PartyDisband,
PartyKick,
PartyLeave,
PartyInvite,
PartyAcceptInvite,
PartyIgnoreInvite,
PartySetLeader,
PartySetQuest,
LinkedRemove,
LinkedAdd,
LinkedGetAll,
LinkedSet,
BankGet,
BanksGet,
BankSave,
BankRemove,
QuestCategoryGet,
PlayerDataGet,
PlayerDataRemove,
PlayerDataMapRegen,
JobSave,
JobGet,
JobSpawnerAdd,
JobSpawnerRemove,
RoleCompanionUpdate,
RoleSave,
RoleGet,
MailOpenSetup,
TransformSave,
TransformGet,
TransformLoad,
TraderMarketSave,
CloneList,
CloneSave,
CloneRemove,
CloneTagList,
CloneAllTags,
CloneAllTagsShort,
ClonePreSave,
EventScript,
PlayerScript,
ForgeScript,
GlobalNPCScript,
ItemScript,
ItemScriptError,
BlockScript,
NPCScript,
ScriptInfo,
EffectScript,
DimensionTeleport,
EffectList,
EffectGet,
EffectScriptGet,
EffectRemove,
EffectSave,
}
@@ -0,0 +1,12 @@
package kamkeel.npcs.network.enums;
public enum EnumSoundOperation {
CONTINUE_SOUNDS,
PAUSE_SOUNDS,
PLAY_MUSIC,
PLAY_SOUND,
PLAY_SOUND_TO,
PLAY_SOUND_TO_NO_ID,
STOP_SOUND_FOR,
STOP_SOUNDS
}
@@ -0,0 +1,7 @@
package kamkeel.npcs.network.enums;
public enum EnumSyncAction {
RELOAD,
UPDATE,
REMOVE
}
@@ -0,0 +1,15 @@
package kamkeel.npcs.network.enums;
public enum EnumSyncType {
FACTION,
DIALOG,
DIALOG_CATEGORY,
QUEST,
QUEST_CATEGORY,
PLAYERDATA,
MAGIC,
WORKBENCH_RECIPES,
CARPENTRY_RECIPES,
ANVIL_RECIPES,
CUSTOM_EFFECTS
}
@@ -0,0 +1,76 @@
package kamkeel.npcs.network.packets.data;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.achievement.GuiAchievement;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.stats.Achievement;
import net.minecraft.util.StatCollector;
import noppes.npcs.CustomItems;
import noppes.npcs.client.MessageAchievement;
import noppes.npcs.config.ConfigClient;
import java.io.IOException;
public final class AchievementPacket extends AbstractPacket {
public static final String packetName = "Data|Achievement";
private boolean isParty;
private String description;
private String message;
public AchievementPacket() {
}
public AchievementPacket(boolean isParty, String description, String message) {
this.isParty = isParty;
this.description = description;
this.message = message;
}
public static void sendAchievement(EntityPlayerMP playerMP, boolean isParty, String description, String message) {
AchievementPacket packet = new AchievementPacket(isParty, description, message);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.ACHIEVEMENT;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeBoolean(this.isParty);
ByteBufUtils.writeString(out, this.description);
ByteBufUtils.writeString(out, this.message);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!ConfigClient.BannerAlerts)
return;
boolean isNotParty = !in.readBoolean();
String description = StatCollector.translateToLocal(ByteBufUtils.readString(in));
String message = ByteBufUtils.readString(in);
Achievement ach = isNotParty ? new MessageAchievement(message, description) : new MessageAchievement(CustomItems.bag == null ? Items.paper : CustomItems.bag, message, description);
Minecraft.getMinecraft().guiAchievement.func_146256_a(ach);
ObfuscationReflectionHelper.setPrivateValue(GuiAchievement.class, Minecraft.getMinecraft().guiAchievement, ach.getDescription(), 4);
}
}
@@ -0,0 +1,63 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentTranslation;
import noppes.npcs.config.ConfigClient;
import java.io.IOException;
public final class ChatAlertPacket extends AbstractPacket {
public static final String packetName = "Data|ChatAlert";
private Object[] objects;
public ChatAlertPacket() {
}
public ChatAlertPacket(final Object... obs) {
this.objects = obs;
}
public static void sendChatAlert(EntityPlayerMP playerMP, final Object... obs) {
ChatAlertPacket packet = new ChatAlertPacket(obs);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.CHAT_ALERT;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.fillBuffer(out, this.objects);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!ConfigClient.ChatAlerts)
return;
StringBuilder message = new StringBuilder();
String str;
while ((str = ByteBufUtils.readString(in)) != null && !str.isEmpty()) {
message.append(str);
}
player.addChatMessage(new ChatComponentTranslation(message.toString()));
}
}
@@ -0,0 +1,70 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.client.RenderChatMessages;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class ChatBubblePacket extends AbstractPacket {
public static final String packetName = "Data|ChatBubble";
private int entityId;
private String text;
private boolean hideText;
public ChatBubblePacket() {
}
public ChatBubblePacket(int entityId, String text, boolean hideText) {
this.entityId = entityId;
this.text = text;
this.hideText = hideText;
}
@Override
public Enum getType() {
return EnumDataPacket.CHATBUBBLE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityId);
ByteBufUtils.writeString(out, this.text);
out.writeBoolean(this.hideText);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(in.readInt());
if (!(entity instanceof EntityNPCInterface))
return;
EntityNPCInterface npc = (EntityNPCInterface) entity;
if (npc.messages == null)
npc.messages = new RenderChatMessages();
String text = NoppesStringUtils.formatText(ByteBufUtils.readString(in), player, npc);
npc.messages.addMessage(text, npc);
if (in.readBoolean())
player.addChatMessage(new ChatComponentTranslation(npc.getCommandSenderName() + ": " + text));
}
}
@@ -0,0 +1,57 @@
package kamkeel.npcs.network.packets.data;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd;
import java.io.IOException;
public final class ClonerPacket extends LargeAbstractPacket {
public static final String packetName = "Data|Clone";
private NBTTagCompound compound;
public ClonerPacket() {
}
public ClonerPacket(NBTTagCompound comp) {
this.compound = comp;
}
@Override
public Enum getType() {
return EnumDataPacket.CLONE_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
ByteBufUtils.writeBigNBT(buffer, compound);
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@SideOnly(Side.CLIENT)
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
NBTTagCompound nbt = ByteBufUtils.readBigNBT(data);
NoppesUtil.openGUI(player, new GuiNpcMobSpawnerAdd(nbt));
}
}
@@ -0,0 +1,78 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumConfigOperation;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import noppes.npcs.client.ClientProxy;
import noppes.npcs.client.ClientProxy.FontContainer;
import noppes.npcs.config.ConfigClient;
import java.io.IOException;
public final class ConfigCommandPacket extends AbstractPacket {
public static final String packetName = "Data|ConfigCommand";
private EnumConfigOperation configOperation;
private Object[] objects;
public ConfigCommandPacket() {
}
public ConfigCommandPacket(EnumConfigOperation operation, Object... obs) {
this.configOperation = operation;
this.objects = obs;
}
@Override
public Enum getType() {
return EnumDataPacket.CONFIG_COMMAND;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.configOperation.ordinal());
ByteBufUtils.fillBuffer(out, objects);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
EnumConfigOperation configType = EnumConfigOperation.values()[in.readInt()];
if (configType == EnumConfigOperation.FONT) { // Font Configuration
String font = ByteBufUtils.readString(in);
if(font == null)
return;
int size = in.readInt();
if (!font.isEmpty()) {
ConfigClient.FontType = font;
ConfigClient.FontSize = size;
ClientProxy.Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
ConfigClient.FontTypeProperty.set(ConfigClient.FontType);
ConfigClient.FontSizeProperty.set(ConfigClient.FontSize);
if (ConfigClient.config.hasChanged()) {
ConfigClient.config.save();
}
player.addChatMessage(new ChatComponentTranslation("Font set to %s", ClientProxy.Font.getName()));
} else {
player.addChatMessage(new ChatComponentTranslation("Current font is %s", ClientProxy.Font.getName()));
}
}
}
}
@@ -0,0 +1,62 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.client.ClientEventHandler;
import java.io.IOException;
public final class DisableMouseInputPacket extends AbstractPacket {
public static final String packetName = "Data|DisableMouseInput";
private long duration;
private String keys;
public DisableMouseInputPacket() {
}
public DisableMouseInputPacket(long duration, String keys) {
this.duration = duration;
this.keys = keys;
}
@Override
public Enum getType() {
return EnumDataPacket.DISABLE_MOUSE_INPUT;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeLong(this.duration);
ByteBufUtils.writeString(out, this.keys);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
long duration = in.readLong();
String parsedButtons = ByteBufUtils.readString(in);
if (parsedButtons == null || parsedButtons.isEmpty()) {
ClientEventHandler.disabledButtonTimes.put(-1, duration);
return;
}
String[] buttonIds = parsedButtons.split(";");
for (String button : buttonIds) {
ClientEventHandler.disabledButtonTimes.put(Integer.parseInt(button), duration);
}
}
}
@@ -0,0 +1,41 @@
package kamkeel.npcs.network.packets.data;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import java.io.IOException;
public final class LoginPacket extends AbstractPacket {
public static final String packetName = "CNPC+|Login";
public LoginPacket() {
}
@Override
public Enum getType() {
return EnumDataPacket.LOGIN;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
// ByteBufUtils.writeUTF8String(out, this.data.player.getCommandSenderName());
// ByteBufUtils.writeNBT(out,this.data.saveFromNBT(new NBTTagCompound()));
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
String playerName = ByteBufUtils.readUTF8String(in);
}
}
@@ -0,0 +1,60 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class MarkDataPacket extends AbstractPacket {
public static final String packetName = "Data|MarkData";
private int entityID;
private NBTTagCompound compound;
public MarkDataPacket() {
}
public MarkDataPacket(int entityID, NBTTagCompound compound) {
this.entityID = entityID;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.MARK_DATA;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityID);
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Entity entity = player.worldObj.getEntityByID(in.readInt());
if (!(entity instanceof EntityNPCInterface)) return;
EntityNPCInterface npc = (EntityNPCInterface) entity;
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
MarkData data = MarkData.get(npc);
data.setNBT(nbt);
}
}
@@ -0,0 +1,57 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.OverlayQuestTracking;
import java.io.IOException;
public final class OverlayQuestTrackingPacket extends AbstractPacket {
public static final String packetName = "Data|OverlayQuestTracking";
private NBTTagCompound compound;
public OverlayQuestTrackingPacket() {
}
public OverlayQuestTrackingPacket(NBTTagCompound compound) {
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.OVERLAY_QUEST_TRACKING;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
try {
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
ClientCacheHandler.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft());
ClientCacheHandler.questTrackingOverlay.setOverlayData(nbt);
} catch (IOException e) {
ClientCacheHandler.questTrackingOverlay = null;
}
}
}
@@ -0,0 +1,95 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import java.io.IOException;
import java.util.Random;
public final class ParticlePacket extends AbstractPacket {
public static final String packetName = "Data|Particle";
private double x;
private double y;
private double z;
private float height;
private float width;
private float yOffset;
private String particle;
public ParticlePacket() {
}
public ParticlePacket(double x, double y, double z, float height, float width, float yOffset, String particle) {
this.x = x;
this.y = y;
this.z = z;
this.height = height;
this.width = width;
this.yOffset = yOffset;
this.particle = particle;
}
@Override
public Enum getType() {
return EnumDataPacket.PARTICLE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeDouble(x);
out.writeDouble(y);
out.writeDouble(z);
out.writeFloat(height);
out.writeFloat(width);
out.writeFloat(yOffset);
ByteBufUtils.writeString(out, particle);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
spawnParticle(in);
}
@SideOnly(Side.CLIENT)
public static void spawnParticle(ByteBuf buffer) throws IOException {
double posX = buffer.readDouble();
double posY = buffer.readDouble();
double posZ = buffer.readDouble();
float height = buffer.readFloat();
float width = buffer.readFloat();
float yOffset = buffer.readFloat();
String particle = ByteBufUtils.readString(buffer);
if(particle != null){
World worldObj = Minecraft.getMinecraft().theWorld;
Random rand = worldObj.rand;
if (particle.equals("heal")) {
for (int k = 0; k < 6; k++) {
worldObj.spawnParticle("instantSpell", posX + (rand.nextDouble() - 0.5D) * (double) width, (posY + rand.nextDouble() * (double) height) - (double) yOffset, posZ + (rand.nextDouble() - 0.5D) * (double) width, 0, 0, 0);
worldObj.spawnParticle("spell", posX + (rand.nextDouble() - 0.5D) * (double) width, (posY + rand.nextDouble() * (double) height) - (double) yOffset, posZ + (rand.nextDouble() - 0.5D) * (double) width, 0, 0, 0);
}
}
}
}
}
@@ -0,0 +1,58 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
public static final String packetName = "Data|PlayerUpdateSkinOverlays";
private String playerName;
private NBTTagCompound compound;
public PlayerUpdateSkinOverlaysPacket() {
}
public PlayerUpdateSkinOverlaysPacket(String playerName, NBTTagCompound compound) {
this.playerName = playerName;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.PLAYER_UPDATE_SKIN_OVERLAYS;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeString(out, this.playerName);
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
String playerName = ByteBufUtils.readString(in);
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);
if (sendingPlayer != null) {
NoppesUtil.updateSkinOverlayData(sendingPlayer, nbt);
}
}
}
@@ -0,0 +1,55 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
public final class QuestCompletionPacket extends AbstractPacket {
public static final String packetName = "Data|QuestCompletion";
private NBTTagCompound compound;
public QuestCompletionPacket() {
}
public QuestCompletionPacket(NBTTagCompound compound) {
this.compound = compound;
}
public static void sendQuestComplete(EntityPlayerMP playerMP, NBTTagCompound compound) {
QuestCompletionPacket packet = new QuestCompletionPacket(compound);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.QUEST_COMPLETION;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NoppesUtil.guiQuestCompletion(player, ByteBufUtils.readNBT(in));
}
}
@@ -0,0 +1,60 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.client.gui.util.IScrollData;
import java.io.IOException;
public final class ScrollSelectedPacket extends AbstractPacket {
public static final String packetName = "Data|ScrollSelected";
private String selected;
public ScrollSelectedPacket() {
}
public ScrollSelectedPacket(String selected) {
this.selected = selected;
}
public static void setSelectedList(EntityPlayerMP playerMP, String item) {
ScrollSelectedPacket packet = new ScrollSelectedPacket(item);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.SCROLL_SELECTED;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeString(out, this.selected);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof IScrollData) {
String selected = ByteBufUtils.readString(in);
((IScrollData) gui).setSelected(selected);
}
}
}
@@ -0,0 +1,145 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.controllers.ScriptClientSound;
import noppes.npcs.client.controllers.ScriptSoundController;
import java.io.IOException;
public final class SoundManagementPacket extends AbstractPacket {
private EnumSoundOperation operation;
private String soundName;
private float x, y, z;
private NBTTagCompound nbt;
private int soundId;
public SoundManagementPacket() {
}
public SoundManagementPacket(EnumSoundOperation operation) {
this.operation = operation;
}
public SoundManagementPacket(EnumSoundOperation operation, String soundName) {
this.operation = operation;
this.soundName = soundName;
}
public SoundManagementPacket(EnumSoundOperation operation, String soundName, float x, float y, float z) {
this.operation = operation;
this.soundName = soundName;
this.x = x;
this.y = y;
this.z = z;
}
public SoundManagementPacket(EnumSoundOperation operation, int soundId, NBTTagCompound nbt) {
this.operation = operation;
this.soundId = soundId;
this.nbt = nbt;
}
public SoundManagementPacket(EnumSoundOperation operation, NBTTagCompound nbt) {
this.operation = operation;
this.nbt = nbt;
}
public SoundManagementPacket(EnumSoundOperation operation, int soundId) {
this.operation = operation;
this.soundId = soundId;
}
@Override
public Enum getType() {
return EnumDataPacket.SOUND;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(operation.ordinal());
switch (operation) {
case PLAY_MUSIC:
case PLAY_SOUND:
ByteBufUtils.writeString(out, soundName);
if (operation == EnumSoundOperation.PLAY_SOUND) {
out.writeFloat(x);
out.writeFloat(y);
out.writeFloat(z);
}
break;
case PLAY_SOUND_TO:
out.writeInt(soundId);
ByteBufUtils.writeNBT(out, nbt);
break;
case PLAY_SOUND_TO_NO_ID:
ByteBufUtils.writeNBT(out, nbt);
break;
case STOP_SOUND_FOR:
out.writeInt(soundId);
break;
default:
break;
}
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
EnumSoundOperation operation = EnumSoundOperation.values()[in.readInt()];
switch (operation) {
case CONTINUE_SOUNDS:
ScriptSoundController.Instance.continueAllSounds();
break;
case PAUSE_SOUNDS:
ScriptSoundController.Instance.pauseAllSounds();
break;
case PLAY_MUSIC:
String soundName = ByteBufUtils.readString(in);
MusicController.Instance.playMusicBackground(soundName, player, Integer.MAX_VALUE);
break;
case PLAY_SOUND:
String name = ByteBufUtils.readString(in);
float x = in.readFloat();
float y = in.readFloat();
float z = in.readFloat();
MusicController.Instance.playSound(name, x, y, z);
break;
case PLAY_SOUND_TO:
int id = in.readInt();
NBTTagCompound comp = ByteBufUtils.readNBT(in);
ScriptClientSound sound = ScriptClientSound.fromScriptSound(comp, player.worldObj);
ScriptSoundController.Instance.playSound(id, sound);
break;
case PLAY_SOUND_TO_NO_ID:
NBTTagCompound tagCompound = ByteBufUtils.readNBT(in);
ScriptClientSound soundNoId = ScriptClientSound.fromScriptSound(tagCompound, player.worldObj);
ScriptSoundController.Instance.playSound(soundNoId);
break;
case STOP_SOUND_FOR:
int stopID = in.readInt();
ScriptSoundController.Instance.stopSound(stopID);
break;
case STOP_SOUNDS:
ScriptSoundController.Instance.stopAllSounds();
break;
default:
break;
}
}
}
@@ -0,0 +1,40 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import java.io.IOException;
public final class SwingPlayerArmPacket extends AbstractPacket {
public static final String packetName = "Data|SwingPlayerArm";
public SwingPlayerArmPacket() {
}
@Override
public Enum getType() {
return EnumDataPacket.SWING_PLAYER_ARM;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Minecraft.getMinecraft().thePlayer.swingItem();
}
}
@@ -0,0 +1,93 @@
package kamkeel.npcs.network.packets.data;
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.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.network.packets.request.animation.AnimationCachePacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class UpdateAnimationsPacket extends AbstractPacket {
public static final String packetName = "Data|UpdateAnimations";
private NBTTagCompound animationCompound;
private String playername;
public UpdateAnimationsPacket() {
}
public UpdateAnimationsPacket(NBTTagCompound animationCompound, String playername) {
this.animationCompound = animationCompound;
this.playername = playername;
}
@Override
public Enum getType() {
return EnumDataPacket.UPDATE_ANIMATIONS;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.animationCompound);
ByteBufUtils.writeString(out, this.playername);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
AnimationData animationData = null;
if (nbt.hasKey("EntityId")) {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(nbt.getInteger("EntityId"));
if (entity instanceof EntityNPCInterface) {
animationData = ((EntityNPCInterface) entity).display.animationData;
}
} else {
String playerName = ByteBufUtils.readString(in);
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);
if (sendingPlayer != null) {
if (!ClientCacheHandler.playerAnimations.containsKey(sendingPlayer.getUniqueID())) {
ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer));
}
animationData = ClientCacheHandler.playerAnimations.get(sendingPlayer.getUniqueID());
animationData.parent = sendingPlayer;
}
}
if (animationData != null) {
int animationId;
if (nbt.hasKey("AnimationID")) {
animationId = nbt.getInteger("AnimationID");
} else {
Animation animation = new Animation();
animation.readFromNBT(nbt.getCompoundTag("Animation"));
ClientCacheHandler.animationCache.put(animation.getID(), animation);
animationId = animation.getID();
}
animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId));
animationData.readFromNBT(nbt);
PacketClient.sendClient(new AnimationCachePacket(animationId));
}
}
}
@@ -0,0 +1,51 @@
package kamkeel.npcs.network.packets.data;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.village.MerchantRecipeList;
import noppes.npcs.ServerEventsHandler;
import java.io.IOException;
public final class VillagerListPacket extends AbstractPacket {
public static final String packetName = "Data|VillagerList";
private MerchantRecipeList merchantrecipelist;
public VillagerListPacket() {
}
public VillagerListPacket(MerchantRecipeList merchantrecipelist) {
this.merchantrecipelist = merchantrecipelist;
}
@Override
public Enum getType() {
return EnumDataPacket.VILLAGER_LIST;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.fillBuffer(out, merchantrecipelist);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
MerchantRecipeList recipes = MerchantRecipeList.func_151390_b(new PacketBuffer(in));
ServerEventsHandler.Merchant.setRecipes(recipes);
}
}
@@ -0,0 +1,67 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.util.IGuiClose;
import java.io.IOException;
public final class GuiClosePacket extends AbstractPacket {
public static final String packetName = "Data|GuiClose";
private int code;
private NBTTagCompound compound;
public GuiClosePacket() {
}
public GuiClosePacket(int code, NBTTagCompound compound) {
this.code = code;
this.compound = compound;
}
public static void closeGUI(EntityPlayerMP playerMP, int closeCode, NBTTagCompound compound) {
GuiClosePacket packet = new GuiClosePacket(closeCode, compound);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_CLOSE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(code);
ByteBufUtils.writeNBT(out, compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof IGuiClose) {
int closeCode = in.readInt();
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
((IGuiClose) gui).setClose(closeCode, nbt);
}
Minecraft.getMinecraft().displayGuiScreen(null);
Minecraft.getMinecraft().setIngameFocus();
}
}
@@ -0,0 +1,65 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.util.IGuiError;
import java.io.IOException;
public final class GuiErrorPacket extends AbstractPacket {
public static final String packetName = "Data|GuiError";
private int code;
private NBTTagCompound compound;
public GuiErrorPacket() {
}
public GuiErrorPacket(int code, NBTTagCompound compound) {
this.code = code;
this.compound = compound;
}
public static void errorGUI(EntityPlayerMP playerMP, int closeCode, NBTTagCompound compound) {
GuiErrorPacket packet = new GuiErrorPacket(closeCode, compound);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_ERROR;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(code);
ByteBufUtils.writeNBT(out, compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof IGuiError) {
int errorCode = in.readInt();
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
((IGuiError) gui).setError(errorCode, nbt);
}
}
}
@@ -0,0 +1,67 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.player.GuiBook;
import java.io.IOException;
public final class GuiOpenBookPacket extends AbstractPacket {
public static final String packetName = "Data|GuiOpenBook";
private int i;
private int j;
private int k;
private NBTTagCompound nbtTagCompound;
public GuiOpenBookPacket() {
}
public GuiOpenBookPacket(int i, int j, int k, NBTTagCompound nbtTagCompound) {
this.i = i;
this.j = j;
this.k = k;
this.nbtTagCompound = nbtTagCompound;
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_BOOK;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.i);
out.writeInt(this.j);
out.writeInt(this.k);
ByteBufUtils.writeNBT(out, this.nbtTagCompound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
ItemStack book = ItemStack.loadItemStackFromNBT(nbt);
if(book != null)
NoppesUtil.openGUI(player, new GuiBook(player, book, x, y, z));
}
}
@@ -0,0 +1,68 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.CustomNpcs;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.constants.EnumGuiType;
import java.io.IOException;
public final class GuiOpenPacket extends AbstractPacket {
public static final String packetName = "Data|OpenGui";
private EnumGuiType type;
private int x;
private int y;
private int z;
public GuiOpenPacket() {
}
public GuiOpenPacket(EnumGuiType type, int x, int y, int z) {
this.type = type;
this.x = x;
this.y = y;
this.z = z;
}
public static void openGUI(EntityPlayerMP playerMP, EnumGuiType type, int x, int y, int z) {
GuiOpenPacket packet = new GuiOpenPacket(type, x, y, z);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_OPEN;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
EnumGuiType gui = EnumGuiType.values()[in.readInt()];
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, x, y, z);
}
}
@@ -0,0 +1,50 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
public final class GuiRedstonePacket extends AbstractPacket {
public static final String packetName = "Data|GuiRedstone";
private NBTTagCompound compound;
public GuiRedstonePacket() {
}
public GuiRedstonePacket(NBTTagCompound compound) {
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_REDSTONE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
NoppesUtil.saveRedstoneBlock(player, nbt);
}
}
@@ -0,0 +1,42 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class GuiTeleporterPacket extends AbstractPacket {
public static final String packetName = "Data|Teleporter";
public GuiTeleporterPacket() {
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_TELEPORTER;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
CustomNpcs.proxy.openGui((EntityNPCInterface) null, EnumGuiType.NpcDimensions);
}
}
@@ -0,0 +1,50 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
public final class GuiWaypointPacket extends AbstractPacket {
public static final String packetName = "Data|GuiWaypoint";
private NBTTagCompound compound;
public GuiWaypointPacket() {
}
public GuiWaypointPacket(NBTTagCompound compound) {
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_WAYPOINT;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
NoppesUtil.saveWayPointBlock(player, nbt);
}
}
@@ -0,0 +1,42 @@
package kamkeel.npcs.network.packets.data.gui;
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.enums.EnumDataPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
public final class IsGuiOpenPacket extends AbstractPacket {
public static final String packetName = "Data|IsGuiOpen";
public IsGuiOpenPacket() {
}
@Override
public Enum getType() {
return EnumDataPacket.ISGUIOPEN;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
boolean isGuiOpen = Minecraft.getMinecraft().currentScreen != null;
NoppesUtil.isGUIOpen(isGuiOpen);
}
}
@@ -0,0 +1,73 @@
package kamkeel.npcs.network.packets.data.large;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IGuiData;
import java.io.IOException;
public final class GuiDataPacket extends LargeAbstractPacket {
public static final String packetName = "Data|GuiData";
private NBTTagCompound compound;
public GuiDataPacket() {
}
public GuiDataPacket(NBTTagCompound comp) {
this.compound = comp;
}
public static void sendGuiData(EntityPlayerMP playerMP, NBTTagCompound compound) {
GuiDataPacket packet = new GuiDataPacket(compound);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.GUI_DATA;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
ByteBufUtils.writeBigNBT(buffer, compound);
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@SideOnly(Side.CLIENT)
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui()) {
gui = ((GuiNPCInterface) gui).getSubGui();
} else if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui()) {
gui = ((GuiContainerNPCInterface) gui).getSubGui();
}
if (gui instanceof IGuiData) {
NBTTagCompound nbt = ByteBufUtils.readBigNBT(data);
((IGuiData) gui).setGuiData(nbt);
}
}
}
@@ -0,0 +1,73 @@
package kamkeel.npcs.network.packets.data.large;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IPartyData;
import java.io.IOException;
public final class PartyDataPacket extends LargeAbstractPacket {
public static final String packetName = "Data|PartyData";
private NBTTagCompound compound;
public PartyDataPacket() {
}
public PartyDataPacket(NBTTagCompound comp) {
this.compound = comp;
}
public static void sendPartyData(EntityPlayerMP playerMP, NBTTagCompound compound) {
PartyDataPacket packet = new PartyDataPacket(compound);
PacketHandler.Instance.sendToPlayer(packet, playerMP);
}
@Override
public Enum getType() {
return EnumDataPacket.PARTY_DATA;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
ByteBufUtils.writeBigNBT(buffer, compound);
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@SideOnly(Side.CLIENT)
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui()) {
gui = ((GuiNPCInterface) gui).getSubGui();
} else if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui()) {
gui = ((GuiContainerNPCInterface) gui).getSubGui();
}
if (gui instanceof IPartyData) {
NBTTagCompound nbt = ByteBufUtils.readBigNBT(data);
((IPartyData) gui).setPartyData(nbt);
}
}
}
@@ -0,0 +1,61 @@
package kamkeel.npcs.network.packets.data.large;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
import java.util.Map;
public final class ScrollDataPacket extends LargeAbstractPacket {
public static final String packetName = "Large|ScrollData";
private Map<String, Integer> data;
public ScrollDataPacket() {
}
public ScrollDataPacket(Map<String, Integer> data) {
this.data = data;
}
public static void sendScrollData(EntityPlayerMP player, Map<String, Integer> map) {
ScrollDataPacket packet = new ScrollDataPacket(map);
PacketHandler.Instance.sendToPlayer(packet, player);
}
@Override
public Enum getType() {
return EnumDataPacket.SCROLL_DATA;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(data.size());
for (Map.Entry<String, Integer> entry : data.entrySet()) {
buffer.writeInt(entry.getValue());
ByteBufUtils.writeString(buffer, entry.getKey());
}
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
NoppesUtil.setScrollData(data);
}
}
@@ -0,0 +1,61 @@
package kamkeel.npcs.network.packets.data.large;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
import java.util.Map;
public final class ScrollGroupPacket extends LargeAbstractPacket {
public static final String packetName = "Large|ScrollGroup";
private Map<String, Integer> data;
public ScrollGroupPacket() {
}
public ScrollGroupPacket(Map<String, Integer> data) {
this.data = data;
}
public static void sendScrollGroup(EntityPlayerMP player, Map<String, Integer> map) {
ScrollGroupPacket packet = new ScrollGroupPacket(map);
PacketHandler.Instance.sendToPlayer(packet, player);
}
@Override
public Enum getType() {
return EnumDataPacket.SCROLL_GROUP;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(data.size());
for (Map.Entry<String, Integer> entry : data.entrySet()) {
buffer.writeInt(entry.getValue());
ByteBufUtils.writeString(buffer, entry.getKey());
}
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
NoppesUtil.setScrollGroup(data);
}
}
@@ -0,0 +1,60 @@
package kamkeel.npcs.network.packets.data.large;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.client.NoppesUtil;
import java.io.IOException;
import java.util.List;
public final class ScrollListPacket extends LargeAbstractPacket {
public static final String packetName = "Large|ScrollList";
private List<String> data;
public ScrollListPacket() {
}
public ScrollListPacket(List<String> data) {
this.data = data;
}
public static void sendList(EntityPlayerMP player, List<String> list) {
ScrollListPacket packet = new ScrollListPacket(list);
PacketHandler.Instance.sendToPlayer(packet, player);
}
@Override
public Enum getType() {
return EnumDataPacket.SCROLL_LIST;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(data.size());
for (String entry : data) {
ByteBufUtils.writeString(buffer, entry);
}
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
NoppesUtil.setScrollList(data);
}
}
@@ -0,0 +1,64 @@
package kamkeel.npcs.network.packets.data.large;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import java.io.IOException;
public final class SyncEffectPacket extends LargeAbstractPacket {
private NBTTagCompound syncData;
public SyncEffectPacket() {}
public SyncEffectPacket(NBTTagCompound syncData) {
this.syncData = syncData;
}
@Override
public Enum getType() {
return EnumDataPacket.SYNC_EFFECTS;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
ByteBufUtils.writeBigNBT(buffer, syncData);
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@SideOnly(Side.CLIENT)
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
if (CustomNpcs.side() != Side.CLIENT)
return;
try {
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
SyncController.clientSyncEffects(tag);
}
catch (RuntimeException e){
LogWriter.error(String.format("Attempted to Sync Effects but it was too big"));
}
}
}
@@ -0,0 +1,108 @@
package kamkeel.npcs.network.packets.data.large;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.LargeAbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import java.io.IOException;
/**
* A large sync packet that sends chunked data to the client for a given SyncType
* along with a SyncAction (RELOAD, UPDATE, REMOVE).
*/
public final class SyncPacket extends LargeAbstractPacket {
private EnumSyncType enumSyncType;
private EnumSyncAction enumSyncAction;
private NBTTagCompound syncData;
private int operationID;
public SyncPacket() {
}
/**
* Constructs a new LargeSyncPacket.
*/
public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) {
this.enumSyncType = enumSyncType;
this.enumSyncAction = enumSyncAction;
this.syncData = syncData;
this.operationID = catId;
}
@Override
public Enum getType() {
return EnumDataPacket.SYNC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
protected byte[] getData() throws IOException {
ByteBuf buffer = Unpooled.buffer();
// 1) Write SyncType
buffer.writeInt(enumSyncType.ordinal());
// 2) Write SyncAction
buffer.writeInt(enumSyncAction.ordinal());
// 3) Optional Category ID
buffer.writeInt(operationID);
// 4) Write the NBTTagCompound
ByteBufUtils.writeBigNBT(buffer, syncData);
// Copy the buffer’s readable bytes into a byte[]
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
return bytes;
}
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
if (CustomNpcs.side() != Side.CLIENT)
return;
// Reconstruct everything from the ByteBuf
int syncTypeOrdinal = data.readInt();
int syncActionOrdinal = data.readInt();
int categoryID = data.readInt();
EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal];
EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal];
try {
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
// Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach)
handleSyncPacketClient(type, action, categoryID, tag);
}
catch (RuntimeException e){
LogWriter.error(String.format("Attempted to Sync %s but it was too big", type.toString()));
}
}
private void handleSyncPacketClient(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int id, NBTTagCompound data) {
switch (enumSyncAction) {
case RELOAD:
SyncController.clientSync(enumSyncType, data);
break;
case UPDATE:
SyncController.clientUpdate(enumSyncType, id, data);
break;
case REMOVE:
SyncController.clientSyncRemove(enumSyncType, id);
break;
}
}
}
@@ -0,0 +1,52 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class DeleteNpcPacket extends AbstractPacket {
public static final String packetName = "Data|DeleteNpc";
private int entityId;
public DeleteNpcPacket() {
}
public DeleteNpcPacket(int id) {
this.entityId = id;
}
@Override
public Enum getType() {
return EnumDataPacket.DELETE_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityId);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(in.readInt());
if (entity instanceof EntityNPCInterface) {
((EntityNPCInterface) entity).delete();
}
}
}
@@ -0,0 +1,74 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class DialogPacket extends AbstractPacket {
public static final String packetName = "Data|Dialog";
private String dummyName;
private int entityID;
private NBTTagCompound compound;
public DialogPacket() {
}
public DialogPacket(String dummyName, int entityID, NBTTagCompound compound) {
this.dummyName = dummyName;
this.entityID = entityID;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.DIALOG;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityID);
ByteBufUtils.writeString(out, this.dummyName);
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
int entityID = in.readInt();
String name = ByteBufUtils.readString(in);
NBTTagCompound tagCompound = ByteBufUtils.readNBT(in);
// Dummy NPC
if (entityID == -1) {
EntityDialogNpc npc = new EntityDialogNpc(player.worldObj);
npc.display.name = name;
NoppesUtil.openDialog(tagCompound, npc, player);
} else {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(entityID);
if (!(entity instanceof EntityNPCInterface)) {
return;
}
NoppesUtil.openDialog(tagCompound, (EntityNPCInterface) entity, player);
}
}
}
@@ -0,0 +1,54 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class EditNpcPacket extends AbstractPacket {
public static final String packetName = "Data|EditNpc";
int entityId;
public EditNpcPacket() {
}
public EditNpcPacket(int entityId) {
this.entityId = entityId;
}
@Override
public Enum getType() {
return EnumDataPacket.EDIT_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityId);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(in.readInt());
if (!(entity instanceof EntityNPCInterface)) {
return;
}
NoppesUtil.setLastNpc((EntityNPCInterface) entity);
}
}
@@ -0,0 +1,59 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class RolePacket extends AbstractPacket {
public static final String packetName = "Data|Role";
private NBTTagCompound compound;
public RolePacket() {
}
public RolePacket(NBTTagCompound compound) {
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.ROLE_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NBTTagCompound compound = ByteBufUtils.readNBT(in);
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
if (entity instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.advanced.setRole(compound.getInteger("Role"));
npc.roleInterface.readFromNBT(compound);
NoppesUtil.setLastNpc(npc);
}
}
}
@@ -0,0 +1,55 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class UpdateNpcPacket extends AbstractPacket {
public static final String packetName = "Data|UpdateNpc";
private NBTTagCompound npcCompound;
public UpdateNpcPacket() {
}
public UpdateNpcPacket(NBTTagCompound npcCompound) {
this.npcCompound = npcCompound;
}
@Override
public Enum getType() {
return EnumDataPacket.UPDATE_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.npcCompound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
NBTTagCompound compound = ByteBufUtils.readNBT(in);
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
if (entity instanceof EntityNPCInterface) {
((EntityNPCInterface) entity).readSpawnData(compound);
}
}
}
@@ -0,0 +1,65 @@
package kamkeel.npcs.network.packets.data.npc;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public final class WeaponNpcPacket extends AbstractPacket {
public static final String packetName = "Data|WeaponNpc";
private int entityId;
private int weaponIndex;
private NBTTagCompound compound;
public WeaponNpcPacket() {
}
public WeaponNpcPacket(int entityId, int weaponIndex, NBTTagCompound compound) {
this.entityId = entityId;
this.weaponIndex = weaponIndex;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.WEAPON_NPC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.entityId);
out.writeInt(this.weaponIndex);
ByteBufUtils.writeNBT(out, this.compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(in.readInt());
if (!(entity instanceof EntityNPCInterface))
return;
EntityNPCInterface npc = (EntityNPCInterface) entity;
int weaponSlotIndex = in.readInt();
ItemStack stack = ItemStack.loadItemStackFromNBT(ByteBufUtils.readNBT(in));
npc.inventory.weapons.put(weaponSlotIndex, stack);
}
}
@@ -0,0 +1,48 @@
package kamkeel.npcs.network.packets.data.script;
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.enums.EnumDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.client.ClientCacheHandler;
import java.io.IOException;
public final class ScriptOverlayClosePacket extends AbstractPacket {
public static final String packetName = "Data|ScriptOverlayClose";
private int particleId;
public ScriptOverlayClosePacket() {
}
public ScriptOverlayClosePacket(int particleId) {
this.particleId = particleId;
}
@Override
public Enum getType() {
return EnumDataPacket.SCRIPT_OVERLAY_CLOSE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.particleId);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
int overlayId = in.readInt();
ClientCacheHandler.customOverlays.remove(overlayId);
}
}
@@ -0,0 +1,53 @@
package kamkeel.npcs.network.packets.data.script;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import java.io.IOException;
public final class ScriptOverlayDataPacket extends AbstractPacket {
public static final String packetName = "Data|ScriptOverlayData";
private NBTTagCompound overlayCompound;
public ScriptOverlayDataPacket() {
}
public ScriptOverlayDataPacket(NBTTagCompound overlayCompound) {
this.overlayCompound = overlayCompound;
}
@Override
public Enum getType() {
return EnumDataPacket.SCRIPT_OVERLAY_DATA;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, this.overlayCompound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft());
overlayCustom.setOverlayData(ByteBufUtils.readNBT(in));
ClientCacheHandler.customOverlays.put(overlayCustom.overlay.getID(), overlayCustom);
}
}
@@ -0,0 +1,90 @@
package kamkeel.npcs.network.packets.data.script;
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.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.client.fx.CustomFX;
import noppes.npcs.scripted.ScriptParticle;
import java.io.IOException;
public final class ScriptedParticlePacket extends AbstractPacket {
public static final String packetName = "Data|ScriptedParticle";
private NBTTagCompound compound;
public ScriptedParticlePacket() {
}
public ScriptedParticlePacket(NBTTagCompound compound) {
this.compound = compound;
}
@Override
public Enum getType() {
return EnumDataPacket.SCRIPTED_PARTICLE;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, compound);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (CustomNpcs.side() != Side.CLIENT)
return;
spawnScriptedParticle(player, in);
}
@SideOnly(Side.CLIENT)
public static void spawnScriptedParticle(EntityPlayer player, ByteBuf buffer) {
Minecraft minecraft = Minecraft.getMinecraft();
NBTTagCompound compound;
ScriptParticle particle;
try {
compound = ByteBufUtils.readNBT(buffer);
particle = ScriptParticle.fromNBT(compound);
} catch (IOException ignored) {
return;
}
World worldObj = player.worldObj;
if (worldObj == null) {
return;
}
Entity entity = null;
if (compound.hasKey("EntityID")) {
entity = worldObj.getEntityByID(compound.getInteger("EntityID"));
if (entity != null)
worldObj = entity.worldObj;
else return;
}
CustomFX fx = CustomFX.fromScriptedParticle(particle, worldObj, entity);
for (int i = 0; i < particle.amount; i++) {
minecraft.effectRenderer.addEffect(fx);
}
}
}
@@ -0,0 +1,107 @@
package kamkeel.npcs.network.packets.player;
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.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.BankData;
import java.io.IOException;
public class BankActionPacket extends AbstractPacket {
public static final String packetName = "Player|Bank";
private Action type;
private int slotID;
private int bankID;
public BankActionPacket() {
}
private BankActionPacket(Action action, int bankID, int slotID) {
this.type = action;
this.bankID = bankID;
this.slotID = slotID;
}
@Override
public boolean needsNPC() {
return true;
}
public static void Open(int bankID, int slotID) {
PacketClient.sendClient(new BankActionPacket(Action.OpenSlot, bankID, slotID));
}
public static void Upgrade() {
PacketClient.sendClient(new BankActionPacket(Action.Upgrade, -1, -1));
}
public static void Unlock() {
PacketClient.sendClient(new BankActionPacket(Action.Unlock, -1, -1));
}
@Override
public Enum getType() {
return EnumPlayerPacket.BankAction;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
@SideOnly(Side.CLIENT)
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
if (type == Action.OpenSlot) {
out.writeInt(bankID);
out.writeInt(slotID);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Action requestedAction = Action.values()[in.readInt()];
if (!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
if(npc.advanced.role != EnumRoleType.Bank)
return;
switch (requestedAction) {
case Unlock:
NoppesUtilPlayer.bankUnlock(playerMP, npc);
break;
case Upgrade:
NoppesUtilPlayer.bankUpgrade(playerMP, npc);
break;
case OpenSlot:
int bankID = in.readInt();
int slotID = in.readInt();
BankData data = PlayerDataController.Instance.getBankData(playerMP,bankID).getBankOrDefault(bankID);
data.openBankGui(playerMP, npc, bankID, slotID);
break;
}
}
private enum Action {
Unlock,
Upgrade,
OpenSlot
}
}
@@ -0,0 +1,87 @@
package kamkeel.npcs.network.packets.player;
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.enums.EnumPlayerPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.PlayerFactionData;
import noppes.npcs.controllers.data.PlayerQuestData;
import java.io.IOException;
public class CheckPlayerValue extends AbstractPacket {
public static final String packetName = "Player|CheckPlayerVal";
private Type type;
public CheckPlayerValue() {
}
public CheckPlayerValue(Type type) {
this.type = type;
}
@Override
public Enum getType() {
return EnumPlayerPacket.GetPlayerValue;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
@SideOnly(Side.CLIENT)
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
Type type = Type.values()[in.readInt()];
switch (type) {
case Faction:
PlayerFactionData data = PlayerDataController.Instance.getPlayerData(playerMP).factionData;
GuiDataPacket.sendGuiData(playerMP, data.getPlayerGuiData());
break;
case QuestLog:
NoppesUtilPlayer.sendQuestLogData(playerMP);
break;
case TrackedQuest:
NoppesUtilPlayer.sendTrackedQuest(playerMP);
break;
case CheckQuestCompletion:
PlayerData playerData = PlayerDataController.Instance.getPlayerData(playerMP);
PlayerQuestData questData = PlayerDataController.Instance.getPlayerData(playerMP).questData;
Party playerParty = playerData.getPlayerParty();
if(playerParty != null)
PartyController.Instance().checkQuestCompletion(playerParty, null);
questData.checkQuestCompletion(playerData, null);
break;
}
}
public enum Type {
Faction,
QuestLog,
TrackedQuest,
CheckQuestCompletion
}
}
@@ -0,0 +1,93 @@
package kamkeel.npcs.network.packets.player;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.EnumCompanionTalent;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.roles.RoleCompanion;
import java.io.IOException;
public class CompanionActionPacket extends AbstractPacket {
public static final String packetName = "Player|CompanionAction";
private Type type;
private int talentOrdinal;
private int exp;
public CompanionActionPacket() {
}
public static void OpenInventory() {
CompanionActionPacket packet = new CompanionActionPacket();
packet.type = Type.OpenInventory;
PacketClient.sendClient(packet);
}
public static void TalentExp(EnumCompanionTalent talent, int exp) {
CompanionActionPacket packet = new CompanionActionPacket();
packet.type = Type.TalentExp;
packet.talentOrdinal = talent.ordinal();
packet.exp = exp;
PacketClient.sendClient(packet);
}
@Override
public boolean needsNPC() {
return true;
}
@Override
public Enum getType() {
return EnumPlayerPacket.CompanionAction;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
if (type == Type.TalentExp) {
out.writeInt(talentOrdinal);
out.writeInt(exp);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Type type = Type.values()[in.readInt()];
if(npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
return;
if (type == Type.OpenInventory) {
NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc);
return;
}
int id = in.readInt();
int exp = in.readInt();
RoleCompanion role = (RoleCompanion) npc.roleInterface;
if(exp <= 0 || !role.canAddExp(-exp) || id < 0 || id >= EnumCompanionTalent.values().length) //should never happen unless hacking
return;
EnumCompanionTalent talent = EnumCompanionTalent.values()[id];
role.addExp(-exp);
role.addTalentExp(talent, exp);
}
private enum Type {
OpenInventory,
TalentExp
}
}
@@ -0,0 +1,56 @@
package kamkeel.npcs.network.packets.player;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
public class DialogSelectPacket extends AbstractPacket {
public static final String packetName = "Player|DialogSelect";
private int dialogID, optionID;
public DialogSelectPacket(){
}
public DialogSelectPacket(int dialogID, int optionID) {
this.dialogID = dialogID;
this.optionID = optionID;
}
@Override
public boolean needsNPC() {
return true;
}
@Override
public Enum getType() {
return EnumPlayerPacket.DialogSelect;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(dialogID);
out.writeInt(optionID);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
NoppesUtilPlayer.dialogSelected(in.readInt(), in.readInt(), playerMP, npc);
}
}
@@ -0,0 +1,84 @@
package kamkeel.npcs.network.packets.player;
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.enums.EnumPlayerPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.constants.EnumJobType;
import java.io.IOException;
public class FollowerPacket extends AbstractPacket {
public static final String packetName = "Player|Follower";
private Action type;
public FollowerPacket() {
}
public FollowerPacket(Action action) {
this.type = action;
}
@Override
public boolean needsNPC() {
return true;
}
@Override
public Enum getType() {
return EnumPlayerPacket.FollowerAction;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
@SideOnly(Side.CLIENT)
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
Action requestedAction = Action.values()[in.readInt()];
if (!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
if (npc.advanced.job != EnumJobType.Follower)
return;
switch (requestedAction) {
case Hire:
NoppesUtilPlayer.hireFollower(playerMP, npc);
break;
case Extend:
NoppesUtilPlayer.extendFollower(playerMP, npc);
GuiDataPacket.sendGuiData(playerMP, npc.roleInterface.writeToNBT(new NBTTagCompound()));
break;
case State:
NoppesUtilPlayer.changeFollowerState(playerMP, npc);
GuiDataPacket.sendGuiData(playerMP, npc.roleInterface.writeToNBT(new NBTTagCompound()));
break;
}
}
public enum Action {
Hire,
Extend,
State
}
}
@@ -0,0 +1,47 @@
package kamkeel.npcs.network.packets.player;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.constants.EnumRoleType;
import java.io.IOException;
public class GetNPCRole extends AbstractPacket {
public static final String packetName = "Player|GetNPCRole";
@Override
public Enum getType() {
return EnumPlayerPacket.GetRole;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@Override
public boolean needsNPC() {
return true;
}
@Override
public void sendData(ByteBuf out) throws IOException {
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if(!(player instanceof EntityPlayerMP))
return;
if (npc.advanced.role == EnumRoleType.None)
return;
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
}
Loaded 100 of 602 files, more files were not shown because too many files have changed in this diff. Show more