mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 12:46:04 +01:00
Add missing Util changes
This commit is contained in:
parent
0a6b1235db
commit
c366b5f79e
@ -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);
|
NPCPushEvent event = new NPCPushEvent(npc, vector);
|
||||||
event.setCancelled(
|
event.setCancelled(allowed);
|
||||||
npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true) || !npc.data().get(NPC.COLLIDABLE_METADATA, true));
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
return event;
|
return !event.isCancelled() ? event.getCollisionVector() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float clampYaw(float yaw) {
|
public static float clampYaw(float yaw) {
|
||||||
|
@ -25,7 +25,6 @@ import com.mojang.datafixers.util.Pair;
|
|||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.trait.trait.Inventory;
|
import net.citizensnpcs.api.trait.trait.Inventory;
|
||||||
import net.citizensnpcs.nms.v1_16_R3.network.EmptyNetHandler;
|
import net.citizensnpcs.nms.v1_16_R3.network.EmptyNetHandler;
|
||||||
@ -257,25 +256,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void i(double x, double y, double z) {
|
public void i(double x, double y, double z) {
|
||||||
if (npc == null) {
|
Vector vector = Util.callPushEvent(npc, x, y, z);
|
||||||
super.i(x, y, z);
|
if (vector != null) {
|
||||||
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();
|
|
||||||
super.i(vector.getX(), vector.getY(), vector.getZ());
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user