Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed /pay always print help #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/com/greatmancode/craftconomy3/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* This file is part of Craftconomy3.
*
* Copyright (c) 2011-2016, Greatman <http://github.com/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 <http://www.gnu.org/licenses/>.
*/
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<String, Command> commandList = new HashMap<String, Command>();
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());
}
}
}