Removed and replaced Command system with the SongodaCore system.
This commit is contained in:
parent
c53919c184
commit
b66120c10c
|
@ -58,6 +58,21 @@ public class EpicEnchants extends SongodaPlugin {
|
|||
// Run Songoda Updater
|
||||
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
|
||||
|
||||
// setup commands
|
||||
this.commandManager = new com.songoda.core.commands.CommandManager(this);
|
||||
this.commandManager.addMainCommand("ee")
|
||||
.addSubCommand(new CommandReload(this))
|
||||
.addSubCommand(new CommandAlchemist(this))
|
||||
.addSubCommand(new CommandApply(this))
|
||||
.addSubCommand(new CommandEnchanter(this))
|
||||
.addSubCommand(new CommandGiveBook(this))
|
||||
.addSubCommand(new CommandGiveItemDust(this))
|
||||
.addSubCommand(new CommandGiveRandomBook(this))
|
||||
.addSubCommand(new CommandGiveScroll(this))
|
||||
.addSubCommand(new CommandList(this))
|
||||
.addSubCommand(new CommandSettings(this))
|
||||
.addSubCommand(new CommandTinkerer(this));
|
||||
|
||||
EconomyManager.load();
|
||||
|
||||
// Setup Config
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private final boolean noConsole;
|
||||
private AbstractCommand parent = null;
|
||||
private boolean hasArgs = false;
|
||||
private String command;
|
||||
|
||||
private List<String> subCommand = new ArrayList<>();
|
||||
|
||||
protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) {
|
||||
if (parent != null) {
|
||||
this.subCommand = Arrays.asList(command);
|
||||
} else {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
}
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
|
||||
this.hasArgs = hasArgs;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getSubCommand() {
|
||||
return subCommand;
|
||||
}
|
||||
|
||||
public void addSubCommand(String command) {
|
||||
subCommand.add(command);
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args);
|
||||
|
||||
protected abstract List<String> onTab(EpicEnchants instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public boolean hasArgs() {
|
||||
return hasArgs;
|
||||
}
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.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 {
|
||||
|
||||
private static final List<AbstractCommand> commands = new ArrayList<>();
|
||||
private EpicEnchants plugin;
|
||||
private TabManager tabManager;
|
||||
|
||||
public CommandManager(EpicEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.tabManager = new TabManager(this);
|
||||
|
||||
plugin.getCommand("EpicEnchants").setExecutor(this);
|
||||
|
||||
AbstractCommand commandEpicEnchants = addCommand(new CommandEpicEnchants());
|
||||
|
||||
addCommand(new CommandSettings(commandEpicEnchants));
|
||||
addCommand(new CommandReload(commandEpicEnchants));
|
||||
addCommand(new CommandApply(commandEpicEnchants));
|
||||
addCommand(new CommandList(commandEpicEnchants));
|
||||
addCommand(new CommandGiveBook(commandEpicEnchants));
|
||||
addCommand(new CommandGiveRandomBook(commandEpicEnchants));
|
||||
addCommand(new CommandGiveItemDust(commandEpicEnchants));
|
||||
addCommand(new CommandGiveScroll(commandEpicEnchants));
|
||||
addCommand(new CommandAlchemist(commandEpicEnchants));
|
||||
addCommand(new CommandEnchanter(commandEpicEnchants));
|
||||
addCommand(new CommandTinkerer(commandEpicEnchants));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
plugin.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 0 || abstractCommand.hasArgs()) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
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 commands.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
plugin.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package com.songoda.epicenchants.command;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TabManager implements TabCompleter {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
|
||||
TabManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commandManager.getCommands()) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 1) {
|
||||
List<String> subs = new ArrayList<>();
|
||||
for (AbstractCommand ac : commandManager.getCommands()) {
|
||||
if (ac.getSubCommand() == null) continue;
|
||||
subs.addAll(ac.getSubCommand());
|
||||
}
|
||||
subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase()));
|
||||
return subs;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
List<String> list = abstractCommand.onTab(EpicEnchants.getInstance(), sender, strings);
|
||||
String str = strings[strings.length - 1];
|
||||
if (list != null && str != null && str.length() >= 1) {
|
||||
try {
|
||||
list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase()));
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEpicEnchants extends AbstractCommand {
|
||||
|
||||
public CommandEpicEnchants() {
|
||||
super(null, false, "EpicEnchants");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/EpicEnchants";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.AlchemistMenu;
|
||||
import com.songoda.epicenchants.menus.TinkererMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -11,19 +10,23 @@ import java.util.List;
|
|||
|
||||
public class CommandAlchemist extends AbstractCommand {
|
||||
|
||||
public CommandAlchemist(AbstractCommand parent) {
|
||||
super(parent, true, "alchemist");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandAlchemist(EpicEnchants plugin) {
|
||||
super(true, "alchemist");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new AlchemistMenu(instance, instance.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
||||
new AlchemistMenu(plugin, plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -34,7 +37,7 @@ public class CommandAlchemist extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee alchemist";
|
||||
return "alchemist";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,12 +1,11 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.enums.EnchantResult;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.utils.Tuple;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -21,47 +20,50 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromR
|
|||
|
||||
public class CommandApply extends AbstractCommand {
|
||||
|
||||
public CommandApply(AbstractCommand parent) {
|
||||
super(parent, true, "apply");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandApply(EpicEnchants plugin) {
|
||||
super(true, "apply");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee apply [enchant] [level] <success-rate> <destroy-rate>
|
||||
//apply [enchant] [level] <success-rate> <destroy-rate>
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 5)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 4)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Optional<Enchant> optionalEnchant = instance.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
|
||||
|
||||
if (!optionalEnchant.isPresent()) {
|
||||
instance.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
if (!CommandCommons.isInt(args[1], sender))
|
||||
return ReturnType.FAILURE;
|
||||
|
||||
int successRate = 100;
|
||||
int destroyRate = 0;
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
destroyRate = Integer.parseInt(args[4]);
|
||||
destroyRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
Enchant enchant = optionalEnchant.get();
|
||||
int level = Integer.parseInt(args[2]);
|
||||
int level = Integer.parseInt(args[1]);
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!enchant.getItemWhitelist().contains(player.getItemInHand().getType())) {
|
||||
System.out.println("List = " + enchant.getItemWhitelist());
|
||||
instance.getLocale().getMessage("command.apply.invaliditem")
|
||||
plugin.getLocale().getMessage("command.apply.invaliditem")
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
|
@ -69,10 +71,10 @@ public class CommandApply extends AbstractCommand {
|
|||
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
ItemStack before = player.getItemInHand();
|
||||
Tuple<ItemStack, EnchantResult> result = instance.getEnchantUtils().apply(before, enchant, level,
|
||||
Tuple<ItemStack, EnchantResult> result = plugin.getEnchantUtils().apply(before, enchant, level,
|
||||
successRate, destroyRate);
|
||||
|
||||
instance.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
||||
plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
|
@ -86,12 +88,12 @@ public class CommandApply extends AbstractCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
return instance.getEnchantManager().getValues()
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return plugin.getEnchantManager().getValues()
|
||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
Enchant enchant = instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 2) {
|
||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
||||
.stream().findFirst().orElse(null);
|
||||
List<String> levels = new ArrayList<>();
|
||||
if (enchant != null) {
|
||||
|
@ -99,7 +101,7 @@ public class CommandApply extends AbstractCommand {
|
|||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels;
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
} else if (args.length == 3 || args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
|
@ -115,7 +117,7 @@ public class CommandApply extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee apply <enchant> <level> [success-rate] [destroy-rate]";
|
||||
return "apply <enchant> <level> [success-rate] [destroy-rate]";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.EnchanterMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -10,19 +10,22 @@ import java.util.List;
|
|||
|
||||
public class CommandEnchanter extends AbstractCommand {
|
||||
|
||||
public CommandEnchanter(AbstractCommand parent) {
|
||||
super(parent, true, "enchanter");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandEnchanter(EpicEnchants plugin) {
|
||||
super(true, "enchanter");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new EnchanterMenu(instance, instance.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
||||
new EnchanterMenu(plugin, plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -33,7 +36,7 @@ public class CommandEnchanter extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee enchanter";
|
||||
return "enchanter";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,8 +1,8 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -16,27 +16,30 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class CommandGiveBook extends AbstractCommand {
|
||||
|
||||
public CommandGiveBook(AbstractCommand parent) {
|
||||
super(parent, false, "givebook");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveBook(EpicEnchants plugin) {
|
||||
super(false, "givebook");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
||||
//givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Optional<Enchant> optionalEnchant = instance.getEnchantManager().getValue(args[2].replaceAll("_", " "));
|
||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
||||
|
||||
if (!optionalEnchant.isPresent()) {
|
||||
instance.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -45,26 +48,26 @@ public class CommandGiveBook extends AbstractCommand {
|
|||
int successRate = -1;
|
||||
int destroyRate = -1;
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
level = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
level = Integer.parseInt(args[3]);
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[4]);
|
||||
destroyRate = Integer.parseInt(args[4]);
|
||||
}
|
||||
|
||||
if (args.length > 5) {
|
||||
if (!CommandCommons.isInt(args[5], sender))
|
||||
return ReturnType.FAILURE;
|
||||
destroyRate = Integer.parseInt(args[5]);
|
||||
}
|
||||
|
||||
if (level != -1 && (level > enchant.getMaxLevel() || level < 1)) {
|
||||
instance.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
||||
if (level != -0 && (level > enchant.getMaxLevel() || level < 0)) {
|
||||
plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.processPlaceholder("max_level", enchant.getMaxLevel())
|
||||
.sendPrefixedMessage(sender);
|
||||
|
@ -72,10 +75,10 @@ public class CommandGiveBook extends AbstractCommand {
|
|||
}
|
||||
|
||||
target.getPlayer().getInventory().addItem(enchant.getBook().get(enchant, level, successRate, destroyRate));
|
||||
instance.getLocale().getMessage("command.book.received")
|
||||
plugin.getLocale().getMessage("command.book.received")
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.book.gave")
|
||||
plugin.getLocale().getMessage("command.book.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||
.sendPrefixedMessage(sender);
|
||||
|
@ -83,14 +86,14 @@ public class CommandGiveBook extends AbstractCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getEnchantManager().getValues()
|
||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
Enchant enchant = instance.getEnchantManager().getValues()
|
||||
} else if (args.length == 3) {
|
||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
||||
.stream().findFirst().orElse(null);
|
||||
List<String> levels = new ArrayList<>();
|
||||
if (enchant != null) {
|
||||
|
@ -98,7 +101,7 @@ public class CommandGiveBook extends AbstractCommand {
|
|||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels;
|
||||
} else if (args.length == 5 || args.length == 6) {
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
|
@ -114,7 +117,7 @@ public class CommandGiveBook extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee givebook <player> <enchant> [level] [success-rate] [destroy-rate]";
|
||||
return "givebook <player> <enchant> [level] [success-rate] [destroy-rate]";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,9 +1,8 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.objects.Group;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -13,33 +12,35 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveItemDust extends AbstractCommand {
|
||||
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveItemDust(AbstractCommand parent) {
|
||||
super(parent, false, "giveitemdust");
|
||||
public CommandGiveItemDust(EpicEnchants plugin) {
|
||||
super(false, "giveitemdust");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee giveitemdust <player> <group> [type] [percentage]
|
||||
//giveitemdust <player> <group> [type] [percentage]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
List<Group> groups = instance.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[2])).collect(Collectors.toList());
|
||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
instance.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -48,21 +49,21 @@ public class CommandGiveItemDust extends AbstractCommand {
|
|||
String dustType = null;
|
||||
int percentage = -1;
|
||||
|
||||
if (args.length > 2) {
|
||||
dustType = args[2];
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
dustType = args[3];
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
percentage = Integer.parseInt(args[4]);
|
||||
percentage = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, dustType, percentage, true));
|
||||
instance.getLocale().getMessage("command.dust.received")
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getDust(group, dustType, percentage, true));
|
||||
plugin.getLocale().getMessage("command.dust.received")
|
||||
.processPlaceholder("group", group.getIdentifier())
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.dust.gave")
|
||||
plugin.getLocale().getMessage("command.dust.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.processPlaceholder("group", group.getIdentifier())
|
||||
.sendPrefixedMessage(sender);
|
||||
|
@ -70,19 +71,19 @@ public class CommandGiveItemDust extends AbstractCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getGroupManager().getValues().stream()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getGroupManager().getValues().stream()
|
||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
} else if (args.length == 3) {
|
||||
List<String> dusts = new ArrayList<>();
|
||||
|
||||
FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts");
|
||||
FileConfiguration dustConfig = plugin.getFileManager().getConfiguration("items/dusts");
|
||||
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
|
||||
return dusts;
|
||||
} else if (args.length == 5) {
|
||||
} else if (args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
|
@ -98,7 +99,7 @@ public class CommandGiveItemDust extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee giveitemdust <player> <group> [type] [percentage]";
|
||||
return "giveitemdust <player> <group> [type] [percentage]";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,7 +1,7 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Group;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -13,49 +13,52 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class CommandGiveRandomBook extends AbstractCommand {
|
||||
|
||||
public CommandGiveRandomBook(AbstractCommand parent) {
|
||||
super(parent, false, "giverandombook");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveRandomBook(EpicEnchants plugin) {
|
||||
super(false, "giverandombook");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee giverandombook <player> <group>
|
||||
//giverandombook <player> <group>
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 6)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
||||
List<Group> groups = instance.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[2])).collect(Collectors.toList());
|
||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
instance.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Group group = groups.get(0);
|
||||
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
|
||||
instance.getLocale().getMessage("command.randombook.received")
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getMysteryBook(group));
|
||||
plugin.getLocale().getMessage("command.randombook.received")
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command.randombook.gave")
|
||||
plugin.getLocale().getMessage("command.randombook.gave")
|
||||
.processPlaceholder("player", target.getPlayer().getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return instance.getGroupManager().getValues().stream()
|
||||
} else if (args.length == 2) {
|
||||
return plugin.getGroupManager().getValues().stream()
|
||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
|
@ -68,7 +71,7 @@ public class CommandGiveRandomBook extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee giverandombook <player> <group>";
|
||||
return "giverandombook <player> <group>";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,9 +1,8 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -15,22 +14,25 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandGiveScroll extends AbstractCommand {
|
||||
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandGiveScroll(AbstractCommand parent) {
|
||||
super(parent, false, "givescroll");
|
||||
public CommandGiveScroll(EpicEnchants plugin) {
|
||||
super(false, "givescroll");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//ee givescroll <giveType> <player> [amount] [success-rate]
|
||||
//givescroll <giveType> <player> [amount] [success-rate]
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 6)
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 2 || args.length > 5)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
String giveType = args[1];
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[2]);
|
||||
String giveType = args[0];
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (target == null) {
|
||||
instance.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -38,52 +40,52 @@ public class CommandGiveScroll extends AbstractCommand {
|
|||
int successRate = -1;
|
||||
|
||||
|
||||
if (args.length > 2) {
|
||||
if (!CommandCommons.isInt(args[2], sender))
|
||||
return ReturnType.FAILURE;
|
||||
amount = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (!CommandCommons.isInt(args[3], sender))
|
||||
return ReturnType.FAILURE;
|
||||
amount = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
if (args.length > 4) {
|
||||
if (!CommandCommons.isInt(args[4], sender))
|
||||
return ReturnType.FAILURE;
|
||||
successRate = Integer.parseInt(args[4]);
|
||||
successRate = Integer.parseInt(args[3]);
|
||||
}
|
||||
|
||||
String messageKey;
|
||||
switch (giveType.toLowerCase()) {
|
||||
case "whitescroll":
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getWhiteScroll(amount));
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getWhiteScroll(amount));
|
||||
messageKey = "whitescroll";
|
||||
break;
|
||||
case "blackscroll":
|
||||
messageKey = "blackscroll";
|
||||
target.getPlayer().getInventory().addItem(instance.getSpecialItems().getBlackScroll(amount, successRate));
|
||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getBlackScroll(amount, successRate));
|
||||
break;
|
||||
default:
|
||||
instance.getLocale().getMessage("command.giveunknown")
|
||||
plugin.getLocale().getMessage("command.giveunknown")
|
||||
.processPlaceholder("unknown", giveType)
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
instance.getLocale().getMessage("command." + messageKey + ".received")
|
||||
plugin.getLocale().getMessage("command." + messageKey + ".received")
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
instance.getLocale().getMessage("command." + messageKey + ".gave")
|
||||
plugin.getLocale().getMessage("command." + messageKey + ".gave")
|
||||
.processPlaceholder("player", target.getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
if (args.length == 2) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.asList("whitescroll", "blackscroll");
|
||||
} else if (args.length == 3) {
|
||||
} else if (args.length == 2) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 4 || args.length == 5) {
|
||||
} else if (args.length == 3 || args.length == 4) {
|
||||
List<String> rates = new ArrayList<>();
|
||||
for (int i = 1; i <= (args.length == 4 ? 10 : 100); i ++)
|
||||
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i ++)
|
||||
rates.add(String.valueOf(i));
|
||||
return rates;
|
||||
}
|
||||
|
@ -97,7 +99,7 @@ public class CommandGiveScroll extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee givescroll <whitescroll/blackscroll> <player> [amount] [success-rate]";
|
||||
return "givescroll <whitescroll/blackscroll> <player> [amount] [success-rate]";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,44 +1,38 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.epicenchants.CommandCommons;
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.enums.EnchantResult;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import com.songoda.epicenchants.utils.Tuple;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
|
||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
|
||||
|
||||
public class CommandList extends AbstractCommand {
|
||||
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandList(AbstractCommand parent) {
|
||||
super(parent, true, "list");
|
||||
public CommandList(EpicEnchants plugin) {
|
||||
super(true, "list");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length > 1 && args[1].equalsIgnoreCase("chat")) {
|
||||
instance.getLocale().newMessage(instance.getEnchantManager().getValues().stream()
|
||||
plugin.getLocale().newMessage(plugin.getEnchantManager().getValues().stream()
|
||||
.sorted(Comparator.comparing(enchant -> enchant.getGroup().getOrder()))
|
||||
.map(enchant -> enchant.getColoredIdentifier(true)).collect(Collectors.joining("&7, ")))
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
instance.getInfoManager().getMainInfoMenu().open((Player)sender);
|
||||
plugin.getInfoManager().getMainInfoMenu().open((Player)sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -49,7 +43,7 @@ public class CommandList extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee list [chat]";
|
||||
return "list [chat]";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,26 +1,29 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super(parent, false, "reload");
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandReload(EpicEnchants plugin) {
|
||||
super(false, "reload");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
instance.reloadConfig();
|
||||
instance.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.reloadConfig();
|
||||
plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -31,7 +34,7 @@ public class CommandReload extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee reload";
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,27 +1,30 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super(parent, true, "Settings");
|
||||
public CommandSettings(EpicEnchants plugin) {
|
||||
super(true, "Settings");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
instance.getGuiManager().showGUI((Player) sender, new PluginConfigGui(instance));
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(plugin));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -32,7 +35,7 @@ public class CommandSettings extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee settings";
|
||||
return "settings";
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,8 +1,7 @@
|
|||
package com.songoda.epicenchants.command.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.command.AbstractCommand;
|
||||
import com.songoda.epicenchants.menus.EnchanterMenu;
|
||||
import com.songoda.epicenchants.menus.TinkererMenu;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -10,20 +9,23 @@ import org.bukkit.entity.Player;
|
|||
import java.util.List;
|
||||
|
||||
public class CommandTinkerer extends AbstractCommand {
|
||||
|
||||
private final EpicEnchants plugin;
|
||||
|
||||
public CommandTinkerer(AbstractCommand parent) {
|
||||
super(parent, true, "tinkerer");
|
||||
public CommandTinkerer(EpicEnchants plugin) {
|
||||
super(true, "tinkerer");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player)sender;
|
||||
new TinkererMenu(instance, instance.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
||||
new TinkererMenu(plugin, plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(EpicEnchants instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -34,7 +36,7 @@ public class CommandTinkerer extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ee tinkerer";
|
||||
return "tinkerer";
|
||||
}
|
||||
|
||||
@Override
|
Loading…
Reference in New Issue