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