mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 13:25:10 +00:00
All external scripts of type "Java" are now synced to client on login/script reload
This commit is contained in:
1 parent
8a2ba6ae4e
commit
a8b3c0b8d4
4 files changed
+49
-27
No files matched your search
@@ -12,6 +12,7 @@ public class ScriptCommand extends CommandKamkeelBase {
|
||||
@SubCommand(desc = "Reload scripts data and folders.")
|
||||
public Boolean reload(ICommandSender sender, String args[]) {
|
||||
ScriptController.Instance.loadCategories();
|
||||
ScriptController.Instance.syncClientScripts(null);
|
||||
|
||||
if (ScriptController.Instance.loadPlayerScripts())
|
||||
sendResult(sender, "Reload player scripts successfully");
|
||||
|
||||
@@ -5,22 +5,20 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
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.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ScriptFilesPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ScriptLanguages";
|
||||
public static String packetName = "Request|ScriptFiles";
|
||||
|
||||
private String lang;
|
||||
|
||||
@@ -38,7 +36,7 @@ public final class ScriptFilesPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
return PacketHandler.DATA_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,33 +47,49 @@ public final class ScriptFilesPacket extends AbstractPacket {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, this.lang);
|
||||
ByteBufUtils.writeNBT(out, getScriptsNbt(lang));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(in);
|
||||
|
||||
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT))
|
||||
return;
|
||||
String lang = compound.getString("lang");
|
||||
String ext = compound.getString("ext");
|
||||
Map<String, String> scripts = NBTTags.getStringStringMap(compound.getTagList("Scripts", 10));
|
||||
|
||||
lang = ByteBufUtils.readString(in);
|
||||
ScriptController cont = ScriptController.Instance;
|
||||
if (!cont.languages.containsKey(lang) && ext != null)
|
||||
cont.languages.put(lang, ext);
|
||||
|
||||
for (Map.Entry<String, String> script : scripts.entrySet()) {
|
||||
cont.scripts.put(script.getKey(), script.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound getScriptsNbt(String lang) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
List<String> files = ScriptController.Instance.getScripts(lang);
|
||||
compound.setString("lang", lang);
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
NBTTagList scripts = new NBTTagList();
|
||||
for (String script : files)
|
||||
scripts.appendTag(new NBTTagString(script));
|
||||
compound.setTag("Scripts", scripts);
|
||||
Map<String, String> scriptss = new HashMap<>();
|
||||
String ext = ScriptController.Instance.languages.get(lang);
|
||||
if (ext != null) {
|
||||
for (Map.Entry<String, String> script : ScriptController.Instance.scripts.entrySet()) {
|
||||
if (script.getKey().endsWith(ext))
|
||||
scriptss.put(script.getKey(), script.getValue());
|
||||
}
|
||||
compound.setString("ext", ext);
|
||||
}
|
||||
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
compound.setTag("Scripts", NBTTags.nbtStringStringMap(scriptss));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static void Get(String lang) {
|
||||
PacketClient.sendClient(new ScriptFilesPacket(lang));
|
||||
public static void sendToAll(String lang) {
|
||||
PacketHandler.Instance.sendToAll(new ScriptFilesPacket(lang));
|
||||
}
|
||||
|
||||
public static void sendToPlayer(EntityPlayerMP player, String lang) {
|
||||
PacketHandler.Instance.sendToPlayer(new ScriptFilesPacket(lang), player);
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,11 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.client.AnalyticsTracking;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class ServerTickHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -64,6 +60,7 @@ public class ServerTickHandler {
|
||||
ProfileController.Instance.login(player);
|
||||
SyncController.beginLogin(player);
|
||||
SyncController.syncEffects(player);
|
||||
ScriptController.Instance.syncClientScripts(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -3,7 +3,9 @@ package noppes.npcs.controllers;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jdk.nashorn.api.scripting.ClassFilter;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import kamkeel.npcs.network.packets.request.script.ScriptFilesPacket;
|
||||
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;
|
||||
@@ -230,6 +232,14 @@ public class ScriptController {
|
||||
customNPCThread.execute(this::saveGlobalNpcScripts);
|
||||
}
|
||||
|
||||
public void syncClientScripts(EntityPlayerMP player) {
|
||||
if (player != null) {
|
||||
ScriptFilesPacket.sendToPlayer(player, "Java");
|
||||
} else {
|
||||
ScriptFilesPacket.sendToAll("Java");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCategories() {
|
||||
dir = new File(CustomNpcs.getWorldSaveDirectory(), "scripts");
|
||||
if (!dir.exists())
|
||||
|
||||
Reference in new issue
Block a user