Refactor commands

This commit is contained in:
dfsek 2020-10-01 02:50:37 -07:00
parent efd52a2002
commit 88067a04c8
21 changed files with 38 additions and 44 deletions

View File

@ -2,6 +2,7 @@ package com.dfsek.terra.command;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -30,7 +31,7 @@ public class BiomeCommand extends PlayerCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.command; package com.dfsek.terra.command;
import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.config.genconfig.OreConfig; import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -33,7 +34,7 @@ public class OreCommand extends PlayerCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.command; package com.dfsek.terra.command;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.config.ConfigUtil; import com.dfsek.terra.config.ConfigUtil;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.command; package com.dfsek.terra.command;
import com.dfsek.terra.command.type.Command;
import com.dfsek.terra.generation.TerraChunkGenerator; import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -5,20 +5,18 @@ import com.dfsek.terra.command.profile.ProfileCommand;
import com.dfsek.terra.command.structure.StructureCommand; import com.dfsek.terra.command.structure.StructureCommand;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.OreConfig; import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class TerraCommand implements CommandExecutor, TabExecutor { public class TerraCommand implements CommandExecutor, TabExecutor {
private final List<com.dfsek.terra.command.Command> commands = Arrays.asList(new ReloadCommand(), private final List<com.dfsek.terra.command.type.Command> commands = Arrays.asList(new ReloadCommand(),
new BiomeCommand(), new BiomeCommand(),
new OreCommand(), new OreCommand(),
new ProfileCommand(), new ProfileCommand(),
@ -29,7 +27,7 @@ public class TerraCommand implements CommandExecutor, TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 0) { if(args.length > 0) {
for(com.dfsek.terra.command.Command c : commands) { 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)); if(c.getName().equals(args[0])) return c.execute(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
} }
sender.sendMessage("Invalid command."); sender.sendMessage("Invalid command.");

View File

@ -1,19 +1,13 @@
package com.dfsek.terra.command.image; package com.dfsek.terra.command.image;
import com.dfsek.terra.Terra; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.command.PlayerCommand;
import com.dfsek.terra.command.WorldCommand;
import com.dfsek.terra.command.image.gui.GUICommand; import com.dfsek.terra.command.image.gui.GUICommand;
import com.dfsek.terra.config.WorldConfig;
import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ImageCommand extends WorldCommand { public class ImageCommand extends WorldCommand {
@ -26,7 +20,7 @@ public class ImageCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Arrays.asList(new RenderCommand(), new GUICommand()); return Arrays.asList(new RenderCommand(), new GUICommand());
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.command.image; package com.dfsek.terra.command.image;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.image.WorldImageGenerator; import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -37,7 +37,7 @@ public class RenderCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,6 @@
package com.dfsek.terra.command.image.gui; package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.WorldConfig;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -25,7 +24,7 @@ public class GUICommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Arrays.asList(new StepGUICommand(), new RawGUICommand()); return Arrays.asList(new StepGUICommand(), new RawGUICommand());
} }

View File

@ -1,6 +1,6 @@
package com.dfsek.terra.command.image.gui; package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.ConfigUtil; import com.dfsek.terra.config.ConfigUtil;
import com.dfsek.terra.config.WorldConfig; import com.dfsek.terra.config.WorldConfig;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
@ -31,7 +31,7 @@ public class RawGUICommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,6 +1,6 @@
package com.dfsek.terra.command.image.gui; package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.ConfigUtil; import com.dfsek.terra.config.ConfigUtil;
import com.dfsek.terra.config.WorldConfig; import com.dfsek.terra.config.WorldConfig;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
@ -31,7 +31,7 @@ public class StepGUICommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,6 +1,6 @@
package com.dfsek.terra.command.profile; package com.dfsek.terra.command.profile;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class ProfileCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Arrays.asList(new QueryCommand(), new ResetCommand(), new StartCommand(), new StopCommand()); return Arrays.asList(new QueryCommand(), new ResetCommand(), new StartCommand(), new StopCommand());
} }

View File

@ -1,8 +1,7 @@
package com.dfsek.terra.command.profile; package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.PlayerCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.command.WorldCommand;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +25,7 @@ public class QueryCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.command.profile; package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class ResetCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.command.profile; package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class StartCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.command.profile; package com.dfsek.terra.command.profile;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.command.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class StopCommand extends WorldCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -2,7 +2,7 @@ package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.WorldEditUtil; import com.dfsek.terra.WorldEditUtil;
import com.dfsek.terra.command.PlayerCommand; import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.structure.GaeaStructure; import com.dfsek.terra.structure.GaeaStructure;
import com.dfsek.terra.structure.InitializationException; import com.dfsek.terra.structure.InitializationException;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
@ -69,7 +69,7 @@ public class ExportCommand extends PlayerCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.command.structure; package com.dfsek.terra.command.structure;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.command.PlayerCommand; import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.structure.GaeaStructure; import com.dfsek.terra.structure.GaeaStructure;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -33,7 +33,7 @@ public class LoadCommand extends PlayerCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -1,6 +1,6 @@
package com.dfsek.terra.command.structure; package com.dfsek.terra.command.structure;
import com.dfsek.terra.command.PlayerCommand; import com.dfsek.terra.command.type.PlayerCommand;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -18,7 +18,7 @@ public class StructureCommand extends PlayerCommand {
} }
@Override @Override
public List<com.dfsek.terra.command.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Arrays.asList(new ExportCommand(), new LoadCommand()); return Arrays.asList(new ExportCommand(), new LoadCommand());
} }

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.command; package com.dfsek.terra.command.type;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -13,7 +13,7 @@ public abstract class Command {
public abstract int arguments(); public abstract int arguments();
public final boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { public final boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 0) { if(args.length > 0) {
for(com.dfsek.terra.command.Command c : getSubCommands()) { 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.execute(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new));
} }
if(args.length != arguments()) { if(args.length != arguments()) {

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.command; package com.dfsek.terra.command.type;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.command; package com.dfsek.terra.command.type;
import com.dfsek.terra.generation.TerraChunkGenerator; import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World; import org.bukkit.World;