CustomNpcs:

-Added ScriptOpsOnly config, which controls if only ops can see and edit scripts.
-Added ScriptDevs config, a list of the UUIDs of players who should be able to see and edit scripts. If left empty and ScriptOpsOnly is false, everyone can see and edit scripts with a scripter.

IPlayer:
-Added isScriptDev() function to check if the player can see and edit scripts.
This commit is contained in:
c0508383 committed 2022-07-07 16:22:50 -05:00
1 parent 5fdef1cd0c
commit 22e01bba1f
6 files changed
+72 -26

No files matched your search

+30
View File
@@ -16,6 +16,7 @@ import net.minecraft.block.BlockVine;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
@@ -29,7 +30,9 @@ import noppes.npcs.entity.old.*;
import noppes.npcs.scripted.NpcAPI;
import java.io.File;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
@Mod(modid = "customnpcs", name = "CustomNpcs", version = "1.6-beta2")
public class CustomNpcs {
@@ -91,6 +94,16 @@ public class CustomNpcs {
@ConfigProp(info = "Only ops can create and edit npcs")
public static boolean OpsOnly = false;
@ConfigProp(info = "Only ops can see and edit scripts")
public static boolean ScriptOpsOnly = false;
@ConfigProp(info = "Comme separated list of player UUIDs that can see and edit scripts. If ScriptsOpsOnly is true,\n" +
"ops and players with these IDs can see and edit scripts. Example:\n" +
"b876ec32-e396-476b-a115-8438d83c67d4,069a79f4-44e9-4726-a5be-fca90e38aaf5,29cc52dd-2c50-4e8f-a388-be6c497cf0b4\n" +
"Get a player's UUID from a site like NameMC or the API IPlayer.getUniqueID() function!\n" +
"If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter.")
public static String ScriptDevIDs = "";
@ConfigProp(info = "Default interact line. Leave empty to not have one")
public static String DefaultInteractLine = "Hello @p";
@@ -146,6 +159,8 @@ public class CustomNpcs {
public static ConfigLoader Config;
public static ArrayList<UUID> ScriptDevs = new ArrayList<>();
public static final MarkovGenerator[] MARKOV_GENERATOR = new MarkovGenerator[10];
public CustomNpcs() {
@@ -170,6 +185,14 @@ public class CustomNpcs {
Config = new ConfigLoader(this.getClass(), new File(dir, "config"), "CustomNpcs");
Config.loadConfig();
try {
ScriptDevs.clear();
String[] uuidStrings = ScriptDevIDs.split(";");
for (String s : uuidStrings) {
ScriptDevs.add(UUID.fromString(s));
}
} catch (Exception ignored) {}
if (NpcNavRange < 16) {
NpcNavRange = 16;
}
@@ -379,4 +402,11 @@ public class CustomNpcs {
public static MinecraftServer getServer(){
return MinecraftServer.getServer();
}
public static boolean isScriptDev(EntityPlayer player) {
if(CustomNpcs.ScriptOpsOnly && !MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile()) ||
ScriptDevs.contains(player.getUniqueID())){
return true;
} else return ScriptDevIDs.isEmpty();
}
}
@@ -119,20 +119,22 @@ public class PacketHandlerServer{
clonePackets(type, buffer, player);
else if (item.getItem() == CustomItems.teleporter)
featherPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
playerScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave)
npcScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
getScriptsEnabled(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
scriptPackets(type, buffer, player, npc);
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
blockPackets(type, buffer, player);
else if (CustomNpcs.isScriptDev(player)) {
if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
playerScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave)
npcScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
getScriptsEnabled(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
scriptPackets(type, buffer, player, npc);
}
}
}
} catch (Exception e) {
@@ -5,6 +5,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -31,11 +33,15 @@ public class ItemNpcScripter extends Item{
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
if(!par2World.isRemote)
return par1ItemStack;
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, par3EntityPlayer);
return par1ItemStack;
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player){
if(!world.isRemote)
return itemStack;
if(!CustomNpcs.isScriptDev(player)){
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
} else {
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, player);
}
return itemStack;
}
@SideOnly(Side.CLIENT)
@@ -13,6 +13,8 @@ import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
@@ -60,12 +62,16 @@ public class ItemScripted extends Item implements ItemRenderInterface {
return super.setUnlocalizedName(name);
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entityPlayer)
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if(entityPlayer.isSneaking() && entityPlayer.capabilities.isCreativeMode) {
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, entityPlayer);
if(player.isSneaking() && player.capabilities.isCreativeMode) {
if(!CustomNpcs.isScriptDev(player)){
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
} else {
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, player);
}
}
entityPlayer.setItemInUse(stack, this.getMaxItemUseDuration(stack));
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
@@ -17,11 +17,7 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.Vec3;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldSettings;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.Server;
import noppes.npcs.*;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.containers.ContainerCustomGui;
@@ -589,6 +585,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
return this.data;
}
public boolean isScriptingDev() {
return CustomNpcs.isScriptDev(player);
}
public IQuest[] getActiveQuests() {
PlayerQuestData data = (PlayerQuestData) this.getData().getQuestData();
List<IQuest> quests = new ArrayList();
@@ -236,6 +236,8 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
public IPlayerData getData();
boolean isScriptingDev();
IQuest[] getActiveQuests();
IContainer getOpenContainer();