Search in sources :

Example 91 with ElementTag

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

the class TeamCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("id");
    ElementTag name = scriptEntry.getElement("name");
    ListTag add = scriptEntry.getObjectTag("add");
    ListTag remove = scriptEntry.getObjectTag("remove");
    ElementTag prefix = scriptEntry.getElement("prefix");
    ElementTag suffix = scriptEntry.getElement("suffix");
    ElementTag option = scriptEntry.getElement("option");
    ElementTag status = scriptEntry.getElement("status");
    ElementTag color = scriptEntry.getElement("color");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, name, add, remove, prefix, suffix, color, option, status);
    }
    Scoreboard board;
    if (id.asString().equalsIgnoreCase("main")) {
        board = ScoreboardHelper.getMain();
    } else {
        if (ScoreboardHelper.hasScoreboard(id.asString())) {
            board = ScoreboardHelper.getScoreboard(id.asString());
        } else {
            board = ScoreboardHelper.createScoreboard(id.asString());
        }
    }
    Team team = board.getTeam(name.asString());
    if (team == null) {
        String low = CoreUtilities.toLowerCase(name.asString());
        team = board.getTeams().stream().filter(t -> CoreUtilities.toLowerCase(t.getName()).equals(low)).findFirst().orElse(null);
        if (team == null) {
            team = board.registerNewTeam(name.asString());
        }
    }
    if (add != null) {
        for (String string : add) {
            string = translateEntry(string, scriptEntry.context);
            if (!team.hasEntry(string)) {
                team.addEntry(string);
            }
        }
    }
    if (remove != null) {
        for (String string : remove) {
            string = translateEntry(string, scriptEntry.context);
            if (team.hasEntry(string)) {
                team.removeEntry(string);
            }
        }
    }
    if (option != null) {
        String optName = CoreUtilities.toLowerCase(option.asString());
        String statusName = CoreUtilities.toLowerCase(status.asString());
        if (optName.equals("friendly_fire")) {
            team.setAllowFriendlyFire(statusName.equals("always"));
        } else if (optName.equals("see_invisible")) {
            team.setCanSeeFriendlyInvisibles(statusName.equals("always"));
        } else {
            team.setOption(Team.Option.valueOf(optName.toUpperCase()), Team.OptionStatus.valueOf(statusName.toUpperCase()));
        }
    }
    if (prefix != null) {
        team.setPrefix(prefix.asString());
    }
    if (suffix != null) {
        team.setSuffix(suffix.asString());
    }
    if (color != null) {
        team.setColor(ChatColor.valueOf(color.asString().toUpperCase()));
    }
    if (team.getEntries().isEmpty()) {
        team.unregister();
    }
}
Also used : ListTag(com.denizenscript.denizencore.objects.core.ListTag) Team(org.bukkit.scoreboard.Team) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Argument(com.denizenscript.denizencore.objects.Argument) Scoreboard(org.bukkit.scoreboard.Scoreboard) ScoreboardHelper(com.denizenscript.denizen.utilities.ScoreboardHelper) TagContext(com.denizenscript.denizencore.tags.TagContext) EntityTag(com.denizenscript.denizen.objects.EntityTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ChatColor(org.bukkit.ChatColor) Debug(com.denizenscript.denizen.utilities.debugging.Debug) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) CoreUtilities(com.denizenscript.denizencore.utilities.CoreUtilities) Scoreboard(org.bukkit.scoreboard.Scoreboard) Team(org.bukkit.scoreboard.Team) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 92 with ElementTag

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

the class ToastCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag text = scriptEntry.getElement("text");
    ElementTag frame = scriptEntry.getElement("frame");
    ItemTag icon = scriptEntry.getObjectTag("icon");
    final List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, name, text, frame, icon, db("targets", targets));
    }
    final Advancement advancement = new Advancement(true, new NamespacedKey(Denizen.getInstance(), UUID.randomUUID().toString()), null, icon.getItemStack(), text.asString(), "", null, Advancement.Frame.valueOf(frame.asString().toUpperCase()), true, false, true, 0, 0, 1);
    final AdvancementHelper advancementHelper = NMSHandler.getAdvancementHelper();
    for (PlayerTag target : targets) {
        Player player = target.getPlayerEntity();
        if (player != null) {
            advancementHelper.grant(advancement, player);
            advancementHelper.revoke(advancement, player);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AdvancementHelper(com.denizenscript.denizen.nms.interfaces.AdvancementHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NamespacedKey(org.bukkit.NamespacedKey) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) Advancement(com.denizenscript.denizen.nms.util.Advancement)

Example 93 with ElementTag

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

the class ToastCommand method parseArgs.

// <--[command]
// @Name Toast
// @Syntax toast [<text>] (targets:<player>|...) (icon:<item>) (frame:{task}/challenge/goal)
// @Required 1
// @Maximum 4
// @Short Shows the player a custom advancement toast.
// @Group player
// 
// @Description
// Displays a client-side custom advancement "toast" notification popup to the player(s).
// If no target is specified it will default to the attached player.
// The icon argument changes the icon displayed in the toast pop-up notification.
// The frame argument changes the type of advancement.
// 
// @Tags
// None
// 
// @Usage
// Welcomes the player with an advancement toast.
// - toast "Welcome <player.name>!"
// 
// @Usage
// Sends the player an advancement toast with a custom icon.
// - toast "Diggy Diggy Hole" icon:iron_spade
// 
// @Usage
// Sends the player a "Challenge Complete!" type advancement toast.
// - toast "You finished a challenge!" frame:challenge icon:diamond
// 
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("icon") && arg.matchesPrefix("icon", "i") && arg.matchesArgumentType(ItemTag.class)) {
            scriptEntry.addObject("icon", arg.asType(ItemTag.class));
        } else if (!scriptEntry.hasObject("frame") && arg.matchesPrefix("frame", "f") && arg.matchesEnum(Advancement.Frame.class)) {
            scriptEntry.addObject("frame", arg.asElement());
        } 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")) {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must specify valid player targets!");
        } else {
            scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
        }
    }
    scriptEntry.defaultObject("icon", new ItemTag(Material.AIR));
    scriptEntry.defaultObject("frame", new ElementTag("TASK"));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 94 with ElementTag

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

the class AnimateChestCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag action = scriptEntry.getElement("action");
    ElementTag sound = scriptEntry.getElement("sound");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, db("block type", location.getBlock().getType().name()), action, sound, db("players", players));
    }
    PacketHelper packetHelper = NMSHandler.getPacketHelper();
    switch(ChestAction.valueOf(action.asString().toUpperCase())) {
        case OPEN:
            for (PlayerTag player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
                }
                packetHelper.showBlockAction(ent, location, 1, 1);
            }
            break;
        case CLOSE:
            for (PlayerTag player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
                }
                packetHelper.showBlockAction(ent, location, 1, 0);
            }
            break;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 95 with ElementTag

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

the class FireworkCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("type") && arg.matches("random")) {
            scriptEntry.addObject("type", new ElementTag(FireworkEffect.Type.values()[CoreUtilities.getRandom().nextInt(FireworkEffect.Type.values().length)].name()));
        } else if (!scriptEntry.hasObject("type") && arg.matchesEnum(FireworkEffect.Type.class)) {
            scriptEntry.addObject("type", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location!");
    }
    scriptEntry.defaultObject("type", new ElementTag("ball"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

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