Add tab completion to new command system, remove Brigadier

This commit is contained in:
dfsek 2020-10-01 21:54:43 -07:00
parent e36e5f390c
commit 8b0c2030ee
27 changed files with 229 additions and 124 deletions

14
pom.xml
View File

@ -33,10 +33,6 @@
<pattern>org.apache.commons</pattern>
<shadedPattern>com.dfsek.terra.lib.commons</shadedPattern>
</relocation>
<relocation>
<pattern>me.lucko.commodore</pattern>
<shadedPattern>com.dfsek.terra.lib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
@ -59,10 +55,6 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>gaea.local</id>
<name>gaea-local</name>
@ -97,12 +89,6 @@
<artifactId>gaea</artifactId>
<version>1.10.82</version>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>commodore</artifactId>
<version>1.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-imaging</artifactId>

View File

@ -3,12 +3,7 @@ package com.dfsek.terra;
import com.dfsek.terra.command.TerraCommand;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.commodore.Commodore;
import me.lucko.commodore.CommodoreProvider;
import me.lucko.commodore.file.CommodoreFileFormat;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.generator.ChunkGenerator;
@ -16,7 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.Objects;
public class Terra extends JavaPlugin {
private static FileConfiguration config;
@ -37,33 +32,17 @@ public class Terra extends JavaPlugin {
Debug.setMain(this);
ConfigUtil.loadConfig(this);
PluginCommand command = getCommand("terra");
command.setExecutor(new TerraCommand());
if (CommodoreProvider.isSupported()) {
Commodore commodore = CommodoreProvider.getCommodore(this);
try {
register(this, command, commodore);
} catch(Exception e) {
e.printStackTrace();
}
} else getLogger().severe("Brigadier is not properly supported! Commands will NOT work properly!");
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
TerraCommand command = new TerraCommand();
c.setExecutor(command);
c.setTabCompleter(command);
saveDefaultConfig();
config = getConfig();
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, ConfigUtil.dataSave, ConfigUtil.dataSave);
}
public static void register(JavaPlugin plugin, Command pluginCommand, Commodore commodore) throws Exception {
try (InputStream is = Terra.class.getResourceAsStream("/terra.commodore")) {
if (is == null) {
throw new Exception("Brigadier command data missing from jar");
}
LiteralCommandNode<?> commandNode = CommodoreFileFormat.parse(is);
commodore.register(pluginCommand, commandNode, player -> player.hasPermission("terra.command"));
}
}
@Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
return new TerraChunkGenerator();

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.async;
public class AsyncBiomeFinder {
}

View File

@ -4,9 +4,9 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.WorldConfig;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.generation.GenerationPhase;
@ -16,7 +16,7 @@ import java.util.List;
public class BiomeCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
sender.sendMessage("You are in " + TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
@ -37,4 +37,9 @@ public class BiomeCommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -0,0 +1,41 @@
package com.dfsek.terra.command;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class BiomeTeleportCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
return false;
}
@Override
public String getName() {
return "tpbiome";
}
@Override
public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
if(!(sender instanceof Player) || !(((Player) sender).getWorld().getGenerator() instanceof TerraChunkGenerator)) return Collections.emptyList();
return TerraWorld.getWorld(((Player) sender).getWorld()).getConfig().getBiomeIDs();
}
}

View File

