Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
*Command now have valid argument length
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolli committed Feb 19, 2013
1 parent b4012d4 commit 6d1cbe7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/com/Zolli/EnderCore/Commands/ECCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface ECCommand {

public boolean execute(CommandSender sender, String args[]);
public boolean execute(CommandSender sender, String args[], String chainedParams);
public String getName();
public List<String> getPermission();
public int getArgsLength();
Expand Down
7 changes: 4 additions & 3 deletions src/com/Zolli/EnderCore/Commands/command/infoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.Zolli.EnderCore.Commands.ECCommand;
import com.Zolli.EnderCore.Commands.consoleMenuBuilder;
Expand All @@ -30,18 +29,20 @@ public List<String> getPermission() {

@Override
public int getArgsLength() {
return 0;
return 2;
}

@Override
public boolean execute(CommandSender sender, String[] args) {
public boolean execute(CommandSender sender, String[] allArgs, String chainedParams) {
consoleMenuBuilder m = new consoleMenuBuilder("EnderCore - Info");
m.addMenuItem("/ec info - Display this message");
m.addMenuItem("/ec help - Display short help message");
m.addMenuItem("/ec purge - Pureg all data in database");
m.addMenuItem("/ec status - Display status info");

m.build(sender);

System.out.println(chainedParams);
return false;
}

Expand Down
14 changes: 13 additions & 1 deletion src/com/Zolli/EnderCore/Commands/commandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ public commandHandler(EnderCore instance) {
public void registerCommand(String name, ECCommand command) {
this.handledCommands.put(name, command);
}

private String buildArgs(String[] str, int length) {
int arrayLength = str.length;
String param = "";
for(int i = length+1 ; i < arrayLength ; i++ ) {
param = param + str[i] + " ";
}

return param;
}

@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
ECCommand command = this.handledCommands.get(arg3[0]);
this.commandPermissions = command.getPermission();
command.execute(sender, arg3);
String chainedParam = this.buildArgs(arg3, command.getArgsLength());

command.execute(sender, arg3, chainedParam);
return false;
}

Expand Down

0 comments on commit 6d1cbe7

Please sign in to comment.