Merge branch 'Pyrbu:master' into master

This commit is contained in:
D3v1s0m 2023-04-24 19:29:40 +05:30 committed by GitHub
commit b9109eec05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -58,8 +58,7 @@ public class NPC {
this.npcName = NamingType.DEFAULT.resolve(this); this.npcName = NamingType.DEFAULT.resolve(this);
this.npcSkin = NPCSkin.forValues(npcModel.getSkin(), npcModel.getSignature()); this.npcSkin = NPCSkin.forValues(npcModel.getSkin(), npcModel.getSignature());
this.uuid = npcModel.getUuid(); this.uuid = npcModel.getUuid();
if (load) if (load) onLoad();
onLoad();
} }
public NPC(NPCModel npcModel) { public NPC(NPCModel npcModel) {
@ -72,8 +71,7 @@ public class NPC {
public static void unregister(int id) { public static void unregister(int id) {
NPC npc = find(id); NPC npc = find(id);
if (npc == null) if (npc == null) throw new IllegalStateException("can't find npc with id " + id);
throw new IllegalStateException("can't find npc with id " + id);
NPC_MAP.remove(id); NPC_MAP.remove(id);
npc.deleteViewers(); npc.deleteViewers();
} }
@ -97,8 +95,7 @@ public class NPC {
updateProfile(this.gameProfile.getProperties()); updateProfile(this.gameProfile.getProperties());
setLocation(getNpcPojo().getLocation().toBukkitLocation(), false); setLocation(getNpcPojo().getLocation().toBukkitLocation(), false);
this.hologram.createHologram(); this.hologram.createHologram();
if (this.npcPojo.getPathName() != null) if (this.npcPojo.getPathName() != null) setPath(NPCPath.AbstractTypeWriter.find(this.npcPojo.getPathName()));
setPath(NPCPath.AbstractTypeWriter.find(this.npcPojo.getPathName()));
this.npcPojo.getCustomizationMap().forEach((key, value) -> this.npcPojo.getNpcType().updateCustomization(this, key, value)); this.npcPojo.getCustomizationMap().forEach((key, value) -> this.npcPojo.getNpcType().updateCustomization(this, key, value));
} }
NPC_MAP.put(getNpcPojo().getId(), this); NPC_MAP.put(getNpcPojo().getId(), this);
@ -180,12 +177,9 @@ public class NPC {
public void setSecondLayerSkin() { public void setSecondLayerSkin() {
try { try {
Object dataWatcherObject = Reflections.GET_DATA_WATCHER_METHOD.get().invoke(this.nmsEntity); Object dataWatcherObject = Reflections.GET_DATA_WATCHER_METHOD.get().invoke(this.nmsEntity);
if (Utils.versionNewer(9)) { if (Utils.versionNewer(9)) Reflections.SET_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, Reflections.DATA_WATCHER_OBJECT_CONSTRUCTOR.get()
Reflections.SET_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, Reflections.DATA_WATCHER_OBJECT_CONSTRUCTOR.get()
.newInstance(this.npcSkin.getLayerIndex(), Reflections.DATA_WATCHER_REGISTER_FIELD.get()), (byte) 127); .newInstance(this.npcSkin.getLayerIndex(), Reflections.DATA_WATCHER_REGISTER_FIELD.get()), (byte) 127);
} else { else Reflections.WATCH_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, 10, (byte) 127);
Reflections.WATCH_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, 10, (byte) 127);
}
} catch (ReflectiveOperationException operationException) { } catch (ReflectiveOperationException operationException) {
throw new UnexpectedCallException(operationException); throw new UnexpectedCallException(operationException);
} }
@ -244,7 +238,7 @@ public class NPC {
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnPlayer(entityID, PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnPlayer(entityID,
this.gameProfile.getId(), SpigotConversionUtil.fromBukkitLocation(location.toBukkitLocation()))); this.gameProfile.getId(), SpigotConversionUtil.fromBukkitLocation(location.toBukkitLocation())));
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entityID, PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entityID,
List.of(new EntityData(17, EntityDataTypes.BYTE, Byte.MAX_VALUE)))); List.of(new EntityData(17, EntityDataTypes.BYTE, Byte.MAX_VALUE)))); // 17 only works on ~1.19, this will need to be fixed in the entity rewrite
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityHeadLook(entityID, location.getYaw())); PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityHeadLook(entityID, location.getYaw()));
}); });
} }
@ -325,10 +319,10 @@ public class NPC {
public void updateProfile(PropertyMap propertyMap) { public void updateProfile(PropertyMap propertyMap) {
if (this.npcPojo.getNpcType() != NPCType.PLAYER) return; if (this.npcPojo.getNpcType() != NPCType.PLAYER) return;
try { try {
Object gameProfileObj = Reflections.GET_PROFILE_METHOD.get().invoke(this.nmsEntity); Object gameProfile = Reflections.GET_PROFILE_METHOD.get().invoke(this.nmsEntity);
Utils.setValue(gameProfileObj, "name", this.gameProfile.getName()); Utils.setValue(gameProfile, "name", this.gameProfile.getName());
Utils.setValue(gameProfileObj, "id", this.gameProfile.getId()); Utils.setValue(gameProfile, "id", this.gameProfile.getId());
Utils.setValue(gameProfileObj, "properties", propertyMap); Utils.setValue(gameProfile, "properties", propertyMap);
} catch (ReflectiveOperationException operationException) { } catch (ReflectiveOperationException operationException) {
throw new UnexpectedCallException(operationException); throw new UnexpectedCallException(operationException);
} }
@ -337,6 +331,8 @@ public class NPC {
public void sendEquipPackets(ZUser zUser) { public void sendEquipPackets(ZUser zUser) {
if (this.npcPojo.getNpcEquip().isEmpty()) return; if (this.npcPojo.getNpcEquip().isEmpty()) return;
List<Equipment> equipment = npcPojo.getNpcEquip().entrySet().stream() List<Equipment> equipment = npcPojo.getNpcEquip().entrySet().stream()
.filter(entry -> Objects.nonNull(entry.getKey()))
.filter(entry -> Objects.nonNull(entry.getValue()))
.map(entry -> new Equipment(entry.getKey(), SpigotConversionUtil.fromBukkitItemStack(entry.getValue()))) .map(entry -> new Equipment(entry.getKey(), SpigotConversionUtil.fromBukkitItemStack(entry.getValue())))
.toList(); .toList();