@ -8,6 +8,7 @@ import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -17,7 +18,7 @@ import java.util.Random;
public class OreCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
Block bl = sender.getTargetBlockExact(25);
if(args.length > 0) {
OreConfig ore = TerraWorld.getWorld(w).getConfig().getOre(args[0]);
@ -51,4 +52,9 @@ public class OreCommand extends WorldCommand {
public String getName() {
return "ore";
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -21,7 +21,7 @@ public class ReloadCommand extends Command {
}
@Override
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
ConfigUtil.loadConfig(Terra.getInstance());
sender.sendMessage("Reloaded Terra config.");
return true;
@ -31,4 +31,9 @@ public class ReloadCommand extends Command {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -2,7 +2,9 @@ package com.dfsek.terra.command;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@ -15,7 +17,7 @@ public class SaveDataCommand extends Command {
}
@Override
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
TerraChunkGenerator.saveAll();
sender.sendMessage("Saved population data.");
return true;
@ -30,4 +32,9 @@ public class SaveDataCommand extends Command {
public List<Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -3,19 +3,15 @@ package com.dfsek.terra.command;
import com.dfsek.terra.command.image.ImageCommand;
import com.dfsek.terra.command.profile.ProfileCommand;
import com.dfsek.terra.command.structure.StructureCommand;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import com.dfsek.terra.command.type.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class TerraCommand implements CommandExecutor, TabExecutor {
public class TerraCommand extends Command {
private final List<com.dfsek.terra.command.type.Command> commands = Arrays.asList(new ReloadCommand(),
new BiomeCommand(),
new OreCommand(),
@ -25,7 +21,17 @@ public class TerraCommand implements CommandExecutor, TabExecutor {
new ImageCommand());
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public String getName() {
return "terra";
}
@Override
public List<Command> getSubCommands() {
return commands;
}
@Override
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 0) {
for(com.dfsek.terra.command.type.Command c : commands) {
if(c.getName().equals(args[0])) return c.execute(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
@ -41,12 +47,16 @@ public class TerraCommand implements CommandExecutor, TabExecutor {
sender.sendMessage("structure - Load and export structures");
sender.sendMessage("profile - Profiler options");
}
return false;
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
/*if(args[0].equals("tpbiome")) return BiomeConfig.getBiomeIDs();
else if(args[0].equals("ore")) return OreConfig.getOreIDs();
else*/ return Collections.emptyList();
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -4,15 +4,17 @@ import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.command.image.gui.GUICommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ImageCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
sender.sendMessage("---------------Terra/image---------------");
sender.sendMessage("render - Render an image with a given width and height, that can later be imported as a world.");
sender.sendMessage("gui - Open debug GUI (Must be enabled in config)");
@ -33,4 +35,9 @@ public class ImageCommand extends WorldCommand {
public String getName() {
return "image";
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -5,6 +5,7 @@ import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -14,7 +15,7 @@ import java.util.List;
public class RenderCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
try {
WorldImageGenerator g = new WorldImageGenerator(world, Integer.parseInt(args[0]), Integer.parseInt(args[1]));
g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ());
@ -45,4 +46,9 @@ public class RenderCommand extends WorldCommand {
public int arguments() {
return 2;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -3,15 +3,17 @@ package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class GUICommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
sender.sendMessage("-------------Terra/image/gui-------------");
sender.sendMessage("raw - Open GUI with raw Biome data");
sender.sendMessage("step - Re-render data to show borders more clearly");
@ -32,4 +34,9 @@ public class GUICommand extends WorldCommand {
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -7,6 +7,7 @@ import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -15,7 +16,7 @@ import java.util.List;
public class RawGUICommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(! ConfigUtil.debug) {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
return true;
@ -40,4 +41,9 @@ public class RawGUICommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -7,6 +7,7 @@ import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -15,7 +16,7 @@ import java.util.List;
public class StepGUICommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(! ConfigUtil.debug) {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
return true;
@ -40,4 +41,9 @@ public class StepGUICommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -3,15 +3,17 @@ package com.dfsek.terra.command.profile;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ProfileCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
sender.sendMessage("---------------Terra/profile---------------");
sender.sendMessage("start - Starts the profiler");
sender.sendMessage("stop - Stops the profiler");
@ -34,4 +36,9 @@ public class ProfileCommand extends WorldCommand {
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.WorldProfiler;
@ -13,7 +14,7 @@ import java.util.List;
public class QueryCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
WorldProfiler profile = TerraProfiler.fromWorld(w);
sender.sendMessage(profile.getResultsFormatted());
return true;
@ -33,4 +34,9 @@ public class QueryCommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.WorldProfiler;
@ -13,7 +14,7 @@ import java.util.List;
public class ResetCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.reset();
sender.sendMessage("Profiler has been reset.");
@ -34,4 +35,9 @@ public class ResetCommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.WorldProfiler;
@ -13,7 +14,7 @@ import java.util.List;
public class StartCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.setProfiling(true);
sender.sendMessage("Profiler has started.");
@ -34,4 +35,9 @@ public class StartCommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.WorldProfiler;
@ -13,7 +14,7 @@ import java.util.List;
public class StopCommand extends WorldCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
WorldProfiler profile = TerraProfiler.fromWorld(world);
profile.setProfiling(false);
sender.sendMessage("Profiler has stopped.");
@ -34,4 +35,9 @@ public class StopCommand extends WorldCommand {
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -12,6 +12,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -22,7 +23,7 @@ import java.util.List;
public class ExportCommand extends PlayerCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
if(we == null) {
sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures.");
@ -63,6 +64,11 @@ public class ExportCommand extends PlayerCommand {
return true;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
@Override
public String getName() {
return "export";

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.Terra;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.structure.GaeaStructure;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -14,7 +15,7 @@ import java.util.List;
public class LoadCommand extends PlayerCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
try {
GaeaStructure.Rotation r = GaeaStructure.Rotation.fromDegrees(Integer.parseInt(args[1]));
GaeaStructure struc = GaeaStructure.load(new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
@ -32,6 +33,11 @@ public class LoadCommand extends PlayerCommand {
return "load";
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
@Override
public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList();

View File

@ -2,15 +2,17 @@ package com.dfsek.terra.command.structure;
import com.dfsek.terra.command.type.PlayerCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class StructureCommand extends PlayerCommand {
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("---------------Terra/structure---------------");
sender.sendMessage("export - Export your current WorldEdit selection as a Terra structure.");
sender.sendMessage("load - Load a Terra structure");
@ -22,6 +24,11 @@ public class StructureCommand extends PlayerCommand {
return Arrays.asList(new ExportCommand(), new LoadCommand());
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
@Override
public int arguments() {
return 1;

View File

@ -1,15 +1,21 @@
package com.dfsek.terra.command.type;
import com.dfsek.terra.Debug;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Represents a command or subcommand, can be nested via getSubCommands.
*/
public abstract class Command {
public abstract class Command implements CommandExecutor, TabCompleter {
/**
* Gets the name of the command/subcommand
* @return Name of command
@ -34,8 +40,8 @@ public abstract class Command {
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
public abstract boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args);
public abstract boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args);
/**
* Gets the number of arguments
* @return Number of arguments
@ -54,18 +60,31 @@ public abstract class Command {
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
public final boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) {
@Override
public final boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 0) {
for(Command c : getSubCommands()) {
if(c.getName().equals(args[0])) return c.execute(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
if(c.getName().equals(args[0])) return c.onCommand(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
}
if(args.length != arguments()) {
sender.sendMessage("Invalid command.");
return true;
}
return onCommand(sender, command, label, args);
return execute(sender, command, label, args);
}
return onCommand(sender, command, label, new String[] {});
return execute(sender, command, label, new String[] {});
}
public abstract List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args);
@Override
public final @Nullable List<String> onTabComplete(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String alias, @NotNull String[] args) {
List<String> complete = new ArrayList<>();
if(args.length > 0) for(Command c : getSubCommands()) {
if(c.getName().startsWith(args[0])) complete.add(c.getName());
if(c.getName().equals(args[0])) return c.onTabComplete(sender, command, alias, Arrays.stream(args, 1, args.length).toArray(String[]::new));
}
complete.addAll(getTabCompletions(sender, alias, args));
return complete;
}
}

View File

@ -21,13 +21,13 @@ public abstract class PlayerCommand extends Command {
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
public final boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage("Command is for players only.");
return true;
}
Player p = (Player) sender;
return onCommand(p, command, label, args);
return execute(p, command, label, args);
}
/**
* Executes the given command, returning its success.
@ -41,5 +41,5 @@ public abstract class PlayerCommand extends Command {
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
public abstract boolean onCommand(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args);
public abstract boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args);
}

View File

@ -23,9 +23,9 @@ public abstract class WorldCommand extends PlayerCommand {
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public final boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(sender.getWorld().getGenerator() instanceof TerraChunkGenerator) {
return onCommand(sender, command, label, args, sender.getWorld());
return execute(sender, command, label, args, sender.getWorld());
} else {
sender.sendMessage("World is not a Terra world!");
}
@ -45,5 +45,5 @@ public abstract class WorldCommand extends PlayerCommand {
* @param world World in which command was executed
* @return true if a valid command, otherwise false
*/
public abstract boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world);
public abstract boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world);
}

View File

@ -34,7 +34,9 @@ public class ConfigLoader {
configs.put(o.getID(), o);
main.getLogger().info("Loaded " + o.toString() + " from file " + path.toString());
} catch(IllegalAccessException | InstantiationException | NoSuchMethodException e) {
main.getLogger().severe("An error occurred while loading configurations.");
e.printStackTrace();
main.getLogger().severe("Please report this to Terra.");
} catch(IllegalArgumentException | InvocationTargetException e) {
if(ConfigUtil.debug) e.printStackTrace();
main.getLogger().severe("Configuration error for Terra object. File: " + path.toString());

View File

@ -1,41 +0,0 @@
terra {
biome;
reload;
profile {
start;
stop;
reset;
query;
}
tpbiome {
biome brigadier:string single_word;
}
ore {
ore brigadier:string single_word;
}
image {
render {
size_x brigadier:integer {
size_z brigadier:integer;
}
}
gui {
raw;
step;
}
}
structure {
export {
structure brigadier:string single_word;
}
load {
structure brigadier:string single_word {
rotation brigadier:integer {
respect_chunk brigadier:bool;
}
}
}
getspawn;
}
save-data;
}