mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 13:09:11 +00:00
Added ScriptFilesPacket, which fetches all files of a given language
This commit is contained in:
1 parent
0a47eb953e
commit
818c62bdf9
4 files changed
+85
-10
No files matched your search
@@ -209,15 +209,7 @@ 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.BlockScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.EventScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.ForgeScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.GlobalNPCScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.NPCScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.PlayerScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.RecipeScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.ScriptInfoPacket;
|
||||
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.script.item.LinkedItemScriptPacket;
|
||||
@@ -297,6 +289,7 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new NPCScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ScriptInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new ScriptFilesPacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectScriptPacket());
|
||||
|
||||
// Cloner Packets
|
||||
|
||||
@@ -172,6 +172,7 @@ public enum EnumRequestPacket {
|
||||
BlockScript,
|
||||
NPCScript,
|
||||
ScriptInfo,
|
||||
ScriptFiles,
|
||||
EffectScript,
|
||||
|
||||
DimensionTeleport,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
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.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.controllers.ScriptController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public final class ScriptFilesPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ScriptLanguages";
|
||||
|
||||
private String lang;
|
||||
|
||||
public ScriptFilesPacket() {
|
||||
}
|
||||
|
||||
public ScriptFilesPacket(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ScriptFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.SCRIPT_GLOBAL;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, this.lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT))
|
||||
return;
|
||||
|
||||
lang = ByteBufUtils.readString(in);
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
List<String> files = ScriptController.Instance.getScripts(lang);
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
NBTTagList scripts = new NBTTagList();
|
||||
for (String script : files)
|
||||
scripts.appendTag(new NBTTagString(script));
|
||||
compound.setTag("Scripts", scripts);
|
||||
}
|
||||
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
|
||||
public static void Get(String lang) {
|
||||
PacketClient.sendClient(new ScriptFilesPacket(lang));
|
||||
}
|
||||
}
|
||||
@@ -349,7 +349,7 @@ public class ScriptController {
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<String> getScripts(String language) {
|
||||
public List<String> getScripts(String language) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
String ext = languages.get(language);
|
||||
if (ext == null)
|
||||
|
||||
Reference in new issue
Block a user