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