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()));
}
}
}
Aggregations