Search in sources :

Example 81 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ActionBarCommand method parseArgs.

// <--[command]
// @Name ActionBar
// @Syntax actionbar [<text>] (targets:<player>|...) (format:<name>) (per_player)
// @Required 1
// @Maximum 4
// @Short Sends a message to a player's action bar.
// @group player
// 
// @Description
// Sends a message to the target's action bar area.
// If no target is specified it will default to the attached player.
// Accepts the 'format:<name>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
// 
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- actionbar 'hello <player.name>' targets:<server.online_players>"
// would normally show "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
// 
// @Tags
// None
// 
// @Usage
// Use to send a message to the player's action bar.
// - actionbar "Hey there <player.name>!"
// 
// @Usage
// Use to send a message to a list of players.
// - actionbar "Hey, welcome to the server!" targets:<[thatplayer]>|<[player]>|<[someplayer]>
// 
// @Usage
// Use to send a message to a list of players, with a formatted message.
// - actionbar "Hey there!" targets:<[thatplayer]>|<[player]> format:ServerChat
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + "'");
            }
            scriptEntry.addObject("format", new ScriptTag(format));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("targets", "target")) {
            scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new ElementTag(true));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets") && !Utilities.entryHasPlayer(scriptEntry)) {
        throw new InvalidArgumentsException("Must specify target(s).");
    }
    if (!scriptEntry.hasObject("targets")) {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must specify valid player Targets!");
        } else {
            scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
        }
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 82 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class BlockCrackCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    ElementTag progress = scriptEntry.getElement("progress");
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag stack = scriptEntry.getElement("stack");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("players", players), progress, location, stack);
    }
    Location loc = location.getBlock().getLocation();
    if (!progressTracker.containsKey(loc)) {
        progressTracker.put(loc, new HashMap<>());
        lastBase += 10;
    }
    Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
    boolean stackVal = stack.asBoolean();
    PacketHelper packetHelper = NMSHandler.getPacketHelper();
    for (PlayerTag player : players) {
        if (!player.isOnline()) {
            Debug.echoError("Players must be online!");
            continue;
        }
        Player playerEnt = player.getPlayerEntity();
        UUID uuid = playerEnt.getUniqueId();
        if (!uuidInt.containsKey(uuid)) {
            IntHolder newIntHolder = new IntHolder();
            newIntHolder.theInt = lastBase;
            newIntHolder.base = lastBase;
            uuidInt.put(uuid, newIntHolder);
        }
        IntHolder intHolder = uuidInt.get(uuid);
        if (!stackVal && intHolder.theInt > intHolder.base) {
            for (int i = intHolder.base; i <= intHolder.theInt; i++) {
                packetHelper.showBlockCrack(playerEnt, i, loc, -1);
            }
            intHolder.theInt = intHolder.base;
        } else if (stackVal && intHolder.theInt - intHolder.base > 10) {
            continue;
        }
        int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
        packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
    }
}
Also used : Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 83 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class PermissionCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ElementTag permission = scriptEntry.getElement("permission");
    ElementTag group = scriptEntry.getElement("group");
    WorldTag world = scriptEntry.getObjectTag("world");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, permission, group, world);
    }
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer() : null;
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (group != null) {
                if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    Debug.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())) {
                    Debug.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
                } else {
                    Depends.permissions.playerAdd(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            break;
        case REMOVE:
            if (group != null) {
                if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    Debug.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())) {
                    Debug.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.playerRemove(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            break;
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) World(org.bukkit.World)

Example 84 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ShowFakeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NetworkInterceptHelper.enable();
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag cancel = scriptEntry.getElement("cancel");
    List<MaterialTag> materials = (List<MaterialTag>) scriptEntry.getObject("materials");
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), duration, cancel, db("materials", materials), db("locations", locations), db("players", players));
    }
    boolean shouldCancel = cancel.asBoolean();
    int i = 0;
    for (LocationTag loc : locations) {
        if (!shouldCancel) {
            FakeBlock.showFakeBlockTo(players, loc.getBlockLocation(), materials.get(i % materials.size()), duration, locations.size() < 5);
        } else {
            FakeBlock.stopShowingTo(players, loc.getBlockLocation());
        }
        i++;
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 85 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class GroupCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    WorldTag world = scriptEntry.getObjectTag("world");
    ElementTag group = scriptEntry.getElement("group");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, world, group);
    }
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer();
    boolean inGroup = Depends.permissions.playerInGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (inGroup) {
                Debug.echoDebug(scriptEntry, "Player " + player.getName() + " is already in group " + group);
            } else {
                Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
            }
            break;
        case REMOVE:
            if (!inGroup) {
                Debug.echoDebug(scriptEntry, "Player " + player.getName() + " is not in group " + group);
            } else {
                Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
            }
            break;
        case SET:
            for (String grp : Depends.permissions.getPlayerGroups((bukkitWorld == null ? null : bukkitWorld.getName()), player)) {
                Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, grp);
            }
            Depends.permissions.playerAddGroup((bukkitWorld == null ? null : bukkitWorld.getName()), player, group.asString());
            break;
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) World(org.bukkit.World)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12