mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-28 05:35:45 +01:00
Temporary hack to fix age throwing errors, don't give every NPC age on create
This commit is contained in:
parent
434bc6168b
commit
4698e70f77
@ -204,6 +204,7 @@ public class NPCCommands {
|
|||||||
npc.spawn(player.getLocation());
|
npc.spawn(player.getLocation());
|
||||||
|
|
||||||
// Set age after entity spawns
|
// Set age after entity spawns
|
||||||
|
if (npc.getBukkitEntity() instanceof Ageable)
|
||||||
npc.getTrait(Age.class).setAge(age);
|
npc.getTrait(Age.class).setAge(age);
|
||||||
|
|
||||||
selector.select(player, npc);
|
selector.select(player, npc);
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.entity.Ageable;
|
|||||||
public class Age extends Trait implements Runnable, Toggleable {
|
public class Age extends Trait implements Runnable, Toggleable {
|
||||||
private int age = 0;
|
private int age = 0;
|
||||||
private boolean locked = true;
|
private boolean locked = true;
|
||||||
|
private boolean ageable = false;
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
|
|
||||||
public Age(NPC npc) {
|
public Age(NPC npc) {
|
||||||
@ -26,14 +27,18 @@ public class Age extends Trait implements Runnable, Toggleable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNPCSpawn() {
|
public void onNPCSpawn() {
|
||||||
|
if (npc instanceof Ageable) {
|
||||||
Ageable entity = (Ageable) npc.getBukkitEntity();
|
Ageable entity = (Ageable) npc.getBukkitEntity();
|
||||||
entity.setAge(age);
|
entity.setAge(age);
|
||||||
entity.setAgeLock(locked);
|
entity.setAgeLock(locked);
|
||||||
|
ageable = true;
|
||||||
|
} else
|
||||||
|
ageable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!locked)
|
if (!locked && ageable)
|
||||||
age = ((Ageable) npc.getBukkitEntity()).getAge();
|
age = ((Ageable) npc.getBukkitEntity()).getAge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,12 +50,14 @@ public class Age extends Trait implements Runnable, Toggleable {
|
|||||||
|
|
||||||
public void setAge(int age) {
|
public void setAge(int age) {
|
||||||
this.age = age;
|
this.age = age;
|
||||||
|
if (ageable)
|
||||||
((Ageable) npc.getBukkitEntity()).setAge(age);
|
((Ageable) npc.getBukkitEntity()).setAge(age);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean toggle() {
|
public boolean toggle() {
|
||||||
locked = !locked;
|
locked = !locked;
|
||||||
|
if (ageable)
|
||||||
((Ageable) npc.getBukkitEntity()).setAgeLock(locked);
|
((Ageable) npc.getBukkitEntity()).setAgeLock(locked);
|
||||||
return locked;
|
return locked;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user