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