Search in sources :

Example 46 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class MaterialHalf method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.half>
    // @returns ElementTag
    // @mechanism MaterialTag.half
    // @group properties
    // @description
    // Returns the current half for a bisected material (like a door, double-plant, chest, or a bed).
    // Output for "Bisected" blocks (doors/double plants/...) is "BOTTOM" or "TOP".
    // Output for beds is "HEAD" or "FOOT".
    // Output for chests is "LEFT" or "RIGHT".
    // -->
    PropertyParser.<MaterialHalf, ElementTag>registerStaticTag(ElementTag.class, "half", (attribute, material) -> {
        String halfName = material.getHalfName();
        if (halfName == null) {
            return null;
        }
        return new ElementTag(halfName);
    });
    // <--[tag]
    // @attribute <MaterialTag.relative_vector>
    // @returns LocationTag
    // @mechanism MaterialTag.half
    // @group properties
    // @description
    // Returns a vector location of the other block for a bisected material.
    // -->
    PropertyParser.<MaterialHalf, LocationTag>registerStaticTag(LocationTag.class, "relative_vector", (attribute, material) -> {
        Vector vector = material.getRelativeBlockVector();
        if (vector == null) {
            return null;
        }
        return new LocationTag(vector);
    });
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Vector(org.bukkit.util.Vector)

Example 47 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class PoseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    TargetType target = (TargetType) scriptEntry.getObject("target");
    NPCTag npc = Utilities.getEntryNPC(scriptEntry);
    Action action = (Action) scriptEntry.getObject("action");
    ElementTag idElement = scriptEntry.getElement("pose_id");
    LocationTag pose_loc = scriptEntry.getObjectTag("pose_loc");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Target", target), (target == TargetType.PLAYER ? Utilities.getEntryPlayer(scriptEntry) : ""), npc, db("Action", action), idElement, pose_loc);
    }
    if (!npc.getCitizen().hasTrait(Poses.class)) {
        npc.getCitizen().addTrait(Poses.class);
    }
    Poses poses = npc.getCitizen().getOrAddTrait(Poses.class);
    String id = idElement.asString();
    switch(action) {
        case ASSUME:
            if (!poses.hasPose(id)) {
                Debug.echoError("Pose \"" + id + "\" doesn't exist for " + npc.toString());
            }
            if (target.name().equals("NPC")) {
                poses.assumePose(id);
            } else {
                Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
                Location location = player.getLocation();
                location.setYaw(poses.getPose(id).getYaw());
                location.setPitch(poses.getPose(id).getPitch());
                // The only way to change a player's yaw and pitch in Bukkit is to use teleport on them
                player.teleport(location);
            }
            break;
        case ADD:
            if (!poses.addPose(id, pose_loc)) {
                Debug.echoError(npc.toString() + " already has that pose!");
            }
            break;
        case REMOVE:
            if (!poses.removePose(id)) {
                Debug.echoError(npc.toString() + " does not have that pose!");
            }
            break;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Player(org.bukkit.entity.Player) NPCTag(com.denizenscript.denizen.objects.NPCTag) Poses(net.citizensnpcs.trait.Poses) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Location(org.bukkit.Location)

Example 48 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag 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 49 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag 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 50 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag 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)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)133 EventHandler (org.bukkit.event.EventHandler)69 EntityTag (com.denizenscript.denizen.objects.EntityTag)45 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)40 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)33 List (java.util.List)21 ItemTag (com.denizenscript.denizen.objects.ItemTag)18 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)13 NPCTag (com.denizenscript.denizen.objects.NPCTag)12 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)8 Entity (org.bukkit.entity.Entity)8 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)6 Player (org.bukkit.entity.Player)6 Vector (org.bukkit.util.Vector)6 UUID (java.util.UUID)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5