Add missing Util changes

This commit is contained in:
fullwall 2021-01-03 00:14:00 +08:00
parent 0a6b1235db
commit c366b5f79e
2 changed files with 20 additions and 22 deletions

View File

@ -46,12 +46,26 @@ public class Util {
}
}
public static NPCPushEvent callPushEvent(NPC npc, Vector vector) {
public static Vector callPushEvent(NPC npc, double x, double y, double z) {
if (npc == null) {
return new Vector(x, y, z);
}
boolean allowed = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)
|| !npc.data().get(NPC.COLLIDABLE_METADATA, true);
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
if (allowed) {
return new Vector(x, y, z);
}
return allowed ? new Vector(x, y, z) : null;
}
// when another entity collides, this method is called to push the
// NPC so we prevent it from doing anything if the event is
// cancelled.
Vector vector = new Vector(x, y, z);
NPCPushEvent event = new NPCPushEvent(npc, vector);
event.setCancelled(
npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true) || !npc.data().get(NPC.COLLIDABLE_METADATA, true));
event.setCancelled(allowed);
Bukkit.getPluginManager().callEvent(event);
return event;
return !event.isCancelled() ? event.getCollisionVector() : null;
}
public static float clampYaw(float yaw) {

View File

@ -25,7 +25,6 @@ import com.mojang.datafixers.util.Pair;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Inventory;
import net.citizensnpcs.nms.v1_16_R3.network.EmptyNetHandler;
@ -257,25 +256,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void i(double x, double y, double z) {
if (npc == null) {
super.i(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
super.i(x, y, z);
}
return;
}
Vector vector = new Vector(x, y, z);
NPCPushEvent event = Util.callPushEvent(npc, vector);
if (!event.isCancelled()) {
vector = event.getCollisionVector();
Vector vector = Util.callPushEvent(npc, x, y, z);
if (vector != null) {
super.i(vector.getX(), vector.getY(), vector.getZ());
}
// when another entity collides, this method is called to push the
// NPC so we prevent it from doing anything if the event is
// cancelled.
}
@Override