Search in sources :

Example 1 with PacketHelper

use of com.denizenscript.denizen.nms.interfaces.PacketHelper 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 2 with PacketHelper

use of com.denizenscript.denizen.nms.interfaces.PacketHelper 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 3 with PacketHelper

use of com.denizenscript.denizen.nms.interfaces.PacketHelper in project Denizen 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 4 with PacketHelper

use of com.denizenscript.denizen.nms.interfaces.PacketHelper in project Denizen 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 5 with PacketHelper

use of com.denizenscript.denizen.nms.interfaces.PacketHelper in project Denizen-For-Bukkit by DenizenScript.

the class FakeItemCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
    final ElementTag elSlot = scriptEntry.getElement("slot");
    DurationTag duration = scriptEntry.getObjectTag("duration");
    final List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    final ElementTag player_only = scriptEntry.getElement("player_only");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("items", items), elSlot, duration, db("players", players), player_only);
    }
    if (players.size() == 0) {
        return;
    }
    int slot = SlotHelper.nameToIndex(elSlot.asString(), players.get(0).getPlayerEntity());
    if (slot == -1) {
        Debug.echoError(scriptEntry, "The input '" + elSlot.asString() + "' is not a valid slot!");
        return;
    }
    final boolean playerOnly = player_only.asBoolean();
    final PacketHelper packetHelper = NMSHandler.getPacketHelper();
    for (ItemTag item : items) {
        if (item == null) {
            slot++;
            continue;
        }
        for (PlayerTag player : players) {
            Player ent = player.getPlayerEntity();
            packetHelper.setSlot(ent, translateSlot(ent, slot, playerOnly), item.getItemStack(), playerOnly);
        }
        final int slotSnapshot = slot;
        slot++;
        if (duration.getSeconds() > 0) {
            DenizenCore.schedule(new OneTimeSchedulable(() -> {
                for (PlayerTag player : players) {
                    Player ent = player.getPlayerEntity();
                    int translated = translateSlot(ent, slotSnapshot, playerOnly);
                    ItemStack original = ent.getOpenInventory().getItem(translated);
                    packetHelper.setSlot(ent, translated, original, playerOnly);
                }
            }, (float) duration.getSeconds()));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PacketHelper(com.denizenscript.denizen.nms.interfaces.PacketHelper) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) ItemStack(org.bukkit.inventory.ItemStack) OneTimeSchedulable(com.denizenscript.denizencore.utilities.scheduling.OneTimeSchedulable)

Aggregations

PacketHelper (com.denizenscript.denizen.nms.interfaces.PacketHelper)6 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)6 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)6 List (java.util.List)6 Player (org.bukkit.entity.Player)6 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 ItemTag (com.denizenscript.denizen.objects.ItemTag)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)2 OneTimeSchedulable (com.denizenscript.denizencore.utilities.scheduling.OneTimeSchedulable)2 UUID (java.util.UUID)2 Location (org.bukkit.Location)2 ItemStack (org.bukkit.inventory.ItemStack)2