Search in sources :

Example 66 with ElementTag

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

the class MapCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag id = scriptEntry.getElement("map-id");
    WorldTag create = scriptEntry.getObjectTag("new");
    ElementTag reset = scriptEntry.getElement("reset");
    LocationTag resetLoc = scriptEntry.getObjectTag("reset-loc");
    ElementTag image = scriptEntry.getElement("image");
    ScriptTag script = scriptEntry.getObjectTag("script");
    ElementTag resize = scriptEntry.getElement("resize");
    ElementTag width = scriptEntry.getElement("width");
    ElementTag height = scriptEntry.getElement("height");
    ElementTag scale = scriptEntry.getElement("scale");
    ElementTag tracking = scriptEntry.getElement("tracking");
    ElementTag x = scriptEntry.getElement("x-value");
    ElementTag y = scriptEntry.getElement("y-value");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), id, create, reset, resetLoc, image, script, resize, width, height, x, y);
    }
    MapView map;
    if (create != null) {
        map = Bukkit.getServer().createMap(create.getWorld());
        scriptEntry.addObject("created_map", new ElementTag(map.getId()));
        Debug.echoDebug(scriptEntry, "Created map with id " + map.getId() + ".");
    } else if (id != null) {
        map = Bukkit.getServer().getMap((short) id.asInt());
        if (map == null) {
            Debug.echoError("No map found for ID '" + id.asInt() + "'!");
            return;
        }
    } else {
        // not possible
        return;
    }
    if (reset.asBoolean()) {
        if (tracking != null) {
            map.setTrackingPosition(true);
        }
        if (scale != null) {
            map.setScale(MapView.Scale.valueOf(scale.asString().toUpperCase()));
        }
        List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
        for (MapRenderer renderer : oldRenderers) {
            map.addRenderer(renderer);
        }
        if (resetLoc != null) {
            map.setCenterX(resetLoc.getBlockX());
            map.setCenterZ(resetLoc.getBlockZ());
            map.setWorld(resetLoc.getWorld());
        }
    }
    if (script != null) {
        DenizenMapManager.removeDenizenRenderers(map);
        ((MapScriptContainer) script.getContainer()).applyTo(map);
    }
    if (image != null) {
        DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
        int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
        int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
        if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) {
            dmr.autoUpdate = true;
        }
        dmr.addObject(new MapImage(dmr, x.asString(), y.asString(), "true", false, image.asString(), wide, high));
        dmr.hasChanged = true;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MapImage(com.denizenscript.denizen.utilities.maps.MapImage) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) MapView(org.bukkit.map.MapView) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapScriptContainer(com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)

Example 67 with ElementTag

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

