diff --git a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index 07f9441e4..6bd141802 100644 --- a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -49,4 +49,8 @@ public interface TerraPlugin extends LoaderRegistrar { DebugLogger getDebugLogger(); EventManager getEventManager(); + + default String getVersion() { + return "@VERSION@"; + } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 14bfb52c5..0a89fdd15 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -150,7 +150,11 @@ public class TerraCommandManager implements CommandManager { pluginInjector.inject(argumentParser); field.setAccessible(true); - field.set(template, argumentParser.parse(state.getSender(), state.getArgument(argument))); + String value = state.getArgument(argument); + + if(value == null) value = holder.argumentMap.get(argumentTarget.value()).defaultValue(); + + field.set(template, argumentParser.parse(state.getSender(), value)); } if(field.isAnnotationPresent(SwitchTarget.class)) { SwitchTarget switchTarget = field.getAnnotation(SwitchTarget.class); @@ -200,7 +204,7 @@ public class TerraCommandManager implements CommandManager { private int getMaxArgumentDepth(CommandHolder holder) { int max = 0; - max = FastMath.max(holder.arguments.size(), max); + max = FastMath.max(holder.arguments.size() + holder.switchList.size(), max); for(CommandHolder value : holder.subcommands.values()) { max = FastMath.max(max, getMaxArgumentDepth(value) + 1); } @@ -240,6 +244,7 @@ public class TerraCommandManager implements CommandManager { private final Map subcommands = new HashMap<>(); private final Map switches = new HashMap<>(); private final List arguments; + private final List switchList; private final Map argumentMap = new HashMap<>(); private CommandHolder(Class clazz) throws MalformedCommandException { @@ -267,7 +272,11 @@ public class TerraCommandManager implements CommandManager { argumentMap.put(argument.value(), argument); } arguments = Arrays.asList(command.arguments()); - } else arguments = Collections.emptyList(); + switchList = Arrays.asList(command.switches()); + } else { + arguments = Collections.emptyList(); + switchList = Collections.emptyList(); + } } } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java index a2625ee26..d0c91a965 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java @@ -20,4 +20,6 @@ public @interface Argument { Class tabCompleter() default NothingCompleter.class; Class> argumentParser() default StringArgumentParser.class; + + String defaultValue() default ""; } diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index c6157d439..ae5bdd1aa 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -10,5 +10,6 @@ public final class CommandUtil { manager.register("profile", ProfileCommand.class); manager.register("reload", ReloadCommand.class); manager.register("addons", AddonsCommand.class); + manager.register("version", VersionCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java index 9b9e7355c..1d5ca4044 100644 --- a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.commands.structure.SpawnCommand; import com.dfsek.terra.commands.structure.StructureExportCommand; import com.dfsek.terra.commands.structure.StructureLoadCommand; @@ -18,6 +19,11 @@ import com.dfsek.terra.commands.structure.StructureLoadCommand; clazz = StructureLoadCommand.class, value = "load", aliases = "ld" + ), + @Subcommand( + clazz = SpawnCommand.class, + value = "spawn", + aliases = "s" ) } ) diff --git a/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java new file mode 100644 index 000000000..b03a3a9ba --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java @@ -0,0 +1,20 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; + +@Command +public class VersionCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + String terraVersion = main.getVersion(); + LangUtil.send("command.version", sender, terraVersion, main.platformName()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java new file mode 100644 index 000000000..629261288 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java @@ -0,0 +1,46 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.structures.parser.lang.constants.NumericConstant; +import com.dfsek.terra.api.structures.script.TerraImplementationArguments; +import com.dfsek.terra.api.structures.script.functions.CheckFunction; +import com.dfsek.terra.api.structures.structure.Rotation; +import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; +import com.dfsek.terra.api.structures.tokenizer.Position; +import com.dfsek.terra.api.util.FastRandom; + +import java.util.HashMap; + +@DebugCommand +@PlayerCommand +@WorldCommand +@Command +public class SpawnCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + Location p = player.getLocation(); + int x = p.getBlockX(); + int y = p.getBlockY(); + int z = p.getBlockZ(); + Position dummy = new Position(0, 0); + + String check = new CheckFunction(main, new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer( + new com.dfsek.terra.api.math.vector.Location(player.getWorld(), x, y, z) + ), Rotation.NONE, new FastRandom(), 0), new HashMap<>()); + + sender.sendMessage("Found: " + check); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index b395b50b8..62b172373 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -17,6 +17,9 @@ import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.commands.structure.argument.ScriptArgumentParser; +import com.dfsek.terra.commands.structure.completer.RotationCompleter; +import com.dfsek.terra.commands.structure.completer.ScriptCompleter; import java.util.concurrent.ThreadLocalRandom; @@ -34,7 +37,8 @@ import java.util.concurrent.ThreadLocalRandom; value = "rotation", required = false, tabCompleter = RotationCompleter.class, - argumentParser = IntegerArgumentParser.class + argumentParser = IntegerArgumentParser.class, + defaultValue = "0" ) }, switches = { diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java b/common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java similarity index 92% rename from common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java rename to common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java index 3c34c74af..3797c08cd 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.argument; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.arg.ArgumentParser; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java rename to common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java index d0f3933bb..3bfed746d 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.completer; import com.dfsek.terra.api.command.tab.TabCompleter; import com.dfsek.terra.api.platform.CommandSender; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java rename to common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java index c650ef685..24f927baa 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.completer; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.tab.TabCompleter; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java index dadc4b968..525315454 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java @@ -1,19 +1,19 @@ package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.SingleBiomeProvider; +import com.dfsek.terra.config.builder.BiomeBuilder; public class SingleBiomeProviderTemplate extends BiomeProviderTemplate { @Value("biome") - private TerraBiome biome; + private BiomeBuilder biome; public SingleBiomeProviderTemplate() { } @Override public BiomeProvider build(long seed) { - return new SingleBiomeProvider(biome); + return new SingleBiomeProvider(biome.apply(seed)); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java deleted file mode 100644 index b9686d186..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.TerraBukkitPlugin; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class VersionCommand extends Command { - public VersionCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "version"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - String terraVersion = ((TerraBukkitPlugin) getMain()).getDescription().getVersion(); - LangUtil.send("command.version", new BukkitCommandSender(sender), terraVersion, getMain().platformName()); - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -}