mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-25 11:46:45 +01:00
CommandManager updated to v2
This commit is contained in:
parent
8d2f36bbdf
commit
1a9520033a
@ -19,5 +19,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Lib1" level="project" />
|
||||
<orderEntry type="library" name="spigot-1.132" level="project" />
|
||||
<orderEntry type="library" name="spigot-1.13.1" level="project" />
|
||||
<orderEntry type="library" name="Lib" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -22,5 +22,7 @@
|
||||
<orderEntry type="library" name="spigot-1.131" level="project" />
|
||||
<orderEntry type="library" name="spigot-1.132" level="project" />
|
||||
<orderEntry type="module" module-name="EpicHoppers-API" />
|
||||
<orderEntry type="library" name="spigot-1.13.1" level="project" />
|
||||
<orderEntry type="library" name="Lib" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -66,6 +66,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
private Locale locale;
|
||||
|
||||
private HopperManager hopperManager;
|
||||
private CommandManager commandManager;
|
||||
private LevelManager levelManager;
|
||||
private BoostManager boostManager;
|
||||
private PlayerDataManager playerDataManager;
|
||||
@ -107,19 +108,20 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
settingsManager = new SettingsManager(this);
|
||||
boostManager = new BoostManager();
|
||||
setupConfig();
|
||||
enchantmentHandler = new EnchantmentHandler();
|
||||
playerDataManager = new PlayerDataManager();
|
||||
|
||||
// Locales
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
|
||||
|
||||
loadLevelManager();
|
||||
|
||||
hopperManager = new EHopperManager();
|
||||
playerDataManager = new PlayerDataManager();
|
||||
boostManager = new BoostManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
loadLevelManager();
|
||||
|
||||
/*
|
||||
* Register hoppers into HopperManger from configuration
|
||||
@ -197,9 +199,6 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(this), this);
|
||||
|
||||
// Command registration
|
||||
this.getCommand("EpicHoppers").setExecutor(new CommandManager(this));
|
||||
|
||||
// Register default hooks
|
||||
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("FactionsFramework")) this.register(HookFactions::new);
|
||||
@ -435,6 +434,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
return boostManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LevelManager getLevelManager() {
|
||||
return levelManager;
|
||||
|
@ -5,30 +5,37 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private final AbstractCommand parent;
|
||||
public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR }
|
||||
|
||||
private final String permissionNode;
|
||||
private final AbstractCommand parent;
|
||||
|
||||
private final String command;
|
||||
|
||||
protected AbstractCommand(String command, String permissionNode, AbstractCommand parent) {
|
||||
private final boolean noConsole;
|
||||
|
||||
protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) {
|
||||
this.command = command;
|
||||
this.parent = parent;
|
||||
this.permissionNode = permissionNode;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public String getPermissionNode() {
|
||||
return permissionNode;
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
protected abstract boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args);
|
||||
protected abstract ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
}
|
||||
|
@ -6,8 +6,10 @@ import com.songoda.epichoppers.command.commands.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
@ -19,6 +21,8 @@ public class CommandManager implements CommandExecutor {
|
||||
public CommandManager(EpicHoppersPlugin instance) {
|
||||
this.instance = instance;
|
||||
|
||||
instance.getCommand("EpicHoppers").setExecutor(this);
|
||||
|
||||
AbstractCommand commandEpicHoppers = addCommand(new CommandEpicHoppers());
|
||||
|
||||
addCommand(new CommandReload(commandEpicHoppers));
|
||||
@ -38,13 +42,13 @@ public class CommandManager implements CommandExecutor {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
|
||||
if (strings.length == 0) {
|
||||
processPerms(abstractCommand, commandSender, strings);
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) {
|
||||
processPerms(abstractCommand, commandSender, strings);
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -53,12 +57,23 @@ public class CommandManager implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processPerms(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
command.runCommand(instance, sender, strings);
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
||||
|
@ -10,19 +10,38 @@ import org.bukkit.entity.Player;
|
||||
public class CommandBook extends AbstractCommand {
|
||||
|
||||
public CommandBook(AbstractCommand parent) {
|
||||
super("book", "epichoppers.admin", parent);
|
||||
super("book", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
if (sender instanceof Player)
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).getInventory().addItem(instance.enchantmentHandler.getbook());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
} else if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cThat username does not exist, or the user is not online!"));
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
Bukkit.getPlayerExact(args[1]).getInventory().addItem(instance.enchantmentHandler.getbook());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
return false;
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/eh book [player]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives Sync Touch book to you or a player.";
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,20 @@ import java.util.Date;
|
||||
public class CommandBoost extends AbstractCommand {
|
||||
|
||||
public CommandBoost(AbstractCommand parent) {
|
||||
super("boost", "epichoppers.admin", parent);
|
||||
super("boost", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length >= 3) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&cThat player does not exist..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else if (!AMath.isInt(args[2])) {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&6" + args[2] + " &7is not a number..."));
|
||||
return ReturnType.FAILURE;
|
||||
} else {
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date currentDate = new Date();
|
||||
@ -50,7 +54,7 @@ public class CommandBoost extends AbstractCommand {
|
||||
time = " &7for &6" + arr2[1] + " years&7.";
|
||||
} else {
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7" + args[3] + " &7is invalid."));
|
||||
return true;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
} else {
|
||||
c.add(Calendar.YEAR, 10);
|
||||
@ -60,9 +64,21 @@ public class CommandBoost extends AbstractCommand {
|
||||
instance.getBoostManager().addBoostToPlayer(boostData);
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7hoppers transfer rates by &6" + args[2] + "x" + time));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&7Syntax error..."));
|
||||
}
|
||||
return false;
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/es boost <player> <multiplier> [m:minute, h:hour, d:day, y:year]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "This allows you to boost a players hoppers be a multiplier (Put 2 for double, 3 for triple and so on).";
|
||||
}
|
||||
}
|
||||
|
@ -8,25 +8,37 @@ import org.bukkit.command.CommandSender;
|
||||
public class CommandEpicHoppers extends AbstractCommand {
|
||||
|
||||
public CommandEpicHoppers() {
|
||||
super("EpicHoppers", null, null);
|
||||
super("EpicHoppers", null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(TextComponent.formatText("&f>>&m------------&6&l EpicHoppers Help &f&m------------&f<<"));
|
||||
sender.sendMessage(TextComponent.formatText(" &7Version " + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
|
||||
|
||||
sender.sendMessage(TextComponent.formatText("&6/EpicHoppers&7 - Displays this page."));
|
||||
if (sender.hasPermission("epichoppers.admin")) {
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh reload &7Reload the Configuration and Language files."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh book [player]&7- Gives Sync Touch book to you or a player."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh give [player] [level]&7 - Give a leveled hopper to a player."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/eh settings&7 - Edit the EpicHoppers Settings."));
|
||||
sender.sendMessage(TextComponent.formatText("&6/es boost <player> <multiplier> [m:minute, h:hour, d:day, y:year]&7 - This allows you to boost a players hoppers be a multiplier (Put 2 for double, 3 for triple and so on)."));
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(TextComponent.formatText("&6" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return false;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/EpicHoppers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
||||
|
@ -11,22 +11,28 @@ import org.bukkit.entity.Player;
|
||||
public class CommandGive extends AbstractCommand {
|
||||
|
||||
public CommandGive(AbstractCommand parent) {
|
||||
super("give", "epichoppers.admin", parent);
|
||||
super("give", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length >= 1) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length <= 2) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cThat username does not exist, or the user is not online!"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Level level = instance.getLevelManager().getLowestLevel();
|
||||
Player player;
|
||||
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cThat player does not exist or is currently offline."));
|
||||
return true;
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cYou need to be a player to give a hopper to yourself."));
|
||||
return true;
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
@ -36,16 +42,28 @@ public class CommandGive extends AbstractCommand {
|
||||
|
||||
if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c."));
|
||||
return true;
|
||||
return ReturnType.FAILURE;
|
||||
} else if (args.length != 1) {
|
||||
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
|
||||
}
|
||||
player.getInventory().addItem(instance.newHopperItem(level));
|
||||
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
|
||||
|
||||
} else if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.references.getPrefix() + TextComponent.formatText("&cThat username does not exist, or the user is not online!"));
|
||||
}
|
||||
return false;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/eh give [player] [level]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Give a leveled hopper to a player.";
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,28 @@ import org.bukkit.command.CommandSender;
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super("reload", "epichoppers.admin", parent);
|
||||
super("reload", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(TextComponent.formatText(instance.references.getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return false;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/eh reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,28 @@ import org.bukkit.entity.Player;
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super("settings", "epichoppers.admin", parent);
|
||||
super("settings", parent, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(EpicHoppersPlugin instance, CommandSender sender, String... args) {
|
||||
Player p = (Player) sender;
|
||||
instance.getSettingsManager().openSettingsManager(p);
|
||||
return false;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epichoppers.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/eh settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit the EpicHoppers Settings.";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user