mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 07:59:08 +00:00
More THings
This commit is contained in:
1 parent
a41a320676
commit
d11f72eb0d
15 files changed
+323
-168
No files matched your search
@@ -28,6 +28,7 @@ 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.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;
|
||||
@@ -293,6 +294,7 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new TileEntityGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new TileEntitySavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MountPacket());
|
||||
REQUEST_PACKET.registerPacket(new DimensionTeleportPacket());
|
||||
}
|
||||
|
||||
public void registerDataPackets(){
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
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;
|
||||
@@ -167,4 +177,53 @@ public class PacketUtil {
|
||||
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, EntityPlayerMP player) 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,5 +152,12 @@ public enum EnumRequestPacket {
|
||||
TraderMarketSave,
|
||||
|
||||
CloneList,
|
||||
CloneSave, CloneRemove, CloneTagList, CloneAllTags, CloneAllTagsShort, ClonePreSave
|
||||
CloneSave,
|
||||
CloneRemove,
|
||||
CloneTagList,
|
||||
CloneAllTags,
|
||||
CloneAllTagsShort,
|
||||
ClonePreSave,
|
||||
|
||||
EventScript, DimensionTeleport
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package kamkeel.npcs.network.packets.request.feather;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class DimensionTeleportPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|DimensionTeleport";
|
||||
|
||||
private int dimensionID;
|
||||
|
||||
public DimensionTeleportPacket() {}
|
||||
|
||||
public DimensionTeleportPacket(int dimensionID) {
|
||||
this.dimensionID = dimensionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.DimensionTeleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(dimensionID);
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.TELEPORTER))
|
||||
return;
|
||||
|
||||
int dimension = in.readInt();
|
||||
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
|
||||
ChunkCoordinates coords = world.getEntrancePortalLocation();
|
||||
if(coords == null){
|
||||
coords = world.getSpawnPoint();
|
||||
if(!world.isAirBlock(coords.posX, coords.posY, coords.posZ))
|
||||
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
|
||||
else{
|
||||
while(world.isAirBlock(coords.posX, coords.posY - 1, coords.posZ) && coords.posY > 0){
|
||||
coords.posY--;
|
||||
}
|
||||
if(coords.posY == 0)
|
||||
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
|
||||
}
|
||||
}
|
||||
NoppesUtilPlayer.teleportPlayer((EntityPlayerMP) player, coords.posX, coords.posY, coords.posZ, dimension);
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,24 @@ import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
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.Quest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendPartyData;
|
||||
import static kamkeel.npcs.network.packets.request.party.PartyInvitePacket.sendInviteData;
|
||||
|
||||
public final class PartyInfoPacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PartyInfo";
|
||||
@@ -60,4 +69,28 @@ public final class PartyInfoPacket extends AbstractPacket {
|
||||
}
|
||||
sendPartyData((EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
public static void sendPartyData(EntityPlayerMP player) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
if (playerData.partyUUID != null) {
|
||||
Party party = PartyController.Instance().getParty(playerData.partyUUID);
|
||||
NBTTagCompound compound = party.writeToNBT();
|
||||
if (party.getQuest() != null) {
|
||||
Quest quest = (Quest) party.getQuest();
|
||||
compound.setString("QuestName", quest.getCategory().getName() + ":" + quest.getName());
|
||||
Vector<String> vector = quest.questInterface.getPartyQuestLogStatus(party);
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (String s : vector) {
|
||||
list.appendTag(new NBTTagString(s));
|
||||
}
|
||||
compound.setTag("QuestProgress", list);
|
||||
if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isPartyCompleted(party)) {
|
||||
compound.setString("QuestCompleteWith", quest.completerNpc);
|
||||
}
|
||||
}
|
||||
PartyDataPacket.sendPartyData(player, compound);
|
||||
} else {
|
||||
sendInviteData(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
@@ -21,8 +24,8 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.PartyEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendInviteData;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PartyInvitePacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PartyInvite";
|
||||
@@ -72,4 +75,22 @@ public final class PartyInvitePacket extends AbstractPacket {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendInviteData(EntityPlayerMP player) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
if (playerData.partyUUID == null) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList list = new NBTTagList();
|
||||
HashSet<UUID> partyInvites = playerData.getPartyInvites();
|
||||
for (UUID uuid : partyInvites) {
|
||||
Party party = PartyController.Instance().getParty(uuid);
|
||||
NBTTagCompound partyCompound = new NBTTagCompound();
|
||||
partyCompound.setString("PartyLeader", party.getPartyLeaderName());
|
||||
partyCompound.setString("PartyUUID", party.getPartyUUID().toString());
|
||||
list.appendTag(partyCompound);
|
||||
}
|
||||
compound.setTag("PartyInvites", list);
|
||||
PartyDataPacket.sendPartyData(player, compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import noppes.npcs.scripted.event.PartyEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendInviteData;
|
||||
import static kamkeel.npcs.network.packets.request.party.PartyInvitePacket.sendInviteData;
|
||||
|
||||
public final class PartyKickPacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PartyKick";
|
||||
|
||||
@@ -22,7 +22,7 @@ import noppes.npcs.scripted.event.PartyEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendInviteData;
|
||||
import static kamkeel.npcs.network.packets.request.party.PartyInvitePacket.sendInviteData;
|
||||
|
||||
public final class PartyLeavePacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PartyLeave";
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package kamkeel.npcs.network.packets.request.script;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.player.BankActionPacket;
|
||||
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.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.controllers.data.DataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class EventScript extends AbstractPacket {
|
||||
public static String packetName = "Request|EventScript";
|
||||
|
||||
private EventScript.Action type;
|
||||
private int page;
|
||||
private int maxSize;
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public EventScript() {}
|
||||
|
||||
public EventScript(Action type, int page, int maxSize, NBTTagCompound compound) {
|
||||
this.type = type;
|
||||
this.page = page;
|
||||
this.maxSize = maxSize;
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.EventScript;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsNPC(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission(){
|
||||
return CustomNpcsPermissions.SCRIPT_NPC;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(type.ordinal());
|
||||
|
||||
if(type == Action.SAVE){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.SCRIPTER))
|
||||
return;
|
||||
|
||||
Action requestedAction = Action.values()[in.readInt()];
|
||||
DataScript data = npc.script;
|
||||
if(requestedAction == Action.GET){
|
||||
PacketUtil.getScripts(data, (EntityPlayerMP) player);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(int id, int maxSize, NBTTagCompound compound) {
|
||||
PacketClient.sendClient(new EventScript(Action.SAVE, id, maxSize, compound));
|
||||
}
|
||||
public static void Get() {
|
||||
PacketClient.sendClient(new EventScript(Action.GET, -1, -1, new NBTTagCompound()));
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
GET,
|
||||
SAVE
|
||||
}
|
||||
}
|
||||
@@ -4,62 +4,34 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import foxz.utils.Market;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.packets.data.ScrollSelectedPacket;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
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 net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.*;
|
||||
import noppes.npcs.containers.ContainerMail;
|
||||
import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.LinkedNpcController.LinkedData;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.JobSpawner;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
import noppes.npcs.roles.RoleTransporter;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class PacketHandlerServer{
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerPacket(ServerCustomPacketEvent event) {
|
||||
EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity;
|
||||
if(ConfigMain.OpsOnly && !NoppesUtilServer.isOp(player)){
|
||||
warn(player, "tried to use custom npcs without being an op");
|
||||
return;
|
||||
}
|
||||
ByteBuf in = event.packet.payload();
|
||||
EnumPacketServer type = null;
|
||||
try {
|
||||
@@ -72,9 +44,7 @@ public class PacketHandlerServer{
|
||||
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
|
||||
else {
|
||||
if (item != null) {
|
||||
if (item.getItem() == CustomItems.teleporter)
|
||||
featherPackets(type, in, player);
|
||||
else if (ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
|
||||
if (ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
|
||||
if (type == EnumPacketServer.EventScriptDataGet || type == EnumPacketServer.EventScriptDataSave)
|
||||
npcEventScriptPackets(type, in, player, npc);
|
||||
else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
|
||||
@@ -99,49 +69,7 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPartyData(EntityPlayerMP player) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
if (playerData.partyUUID != null) {
|
||||
Party party = PartyController.Instance().getParty(playerData.partyUUID);
|
||||
NBTTagCompound compound = party.writeToNBT();
|
||||
if (party.getQuest() != null) {
|
||||
Quest quest = (Quest) party.getQuest();
|
||||
compound.setString("QuestName", quest.getCategory().getName() + ":" + quest.getName());
|
||||
Vector<String> vector = quest.questInterface.getPartyQuestLogStatus(party);
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (String s : vector) {
|
||||
list.appendTag(new NBTTagString(s));
|
||||
}
|
||||
compound.setTag("QuestProgress", list);
|
||||
if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isPartyCompleted(party)) {
|
||||
compound.setString("QuestCompleteWith", quest.completerNpc);
|
||||
}
|
||||
}
|
||||
PartyDataPacket.sendPartyData(player, compound);
|
||||
} else {
|
||||
sendInviteData(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendInviteData(EntityPlayerMP player) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
if (playerData.partyUUID == null) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList list = new NBTTagList();
|
||||
HashSet<UUID> partyInvites = playerData.getPartyInvites();
|
||||
for (UUID uuid : partyInvites) {
|
||||
Party party = PartyController.Instance().getParty(uuid);
|
||||
NBTTagCompound partyCompound = new NBTTagCompound();
|
||||
partyCompound.setString("PartyLeader", party.getPartyLeaderName());
|
||||
partyCompound.setString("PartyUUID", party.getPartyUUID().toString());
|
||||
list.appendTag(partyCompound);
|
||||
}
|
||||
compound.setTag("PartyInvites", list);
|
||||
PartyDataPacket.sendPartyData(player, compound);
|
||||
}
|
||||
}
|
||||
|
||||
private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
if (type == EnumPacketServer.ScriptGlobalGuiDataGet) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("ScriptsEnabled", ConfigScript.ScriptingEnabled);
|
||||
@@ -175,61 +103,12 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
public static void getScripts(IScriptHandler data, ByteBuf buffer, 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, EntityPlayerMP player) 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"));
|
||||
}
|
||||
}
|
||||
|
||||
private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
|
||||
private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
|
||||
DataScript data = npc.script;
|
||||
if(type == EnumPacketServer.EventScriptDataGet) {
|
||||
getScripts(data,buffer,player);
|
||||
PacketUtil.getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.EventScriptDataSave) {
|
||||
saveScripts(data,buffer,player);
|
||||
PacketUtil.saveScripts(data,buffer,player);
|
||||
npc.updateAI = true;
|
||||
npc.script.hasInited = false;
|
||||
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
|
||||
@@ -241,10 +120,10 @@ public class PacketHandlerServer{
|
||||
private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
PlayerDataScript data = ScriptController.Instance.playerScripts;
|
||||
if(type == EnumPacketServer.ScriptPlayerGet) {
|
||||
getScripts(data,buffer,player);
|
||||
PacketUtil.getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.ScriptPlayerSave) {
|
||||
int tab = buffer.getInt(buffer.readerIndex());
|
||||
saveScripts(data,buffer,player);
|
||||
PacketUtil.saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastPlayerUpdate = System.currentTimeMillis();
|
||||
if(tab == -1)
|
||||
ScriptController.Instance.savePlayerScriptsSync();
|
||||
@@ -254,10 +133,10 @@ public class PacketHandlerServer{
|
||||
private void forgeScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
ForgeDataScript data = ScriptController.Instance.forgeScripts;
|
||||
if (type == EnumPacketServer.ScriptForgeGet) {
|
||||
getScripts(data,buffer,player);
|
||||
PacketUtil.getScripts(data,buffer,player);
|
||||
} else if (type == EnumPacketServer.ScriptForgeSave) {
|
||||
int tab = buffer.getInt(buffer.readerIndex());
|
||||
saveScripts(data,buffer,player);
|
||||
PacketUtil.saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastForgeUpdate = System.currentTimeMillis();
|
||||
if(tab == -1)
|
||||
ScriptController.Instance.saveForgeScriptsSync();
|
||||
@@ -267,10 +146,10 @@ public class PacketHandlerServer{
|
||||
private void npcGlobalScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
GlobalNPCDataScript data = ScriptController.Instance.globalNpcScripts;
|
||||
if(type == EnumPacketServer.ScriptGlobalNPCGet) {
|
||||
getScripts(data,buffer,player);
|
||||
PacketUtil.getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.ScriptGlobalNPCSave) {
|
||||
int tab = buffer.getInt(buffer.readerIndex());
|
||||
saveScripts(data,buffer,player);
|
||||
PacketUtil.saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastGlobalNpcUpdate = System.currentTimeMillis();
|
||||
if(tab == -1)
|
||||
ScriptController.Instance.saveGlobalScriptsSync();
|
||||
@@ -320,27 +199,6 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
if(type == EnumPacketServer.DimensionTeleport){
|
||||
int dimension = buffer.readInt();
|
||||
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
|
||||
ChunkCoordinates coords = world.getEntrancePortalLocation();
|
||||
if(coords == null){
|
||||
coords = world.getSpawnPoint();
|
||||
if(!world.isAirBlock(coords.posX, coords.posY, coords.posZ))
|
||||
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
|
||||
else{
|
||||
while(world.isAirBlock(coords.posX, coords.posY - 1, coords.posZ) && coords.posY > 0){
|
||||
coords.posY--;
|
||||
}
|
||||
if(coords.posY == 0)
|
||||
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
|
||||
}
|
||||
}
|
||||
NoppesUtilPlayer.teleportPlayer(player, coords.posX, coords.posY, coords.posZ, dimension);
|
||||
}
|
||||
}
|
||||
|
||||
private void warn(EntityPlayer player, String warning){
|
||||
MinecraftServer.getServer().logWarning(player.getCommandSenderName() + ": " + warning);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.DimensionsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket;
|
||||
import kamkeel.npcs.network.packets.request.npc.RemoteDeletePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -58,7 +59,7 @@ public class GuiNpcDimension extends GuiNPCInterface implements IScrollData{
|
||||
return;
|
||||
|
||||
if(id == 4){
|
||||
Client.sendData(EnumPacketServer.DimensionTeleport, data.get(scroll.getSelected()));
|
||||
PacketClient.sendClient(new DimensionTeleportPacket(data.get(scroll.getSelected())));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.client.gui.mainmenu;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAIGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAISavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -18,7 +19,7 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG
|
||||
public GuiNpcAI(EntityNPCInterface npc) {
|
||||
super(npc,6);
|
||||
ai = npc.ai;
|
||||
Client.sendData(EnumPacketServer.MainmenuAIGet);
|
||||
PacketClient.sendClient(new MainmenuAIGetPacket());
|
||||
}
|
||||
|
||||
public void initGui()
|
||||
|
||||
@@ -23,10 +23,9 @@ public enum EnumPacketServer {
|
||||
|
||||
ScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true),
|
||||
ScriptDataGet(true),
|
||||
EventScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true),
|
||||
EventScriptDataGet(true),
|
||||
|
||||
DimensionTeleport;
|
||||
EventScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true),
|
||||
EventScriptDataGet(true);
|
||||
|
||||
public CustomNpcsPermissions.Permission permission = null;
|
||||
public boolean needsNpc = false;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendInviteData;
|
||||
import static kamkeel.npcs.network.packets.request.party.PartyInvitePacket.sendInviteData;
|
||||
|
||||
public class PartyController {
|
||||
private static PartyController Instance;
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.network.packets.request.party.PartyInvitePacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -12,7 +13,6 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.PacketHandlerServer;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.*;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
@@ -274,7 +274,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public void ignoreInvite(UUID uuid) {
|
||||
if (uuid != null) {
|
||||
this.partyInvites.remove(uuid);
|
||||
PacketHandlerServer.sendInviteData((EntityPlayerMP) player);
|
||||
PartyInvitePacket.sendInviteData((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user