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