Clean up commands.

This commit is contained in:
Brianna 2020-09-01 13:30:08 -05:00
parent 50f5a5d5b4
commit f61e9e17f7
8 changed files with 50 additions and 50 deletions

View File

@ -105,13 +105,13 @@ public class UltimateStacker extends SongodaPlugin {
// Setup plugin commands
this.commandManager = new CommandManager(this);
this.commandManager.addMainCommand("us")
.addSubCommands(new CommandSettings(guiManager),
new CommandRemoveAll(),
new CommandReload(),
new CommandGiveSpawner(),
new CommandSpawn(),
new CommandLootables(),
new CommandConvert(guiManager)
.addSubCommands(new CommandSettings(this, guiManager),
new CommandRemoveAll(this),
new CommandReload(this),
new CommandGiveSpawner(this),
new CommandSpawn(this),
new CommandLootables(this),
new CommandConvert(this, guiManager)
);
this.lootablesManager = new LootablesManager();

View File

@ -13,13 +13,13 @@ import java.util.List;
public class CommandConvert extends AbstractCommand {
UltimateStacker instance;
GuiManager guiManager;
private final UltimateStacker plugin;
private final GuiManager guiManager;
public CommandConvert(GuiManager guiManager) {
super(true, "convert");
public CommandConvert(UltimateStacker plugin, GuiManager guiManager) {
super(CommandType.PLAYER_ONLY, "convert");
this.guiManager = guiManager;
instance = UltimateStacker.getInstance();
this.plugin = plugin;
}
@Override

View File

@ -16,18 +16,18 @@ import java.util.stream.Collectors;
public class CommandGiveSpawner extends AbstractCommand {
UltimateStacker instance;
private final UltimateStacker plugin;
public CommandGiveSpawner() {
super(false, "givespawner");
instance = UltimateStacker.getInstance();
public CommandGiveSpawner(UltimateStacker plugin) {
super(CommandType.CONSOLE_OK, "givespawner");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2) return ReturnType.SYNTAX_ERROR;
if (Bukkit.getPlayer(args[0]) == null && !args[0].trim().toLowerCase().equals("all")) {
if (Bukkit.getPlayer(args[0]) == null && !args[0].trim().equalsIgnoreCase("all")) {
sender.sendMessage(args[0] + " is not a player...");
return ReturnType.SYNTAX_ERROR;
}
@ -41,7 +41,7 @@ public class CommandGiveSpawner extends AbstractCommand {
}
if (type == null) {
instance.getLocale().newMessage("&7The entity StackType &6" + args[1] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
plugin.getLocale().newMessage("&7The entity StackType &6" + args[1] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
StringBuilder list = new StringBuilder();
for (EntityType types : EntityType.values()) {
@ -56,13 +56,13 @@ public class CommandGiveSpawner extends AbstractCommand {
if (!args[0].trim().toLowerCase().equals("all")) {
Player player = Bukkit.getOfflinePlayer(args[0]).getPlayer();
player.getInventory().addItem(itemStack);
instance.getLocale().getMessage("command.give.success")
plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("type", Methods.compileSpawnerName(type, amt))
.sendPrefixedMessage(player);
} else {
for (Player player : Bukkit.getOnlinePlayers()) {
player.getInventory().addItem(itemStack);
instance.getLocale().getMessage("command.give.success")
plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("type", Methods.compileSpawnerName(type, amt))
.sendPrefixedMessage(player);
}

View File

@ -10,17 +10,17 @@ import java.util.List;
public class CommandLootables extends AbstractCommand {
UltimateStacker instance;
private final UltimateStacker plugin;
public CommandLootables() {
super(true, "lootables");
instance = UltimateStacker.getInstance();
public CommandLootables(UltimateStacker plugin) {
super(CommandType.PLAYER_ONLY, "lootables");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player p = (Player) sender;
instance.getGuiManager().showGUI(p, new GuiEditor(instance.getLootablesManager().getLootManager()));
plugin.getGuiManager().showGUI(p, new GuiEditor(plugin.getLootablesManager().getLootManager()));
return ReturnType.SUCCESS;
}

View File

@ -8,17 +8,17 @@ import java.util.List;
public class CommandReload extends AbstractCommand {
UltimateStacker instance;
private final UltimateStacker plugin;
public CommandReload() {
super(false, "reload");
instance = UltimateStacker.getInstance();
public CommandReload(UltimateStacker plugin) {
super(CommandType.CONSOLE_OK, "reload");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reloadConfig();
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
plugin.reloadConfig();
plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -19,11 +19,11 @@ import java.util.List;
public class CommandRemoveAll extends AbstractCommand {
UltimateStacker instance;
private final UltimateStacker plugin;
public CommandRemoveAll() {
super(false, "removeall");
instance = UltimateStacker.getInstance();
public CommandRemoveAll(UltimateStacker plugin) {
super(CommandType.CONSOLE_OK, "removeall");
this.plugin = plugin;
}
@Override
@ -40,7 +40,7 @@ public class CommandRemoveAll extends AbstractCommand {
}
int amountRemoved = 0;
EntityStackManager stackManager = instance.getEntityStackManager();
EntityStackManager stackManager = plugin.getEntityStackManager();
for (World world : Bukkit.getWorlds()) {
for (Entity entityO : world.getEntities()) {
if (entityO instanceof Player || !(entityO instanceof LivingEntity)) continue;
@ -61,10 +61,10 @@ public class CommandRemoveAll extends AbstractCommand {
if (type.equalsIgnoreCase("items") && amountRemoved == 1) type = "Item";
if (amountRemoved == 0) {
instance.getLocale().newMessage("&7No" + (all ? " " : " stacked ")
plugin.getLocale().newMessage("&7No" + (all ? " " : " stacked ")
+ type + " exist that could be removed.").sendPrefixedMessage(sender);
} else {
instance.getLocale().newMessage("&7Removed &6" + amountRemoved + (all ? " " : " stacked ")
plugin.getLocale().newMessage("&7Removed &6" + amountRemoved + (all ? " " : " stacked ")
+ Methods.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender);
}
return ReturnType.SUCCESS;

View File

@ -12,18 +12,18 @@ import java.util.List;
public class CommandSettings extends AbstractCommand {
UltimateStacker instance;
GuiManager guiManager;
private final UltimateStacker plugin;
private final GuiManager guiManager;
public CommandSettings(GuiManager guiManager) {
public CommandSettings(UltimateStacker plugin, GuiManager guiManager) {
super(CommandType.PLAYER_ONLY, "Settings");
this.guiManager = guiManager;
instance = UltimateStacker.getInstance();
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
guiManager.showGUI((Player) sender, new PluginConfigGui(instance));
guiManager.showGUI((Player) sender, new PluginConfigGui(plugin));
return ReturnType.SUCCESS;
}

View File

@ -22,11 +22,11 @@ import java.util.stream.Collectors;
*/
public class CommandSpawn extends AbstractCommand {
UltimateStacker instance;
private final UltimateStacker plugin;
public CommandSpawn() {
super(true, "spawn");
instance = UltimateStacker.getInstance();
public CommandSpawn(UltimateStacker plugin) {
super(CommandType.PLAYER_ONLY, "spawn");
this.plugin = plugin;
}
@Override
@ -44,7 +44,7 @@ public class CommandSpawn extends AbstractCommand {
}
if (type == null) {
instance.getLocale().newMessage("&7The entity &6" + args[0] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
plugin.getLocale().newMessage("&7The entity &6" + args[0] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
StringBuilder list = new StringBuilder();
for (EntityType types : EntityType.values()) {
@ -54,10 +54,10 @@ public class CommandSpawn extends AbstractCommand {
sender.sendMessage(Methods.formatText("&6" + list));
} else {
LivingEntity entity = (LivingEntity)player.getWorld().spawnEntity(player.getTargetBlock((Set<Material>)null, 200).getLocation(), type);
EntityStack stack = instance.getEntityStackManager().addStack(entity);
EntityStack stack = plugin.getEntityStackManager().addStack(entity);
stack.createDuplicates(((Methods.isInt(args[1])) ? Integer.parseInt(args[1]) : 1) - 1);
stack.updateStack();
instance.getStackingTask().attemptSplit(stack, entity);
plugin.getStackingTask().attemptSplit(stack, entity);
}
return ReturnType.SUCCESS;