Search in sources :

Example 1 with CommandFunction

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowWorld(net.glowstone.GlowWorld) CommandFunction(net.glowstone.data.CommandFunction) Location(org.bukkit.Location)

Example 2 with CommandFunction

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) CommandFunction(net.glowstone.data.CommandFunction) File(java.io.File)

Aggregations

CommandFunction (net.glowstone.data.CommandFunction)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GlowWorld (net.glowstone.GlowWorld)1 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)1 Location (org.bukkit.Location)1