mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-06-19 19:22:32 +02:00
Deregister event handlers in deregisterAll(), empty talk item is now equivalent to * talk item
This commit is contained in:
parent
cd21b9fb8a
commit
529855bd6d
|
@ -11,6 +11,7 @@ import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -79,8 +80,9 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||||
NPC npc = itr.next();
|
NPC npc = itr.next();
|
||||||
npc.despawn(DespawnReason.REMOVAL);
|
npc.despawn(DespawnReason.REMOVAL);
|
||||||
for (Trait t : npc.getTraits()) {
|
for (Trait t : npc.getTraits()) {
|
||||||
|
HandlerList.unregisterAll(t);
|
||||||
t.onRemove();
|
t.onRemove();
|
||||||
}
|
}
|
||||||
itr.remove();
|
itr.remove();
|
||||||
if (saves != null) {
|
if (saves != null) {
|
||||||
saves.clearData(npc);
|
saves.clearData(npc);
|
||||||
|
|
|
@ -103,14 +103,14 @@ public class Util {
|
||||||
// 1.8.8 compatibility
|
// 1.8.8 compatibility
|
||||||
return true;
|
return true;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BAT:
|
case BAT:
|
||||||
case BLAZE:
|
case BLAZE:
|
||||||
case ENDER_DRAGON:
|
case ENDER_DRAGON:
|
||||||
case GHAST:
|
case GHAST:
|
||||||
case WITHER:
|
case WITHER:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ public class Util {
|
||||||
|
|
||||||
public static boolean matchesItemInHand(Player player, String setting) {
|
public static boolean matchesItemInHand(Player player, String setting) {
|
||||||
String parts = setting;
|
String parts = setting;
|
||||||
if (parts.contains("*"))
|
if (parts.contains("*") || parts.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
for (String part : Splitter.on(',').split(parts)) {
|
for (String part : Splitter.on(',').split(parts)) {
|
||||||
Material matchMaterial = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(part, true)
|
Material matchMaterial = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(part, true)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||||
import net.minecraft.server.v1_15_R1.DamageSource;
|
import net.minecraft.server.v1_15_R1.DamageSource;
|
||||||
import net.minecraft.server.v1_15_R1.DataWatcherObject;
|
import net.minecraft.server.v1_15_R1.DataWatcherObject;
|
||||||
import net.minecraft.server.v1_15_R1.EntityHorse;
|
import net.minecraft.server.v1_15_R1.EntityHorse;
|
||||||
|
import net.minecraft.server.v1_15_R1.EntityHorseAbstract;
|
||||||
import net.minecraft.server.v1_15_R1.EntityTypes;
|
import net.minecraft.server.v1_15_R1.EntityTypes;
|
||||||
import net.minecraft.server.v1_15_R1.GenericAttributes;
|
import net.minecraft.server.v1_15_R1.GenericAttributes;
|
||||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||||
|
@ -31,223 +32,223 @@ import net.minecraft.server.v1_15_R1.Vec3D;
|
||||||
import net.minecraft.server.v1_15_R1.World;
|
import net.minecraft.server.v1_15_R1.World;
|
||||||
|
|
||||||
public class HorseController extends MobEntityController {
|
public class HorseController extends MobEntityController {
|
||||||
public HorseController() {
|
public HorseController() {
|
||||||
super(EntityHorseNPC.class);
|
super(EntityHorseNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Horse getBukkitEntity() {
|
public Horse getBukkitEntity() {
|
||||||
return (Horse) super.getBukkitEntity();
|
return (Horse) super.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawn(Location at, NPC npc) {
|
public void spawn(Location at, NPC npc) {
|
||||||
npc.getTrait(HorseModifiers.class);
|
npc.getTrait(HorseModifiers.class);
|
||||||
super.spawn(at, npc);
|
super.spawn(at, npc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
|
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
|
||||||
private double baseMovementSpeed;
|
private double baseMovementSpeed;
|
||||||
private boolean calledNMSHeight = false;
|
private boolean calledNMSHeight = false;
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
private boolean riding;
|
private boolean riding;
|
||||||
|
|
||||||
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world) {
|
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world) {
|
||||||
this(types, world, null);
|
this(types, world, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world, NPC npc) {
|
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world, NPC npc) {
|
||||||
super(types, world);
|
super(types, world);
|
||||||
this.npc = (CitizensNPC) npc;
|
this.npc = (CitizensNPC) npc;
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
NMSImpl.clearGoals(goalSelector, targetSelector);
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
Horse horse = (Horse) getBukkitEntity();
|
Horse horse = (Horse) getBukkitEntity();
|
||||||
horse.setDomestication(horse.getMaxDomestication());
|
horse.setDomestication(horse.getMaxDomestication());
|
||||||
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
|
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void a(DataWatcherObject<?> datawatcherobject) {
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
if (npc != null && !calledNMSHeight) {
|
if (npc != null && !calledNMSHeight) {
|
||||||
calledNMSHeight = true;
|
calledNMSHeight = true;
|
||||||
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
calledNMSHeight = false;
|
calledNMSHeight = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.a(datawatcherobject);
|
super.a(datawatcherobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
if (npc == null || !npc.isFlyable()) {
|
if (npc == null || !npc.isFlyable()) {
|
||||||
super.a(d0, flag, block, blockposition);
|
super.a(d0, flag, block, blockposition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean b(float f, float f1) {
|
public boolean b(float f, float f1) {
|
||||||
if (npc == null || !npc.isFlyable()) {
|
if (npc == null || !npc.isFlyable()) {
|
||||||
return super.b(f, f1);
|
return super.b(f, f1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cj() {
|
public boolean cj() {
|
||||||
if (npc != null && riding) {
|
if (npc != null && riding) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.cj();
|
return super.cj();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkDespawn() {
|
public void checkDespawn() {
|
||||||
if (npc == null) {
|
if (npc == null) {
|
||||||
super.checkDespawn();
|
super.checkDespawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collide(net.minecraft.server.v1_15_R1.Entity entity) {
|
public void collide(net.minecraft.server.v1_15_R1.Entity entity) {
|
||||||
// this method is called by both the entities involved - cancelling
|
// this method is called by both the entities involved - cancelling
|
||||||
// it will not stop the NPC from moving.
|
// it will not stop the NPC from moving.
|
||||||
super.collide(entity);
|
super.collide(entity);
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean d(NBTTagCompound save) {
|
public boolean d(NBTTagCompound save) {
|
||||||
return npc == null ? super.d(save) : false;
|
return npc == null ? super.d(save) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void e(Vec3D vec3d) {
|
public void e(Vec3D vec3d) {
|
||||||
if (npc == null || !npc.isFlyable()) {
|
if (npc == null || !npc.isFlyable()) {
|
||||||
super.e(vec3d);
|
super.e(vec3d);
|
||||||
} else {
|
} else {
|
||||||
NMSImpl.flyingMoveLogic(this, vec3d);
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enderTeleportTo(double d0, double d1, double d2) {
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
if (npc == null) {
|
if (npc == null) {
|
||||||
super.enderTeleportTo(d0, d1, d2);
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
super.enderTeleportTo(d0, d1, d2);
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void h(double x, double y, double z) {
|
public void h(double x, double y, double z) {
|
||||||
if (npc == null) {
|
if (npc == null) {
|
||||||
super.h(x, y, z);
|
super.h(x, y, z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
super.h(x, y, z);
|
super.h(x, y, z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector vector = new Vector(x, y, z);
|
Vector vector = new Vector(x, y, z);
|
||||||
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
vector = event.getCollisionVector();
|
vector = event.getCollisionVector();
|
||||||
super.h(vector.getX(), vector.getY(), vector.getZ());
|
super.h(vector.getX(), vector.getY(), vector.getZ());
|
||||||
}
|
}
|
||||||
// when another entity collides, this method is called to push the
|
// when another entity collides, this method is called to push the
|
||||||
// NPC so we prevent it from doing anything if the event is
|
// NPC so we prevent it from doing anything if the event is
|
||||||
// cancelled.
|
// cancelled.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CraftEntity getBukkitEntity() {
|
public CraftEntity getBukkitEntity() {
|
||||||
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
||||||
NMSImpl.setBukkitEntity(this, new HorseNPC(this));
|
NMSImpl.setBukkitEntity(this, new HorseNPC(this));
|
||||||
}
|
}
|
||||||
return super.getBukkitEntity();
|
return super.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPC getNPC() {
|
public NPC getNPC() {
|
||||||
return npc;
|
return npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SoundEffect getSoundAmbient() {
|
protected SoundEffect getSoundAmbient() {
|
||||||
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SoundEffect getSoundDeath() {
|
protected SoundEffect getSoundDeath() {
|
||||||
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClimbing() {
|
public boolean isClimbing() {
|
||||||
if (npc == null || !npc.isFlyable()) {
|
if (npc == null || !npc.isFlyable()) {
|
||||||
return super.isClimbing();
|
return super.isClimbing();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLeashed() {
|
public boolean isLeashed() {
|
||||||
if (npc == null)
|
if (npc == null)
|
||||||
return super.isLeashed();
|
return super.isLeashed();
|
||||||
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
return super.isLeashed();
|
return super.isLeashed();
|
||||||
if (super.isLeashed()) {
|
if (super.isLeashed()) {
|
||||||
unleash(true, false); // clearLeash with client update
|
unleash(true, false); // clearLeash with client update
|
||||||
}
|
}
|
||||||
return false; // shouldLeash
|
return false; // shouldLeash
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mobTick() {
|
public void mobTick() {
|
||||||
super.mobTick();
|
super.mobTick();
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
|
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
|
||||||
riding = getBukkitEntity().getPassengers().size() > 0;
|
riding = getBukkitEntity().getPassengers().size() > 0;
|
||||||
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
|
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
|
||||||
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());
|
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());
|
||||||
} else {
|
} else {
|
||||||
riding = false;
|
riding = false;
|
||||||
}
|
}
|
||||||
if (riding) {
|
if (riding) {
|
||||||
d(4, true); // datawatcher method
|
d(4, true); // datawatcher method
|
||||||
}
|
}
|
||||||
NMS.setStepHeight(getBukkitEntity(), 1);
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
npc.update();
|
npc.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HorseNPC extends CraftHorse implements NPCHolder {
|
public static class HorseNPC extends CraftHorse implements NPCHolder {
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
public HorseNPC(EntityHorseNPC entity) {
|
public HorseNPC(EntityHorseNPC entity) {
|
||||||
super((CraftServer) Bukkit.getServer(), entity);
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
this.npc = entity.npc;
|
this.npc = entity.npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPC getNPC() {
|
public NPC getNPC() {
|
||||||
return npc;
|
return npc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user