use of net.glowstone.data.CommandFunction in project Glowstone by GlowstoneMC.
the class FunctionCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length == 0 || args.length == 2) {
sendUsageMessage(sender, commandMessages);
return false;
}
GlowWorld world = CommandUtils.getWorld(sender);
Location location = CommandUtils.getLocation(sender);
String functionName = args[0];
Map<String, CommandFunction> functions = world.getFunctions();
if (!functions.containsKey(functionName)) {
new LocalizedStringImpl("function.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, functionName);
return false;
}
CommandFunction function = functions.get(functionName);
if (args.length > 2) {
String condition = args[1].toLowerCase(Locale.ENGLISH);
if (condition.equals("if")) {
// NON-NLS
if (!anyMatch(sender, args[2], location)) {
new LocalizedStringImpl("function.skipped", commandMessages.getResourceBundle()).send(sender, function.getFullName());
return false;
}
} else if (condition.equals("unless")) {
// NON-NLS
if (anyMatch(sender, args[2], location)) {
new LocalizedStringImpl("function.skipped", commandMessages.getResourceBundle()).send(sender, function.getFullName());
return false;
}
} else {
sendUsageMessage(sender, commandMessages);
return false;
}
}
function.execute(sender);
return true;
}
use of net.glowstone.data.CommandFunction in project Glowstone by GlowstoneMC.
the class WorldFunctionIoService method readFunctions.
@Override
public List<CommandFunction> readFunctions() {
List<CommandFunction> functions = new ArrayList<>();
try {
File functionsDir = new File(dataDir, FUNCTIONS_DIR_NAME);
functionsDir.mkdirs();
File[] subdirs = functionsDir.listFiles(File::isDirectory);
for (File dir : subdirs) {
String namespace = dir.getName();
List<CommandFunction> namespaceFunctions = functionsInside(namespace, "", dir);
functions.addAll(namespaceFunctions);
}
} catch (IOException ex) {
ConsoleMessages.Error.Function.LOAD_FAILED.log(ex, world.getName());
}
return functions;
}
Aggregations