Files
CustomNPC-Plus/src/main/java/noppes/npcs/config/ConfigScript.java
T

155 lines
7.2 KiB
Java
Raw Normal View History

2023-01-07 00:21:08 -05:00
package noppes.npcs.config;
import cpw.mods.fml.common.FMLLog;
2023-05-12 20:32:44 -04:00
import kamkeel.developer.Developer;
2023-01-07 00:21:08 -05:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.config.Configuration;
2023-01-07 18:07:23 -05:00
import net.minecraftforge.common.config.Property;
2023-01-07 00:21:08 -05:00
import noppes.npcs.CustomNpcs;
2023-01-07 18:07:23 -05:00
import noppes.npcs.config.legacy.LegacyConfig;
2023-01-07 00:21:08 -05:00
import org.apache.logging.log4j.Level;
import java.io.File;
import java.util.UUID;
public class ConfigScript
{
public static Configuration config;
2023-01-07 18:07:23 -05:00
public final static String GENERAL = "Scripting General";
public final static String CUSTOMIZATION = "Scripting Customization";
/**
* General Properties
**/
public static Property ScriptingEnabledProperty;
2023-01-07 00:21:08 -05:00
public static boolean ScriptingEnabled = true;
2023-01-07 18:07:23 -05:00
public static Property ScriptOpsOnlyProperty;
public static boolean ScriptOpsOnly = false;
public static Property GlobalPlayerScriptsProperty;
2023-01-07 00:21:08 -05:00
public static boolean GlobalPlayerScripts = true;
2023-01-07 18:07:23 -05:00
public static Property GlobalForgeScriptsProperty;
2023-01-07 00:21:08 -05:00
public static boolean GlobalForgeScripts = true;
2023-01-07 18:07:23 -05:00
public static Property GlobalNPCScriptsProperty;
2023-01-07 00:21:08 -05:00
public static boolean GlobalNPCScripts = false;
2023-01-07 18:07:23 -05:00
/**
* Customization Properties
**/
public static Property ScriptingECMA6Property;
public static boolean ScriptingECMA6 = false;
public static Property ExpandedScriptLimitProperty;
2023-01-07 00:21:08 -05:00
public static int ExpandedScriptLimit = 2;
2023-01-07 18:07:23 -05:00
public static Property ScriptDevIDsProperty;
public static String ScriptDevIDs = "";
2023-01-07 00:21:08 -05:00
public static void init(File configFile)
{
config = new Configuration(configFile);
try
{
config.load();
2023-01-07 18:07:23 -05:00
// General
ScriptingEnabledProperty = config.get(GENERAL, "Enable Scripting", true, "Enables/Disables ALL scripting. You can still see and write code in the scripter, but these scripts won't run. True by default");
ScriptingEnabled = ScriptingEnabledProperty.getBoolean(true);
ScriptOpsOnlyProperty = config.get(GENERAL, "OPs Only", false, "Only ops can see and edit scripts");
ScriptOpsOnly = ScriptOpsOnlyProperty.getBoolean(false);
GlobalPlayerScriptsProperty = config.get(GENERAL, "Enable Global Player Scripts", true, "Enables global player event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default.");
GlobalPlayerScripts = GlobalPlayerScriptsProperty.getBoolean(true);
GlobalForgeScriptsProperty = config.get(GENERAL, "Enable Global Forge Event Scripts", true, "Enables global forge event scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. True by default.");
GlobalForgeScripts = GlobalForgeScriptsProperty.getBoolean(true);
GlobalNPCScriptsProperty = config.get(GENERAL, "Enable Global NPC Scripts", false, "Enables global NPC scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. False by default, use with caution!");
GlobalNPCScripts = GlobalNPCScriptsProperty.getBoolean(false);
// Customization
ScriptingECMA6Property = config.get(CUSTOMIZATION, "ECMA6 Scripting Language", false,
2023-01-07 00:21:08 -05:00
"Enables/Disables the use of the the ECMA6 Javascript standard instead of ECMA5.1." +
"\nEnabling this adds many more features to JS in scripts. Only use if on Java 8 or higher." +
2023-01-07 18:07:23 -05:00
"\nNot all ECMA 6 language is supported through this functionality.");
ScriptingECMA6 = ScriptingECMA6Property.getBoolean(false);
ExpandedScriptLimitProperty = config.get(CUSTOMIZATION, "Script Tag Limit", 2,
2023-01-07 00:21:08 -05:00
"If scripts are too long (>65535 characters), they normally won't be saved in NBT data.\n" +
2023-01-07 18:07:23 -05:00
"This config adds additional compound tags to scripts that need it, so you can store much larger scripts!\n" +
"Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution.");
ExpandedScriptLimit = ExpandedScriptLimitProperty.getInt(2);
2023-01-07 00:21:08 -05:00
2023-01-07 18:07:23 -05:00
ScriptDevIDsProperty = config.get(CUSTOMIZATION, "Script Dev UUIDs", "",
2023-01-07 00:21:08 -05:00
"Comma 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,be951074-c7ea-4f02-a725-bf017bc88650\n" +
"Get a player's UUID from a site like NameMC or the API IPlayer.getUniqueID() function!\n" +
2023-01-07 18:07:23 -05:00
"If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter.");
ScriptDevIDs = ScriptDevIDsProperty.getString();
// Convert to Legacy
if(CustomNpcs.legacyExist){
ScriptingEnabled = LegacyConfig.ScriptingEnabled;
ScriptingEnabledProperty.set(ScriptingEnabled);
ScriptOpsOnly = LegacyConfig.ScriptOpsOnly;
ScriptOpsOnlyProperty.set(ScriptOpsOnly);
GlobalPlayerScripts = LegacyConfig.GlobalPlayerScripts;
GlobalPlayerScriptsProperty.set(GlobalPlayerScripts);
GlobalForgeScripts = LegacyConfig.GlobalForgeScripts;
GlobalForgeScriptsProperty.set(GlobalForgeScripts);
GlobalNPCScripts = LegacyConfig.GlobalNPCScripts;
GlobalNPCScriptsProperty.set(GlobalNPCScripts);
ScriptingECMA6 = LegacyConfig.ScriptingECMA6;
ScriptingECMA6Property.set(ScriptingECMA6);
ExpandedScriptLimit = LegacyConfig.ExpandedScriptLimit;
ExpandedScriptLimitProperty.set(ExpandedScriptLimit);
ScriptDevIDs = LegacyConfig.ScriptDevIDs;
ScriptDevIDsProperty.set(ScriptDevIDs);
}
if (ExpandedScriptLimit < 0)
ExpandedScriptLimit = 0;
2023-01-07 00:21:08 -05:00
try {
2023-05-12 20:32:44 -04:00
Developer.ScriptUser.clear();
2023-01-07 00:21:08 -05:00
String[] uuidStrings = ScriptDevIDs.split(",");
for (String s : uuidStrings) {
2023-05-12 20:32:44 -04:00
Developer.ScriptUser.add(UUID.fromString(s));
2023-01-07 00:21:08 -05:00
}
} catch (Exception ignored) {}
}
catch (Exception e)
{
FMLLog.log(Level.ERROR, e, "CNPC+ has had a problem loading its scripting configuration");
}
finally
{
if (config.hasChanged()) {
config.save();
}
}
}
public static boolean isScriptDev(EntityPlayer player) {
if(ScriptOpsOnly && !MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile()) ||
2023-05-12 20:32:44 -04:00
Developer.ScriptUser.contains(player.getUniqueID()) || Developer.Universal.contains(player.getUniqueID())){
2023-01-07 00:21:08 -05:00
return true;
} else return ScriptDevIDs.isEmpty();
}
}