From 96601f990211dd023dfcc59066b4de8ab16f7e98 Mon Sep 17 00:00:00 2001 From: William Bonnaventure Date: Tue, 11 Jul 2017 11:02:53 +0200 Subject: [PATCH 1/2] Fixed /pay command always print help Signed-off-by: William Bonnaventure --- .../com/greatmancode/craftconomy3/Common.java | 3 +- .../craftconomy3/pay/PayShortCommand.java | 110 ++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java diff --git a/src/main/java/com/greatmancode/craftconomy3/Common.java b/src/main/java/com/greatmancode/craftconomy3/Common.java index af4e054e..79e81eea 100644 --- a/src/main/java/com/greatmancode/craftconomy3/Common.java +++ b/src/main/java/com/greatmancode/craftconomy3/Common.java @@ -27,6 +27,7 @@ import com.greatmancode.craftconomy3.commands.group.GroupCreateCommand; import com.greatmancode.craftconomy3.commands.group.GroupDelWorldCommand; import com.greatmancode.craftconomy3.commands.money.*; +import com.greatmancode.craftconomy3.commands.pay.*; import com.greatmancode.craftconomy3.commands.setup.*; import com.greatmancode.craftconomy3.converter.H2ToMySQLConverter; import com.greatmancode.craftconomy3.currency.Currency; @@ -726,7 +727,7 @@ private void registerCommands() { ccgroup.addCommand("delworld", new GroupDelWorldCommand()); commandManager.registerMainCommand("ccgroup", ccgroup); - SubCommand payCommand = new SubCommand("pay", commandManager, null, 1); + SubCommand payCommand = new PayShortCommand("pay", commandManager, null, 1); payCommand.addCommand("", new PayCommand()); commandManager.registerMainCommand("pay", payCommand); } diff --git a/src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java b/src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java new file mode 100644 index 00000000..e844aefd --- /dev/null +++ b/src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java @@ -0,0 +1,110 @@ +/** + * This file is part of Craftconomy3. + * + * Copyright (c) 2011-2016, Greatman + * + * Craftconomy3 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Craftconomy3 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Craftconomy3. If not, see . + */ +package com.greatmancode.craftconomy3.commands.pay; + +import com.greatmancode.tools.commands.interfaces.Command; +import com.greatmancode.tools.commands.CommandHandler; +import com.greatmancode.tools.commands.SubCommand; +import com.greatmancode.tools.commands.interfaces.CommandExecutor; +import lombok.Getter; + +import java.util.*; + +public class PayShortCommand extends SubCommand { + private Map commandList = new HashMap(); + private CommandHandler commandHandler; + private SubCommand parent; + @Getter + private String name; + private int level; + private String subCommandList; + + public PayShortCommand(String name, CommandHandler commandHandler, SubCommand parent, int level){ + super(name, commandHandler, parent, level); + this.name = name; + this.commandHandler = commandHandler; + this.parent = parent; + this.level = level; + } + + @Override + public void addCommand(String name, Command command) { + commandList.put(name, command); + if (command instanceof CommandExecutor) { + commandHandler.getServerCaller().registerPermission(((CommandExecutor) command).getPermissionNode()); + } + super.addCommand(name, command); + } + + @Override + public boolean commandExist(String name) { + return true; + } + + /* + * Command contains the Player name + */ + @Override + public void execute(String command, String sender, String[] args) { + if (level <= commandHandler.getCurrentLevel()) { + if (commandExist(command)) { + Command entry = commandList.get(""); + if (entry instanceof CommandExecutor) { + CommandExecutor cmd = ((CommandExecutor) entry); + if (commandHandler.getServerCaller().getPlayerCaller().checkPermission(sender, cmd.getPermissionNode())) { + if (cmd.playerOnly() && sender.equalsIgnoreCase("console")) { + commandHandler.getServerCaller().getPlayerCaller().sendMessage(sender, "{{DARK_RED}}Only players can do this command!"); + return; + } + if (args.length >= cmd.minArgs() - 1 && args.length <= cmd.maxArgs() - 1) { + String[] newArgs = new String[args.length + 1]; + newArgs[0] = command; + System.arraycopy(args, 0, newArgs, 1, args.length); + cmd.execute(sender, newArgs); + } else { + commandHandler.getServerCaller().getPlayerCaller().sendMessage(sender, cmd.help()); + } + } else { + commandHandler.getServerCaller().getPlayerCaller().sendMessage(sender, "{{DARK_RED}}Permission denied!"); + } + } else if (entry instanceof SubCommand) { + SubCommand subCommand = (SubCommand) entry; + + String subSubCommand = ""; + if (args.length != 0) { + subSubCommand = args[0]; + } + + if (subCommand.commandExist(subSubCommand)) { + String[] newArgs; + if (args.length == 0) { + newArgs = args; + } else { + newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, args.length - 1); + } + ((SubCommand) entry).execute(subSubCommand, sender, newArgs); + } + } + } + } else { + commandHandler.getServerCaller().getPlayerCaller().sendMessage(sender, commandHandler.getWrongLevelMsg()); + } + } +} From f7a23eecc844c8de8afaf5a0abb220d608522817 Mon Sep 17 00:00:00 2001 From: William Bonnaventure Date: Tue, 11 Jul 2017 11:09:26 +0200 Subject: [PATCH 2/2] Move file PayShortCommand.java to the right place Signed-off-by: William Bonnaventure --- .../craftconomy3/{ => commands}/pay/PayShortCommand.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/java/com/greatmancode/craftconomy3/{ => commands}/pay/PayShortCommand.java (100%) diff --git a/src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java b/src/main/java/com/greatmancode/craftconomy3/commands/pay/PayShortCommand.java similarity index 100% rename from src/main/java/com/greatmancode/craftconomy3/pay/PayShortCommand.java rename to src/main/java/com/greatmancode/craftconomy3/commands/pay/PayShortCommand.java