mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 03:55:30 +01:00
* fix: partial backport of #3172 MC ver <= 1.16.5 is not considered as they are no longer supported officially. Fork devs pls do your own backport. * fix: different way to get level in different MC version * fix: finished missing backport for all other MC versions we support
This commit is contained in:
parent
7cc2b0658d
commit
080bf9ce3d
@ -279,6 +279,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
cs();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1589,6 +1590,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, boolean flag, Consumer<Boolean> cb) {
|
||||
float oldw = living.width;
|
||||
float oldl = living.length;
|
||||
|
@ -343,6 +343,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
ct();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1648,6 +1649,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, boolean flag, Consumer<Boolean> cb) {
|
||||
float oldw = living.width;
|
||||
float oldl = living.length;
|
||||
|
@ -352,6 +352,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
cB();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1656,6 +1657,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, boolean flag, Consumer<Boolean> cb) {
|
||||
float oldw = living.width;
|
||||
float oldl = living.length;
|
||||
|
@ -334,6 +334,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
cN();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1704,6 +1705,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, boolean flag, Consumer<Boolean> cb) {
|
||||
float oldw = living.width;
|
||||
float oldl = living.length;
|
||||
|
@ -345,6 +345,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
collideNearby();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1801,6 +1802,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, DataWatcherObject<?> datawatcherobject,
|
||||
Consumer<DataWatcherObject<?>> cb) {
|
||||
EntitySize size;
|
||||
|
@ -344,6 +344,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
collideNearby();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
}
|
||||
|
||||
public void setMoveDestination(double x, double y, double z, double speed) {
|
||||
|
@ -17,6 +17,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1850,6 +1851,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ() || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, DataWatcherObject<?> datawatcherobject,
|
||||
Consumer<DataWatcherObject<?>> cb) {
|
||||
EntitySize size;
|
||||
|
@ -318,6 +318,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
ai.getMoveControl().a();
|
||||
ai.getJumpControl().b();
|
||||
collideNearby();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1870,6 +1871,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ() || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, DataWatcherObject<?> datawatcherobject,
|
||||
Consumer<DataWatcherObject<?>> cb) {
|
||||
EntitySize size;
|
||||
|
@ -143,6 +143,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
this.onGround = false;
|
||||
}
|
||||
pushEntities();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.tick(this);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -2036,6 +2037,24 @@ public class NMSImpl implements NMSBridge {
|
||||
entity.calculateEntityAnimation(entity, entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
|
||||
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
|
||||
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
|
||||
try {
|
||||
return (TreeMap<?, ?>) BEHAVIOR_MAP.invoke(entity.getBrain());
|
||||
|
@ -144,6 +144,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
this.onGround = false;
|
||||
}
|
||||
pushEntities();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.tick(this);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -2044,6 +2045,24 @@ public class NMSImpl implements NMSBridge {
|
||||
entity.calculateEntityAnimation(entity, entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
|
||||
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
|
||||
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
|
||||
try {
|
||||
return (TreeMap<?, ?>) BEHAVIOR_TREE_MAP.invoke(entity.getBrain());
|
||||
|
@ -147,6 +147,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
this.onGround = false;
|
||||
}
|
||||
pushEntities();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.tick(this);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -2244,6 +2245,24 @@ public class NMSImpl implements NMSBridge {
|
||||
entity.calculateEntityAnimation(entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
|
||||
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
|
||||
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
|
||||
try {
|
||||
return (TreeMap<?, ?>) BEHAVIOR_TREE_MAP.invoke(entity.getBrain());
|
||||
|
@ -150,6 +150,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
onGround = false;
|
||||
}
|
||||
pushEntities();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.tick(this);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -2320,6 +2321,24 @@ public class NMSImpl implements NMSBridge {
|
||||
entity.calculateEntityAnimation(entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
|
||||
Location from = new Location(what.level().getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
|
||||
Location to = new Location(what.level().getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
|
||||
try {
|
||||
return (TreeMap<?, ?>) AVAILABLE_BEHAVIORS_BY_PRIORITY.invoke(entity.getBrain());
|
||||
|
@ -281,6 +281,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
updateAI();
|
||||
bL();
|
||||
NMSImpl.callNPCMoveEvent(this);
|
||||
if (npc.useMinecraftAI()) {
|
||||
foodData.a(this);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCMoveEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -1520,6 +1521,24 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
|
||||
final NPC npc = what.getNPC();
|
||||
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
|
||||
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
|
||||
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
|
||||
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
final Location eventFrom = event.getFrom();
|
||||
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
|
||||
} else if (!to.equals(event.getTo())) {
|
||||
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndUpdateHeight(EntityLiving living, boolean flag, Consumer<Boolean> cb) {
|
||||
float oldw = living.width;
|
||||
float oldl = living.length;
|
||||
|
Loading…
Reference in New Issue
Block a user