Search in sources :

Example 1 with PacketHelper

use of net.aufdemrand.denizen.nms.interfaces.PacketHelper in project Denizen-For-Bukkit by DenizenScript.

the class FakeItemCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
    final Element elSlot = scriptEntry.getElement("slot");
    Duration duration = scriptEntry.getdObject("duration");
    final List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
    final Element player_only = scriptEntry.getElement("player_only");
    dB.report(scriptEntry, getName(), aH.debugList("items", items) + elSlot.debug() + duration.debug() + aH.debugList("players", players) + player_only.debug());
    int slot = elSlot.asInt() - 1;
    final boolean playerOnly = player_only.asBoolean();
    final PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
    for (dItem item : items) {
        if (item == null) {
            slot++;
            continue;
        }
        for (dPlayer 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(new Runnable() {

                @Override
                public void run() {
                    for (dPlayer player : players) {
                        Player ent = player.getPlayerEntity();
                        ItemStack original = ent.getOpenInventory().getItem(translateSlot(ent, slotSnapshot, playerOnly));
                        packetHelper.setSlot(ent, slotSnapshot, original, playerOnly);
                    }
                }
            }, (float) duration.getSeconds()));
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) PacketHelper(net.aufdemrand.denizen.nms.interfaces.PacketHelper) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ItemStack(org.bukkit.inventory.ItemStack) OneTimeSchedulable(net.aufdemrand.denizencore.utilities.scheduling.OneTimeSchedulable)

Example 2 with PacketHelper

use of net.aufdemrand.denizen.nms.interfaces.PacketHelper in project Denizen-For-Bukkit by DenizenScript.

the class AnimateChestCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element action = scriptEntry.getElement("action");
    Element sound = scriptEntry.getElement("sound");
    List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
    dB.report(scriptEntry, getName(), location.debug() + action.debug() + sound.debug() + aH.debugObj("players", players.toString()));
    PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
    switch(ChestAction.valueOf(action.asString().toUpperCase())) {
        case OPEN:
            for (dPlayer player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestOpen(), 1, 1);
                }
                packetHelper.showBlockAction(ent, location, 1, 1);
            }
            break;
        case CLOSE:
            for (dPlayer player : players) {
                Player ent = player.getPlayerEntity();
                if (sound.asBoolean()) {
                    ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestClose(), 1, 1);
                }
                packetHelper.showBlockAction(ent, location, 1, 0);
            }
            break;
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) PacketHelper(net.aufdemrand.denizen.nms.interfaces.PacketHelper) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 3 with PacketHelper

use of net.aufdemrand.denizen.nms.interfaces.PacketHelper in project Denizen-For-Bukkit by DenizenScript.

the class BlockCrack method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
    Element progress = scriptEntry.getElement("progress");
    dLocation location = scriptEntry.getdObject("location");
    Element stack = scriptEntry.getElement("stack");
    dB.report(scriptEntry, getName(), aH.debugList("players", players) + progress.debug() + location.debug() + stack.debug());
    Location loc = location.getBlock().getLocation();
    if (!progressTracker.containsKey(loc)) {
        progressTracker.put(loc, new HashMap<UUID, IntHolder>());
        lastBase += 10;
    }
    Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
    boolean stackVal = stack.asBoolean();
    PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
    for (dPlayer player : players) {
        if (!player.isOnline()) {
            dB.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 : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) PacketHelper(net.aufdemrand.denizen.nms.interfaces.PacketHelper) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) UUID(java.util.UUID) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

List (java.util.List)3 PacketHelper (net.aufdemrand.denizen.nms.interfaces.PacketHelper)3 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)3 Element (net.aufdemrand.denizencore.objects.Element)3 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)3 Player (org.bukkit.entity.Player)3 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 UUID (java.util.UUID)1 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)1 Duration (net.aufdemrand.denizencore.objects.Duration)1 OneTimeSchedulable (net.aufdemrand.denizencore.utilities.scheduling.OneTimeSchedulable)1 Location (org.bukkit.Location)1 ItemStack (org.bukkit.inventory.ItemStack)1