Search in sources :

Example 1 with OneTimeSchedulable

use of net.aufdemrand.denizencore.utilities.scheduling.OneTimeSchedulable 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)

Aggregations

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