mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-28 05:35:45 +01:00
Just use instanceofs
This commit is contained in:
parent
841f378750
commit
08e5f8223d
@ -96,13 +96,6 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
|
||||
public void load(DataKey root) {
|
||||
// Spawn the NPC
|
||||
if (getTrait(Spawned.class).shouldSpawn()) {
|
||||
Location spawnLoc = getTrait(CurrentLocation.class).getLocation();
|
||||
if (spawnLoc != null)
|
||||
spawn(spawnLoc);
|
||||
}
|
||||
|
||||
Character character = CitizensAPI.getCharacterManager().getCharacter(root.getString("character"));
|
||||
|
||||
// Load the character if it exists
|
||||
@ -134,6 +127,13 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn the NPC
|
||||
if (getTrait(Spawned.class).shouldSpawn()) {
|
||||
Location spawnLoc = getTrait(CurrentLocation.class).getLocation();
|
||||
if (spawnLoc != null)
|
||||
spawn(spawnLoc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,8 +17,6 @@ public class Powered extends Trait implements Toggleable {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (npc.isSpawned() && !(npc.getBukkitEntity() instanceof Creeper))
|
||||
throw new NPCLoadException("NPC must be a creeper");
|
||||
powered = key.getBoolean("");
|
||||
}
|
||||
|
||||
@ -36,6 +34,7 @@ public class Powered extends Trait implements Toggleable {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
powered = !powered;
|
||||
if (npc.getBukkitEntity() instanceof Creeper)
|
||||
((Creeper) npc.getBukkitEntity()).setPowered(powered);
|
||||
return powered;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
public class Saddle extends Trait implements Toggleable, Listener {
|
||||
private final NPC npc;
|
||||
private boolean saddle;
|
||||
private boolean pig;
|
||||
|
||||
public Saddle(NPC npc) {
|
||||
this.npc = npc;
|
||||
@ -21,20 +22,21 @@ public class Saddle extends Trait implements Toggleable, Listener {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (npc.isSpawned() && !(npc.getBukkitEntity() instanceof Pig))
|
||||
throw new NPCLoadException("NPC must be a pig to have this trait");
|
||||
saddle = key.getBoolean("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Pig)
|
||||
if (npc.getBukkitEntity() instanceof Pig) {
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
pig = true;
|
||||
} else
|
||||
pig = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
|
||||
if (pig && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -46,6 +48,7 @@ public class Saddle extends Trait implements Toggleable, Listener {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
saddle = !saddle;
|
||||
if (pig)
|
||||
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
|
||||
return saddle;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (!(npc.getBukkitEntity() instanceof Sheep))
|
||||
throw new NPCLoadException("NPC must be a sheep to be sheared");
|
||||
sheared = key.getBoolean("");
|
||||
}
|
||||
|
||||
@ -45,6 +43,7 @@ public class Sheared extends Trait implements Toggleable, Listener {
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
sheared = !sheared;
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
|
||||
return sheared;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class VillagerProfession extends Trait {
|
||||
|
||||
public void setProfession(Profession profession) {
|
||||
this.profession = profession;
|
||||
if (npc.getBukkitEntity() instanceof Villager)
|
||||
((Villager) npc.getBukkitEntity()).setProfession(profession);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.event.entity.SheepDyeWoolEvent;
|
||||
public class WoolColor extends Trait implements Listener {
|
||||
private DyeColor color = DyeColor.WHITE;
|
||||
private final NPC npc;
|
||||
boolean sheep = false;
|
||||
|
||||
public WoolColor(NPC npc) {
|
||||
this.npc = npc;
|
||||
@ -22,8 +23,6 @@ public class WoolColor extends Trait implements Listener {
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
if (npc.isSpawned() && !(npc.getBukkitEntity() instanceof Sheep))
|
||||
throw new NPCLoadException("NPC must be a sheep");
|
||||
try {
|
||||
color = DyeColor.valueOf(key.getString(""));
|
||||
} catch (Exception ex) {
|
||||
@ -33,8 +32,11 @@ public class WoolColor extends Trait implements Listener {
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (npc.getBukkitEntity() instanceof Sheep)
|
||||
if (npc.getBukkitEntity() instanceof Sheep) {
|
||||
((Sheep) npc.getBukkitEntity()).setColor(color);
|
||||
sheep = true;
|
||||
} else
|
||||
sheep = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -50,6 +52,7 @@ public class WoolColor extends Trait implements Listener {
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
this.color = color;
|
||||
if (sheep)
|
||||
((Sheep) npc.getBukkitEntity()).setColor(color);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user