Skip to content

Commit

Permalink
Add missing Util changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 2, 2021
1 parent 0a6b123 commit c366b5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
22 changes: 18 additions & 4 deletions main/src/main/java/net/citizensnpcs/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,26 @@ public static void callCollisionEvent(NPC npc, Entity entity) {
}
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -257,25 +256,10 @@ public SkinPacketTracker getSkinTracker() {

@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
Expand Down

0 comments on commit c366b5f

Please sign in to comment.