Skip to content

Commit

Permalink
Merge pull request #269 from Lildirt/Lildirtfixes
Browse files Browse the repository at this point in the history
Added get_commands() and clear_commands()
  • Loading branch information
LadyCailin committed Mar 3, 2015
2 parents f2a6740 + 01ce998 commit 928344a
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/Commands.java
Expand Up @@ -12,13 +12,17 @@
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CClosure;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.functions.Exceptions.ExceptionType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -331,4 +335,120 @@ public Version since() {
return CHVersion.V3_3_1;
}
}

@api
public static class get_commands extends AbstractFunction {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[0];
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
MCCommandMap map = Static.getServer().getCommandMap();
Collection<MCCommand> commands = map.getCommands();
CArray ret = CArray.GetAssociativeArray(t);
for(MCCommand command : commands) {
CArray ca = CArray.GetAssociativeArray(t);
ca.set("name", new CString(command.getName(), t), t);
ca.set("description", new CString(command.getDescription(), t), t);
Construct permission;
if (command.getPermission() == null) {
permission = CNull.NULL;
} else {
permission = new CString(command.getPermission(), t);
}
ca.set("permission", permission, t);
ca.set("nopermmsg", new CString(command.getPermissionMessage(), t), t);
ca.set("usage", new CString(command.getUsage(), t), t);
CArray aliases = new CArray(t);
for (String a : command.getAliases()) {
aliases.push(new CString(a, t));
}
ca.set("aliases", aliases, t);
ret.set(command.getName(), ca, t);
}
return ret;
}

@Override
public String getName() {
return "get_commands";
}

@Override
public Integer[] numArgs() {
return new Integer[]{0};
}

@Override
public String docs() {
return "array {} Returns an array of command arrays in the format register_command expects."
+ " This does not include " + Implementation.GetServerType().getBranding() + " aliases, as they are not registered commands.";
}

@Override
public Version since() {
return CHVersion.V3_3_1;
}
}

@api
public static class clear_commands extends AbstractFunction {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[0];
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}


@Override
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
MCCommandMap map = Static.getServer().getCommandMap();
map.clearCommands();
return CVoid.VOID;
}

@Override
public String getName() {
return "clear_commands";
}

@Override
public Integer[] numArgs() {
return new Integer[]{0};
}

@Override
public String docs() {
return "void {} Attempts to clear all registered commands on the server. Note that this probably has some special"
+ " limitations, but they are a bit unclear as to what commands can and cannot be unregistered.";
}

@Override
public Version since() {
return CHVersion.V3_3_1;
}
}
}

0 comments on commit 928344a

Please sign in to comment.