use of com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer in project HoloMobHealth by LOOHP.
the class ArmorstandDisplay method getData.
public static ArmorStandDisplayData getData(Player player, UUID entityUUID, World world, PacketContainer packet) {
// ArmorStandDisplayCache cahcedData = cache.get(entityUUID);
// if (cahcedData != null) {
// return cahcedData;
// }
Entity entity = NMSUtils.getEntityFromUUID(entityUUID);
if (entity == null || !EntityTypeUtils.getMobsTypesSet().contains(entity.getType())) {
return null;
}
if (HoloMobHealth.disabledMobTypes.contains(entity.getType())) {
return new ArmorStandDisplayData();
}
String customName = CustomNameUtils.getMobCustomName(entity);
if (!HoloMobHealth.disabledWorlds.contains(world.getName())) {
if (!HoloMobHealth.showCitizens && HoloMobHealth.citizensHook) {
if (CitizensUtils.isNPC(entity)) {
return null;
}
}
if (!HoloMobHealth.showMythicMobs && HoloMobHealth.mythicHook) {
if (MythicMobsUtils.isMythicMob(entity)) {
return null;
}
}
if (!HoloMobHealth.showShopkeepers && HoloMobHealth.shopkeepersHook) {
if (ShopkeepersUtils.isShopkeeper(entity)) {
return null;
}
}
if (!HoloMobHealth.showMyPet && HoloMobHealth.myPetHook) {
if (MyPetUtils.isMyPet(entity)) {
return null;
}
}
if (customName != null) {
for (String each : HoloMobHealth.disabledMobNamesAbsolute) {
if (customName.equals(ChatColorUtils.translateAlternateColorCodes('&', each))) {
return new ArmorStandDisplayData();
}
}
for (String each : HoloMobHealth.disabledMobNamesContains) {
if (ChatColorUtils.stripColor(customName.toLowerCase()).contains(ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', each).toLowerCase()))) {
return new ArmorStandDisplayData();
}
}
}
if (!HoloMobHealth.applyToNamed) {
if (customName != null) {
return null;
}
}
boolean useIdle = false;
if (HoloMobHealth.useAlterHealth && !HoloMobHealth.altShowHealth.containsKey(entityUUID)) {
if (HoloMobHealth.idleUse) {
useIdle = true;
}
}
List<WrappedWatchableObject> data = packet.getWatchableCollectionModifier().read(0);
WrappedDataWatcher watcher = new WrappedDataWatcher(data);
List<Component> components;
if (useIdle) {
components = HoloMobHealth.idleDisplayText.stream().map(each -> ParsePlaceholders.parse(player, (LivingEntity) entity, each)).collect(Collectors.toList());
} else {
components = HoloMobHealth.displayText.stream().map(each -> ParsePlaceholders.parse(player, (LivingEntity) entity, each)).collect(Collectors.toList());
}
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, "");
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, "");
} else {
Optional<?> opt = Optional.empty();
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
if (HoloMobHealth.version.isOld()) {
watcher.setObject(3, (byte) 0);
} else {
watcher.setObject(new WrappedDataWatcherObject(3, Registry.get(Boolean.class)), false);
}
ArmorStandDisplayData newData = new ArmorStandDisplayData(watcher, components, customName, entity);
return newData;
}
return null;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer in project HoloMobHealth by LOOHP.
the class ArmorStandPacket method buildWrappedDataWatcher.
private static WrappedDataWatcher buildWrappedDataWatcher(HoloMobArmorStand entity, Component entityNameComponent, boolean visible) {
WrappedDataWatcher watcher = new WrappedDataWatcher();
if (entity.getType().equals(EntityType.ARMOR_STAND)) {
byte bitmask = 0x20;
if (HoloMobHealth.version.isOld()) {
watcher.setObject(0, bitmask);
} else {
watcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), bitmask);
}
if (entityNameComponent != null && !entityNameComponent.equals(Component.empty())) {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(entityNameComponent, HoloMobHealth.language)));
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(entityNameComponent, HoloMobHealth.language)));
} else {
Optional<?> opt = Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(entityNameComponent)).getHandle());
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
} else {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, "");
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, "");
} else {
Optional<?> opt = Optional.empty();
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
}
if (HoloMobHealth.version.isOld()) {
watcher.setObject(3, (byte) (visible ? 1 : 0));
watcher.setObject(5, (byte) 1);
} else {
watcher.setObject(new WrappedDataWatcherObject(3, Registry.get(Boolean.class)), entityNameComponent != null && (!entityNameComponent.equals(Component.empty()) && visible));
watcher.setObject(new WrappedDataWatcherObject(5, Registry.get(Boolean.class)), true);
}
byte standbitmask = 0x01 | 0x10;
if (HoloMobHealth.version.isNewerOrEqualTo(MCVersion.V1_17)) {
watcher.setObject(new WrappedDataWatcherObject(15, Registry.get(Byte.class)), standbitmask);
} else if (HoloMobHealth.version.isNewerOrEqualTo(MCVersion.V1_15)) {
watcher.setObject(new WrappedDataWatcherObject(14, Registry.get(Byte.class)), standbitmask);
} else if (HoloMobHealth.version.equals(MCVersion.V1_14)) {
watcher.setObject(new WrappedDataWatcherObject(13, Registry.get(Byte.class)), standbitmask);
} else if (!HoloMobHealth.version.isOld()) {
watcher.setObject(new WrappedDataWatcherObject(11, Registry.get(Byte.class)), standbitmask);
} else {
watcher.setObject(10, standbitmask);
}
} else {
byte bitmask = 0x20;
if (HoloMobHealth.version.isOld()) {
watcher.setObject(0, bitmask);
} else {
watcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), bitmask);
}
if (!HoloMobHealth.version.isOld()) {
watcher.setObject(new WrappedDataWatcherObject(4, Registry.get(Boolean.class)), true);
} else {
watcher.setObject(4, (byte) 1);
}
if (HoloMobHealth.version.isNewerOrEqualTo(MCVersion.V1_17)) {
watcher.setObject(new WrappedDataWatcherObject(16, Registry.get(Boolean.class)), true);
} else if (HoloMobHealth.version.isNewerOrEqualTo(MCVersion.V1_15)) {
watcher.setObject(new WrappedDataWatcherObject(15, Registry.get(Boolean.class)), true);
} else if (HoloMobHealth.version.equals(MCVersion.V1_14)) {
watcher.setObject(new WrappedDataWatcherObject(14, Registry.get(Boolean.class)), true);
} else if (!HoloMobHealth.version.isOld()) {
watcher.setObject(new WrappedDataWatcherObject(12, Registry.get(Boolean.class)), true);
} else {
watcher.setObject(10, (byte) 1);
}
}
return watcher;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer in project HoloMobHealth by LOOHP.
the class NameTagDisplay method getWatcher.
public static WrappedDataWatcher getWatcher(Player player, UUID entityUUID, World world, PacketContainer packet) {
// WrappedDataWatcher cachedWatcher = cache.get(entityUUID);
// if (cachedWatcher != null) {
// return cachedWatcher;
// }
Entity entity = NMSUtils.getEntityFromUUID(entityUUID);
if (entity == null || !EntityTypeUtils.getMobsTypesSet().contains(entity.getType())) {
return null;
}
if (HoloMobHealth.disabledMobTypes.contains(entity.getType())) {
return null;
}
String customName = CustomNameUtils.getMobCustomName(entity);
if (HoloMobHealth.rangeEnabled && !RangeModule.isEntityInRangeOfPlayer(player, entity)) {
return null;
}
boolean useIdle = false;
if (HoloMobHealth.useAlterHealth && !HoloMobHealth.altShowHealth.containsKey(entityUUID)) {
if (!HoloMobHealth.idleUse) {
return null;
}
useIdle = true;
}
if (!HoloMobHealth.disabledWorlds.contains(world.getName())) {
if (!HoloMobHealth.showCitizens && HoloMobHealth.citizensHook) {
if (CitizensUtils.isNPC(entity)) {
return null;
}
}
if (!HoloMobHealth.showMythicMobs && HoloMobHealth.mythicHook) {
if (MythicMobsUtils.isMythicMob(entity)) {
return null;
}
}
if (!HoloMobHealth.showShopkeepers && HoloMobHealth.shopkeepersHook) {
if (ShopkeepersUtils.isShopkeeper(entity)) {
return null;
}
}
if (!HoloMobHealth.showMyPet && HoloMobHealth.myPetHook) {
if (MyPetUtils.isMyPet(entity)) {
return null;
}
}
if (customName != null) {
for (String each : HoloMobHealth.disabledMobNamesAbsolute) {
if (customName.equals(ChatColorUtils.translateAlternateColorCodes('&', each))) {
return null;
}
}
for (String each : HoloMobHealth.disabledMobNamesContains) {
if (ChatColorUtils.stripColor(customName.toLowerCase()).contains(ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', each).toLowerCase()))) {
return null;
}
}
}
if (!HoloMobHealth.applyToNamed) {
if (customName != null) {
return null;
}
}
List<WrappedWatchableObject> data = packet.getWatchableCollectionModifier().read(0);
WrappedDataWatcher watcher = new WrappedDataWatcher(data);
Component component = ParsePlaceholders.parse(player, (LivingEntity) entity, useIdle ? HoloMobHealth.idleDisplayText.get(0) : HoloMobHealth.displayText.get(0));
boolean visible = HoloMobHealth.alwaysShow;
if (component != null && !component.equals(Component.empty())) {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(component, HoloMobHealth.language)));
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(component, HoloMobHealth.language)));
} else {
Optional<?> opt = Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(component)).getHandle());
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
} else {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, "");
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, "");
} else {
Optional<?> opt = Optional.empty();
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
}
if (HoloMobHealth.version.isOld()) {
watcher.setObject(3, (byte) (visible ? 1 : 0));
} else {
watcher.setObject(new WrappedDataWatcherObject(3, Registry.get(Boolean.class)), visible);
}
return watcher;
}
return null;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer in project HoloMobHealth by LOOHP.
the class EntityMetadata method sendMetadataPacket.
public static void sendMetadataPacket(Entity entity, Component entityNameComponent, boolean visible, List<Player> players, boolean quiet) {
Bukkit.getScheduler().runTask(HoloMobHealth.plugin, () -> {
PacketContainer packet = HoloMobHealth.protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
// Set packet's entity id
packet.getIntegers().write(0, entity.getEntityId());
// Create data watcher, the Entity Metadata packet requires this
WrappedDataWatcher watcher = new WrappedDataWatcher();
if (entityNameComponent != null && !entityNameComponent.equals(Component.empty())) {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(entityNameComponent, HoloMobHealth.language)));
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(entityNameComponent, HoloMobHealth.language)));
} else {
Optional<?> opt = Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(entityNameComponent)).getHandle());
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
} else {
if (HoloMobHealth.version.isOld()) {
watcher.setObject(2, "");
} else if (HoloMobHealth.version.isLegacy()) {
Serializer serializer = Registry.get(String.class);
WrappedDataWatcherObject object = new WrappedDataWatcherObject(2, serializer);
watcher.setObject(object, "");
} else {
Optional<?> opt = Optional.empty();
watcher.setObject(new WrappedDataWatcherObject(2, Registry.getChatComponentSerializer(true)), opt);
}
}
if (HoloMobHealth.version.isOld()) {
watcher.setObject(3, (byte) (visible ? 1 : 0));
} else {
watcher.setObject(new WrappedDataWatcherObject(3, Registry.get(Boolean.class)), visible);
}
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try {
for (Player player : players) {
if (player.hasPermission("holomobhealth.use")) {
HoloMobHealth.protocolManager.sendServerPacket(player, packet, !quiet);
}
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
});
}
Aggregations