the class SneakCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag fake = scriptEntry.getElement("fake");
    ElementTag stopfake = scriptEntry.getElement("stopfake");
    ElementTag mode = scriptEntry.getElement("mode");
    List<PlayerTag> forPlayers = (List<PlayerTag>) scriptEntry.getObject("for_players");
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), mode, db("entities", entities), db("for_players", forPlayers), fake, stopfake);
    }
    boolean shouldSneak = mode.asString().equalsIgnoreCase("start");
    boolean shouldFake = fake != null && fake.asBoolean();
    boolean shouldStopFake = stopfake != null && stopfake.asBoolean();
    for (EntityTag entity : entities) {
        if (shouldFake || shouldStopFake) {
            if (forPlayers == null) {
                updateFakeSneak(entity.getUUID(), null, shouldSneak, shouldFake);
                for (Player player : NMSHandler.getEntityHelper().getPlayersThatSee(entity.getBukkitEntity())) {
                    NMSHandler.getPacketHelper().sendEntityMetadataFlagsUpdate(player, entity.getBukkitEntity());
                }
            } else {
                for (PlayerTag player : forPlayers) {
                    updateFakeSneak(entity.getUUID(), player.getUUID(), shouldSneak, shouldFake);
                    NMSHandler.getPacketHelper().sendEntityMetadataFlagsUpdate(player.getPlayerEntity(), entity.getBukkitEntity());
                }
            }
        } else if (entity.isCitizensNPC()) {
            SneakingTrait trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(SneakingTrait.class);
            if (shouldSneak) {
                trait.sneak();
            } else {
                trait.stand();
            }
        } else if (entity.isSpawned()) {
            NMSHandler.getEntityHelper().setSneaking(entity.getBukkitEntity(), shouldSneak);
        } else {
            Debug.echoError("Cannot make unspawned entity sneak.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) SneakingTrait(com.denizenscript.denizen.npc.traits.SneakingTrait) List(java.util.List) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 68 with ElementTag

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

the class AttachCommand method parseArgs.

// <--[command]
// @Name attach
// @Syntax attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate/no_pitch) (for:<player>|...)
// @Required 2
// @Maximum 9
// @Short Attaches a list of entities to another entity, for client-visible motion sync.
// @Group entity
// 
// @Description
// Attaches a list of entities to another entity, for client-visible motion sync.
// 
// You must specify the entity or list of entities to be attached.
// You must specify the entity that they will be attached to, or 'cancel' to end attachment.
// 
// Optionally, specify an offset location vector to be a positional offset. This can include a yaw/pitch to offset those as well.
// Note that setting an offset of 0,0,0 will produce slightly different visual results from not setting any offset.
// 
// Optionally, specify 'relative' to indicate that the offset vector should rotate with the target entity.
// If relative is used, optionally specify yaw_offset and/or pitch_offset to add an offset to rotation of the target entity when calculating the attachment offset.
// 
// Optionally, specify 'for' with a player or list of players to only sync motion for those players.
// If unspecified, will sync for everyone.
// 
// Optionally, specify 'sync_server' to keep the serverside position of the attached entities near the target entity.
// This can reduce some visual artifacts (such as entity unloading at distance), but may produce unintended functional artifacts.
// Note that you should generally only use 'sync_server' when you exclude the 'for' argument.
// 
// Optionally specify 'no_rotate' to retain the attached entity's own rotation and ignore the target rotation.
// Optionally instead specify 'no_pitch' to retain the attached entity's own pitch, but use the target yaw.
// 
// Note that attaches involving a player will not be properly visible to that player, but will still be visible to *other* players.
// 
// It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this command functions as expected.
// 
// @Tags
// <EntityTag.attached_entities[(<player>)]>
// <EntityTag.attached_to[(<player>)]>
// <EntityTag.attached_offset[(<player>)]>
// 
// @Usage
// Use to attach random NPC to the air 3 blocks above a linked NPC.
// - attach <server.list_npcs.random> to:<npc> offset:0,3,0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel") && arg.matchesPrefix("to") && arg.matchesArgumentType(EntityTag.class)) {
            scriptEntry.addObject("to", arg.asType(EntityTag.class));
        } else if (!scriptEntry.hasObject("cancel") && !scriptEntry.hasObject("to") && arg.matches("cancel")) {
            scriptEntry.addObject("cancel", new ElementTag(true));
        } else if (!scriptEntry.hasObject("relative") && arg.matches("relative")) {
            scriptEntry.addObject("relative", new ElementTag(true));
        } else if (!scriptEntry.hasObject("sync_server") && arg.matches("sync_server")) {
            scriptEntry.addObject("sync_server", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
            scriptEntry.addObject("no_rotate", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_pitch") && arg.matches("no_pitch")) {
            scriptEntry.addObject("no_pitch", new ElementTag(true));
        } else if (!scriptEntry.hasObject("yaw_offset") && arg.matchesPrefix("yaw_offset") && arg.matchesFloat()) {
            scriptEntry.addObject("yaw_offset", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch_offset") && arg.matchesPrefix("pitch_offset") && arg.matchesFloat()) {
            scriptEntry.addObject("pitch_offset", arg.asElement());
        } else if (!scriptEntry.hasObject("offset") && arg.matchesPrefix("offset") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("offset", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("for") && arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify attaching entities!");
    }
    if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel")) {
        throw new InvalidArgumentsException("Must specify a target entity, or 'cancel'!");
    }
    scriptEntry.defaultObject("cancel", new ElementTag(false));
    scriptEntry.defaultObject("relative", new ElementTag(false));
    scriptEntry.defaultObject("sync_server", new ElementTag(false));
    scriptEntry.defaultObject("no_rotate", new ElementTag(false));
    scriptEntry.defaultObject("no_pitch", new ElementTag(false));
    scriptEntry.defaultObject("yaw_offset", new ElementTag(0f));
    scriptEntry.defaultObject("pitch_offset", new ElementTag(0f));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 69 with ElementTag

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

the class FeedCommand method parseArgs.

// <--[command]
// @Name Feed
// @Syntax feed (<entity>) (amount:<#>) (saturation:<#.#>)
// @Required 0
// @Maximum 3
// @Short Feed the player or npc.
// @Group entity
// 
// @Description
// Feeds the player or npc specified.
// 
// By default targets the player attached to the script queue and feeds a full amount.
// 
// Accepts the 'amount:' argument, which is in half bar increments, up to a total of 20 food points.
// The amount may be negative, to cause hunger instead of satiating it.
// 
// You can optionally also specify an amount to change the saturation by.
// By default, the saturation change will be the same as the food level change.
// This is also up to a total of 20 points. This value may also be negative.
// 
// Also accepts the 'target:<entity>' argument to specify the entity which will be fed the amount.
// 
// @Tags
// <PlayerTag.food_level>
// <PlayerTag.formatted_food_level>
// <PlayerTag.saturation>
// 
// @Usage
// Use to feed the player for 5 foodpoints (or 2.5 bars).
// - feed amount:5
// 
// @Usage
// Use to feed an NPC for 10 foodpoints (or 5 bars).
// - feed <npc> amount:10
// 
// @Usage
// Use to feed a player from a definition fully without refilling saturation.
// - feed <[player]> saturation:0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matchesInteger() && arg.matchesPrefix("amount", "amt", "quantity", "qty", "a", "q") && !scriptEntry.hasObject("amount")) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesInteger() && arg.matchesPrefix("saturation", "sat", "s") && !scriptEntry.hasObject("saturation")) {
            scriptEntry.addObject("saturation", arg.asElement());
        } else if (arg.matchesArgumentType(PlayerTag.class) && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
            scriptEntry.addObject("targetplayer", arg.asType(PlayerTag.class));
        } else if (Depends.citizens != null && arg.matchesArgumentType(NPCTag.class) && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
            scriptEntry.addObject("targetnpc", arg.asType(NPCTag.class));
        } else // Backwards compatibility
        if (arg.matches("npc") && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc") && Utilities.entryHasNPC(scriptEntry)) {
            scriptEntry.addObject("targetnpc", Utilities.getEntryNPC(scriptEntry));
        } else if (arg.matches("player") && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc") && Utilities.entryHasPlayer(scriptEntry)) {
            scriptEntry.addObject("targetplayer", Utilities.getEntryPlayer(scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
        if (Utilities.entryHasPlayer(scriptEntry)) {
            scriptEntry.addObject("targetplayer", Utilities.getEntryPlayer(scriptEntry));
        } else if (Utilities.entryHasNPC(scriptEntry)) {
            scriptEntry.addObject("targetnpc", Utilities.getEntryNPC(scriptEntry));
        } else {
            throw new InvalidArgumentsException("Must specify a player!");
        }
    }
    scriptEntry.defaultObject("amount", new ElementTag(20));
    scriptEntry.defaultObject("saturation", scriptEntry.getObject("amount"));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 70 with ElementTag

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

the class FeedCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    PlayerTag player = scriptEntry.getObjectTag("targetplayer");
    NPCTag npc = scriptEntry.getObjectTag("targetnpc");
    ElementTag amount = scriptEntry.getElement("amount");
    ElementTag saturation = scriptEntry.getElement("saturation");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
    }
    if (npc != null) {
        if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
            Debug.echoError(scriptEntry, "This NPC does not have the HungerTrait enabled! Use /trait hunger");
            return;
        }
        npc.getCitizen().getOrAddTrait(HungerTrait.class).feed(amount.asInt());
    } else {
        int result = Math.max(0, Math.min(20, player.getPlayerEntity().getFoodLevel() + amount.asInt()));
        player.getPlayerEntity().setFoodLevel(result);
        float satResult = Math.max(0, Math.min(20, player.getPlayerEntity().getSaturation() + saturation.asFloat()));
        player.getPlayerEntity().setSaturation(satResult);
        Debug.echoDebug(scriptEntry, "Player food level updated to " + result + " food and " + satResult + " saturation.");
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) HungerTrait(com.denizenscript.denizen.npc.traits.HungerTrait)

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