Search in sources :

Example 76 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class OxygenCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element type = scriptEntry.getElement("type");
    Element mode = scriptEntry.getElement("mode");
    Element amount = scriptEntry.getElement("amount");
    dB.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());
    dPlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer();
    switch(Type.valueOf(type.asString().toUpperCase())) {
        case MAXIMUM:
            switch(Mode.valueOf(mode.asString().toUpperCase())) {
                case SET:
                    player.setMaximumAir(amount.asInt());
                    break;
                case ADD:
                    player.setMaximumAir(player.getMaximumAir() + amount.asInt());
                    break;
                case REMOVE:
                    player.setMaximumAir(player.getMaximumAir() - amount.asInt());
                    break;
            }
            return;
        case REMAINING:
            switch(Mode.valueOf(mode.asString().toUpperCase())) {
                case SET:
                    player.setRemainingAir(amount.asInt());
                    break;
                case ADD:
                    player.setRemainingAir(player.getRemainingAir() + amount.asInt());
                    break;
                case REMOVE:
                    player.setRemainingAir(player.getRemainingAir() - amount.asInt());
                    break;
            }
            return;
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer)

Example 77 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PermissionCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    Element permission = scriptEntry.getElement("permission");
    Element group = scriptEntry.getElement("group");
    dWorld world = (dWorld) scriptEntry.getObject("world");
    // Report to dB
    dB.report(scriptEntry, getName(), action.debug() + permission.debug() + (group != null ? group.debug() : "") + (world != null ? world.debug() : ""));
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer() : null;
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (group != null) {
                if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    dB.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
                } else {
                    Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
                } else {
                    Depends.permissions.playerAdd(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            return;
        case REMOVE:
            if (group != null) {
                if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    dB.echoDebug(scriptEntry, "Group " + group + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (!Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.playerRemove(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            return;
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) OfflinePlayer(org.bukkit.OfflinePlayer) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld) World(org.bukkit.World) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 78 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class SidebarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    Element elTitle = scriptEntry.getElement("title");
    Element elLines = scriptEntry.getElement("lines");
    Element elValue = scriptEntry.getElement("value");
    Element elIncrement = scriptEntry.getElement("increment");
    Element elStart = scriptEntry.getElement("start");
    Element elPlayers = scriptEntry.getElement("players");
    Element elPerPlayer = scriptEntry.getElement("per_player");
    dList players = dList.valueOf(TagManager.tag(elPlayers.asString(), new BukkitTagContext(scriptEntry, false)));
    boolean per_player = elPerPlayer.asBoolean();
    String perTitle = null;
    String perLines = null;
    String perValue = null;
    String perIncrement = null;
    String perStart = null;
    Element title = null;
    dList lines = null;
    dList value = null;
    Element increment = null;
    Element start = null;
    String debug;
    if (per_player) {
        if (elTitle != null) {
            perTitle = elTitle.asString();
        }
        if (elLines != null) {
            perLines = elLines.asString();
        }
        if (elValue != null) {
            perValue = elValue.asString();
        }
        if (elIncrement != null) {
            perIncrement = elIncrement.asString();
        }
        if (elStart != null) {
            perStart = elStart.asString();
        }
        debug = action.debug() + (elTitle != null ? elTitle.debug() : "") + (elLines != null ? elLines.debug() : "") + (elValue != null ? elValue.debug() : "") + (elIncrement != null ? elIncrement.debug() : "") + (elStart != null ? elStart.debug() : "") + players.debug();
    } else {
        BukkitTagContext context = (BukkitTagContext) DenizenAPI.getCurrentInstance().getTagContextFor(scriptEntry, false);
        if (elTitle != null) {
            title = new Element(TagManager.tag(elTitle.asString(), context));
        }
        if (elLines != null) {
            lines = dList.valueOf(TagManager.tag(elLines.asString(), context));
        }
        if (elValue != null) {
            value = dList.valueOf(TagManager.tag(elValue.asString(), context));
        }
        if (elIncrement != null) {
            increment = new Element(TagManager.tag(elIncrement.asString(), context));
        }
        if (elStart != null) {
            start = new Element(TagManager.tag(elStart.asString(), context));
        }
        debug = action.debug() + (title != null ? title.debug() : "") + (lines != null ? lines.debug() : "") + (value != null ? value.debug() : "") + (increment != null ? increment.debug() : "") + (start != null ? start.debug() : "") + players.debug();
    }
    dB.report(scriptEntry, getName(), debug);
    switch(Action.valueOf(action.asString())) {
        case ADD:
            for (dPlayer player : players.filter(dPlayer.class)) {
                if (player == null || !player.isValid()) {
                    dB.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<String> current = sidebar.getLines();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    value = dList.valueOf(TagManager.tag(perValue, context));
                    if (perLines != null) {
                        lines = dList.valueOf(TagManager.tag(perLines, context));
                    }
                }
                if (lines != null) {
                    try {
                        for (int i = 0; i < lines.size(); i++) {
                            int index = Integer.valueOf(lines.get(i)) - 1;
                            String line = value.get(i);
                            current.add(index, line);
                        }
                    } catch (Exception e) {
                        dB.echoError(e);
                        continue;
                    }
                } else {
                    current.addAll(value);
                }
                sidebar.setLines(current);
                sidebar.sendUpdate();
            }
            break;
        case REMOVE:
            for (dPlayer player : players.filter(dPlayer.class)) {
                if (player == null || !player.isValid()) {
                    dB.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<String> current = sidebar.getLines();
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    if (perValue != null) {
                        value = dList.valueOf(TagManager.tag(perValue, context));
                    }
                    if (perLines != null) {
                        lines = dList.valueOf(TagManager.tag(perLines, context));
                    }
                }
                if (lines != null) {
                    try {
                        int offset = 0;
                        for (String line : lines) {
                            int index = Integer.valueOf(line) - 1 - offset;
                            current.remove(index);
                            offset++;
                        }
                    } catch (Exception e) {
                        dB.echoError(e);
                        continue;
                    }
                    sidebar.setLines(current);
                    sidebar.sendUpdate();
                } else if (value != null) {
                    try {
                        Iterator<String> it = current.iterator();
                        while (it.hasNext()) {
                            String next = it.next();
                            for (String line : value) {
                                if (next.equalsIgnoreCase(line)) {
                                    it.remove();
                                }
                            }
                        }
                        for (String line : value) {
                            for (int i = 0; i < current.size(); i++) {
                                if (current.get(i).equalsIgnoreCase(line)) {
                                    current.remove(i);
                                }
                            }
                        }
                    } catch (Exception e) {
                        dB.echoError(e);
                        continue;
                    }
                    sidebar.setLines(current);
                    sidebar.sendUpdate();
                } else {
                    sidebar.remove();
                    sidebars.remove(player.getPlayerEntity().getUniqueId());
                }
            }
            break;
        case SET:
            for (dPlayer player : players.filter(dPlayer.class)) {
                if (player == null || !player.isValid()) {
                    dB.echoError("Invalid player!");
                    continue;
                }
                Sidebar sidebar = createSidebar(player);
                if (sidebar == null) {
                    continue;
                }
                List<String> current = sidebar.getLines();
                boolean currEdited = false;
                if (per_player) {
                    TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
                    if (perValue != null) {
                        value = dList.valueOf(TagManager.tag(perValue, context));
                    }
                    if (perLines != null) {
                        lines = dList.valueOf(TagManager.tag(perLines, context));
                    }
                    if (perStart != null) {
                        start = new Element(TagManager.tag(perStart, context));
                    }
                    if (perIncrement != null) {
                        increment = new Element(TagManager.tag(perIncrement, context));
                    }
                    if (perTitle != null) {
                        title = new Element(TagManager.tag(perTitle, context));
                    }
                }
                if (lines != null) {
                    try {
                        for (int i = 0; i < lines.size(); i++) {
                            int index = Integer.valueOf(lines.get(i)) - 1;
                            String line = value.get(i);
                            if (index > current.size()) {
                                current.add(line);
                            } else {
                                current.set(index, line);
                            }
                        }
                    } catch (Exception e) {
                        dB.echoError(e);
                        continue;
                    }
                    currEdited = true;
                } else if (value != null) {
                    current = value;
                    currEdited = true;
                }
                if (start != null) {
                    sidebar.setStart(start.asInt());
                    currEdited = true;
                }
                if (increment != null) {
                    sidebar.setIncrement(increment.asInt());
                    currEdited = true;
                }
                if (title != null) {
                    sidebar.setTitle(title.asString());
                }
                if (currEdited) {
                    sidebar.setLines(current);
                }
                sidebar.sendUpdate();
            }
            break;
    }
}
Also used : BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) TagContext(net.aufdemrand.denizencore.tags.TagContext) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Iterator(java.util.Iterator) Sidebar(net.aufdemrand.denizen.nms.abstracts.Sidebar) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 79 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class StatisticCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    dList players = scriptEntry.getdObject("players");
    Element statistic = scriptEntry.getElement("statistic");
    Element amount = scriptEntry.getElement("amount");
    dMaterial material = scriptEntry.getdObject("material");
    dEntity entity = scriptEntry.getdObject("entity");
    dB.report(scriptEntry, getName(), action.debug() + statistic.debug() + amount.debug() + players.debug() + (material != null ? material.debug() : entity != null ? entity.debug() : ""));
    Action act = Action.valueOf(action.asString().toUpperCase());
    Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
    int amt = amount.asInt();
    switch(stat.getType()) {
        case BLOCK:
        case ITEM:
            Material mat = material.getMaterial();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, mat, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, mat, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, mat, amt);
                    }
                    break;
            }
            break;
        case ENTITY:
            EntityType ent = entity.getBukkitEntityType();
            switch(act) {
                case ADD:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.incrementStatistic(stat, ent, amt);
                    }
                    break;
                case TAKE:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.decrementStatistic(stat, ent, amt);
                    }
                    break;
                case SET:
                    for (dPlayer player : players.filter(dPlayer.class)) {
                        player.setStatistic(stat, ent, amt);
                    }
                    break;
            }
            break;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Material(org.bukkit.Material)

Example 80 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class StatisticCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_players = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("players", arg.asType(dList.class));
            specified_players = true;
        } else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.values())) {
            scriptEntry.addObject("statistic", arg.asElement());
        } else if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
            if (arg.matchesArgumentType(dMaterial.class)) {
                scriptEntry.addObject("material", arg.asType(dMaterial.class));
            } else if (arg.matchesArgumentType(dEntity.class)) {
                scriptEntry.addObject("entity", arg.asType(dEntity.class));
            }
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a valid action!");
    }
    if (!scriptEntry.hasObject("statistic")) {
        throw new InvalidArgumentsException("Must specify a valid Statistic!");
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new Element(1));
    }
    Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
    if (type != Statistic.Type.UNTYPED) {
        if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
            throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
        } else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
            throw new InvalidArgumentsException("Must specify a valid ENTITY!");
        }
    }
    if (!scriptEntry.hasObject("players") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_players) {
        scriptEntry.addObject("players", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify valid players!");
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9