refactor a day keeps the doctor away

This commit is contained in:
Pyrbu 2023-04-24 14:27:45 +01:00
parent cf34ddc32e
commit df668a8585

@ -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);
} }
@ -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);
} }