mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Merge pull request #152 from Astrashh/dev/debug-enhancements
Debug enhancements (#149)
This commit is contained in:
@@ -35,8 +35,6 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
boolean isDebug();
|
||||
|
||||
Language getLanguage();
|
||||
|
||||
CheckedRegistry<ConfigPack> getConfigRegistry();
|
||||
|
||||
@@ -55,8 +55,8 @@ public class TerraCommandManager implements CommandManager {
|
||||
private void execute(CommandHolder commandHolder, CommandSender sender, List<String> args) throws CommandException {
|
||||
Class<? extends CommandTemplate> commandClass = commandHolder.clazz;
|
||||
|
||||
if(commandClass.isAnnotationPresent(DebugCommand.class) && !main.isDebug()) {
|
||||
sender.sendMessage("Command must be executed with debug mode enabled.");
|
||||
if(commandClass.isAnnotationPresent(DebugCommand.class) && !main.getTerraConfig().isDebugCommands()) {
|
||||
sender.sendMessage("Command must be executed with debug commands enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Map;
|
||||
public class Parser {
|
||||
private final String data;
|
||||
private final Map<String, FunctionBuilder<? extends Function<?>>> functions = new HashMap<>();
|
||||
private final List<String> ignoredFunctions = new GlueList<>();
|
||||
|
||||
private String id;
|
||||
|
||||
@@ -64,6 +65,11 @@ public class Parser {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parser ignoreFunction(String name) {
|
||||
ignoredFunctions.add(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
@@ -339,7 +345,10 @@ public class Parser {
|
||||
while(tokens.hasNext()) {
|
||||
Token token = tokens.get();
|
||||
if(token.getType().equals(Token.Type.BLOCK_END)) break; // Stop parsing at block end.
|
||||
parsedItems.add(parseItem(tokens, parsedVariables, loop));
|
||||
Item<?> parsedItem = parseItem(tokens, parsedVariables, loop);
|
||||
if (parsedItem != Function.NULL) {
|
||||
parsedItems.add(parsedItem);
|
||||
}
|
||||
if(tokens.hasNext() && !token.isLoopLike()) ParserUtil.checkType(tokens.consume(), Token.Type.STATEMENT_END);
|
||||
}
|
||||
return new Block(parsedItems, first.getPosition());
|
||||
@@ -398,6 +407,10 @@ public class Parser {
|
||||
ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_END); // Remove body end
|
||||
|
||||
if(fullStatement) ParserUtil.checkType(tokens.get(), Token.Type.STATEMENT_END);
|
||||
|
||||
if(ignoredFunctions.contains(identifier.getContent())) {
|
||||
return Function.NULL;
|
||||
}
|
||||
|
||||
if(functions.containsKey(identifier.getContent())) {
|
||||
FunctionBuilder<?> builder = functions.get(identifier.getContent());
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
package com.dfsek.terra.api.structures.parser.lang.functions;
|
||||
|
||||
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||
import com.dfsek.terra.api.structures.parser.lang.variables.Variable;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Function<T> extends Returnable<T> {
|
||||
Function<?> NULL = new Function<Object>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class StructureScript {
|
||||
|
||||
parser.registerFunction("block", new BlockFunctionBuilder(main, false))
|
||||
.registerFunction("dynamicBlock", new BlockFunctionBuilder(main, true))
|
||||
.registerFunction("debugBlock", new BlockFunctionBuilder(main, false))
|
||||
.registerFunction("check", new CheckFunctionBuilder(main))
|
||||
.registerFunction("structure", new StructureFunctionBuilder(registry, main))
|
||||
.registerFunction("randomInt", new RandomFunctionBuilder())
|
||||
@@ -101,6 +102,10 @@ public class StructureScript {
|
||||
.registerFunction("max", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("min", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
|
||||
|
||||
if(!main.getTerraConfig().isDebugScript()) {
|
||||
parser.ignoreFunction("debugBlock");
|
||||
}
|
||||
|
||||
block = parser.parse();
|
||||
this.id = parser.getID();
|
||||
tempID = id;
|
||||
|
||||
@@ -18,9 +18,21 @@ import java.util.jar.JarFile;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PluginConfig implements ConfigTemplate {
|
||||
@Value("debug")
|
||||
@Value("debug.commands")
|
||||
@Default
|
||||
private boolean debug = false;
|
||||
private boolean debugCommands = false;
|
||||
|
||||
@Value("debug.log")
|
||||
@Default
|
||||
private boolean debugLog = false;
|
||||
|
||||
@Value("debug.profiler")
|
||||
@Default
|
||||
private boolean debugProfiler = false;
|
||||
|
||||
@Value("debug.script")
|
||||
@Default
|
||||
private boolean debugScript = false;
|
||||
|
||||
@Value("language")
|
||||
@Default
|
||||
@@ -80,15 +92,31 @@ public class PluginConfig implements ConfigTemplate {
|
||||
} catch(ConfigException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("DebugLogger: " + isDebug());
|
||||
|
||||
if(isDebugCommands()) logger.info("Debug commands enabled.");
|
||||
if(isDebugLogging()) logger.info("Debug logging enabled.");
|
||||
if(isDebugProfiler()) logger.info("Debug profiler enabled.");
|
||||
if(isDebugScript()) logger.info("Script debug blocks enabled.");
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
public boolean isDebugCommands() {
|
||||
return debugCommands;
|
||||
}
|
||||
|
||||
public boolean isDebugLogging() {
|
||||
return debugLog;
|
||||
}
|
||||
|
||||
public boolean isDebugProfiler() {
|
||||
return debugProfiler;
|
||||
}
|
||||
|
||||
public boolean isDebugScript() {
|
||||
return debugScript;
|
||||
}
|
||||
|
||||
public long getDataSaveInterval() {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
debug: false
|
||||
debug:
|
||||
commands: false
|
||||
log: false
|
||||
profiler: false
|
||||
script: false
|
||||
data-save: PT6M
|
||||
language: "en_us"
|
||||
dump-default: true
|
||||
|
||||
@@ -172,7 +172,9 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
|
||||
config.load(this); // Load master config.yml
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
debugLogger.setDebug(isDebug());
|
||||
|
||||
debugLogger.setDebug(config.isDebugLogging());
|
||||
if(config.isDebugProfiler()) profiler.start();
|
||||
|
||||
if(!addonRegistry.loadAll()) {
|
||||
getLogger().severe("Failed to load addons. Please correct addon installations to continue.");
|
||||
@@ -254,12 +256,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return LangUtil.getLanguage();
|
||||
|
||||
@@ -180,11 +180,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return LangUtil.getLanguage();
|
||||
@@ -302,6 +297,9 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
debugLogger.setDebug(config.isDebugLogging());
|
||||
if(config.isDebugProfiler()) profiler.start();
|
||||
|
||||
if(!addonRegistry.loadAll()) {
|
||||
throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue.");
|
||||
}
|
||||
|
||||
@@ -332,11 +332,6 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return LangUtil.getLanguage();
|
||||
|
||||
@@ -68,11 +68,6 @@ public class StandalonePlugin implements TerraPlugin {
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
try {
|
||||
|
||||
@@ -86,11 +86,6 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
return privateConfigDir.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user