use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processDisguiseForPacket.
public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
return false;
}
try {
if (packet instanceof PacketPlayOutEntityMetadata) {
PacketPlayOutEntityMetadata metadataPacket = (PacketPlayOutEntityMetadata) packet;
int eid = ENTITY_METADATA_EID.getInt(metadataPacket);
Entity ent = player.world.getEntity(eid);
if (ent == null) {
return false;
}
HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUniqueID());
if (playerMap == null) {
return false;
}
DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
if (disguise == null) {
disguise = playerMap.get(null);
if (disguise == null) {
return false;
}
}
if (ent.getId() == player.getId()) {
if (!disguise.shouldFake) {
return false;
}
List<DataWatcher.Item<?>> data = (List<DataWatcher.Item<?>>) ENTITY_METADATA_LIST.get(metadataPacket);
for (DataWatcher.Item item : data) {
DataWatcherObject<?> watcherObject = item.a();
int watcherId = watcherObject.a();
if (watcherId == 0) {
// Entity flags
PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata();
copyPacket(metadataPacket, altPacket);
data = new ArrayList<>(data);
ENTITY_METADATA_LIST.set(altPacket, data);
data.remove(item);
byte flags = (byte) item.b();
// Invisible flag
flags |= 0x20;
data.add(new DataWatcher.Item(watcherObject, flags));
PacketPlayOutEntityMetadata updatedPacket = getModifiedMetadataFor(altPacket);
oldManager.sendPacket(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
return true;
}
}
} else {
PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getDataWatcher(), true);
oldManager.sendPacket(altPacket, genericfuturelistener);
return true;
}
return false;
}
int ider = -1;
if (packet instanceof PacketPlayOutNamedEntitySpawn) {
ider = ENTITY_ID_NAMEDENTSPAWN.getInt(packet);
} else if (packet instanceof PacketPlayOutSpawnEntity) {
ider = ENTITY_ID_SPAWNENT.getInt(packet);
} else if (packet instanceof PacketPlayOutSpawnEntityLiving) {
ider = ENTITY_ID_SPAWNENTLIVING.getInt(packet);
}
if (ider != -1) {
Entity e = player.getWorld().getEntity(ider);
if (e == null) {
return false;
}
HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUniqueID());
if (playerMap == null) {
return false;
}
DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
if (disguise == null) {
disguise = playerMap.get(null);
if (disguise == null) {
return false;
}
}
antiDuplicate = true;
disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
antiDuplicate = false;
return true;
}
} catch (Throwable ex) {
antiDuplicate = false;
Debug.echoError(ex);
}
return false;
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showSignEditor.
@Override
public boolean showSignEditor(Player player, Location location) {
if (location == null) {
LocationTag fakeSign = new LocationTag(player.getLocation());
fakeSign.setY(0);
FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
send(player, new ClientboundOpenSignEditorPacket(pos));
return true;
}
BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
if (tileEntity instanceof SignBlockEntity) {
SignBlockEntity sign = (SignBlockEntity) tileEntity;
// Prevent client crashing by sending current state of the sign
send(player, sign.getUpdatePacket());
sign.isEditable = true;
sign.setAllowedPlayerEditor(player.getUniqueId());
send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
return true;
} else {
return false;
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processDisguiseForPacket.
public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
return false;
}
try {
if (packet instanceof ClientboundSetEntityDataPacket) {
ClientboundSetEntityDataPacket metadataPacket = (ClientboundSetEntityDataPacket) packet;
int eid = metadataPacket.getId();
Entity ent = player.level.getEntity(eid);
if (ent == null) {
return false;
}
HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUUID());
if (playerMap == null) {
return false;
}
DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
if (disguise == null) {
disguise = playerMap.get(null);
if (disguise == null) {
return false;
}
}
if (ent.getId() == player.getId()) {
if (!disguise.shouldFake) {
return false;
}
List<SynchedEntityData.DataItem<?>> data = metadataPacket.getUnpackedData();
for (SynchedEntityData.DataItem item : data) {
EntityDataAccessor<?> watcherObject = item.getAccessor();
int watcherId = watcherObject.getId();
if (watcherId == 0) {
// Entity flags
ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
data = new ArrayList<>(data);
ENTITY_METADATA_LIST.set(altPacket, data);
data.remove(item);
byte flags = (byte) item.getValue();
// Invisible flag
flags |= 0x20;
data.add(new SynchedEntityData.DataItem(watcherObject, flags));
ClientboundSetEntityDataPacket updatedPacket = getModifiedMetadataFor(altPacket);
oldManager.send(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
return true;
}
}
} else {
ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getEntityData(), true);
oldManager.send(altPacket, genericfuturelistener);
return true;
}
return false;
}
int ider = -1;
if (packet instanceof ClientboundAddPlayerPacket) {
ider = ((ClientboundAddPlayerPacket) packet).getEntityId();
} else if (packet instanceof ClientboundAddEntityPacket) {
ider = ((ClientboundAddEntityPacket) packet).getId();
} else if (packet instanceof ClientboundAddMobPacket) {
ider = ((ClientboundAddMobPacket) packet).getId();
}
if (ider != -1) {
Entity e = player.getLevel().getEntity(ider);
if (e == null) {
return false;
}
HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUUID());
if (playerMap == null) {
return false;
}
DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
if (disguise == null) {
disguise = playerMap.get(null);
if (disguise == null) {
return false;
}
}
antiDuplicate = true;
disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
antiDuplicate = false;
return true;
}
} catch (Throwable ex) {
antiDuplicate = false;
Debug.echoError(ex);
}
return false;
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class StatisticCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
ListTag players = scriptEntry.getObjectTag("players");
ElementTag statistic = scriptEntry.getElement("statistic");
ElementTag amount = scriptEntry.getElement("amount");
MaterialTag material = scriptEntry.getObjectTag("material");
EntityTag entity = scriptEntry.getObjectTag("entity");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, statistic, amount, players, material, entity);
}
Action act = Action.valueOf(action.asString().toUpperCase());
Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
int amt = amount.asInt();
switch(stat.getType()) {
case BLOCK:
case ITEM:
Material mat = material.getMaterial();
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, mat, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, mat, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, mat, amt);
}
break;
}
break;
case ENTITY:
EntityType ent = entity.getBukkitEntityType();
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, ent, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, ent, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, ent, amt);
}
break;
}
break;
case UNTYPED:
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, amt);
}
break;
}
break;
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class AnnounceCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
if (scriptEntry.getResidingQueue().procedural) {
Debug.echoError("'Announce' should not be used in a procedure script. Consider the 'debug' command instead.");
}
ElementTag text = scriptEntry.getElement("text");
AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
ElementTag flag = scriptEntry.getElement("flag");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("message", text), (format != null ? db("format", format.getName()) : ""), db("type", type.name()), flag);
}
String message = format != null ? format.getFormattedText(text.asString(), scriptEntry) : text.asString();
// Use Bukkit to broadcast the message to everybody in the server.
switch(type) {
case ALL:
Denizen.getInstance().getServer().spigot().broadcast(FormattedTextHelper.parse(message, ChatColor.WHITE));
break;
case TO_OPS:
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.isOp()) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
break;
case TO_PERMISSION:
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission(flag.asString())) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
case TO_FLAGGED:
for (Player player : Bukkit.getOnlinePlayers()) {
if (new PlayerTag(player).getFlagTracker().hasFlag(flag.asString())) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
break;
case TO_CONSOLE:
Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
break;
}
}
Aggregations