Use new getOrAddTrait methodf

This commit is contained in:
fullwall 2020-09-14 17:57:58 +08:00
parent 450bff76ec
commit 7450c4db45
86 changed files with 294 additions and 294 deletions

View File

@ -130,7 +130,7 @@ public class EventListen implements Listener {
int owned = 0;
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (!event.getNPC().equals(npc) && npc.hasTrait(Owner.class)
&& npc.getTrait(Owner.class).isOwnedBy(event.getCreator())) {
&& npc.getTraitNullable(Owner.class).isOwnedBy(event.getCreator())) {
owned++;
}
}
@ -263,7 +263,7 @@ public class EventListen implements Listener {
Player damager = (Player) damageEvent.getDamager();
if (npc.hasTrait(ClickRedirectTrait.class)) {
npc = npc.getTrait(ClickRedirectTrait.class).getRedirectNPC();
npc = npc.getTraitNullable(ClickRedirectTrait.class).getRedirectNPC();
if (npc == null)
return;
}
@ -271,7 +271,7 @@ public class EventListen implements Listener {
NPCLeftClickEvent leftClickEvent = new NPCLeftClickEvent(npc, damager);
Bukkit.getPluginManager().callEvent(leftClickEvent);
if (npc.hasTrait(CommandTrait.class)) {
npc.getTrait(CommandTrait.class).dispatch(damager, CommandTrait.Hand.LEFT);
npc.getTraitNullable(CommandTrait.class).dispatch(damager, CommandTrait.Hand.LEFT);
}
} else if (event instanceof EntityDamageByBlockEvent) {
Bukkit.getPluginManager().callEvent(new NPCDamageByBlockEvent(npc, (EntityDamageByBlockEvent) event));
@ -483,7 +483,7 @@ public class EventListen implements Listener {
return;
}
if (npc.hasTrait(ClickRedirectTrait.class)) {
npc = npc.getTrait(ClickRedirectTrait.class).getRedirectNPC();
npc = npc.getTraitNullable(ClickRedirectTrait.class).getRedirectNPC();
if (npc == null)
return;
}
@ -494,7 +494,7 @@ public class EventListen implements Listener {
event.setCancelled(true);
}
if (npc.hasTrait(CommandTrait.class)) {
npc.getTrait(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT);
npc.getTraitNullable(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT);
}
}
@ -609,7 +609,7 @@ public class EventListen implements Listener {
NPCLeftClickEvent leftClickEvent = new NPCLeftClickEvent(npc, damager);
Bukkit.getPluginManager().callEvent(leftClickEvent);
if (npc.hasTrait(CommandTrait.class)) {
npc.getTrait(CommandTrait.class).dispatch(damager, CommandTrait.Hand.LEFT);
npc.getTraitNullable(CommandTrait.class).dispatch(damager, CommandTrait.Hand.LEFT);
}
}
@ -629,7 +629,7 @@ public class EventListen implements Listener {
return;
if ((Util.isHorse(npc.getEntity().getType()) || npc.getEntity().getType() == EntityType.BOAT
|| npc.getEntity().getType() == EntityType.PIG || npc.getEntity() instanceof Minecart)
&& (!npc.hasTrait(Controllable.class) || !npc.getTrait(Controllable.class).isEnabled())) {
&& (!npc.hasTrait(Controllable.class) || !npc.getTraitNullable(Controllable.class).isEnabled())) {
event.setCancelled(true);
}
}
@ -706,7 +706,7 @@ public class EventListen implements Listener {
}
private boolean spawn(NPC npc) {
Location spawn = npc.getTrait(CurrentLocation.class).getLocation();
Location spawn = npc.getOrAddTrait(CurrentLocation.class).getLocation();
if (spawn == null) {
if (Messaging.isDebugging()) {
Messaging.debug("Couldn't find a spawn location for despawned NPC id", npc.getId());

View File

@ -50,7 +50,7 @@ public class EditorCommands {
permission = "citizens.npc.edit.path")
@Requirements(selected = true, ownership = true)
public void path(CommandContext args, CommandSender player, NPC npc) {
Editor editor = npc.getTrait(Waypoints.class).getEditor(player, args);
Editor editor = npc.getOrAddTrait(Waypoints.class).getEditor(player, args);
if (editor == null)
return;
Editor.enterOrLeave((Player) player, editor);
@ -65,6 +65,6 @@ public class EditorCommands {
max = 1,
permission = "citizens.npc.edit.text")
public void text(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
Editor.enterOrLeave(player, npc.getOrAddTrait(Text.class).getEditor(player));
}
}

View File

@ -31,8 +31,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
@ -141,7 +140,7 @@ public class NPCCommands {
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.isSpawned() || (!(npc.getEntity() instanceof Ageable) && !(npc.getEntity() instanceof Zombie)))
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED, npc.getName());
Age trait = npc.getTrait(Age.class);
Age trait = npc.getOrAddTrait(Age.class);
boolean toggleLock = args.hasFlag('l');
if (toggleLock) {
Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
@ -182,7 +181,7 @@ public class NPCCommands {
max = 3,
permission = "citizens.npc.anchor")
public void anchor(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Anchors trait = npc.getTrait(Anchors.class);
Anchors trait = npc.getOrAddTrait(Anchors.class);
if (args.hasValueFlag("save")) {
if (args.getFlag("save").isEmpty())
throw new CommandException(Messages.INVALID_ANCHOR_NAME);
@ -257,7 +256,7 @@ public class NPCCommands {
max = 1)
@Requirements(selected = true, ownership = true, types = EntityType.ARMOR_STAND)
public void armorstand(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ArmorStandTrait trait = npc.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = npc.getOrAddTrait(ArmorStandTrait.class);
if (args.hasValueFlag("visible")) {
trait.setVisible(Boolean.valueOf(args.getFlag("visible")));
}
@ -302,7 +301,7 @@ public class NPCCommands {
flags = "lrpo",
permission = "citizens.npc.command")
public void command(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
CommandTrait commands = npc.getTrait(CommandTrait.class);
CommandTrait commands = npc.getOrAddTrait(CommandTrait.class);
if (args.argsLength() == 1) {
commands.describe(sender);
} else if (args.getString(1).equalsIgnoreCase("add")) {
@ -368,7 +367,7 @@ public class NPCCommands {
if (!npc.hasTrait(Controllable.class)) {
npc.addTrait(new Controllable(false));
}
Controllable trait = npc.getTrait(Controllable.class);
Controllable trait = npc.getOrAddTrait(Controllable.class);
boolean enabled = trait.toggle();
if (args.hasFlag('y')) {
enabled = trait.setEnabled(true);
@ -402,7 +401,7 @@ public class NPCCommands {
Location location = args.getSenderLocation();
location.getChunk().load();
copy.teleport(location, TeleportCause.COMMAND);
copy.getTrait(CurrentLocation.class).setLocation(location);
copy.getOrAddTrait(CurrentLocation.class).setLocation(location);
}
CommandSenderCreateNPCEvent event = sender instanceof Player
@ -474,9 +473,9 @@ public class NPCCommands {
// Initialize necessary traits
if (!Setting.SERVER_OWNS_NPCS.asBoolean()) {
npc.getTrait(Owner.class).setOwner(sender);
npc.getOrAddTrait(Owner.class).setOwner(sender);
}
npc.getTrait(MobType.class).setType(type);
npc.getOrAddTrait(MobType.class).setType(type);
Location spawnLoc = null;
if (sender instanceof Player) {
@ -541,7 +540,7 @@ public class NPCCommands {
// Set age after entity spawns
if (npc.getEntity() instanceof Ageable) {
npc.getTrait(Age.class).setAge(age);
npc.getOrAddTrait(Age.class).setAge(age);
}
selector.select(sender, npc);
Messaging.send(sender, msg + '.');
@ -563,7 +562,7 @@ public class NPCCommands {
if (npc == null) {
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getString(1));
}
npc.getTrait(Spawned.class).setSpawned(false);
npc.getOrAddTrait(Spawned.class).setSpawned(false);
npc.despawn(DespawnReason.REMOVAL);
Messaging.sendTr(sender, Messages.NPC_DESPAWNED, npc.getName());
}
@ -590,7 +589,7 @@ public class NPCCommands {
permission = "citizens.npc.enderman")
public void enderman(CommandContext args, Player sender, NPC npc) throws CommandException {
if (args.hasFlag('a')) {
boolean angry = npc.getTrait(EndermanTrait.class).toggleAngry();
boolean angry = npc.getOrAddTrait(EndermanTrait.class).toggleAngry();
Messaging.sendTr(sender, angry ? Messages.ENDERMAN_ANGRY_SET : Messages.ENDERMAN_ANGRY_UNSET,
npc.getName());
}
@ -636,7 +635,7 @@ public class NPCCommands {
if (player == null) {
throw new CommandException();
}
boolean following = npc.getTrait(FollowTrait.class).toggle(player, protect);
boolean following = npc.getOrAddTrait(FollowTrait.class).toggle(player, protect);
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
player.getName());
}
@ -671,7 +670,7 @@ public class NPCCommands {
Messaging.sendErrorTr(sender, Messages.GAMEMODE_INVALID, args.getString(1));
return;
}
npc.getTrait(GameModeTrait.class).setGameMode(mode);
npc.getOrAddTrait(GameModeTrait.class).setGameMode(mode);
Messaging.sendTr(sender, Messages.GAMEMODE_SET, mode.name().toLowerCase());
}
@ -689,7 +688,7 @@ public class NPCCommands {
ChatColor chatColor = Util.matchEnum(ChatColor.values(), args.getFlag("color"));
if (!(npc.getEntity() instanceof Player))
throw new CommandException(Messages.GLOWING_COLOR_PLAYER_ONLY);
npc.getTrait(ScoreboardTrait.class).setColor(chatColor);
npc.getOrAddTrait(ScoreboardTrait.class).setColor(chatColor);
if (!npc.data().has(NPC.GLOWING_METADATA)) {
npc.data().setPersistent(NPC.GLOWING_METADATA, true);
}
@ -711,7 +710,7 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.gravity")
public void gravity(CommandContext args, CommandSender sender, NPC npc) {
boolean enabled = npc.getTrait(Gravity.class).toggle();
boolean enabled = npc.getOrAddTrait(Gravity.class).toggle();
String key = !enabled ? Messages.GRAVITY_ENABLED : Messages.GRAVITY_DISABLED;
Messaging.sendTr(sender, key, npc.getName());
}
@ -725,7 +724,7 @@ public class NPCCommands {
max = -1,
permission = "citizens.npc.hologram")
public void hologram(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
HologramTrait trait = npc.getTrait(HologramTrait.class);
HologramTrait trait = npc.getOrAddTrait(HologramTrait.class);
if (args.argsLength() == 1) {
String output = Messaging.tr(Messages.HOLOGRAM_DESCRIBE_HEADER, npc.getName());
List<String> lines = trait.getLines();
@ -792,11 +791,11 @@ public class NPCCommands {
permission = "citizens.npc.horse")
@Requirements(selected = true, ownership = true)
public void horse(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
EntityType type = npc.getTrait(MobType.class).getType();
EntityType type = npc.getOrAddTrait(MobType.class).getType();
if (!Util.isHorse(type)) {
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE, Util.prettyEnum(type));
}
HorseModifiers horse = npc.getTrait(HorseModifiers.class);
HorseModifiers horse = npc.getOrAddTrait(HorseModifiers.class);
String output = "";
if (args.hasFlag('c')) {
horse.setCarryingChest(true);
@ -808,18 +807,18 @@ public class NPCCommands {
if (type == EntityType.HORSE && (args.hasValueFlag("color") || args.hasValueFlag("colour"))) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
Color color = Util.matchEnum(Color.values(), colorRaw);
Horse.Color color = Util.matchEnum(Horse.Color.values(), colorRaw);
if (color == null) {
String valid = Util.listValuesPretty(Color.values());
String valid = Util.listValuesPretty(Horse.Color.values());
throw new CommandException(Messages.INVALID_HORSE_COLOR, valid);
}
horse.setColor(color);
output += Messaging.tr(Messages.HORSE_COLOR_SET, Util.prettyEnum(color));
}
if (type == EntityType.HORSE && args.hasValueFlag("style")) {
Style style = Util.matchEnum(Style.values(), args.getFlag("style"));
Horse.Style style = Util.matchEnum(Horse.Style.values(), args.getFlag("style"));
if (style == null) {
String valid = Util.listValuesPretty(Style.values());
String valid = Util.listValuesPretty(Horse.Style.values());
throw new CommandException(Messages.INVALID_HORSE_STYLE, valid);
}
horse.setStyle(style);
@ -854,7 +853,7 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.inventory")
public void inventory(CommandContext args, CommandSender sender, NPC npc) {
npc.getTrait(Inventory.class).openInventory((Player) sender);
npc.getOrAddTrait(Inventory.class).openInventory((Player) sender);
}
@Command(
@ -937,7 +936,7 @@ public class NPCCommands {
}
} else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
for (NPC add : source.sorted()) {
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(sender)) {
if (!npcs.contains(add) && add.getOrAddTrait(Owner.class).isOwnedBy(sender)) {
npcs.add(add);
}
}
@ -945,7 +944,7 @@ public class NPCCommands {
if (args.hasValueFlag("owner")) {
String name = args.getFlag("owner");
for (NPC add : source.sorted()) {
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(name)) {
if (!npcs.contains(add) && add.getOrAddTrait(Owner.class).isOwnedBy(name)) {
npcs.add(add);
}
}
@ -958,7 +957,7 @@ public class NPCCommands {
throw new CommandException(Messages.COMMAND_INVALID_MOBTYPE, type);
for (NPC add : source) {
if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type)
if (!npcs.contains(add) && add.getOrAddTrait(MobType.class).getType() == type)
npcs.add(add);
}
}
@ -990,7 +989,7 @@ public class NPCCommands {
boolean toggle = true;
if (args.hasAnyValueFlag("randomlook", "rlook")) {
boolean enableRandomLook = Boolean.parseBoolean(args.getFlag("randomlook", args.getFlag("rlook")));
npc.getTrait(LookClose.class).setRandomLook(enableRandomLook);
npc.getOrAddTrait(LookClose.class).setRandomLook(enableRandomLook);
Messaging.sendTr(sender,
enableRandomLook ? Messages.LOOKCLOSE_RANDOM_SET : Messages.LOOKCLOSE_RANDOM_STOPPED,
npc.getName());
@ -999,7 +998,7 @@ public class NPCCommands {
if (args.hasAnyValueFlag("randomlookdelay", "rlookdelay")) {
int delay = Integer.parseInt(args.getFlag("randomlookdelay", args.getFlag("rlookdelay")));
delay = Math.max(1, delay);
npc.getTrait(LookClose.class).setRandomLookDelay(delay);
npc.getOrAddTrait(LookClose.class).setRandomLookDelay(delay);
Messaging.sendTr(sender, Messages.LOOKCLOSE_RANDOM_DELAY_SET, npc.getName(), delay);
toggle = false;
}
@ -1010,7 +1009,7 @@ public class NPCCommands {
float min = Float.parseFloat(parts[0]), max = Float.parseFloat(parts[1]);
if (min > max)
throw new IllegalArgumentException();
npc.getTrait(LookClose.class).setRandomLookPitchRange(min, max);
npc.getOrAddTrait(LookClose.class).setRandomLookPitchRange(min, max);
} catch (Exception e) {
throw new CommandException(Messaging.tr(Messages.ERROR_SETTING_LOOKCLOSE_RANGE, flag));
}
@ -1024,7 +1023,7 @@ public class NPCCommands {
float min = Float.parseFloat(parts[0]), max = Float.parseFloat(parts[1]);
if (min > max)
throw new IllegalArgumentException();
npc.getTrait(LookClose.class).setRandomLookYawRange(min, max);
npc.getOrAddTrait(LookClose.class).setRandomLookYawRange(min, max);
} catch (Exception e) {
throw new CommandException(Messaging.tr(Messages.ERROR_SETTING_LOOKCLOSE_RANGE, flag));
}
@ -1033,7 +1032,7 @@ public class NPCCommands {
}
if (toggle) {
Messaging.sendTr(sender,
npc.getTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET : Messages.LOOKCLOSE_STOPPED,
npc.getOrAddTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET : Messages.LOOKCLOSE_STOPPED,
npc.getName());
}
}
@ -1138,10 +1137,10 @@ public class NPCCommands {
NMS.mount(mount.getEntity(), npc.getEntity());
return;
} else if (args.hasFlag('c')) {
npc.getTrait(MountTrait.class).unmount();
npc.getOrAddTrait(MountTrait.class).unmount();
return;
}
boolean enabled = npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled();
boolean enabled = npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled();
if (!enabled) {
Messaging.sendTr(sender, Messages.NPC_NOT_CONTROLLABLE, npc.getName());
return;
@ -1150,7 +1149,7 @@ public class NPCCommands {
throw new CommandException(CommandMessages.MUST_BE_INGAME);
}
Player player = (Player) sender;
boolean success = npc.getTrait(Controllable.class).mount(player);
boolean success = npc.getOrAddTrait(Controllable.class).mount(player);
if (!success) {
Messaging.sendTr(player, Messages.FAILED_TO_MOUNT_NPC, npc.getName());
}
@ -1165,7 +1164,7 @@ public class NPCCommands {
permission = "citizens.npc.moveto")
public void moveto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.isSpawned()) {
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
npc.spawn(npc.getOrAddTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
}
if (!npc.isSpawned()) {
throw new CommandException("NPC could not be spawned.");
@ -1233,7 +1232,7 @@ public class NPCCommands {
public void npc(CommandContext args, CommandSender sender, final NPC npc) {
Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
Messaging.send(sender, " <a>ID: <e>" + npc.getId());
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
Messaging.send(sender, " <a>Type: <e>" + npc.getOrAddTrait(MobType.class).getType());
if (npc.isSpawned()) {
Location loc = npc.getEntity().getLocation();
String format = " <a>Spawned at <e>%d, %d, %d <a>in world<e> %s";
@ -1261,7 +1260,7 @@ public class NPCCommands {
permission = "citizens.npc.ocelot")
@Requirements(selected = true, ownership = true, types = { EntityType.OCELOT })
public void ocelot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
OcelotModifiers trait = npc.getTrait(OcelotModifiers.class);
OcelotModifiers trait = npc.getOrAddTrait(OcelotModifiers.class);
if (args.hasFlag('s')) {
trait.setSitting(true);
} else if (args.hasFlag('n')) {
@ -1289,7 +1288,7 @@ public class NPCCommands {
max = 2,
permission = "citizens.npc.owner")
public void owner(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Owner ownerTrait = npc.getTrait(Owner.class);
Owner ownerTrait = npc.getOrAddTrait(Owner.class);
if (args.argsLength() == 1) {
Messaging.sendTr(sender, Messages.NPC_OWNER, npc.getName(), ownerTrait.getOwner());
return;
@ -1410,7 +1409,7 @@ public class NPCCommands {
npc.data().setPersistent("removefromplayerlist", remove);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.RESPAWN);
npc.spawn(npc.getOrAddTrait(CurrentLocation.class).getLocation(), SpawnReason.RESPAWN);
NMS.addOrRemoveFromPlayerList(npc.getEntity(), remove);
}
Messaging.sendTr(sender, remove ? Messages.REMOVED_FROM_PLAYERLIST : Messages.ADDED_TO_PLAYERLIST,
@ -1427,7 +1426,7 @@ public class NPCCommands {
max = 2,
permission = "citizens.npc.pose")
public void pose(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Poses trait = npc.getTrait(Poses.class);
Poses trait = npc.getOrAddTrait(Poses.class);
if (args.hasValueFlag("save")) {
if (args.getFlag("save").isEmpty())
throw new CommandException(Messages.INVALID_POSE_NAME);
@ -1483,7 +1482,7 @@ public class NPCCommands {
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, CommandSender sender, NPC npc) {
Messaging.sendTr(sender,
npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
npc.getOrAddTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
}
@Command(
@ -1496,7 +1495,7 @@ public class NPCCommands {
permission = "citizens.npc.profession")
@Requirements(selected = true, ownership = true)
public void profession(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
EntityType type = npc.getTrait(MobType.class).getType();
EntityType type = npc.getOrAddTrait(MobType.class).getType();
if (type != EntityType.VILLAGER && !type.name().equals("ZOMBIE_VILLAGER")) {
throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE,
type.name().toLowerCase().replace('_', ' ')));
@ -1507,7 +1506,7 @@ public class NPCCommands {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Joiner.on(',').join(Profession.values()));
}
npc.getTrait(VillagerProfession.class).setProfession(parsed);
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
}
@ -1526,7 +1525,7 @@ public class NPCCommands {
} catch (IllegalArgumentException ex) {
throw new CommandException(Messages.INVALID_RABBIT_TYPE, Joiner.on(',').join(Rabbit.Type.values()));
}
npc.getTrait(RabbitType.class).setType(type);
npc.getOrAddTrait(RabbitType.class).setType(type);
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
}
@ -1543,7 +1542,7 @@ public class NPCCommands {
String owner = args.getFlag("owner");
Collection<NPC> npcs = Lists.newArrayList(CitizensAPI.getNPCRegistry());
for (NPC o : npcs) {
if (o.getTrait(Owner.class).isOwnedBy(owner)) {
if (o.getOrAddTrait(Owner.class).isOwnedBy(owner)) {
o.destroy(sender);
}
}
@ -1574,7 +1573,8 @@ public class NPCCommands {
public void run(NPC npc) throws CommandException {
if (npc == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
if (!(sender instanceof ConsoleCommandSender) && !npc.getTrait(Owner.class).isOwnedBy(sender))
if (!(sender instanceof ConsoleCommandSender)
&& !npc.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
@ -1589,7 +1589,7 @@ public class NPCCommands {
}
if (npc == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
if (!(sender instanceof ConsoleCommandSender) && !npc.getTrait(Owner.class).isOwnedBy(sender))
if (!(sender instanceof ConsoleCommandSender) && !npc.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
@ -1607,7 +1607,7 @@ public class NPCCommands {
public void rename(CommandContext args, CommandSender sender, NPC npc) {
String oldName = npc.getName();
String newName = Colorizer.parseColors(args.getJoinedStrings(1));
int nameLength = SpigotUtil.getMaxNameLength(npc.getTrait(MobType.class).getType());
int nameLength = SpigotUtil.getMaxNameLength(npc.getOrAddTrait(MobType.class).getType());
if (newName.length() > nameLength) {
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG, nameLength);
newName = newName.substring(0, nameLength);
@ -1644,7 +1644,7 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.scoreboard")
public void scoreboard(CommandContext args, CommandSender sender, NPC npc) {
ScoreboardTrait trait = npc.getTrait(ScoreboardTrait.class);
ScoreboardTrait trait = npc.getOrAddTrait(ScoreboardTrait.class);
String output = "";
if (args.hasValueFlag("addtag")) {
for (String tag : args.getFlag("addtag").split(",")) {
@ -1672,7 +1672,7 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.script")
public void script(CommandContext args, CommandSender sender, NPC npc) {
ScriptTrait trait = npc.getTrait(ScriptTrait.class);
ScriptTrait trait = npc.getOrAddTrait(ScriptTrait.class);
if (args.hasValueFlag("add")) {
List<String> files = new ArrayList<String>();
for (String file : args.getFlag("add").split(",")) {
@ -1748,7 +1748,7 @@ public class NPCCommands {
permission = "citizens.npc.sheep")
@Requirements(selected = true, ownership = true, types = { EntityType.SHEEP })
public void sheep(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SheepTrait trait = npc.getTrait(SheepTrait.class);
SheepTrait trait = npc.getOrAddTrait(SheepTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("sheared")) {
trait.setSheared(Boolean.valueOf(args.getFlag("sheared")));
@ -1781,7 +1781,7 @@ public class NPCCommands {
@Requirements(types = EntityType.PLAYER, selected = true, ownership = true)
public void skin(final CommandContext args, final CommandSender sender, final NPC npc) throws CommandException {
String skinName = npc.getName();
final SkinTrait trait = npc.getTrait(SkinTrait.class);
final SkinTrait trait = npc.getOrAddTrait(SkinTrait.class);
if (args.hasFlag('c')) {
trait.clearTexture();
} else if (args.hasValueFlag("url")) {
@ -1873,7 +1873,7 @@ public class NPCCommands {
@Requirements(types = EntityType.PLAYER, selected = true, ownership = true)
public void skinLayers(final CommandContext args, final CommandSender sender, final NPC npc)
throws CommandException {
SkinLayers trait = npc.getTrait(SkinLayers.class);
SkinLayers trait = npc.getOrAddTrait(SkinLayers.class);
if (args.hasValueFlag("cape")) {
trait.setVisible(Layer.CAPE, Boolean.valueOf(args.getFlag("cape")));
}
@ -1909,7 +1909,7 @@ public class NPCCommands {
permission = "citizens.npc.size")
@Requirements(selected = true, ownership = true, types = { EntityType.MAGMA_CUBE, EntityType.SLIME })
public void slimeSize(CommandContext args, CommandSender sender, NPC npc) {
SlimeSize trait = npc.getTrait(SlimeSize.class);
SlimeSize trait = npc.getOrAddTrait(SlimeSize.class);
if (args.argsLength() <= 1) {
trait.describe(sender);
return;
@ -2016,7 +2016,7 @@ public class NPCCommands {
if (respawn.isSpawned()) {
throw new CommandException(Messages.NPC_ALREADY_SPAWNED, respawn.getName());
}
Location location = respawn.getTrait(CurrentLocation.class).getLocation();
Location location = respawn.getOrAddTrait(CurrentLocation.class).getLocation();
if (location == null || args.hasValueFlag("location")) {
if (args.getSenderLocation() == null)
throw new CommandException(Messages.NO_STORED_SPAWN_LOCATION);
@ -2048,12 +2048,12 @@ public class NPCCommands {
min = 2,
permission = "citizens.npc.speak")
public void speak(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
String type = npc.getTrait(Speech.class).getDefaultVocalChord();
String type = npc.getOrAddTrait(Speech.class).getDefaultVocalChord();
String message = Colorizer.parseColors(args.getJoinedStrings(1));
if (message.length() <= 0) {
Messaging.send(sender, "Default Vocal Chord for " + npc.getName() + ": "
+ npc.getTrait(Speech.class).getDefaultVocalChord());
+ npc.getOrAddTrait(Speech.class).getDefaultVocalChord());
return;
}
@ -2140,7 +2140,7 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.tp")
public void tp(CommandContext args, Player player, NPC npc) {
Location to = npc.getTrait(CurrentLocation.class).getLocation();
Location to = npc.getOrAddTrait(CurrentLocation.class).getLocation();
if (to == null) {
Messaging.sendError(player, Messages.TELEPORT_NPC_LOCATION_NOT_FOUND);
return;
@ -2289,7 +2289,7 @@ public class NPCCommands {
permission = "citizens.npc.wither")
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER })
public void wither(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WitherTrait trait = npc.getTrait(WitherTrait.class);
WitherTrait trait = npc.getOrAddTrait(WitherTrait.class);
if (args.hasValueFlag("charged")) {
trait.setCharged(Boolean.valueOf(args.getFlag("charged")));
}
@ -2307,7 +2307,7 @@ public class NPCCommands {
permission = "citizens.npc.wolf")
@Requirements(selected = true, ownership = true, types = EntityType.WOLF)
public void wolf(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WolfModifiers trait = npc.getTrait(WolfModifiers.class);
WolfModifiers trait = npc.getOrAddTrait(WolfModifiers.class);
if (args.hasFlag('a')) {
trait.setAngry(!trait.isAngry());
}

View File

@ -86,7 +86,7 @@ public class TraitCommands {
throw new CommandException(Messages.TRAIT_NOT_CONFIGURABLE);
if (!npc.hasTrait(clazz))
throw new CommandException(Messages.TRAIT_NOT_FOUND_ON_NPC);
CommandConfigurable trait = (CommandConfigurable) npc.getTrait(clazz);
CommandConfigurable trait = (CommandConfigurable) npc.getOrAddTrait(clazz);
trait.configure(args);
}

View File

@ -35,7 +35,7 @@ public class WaypointCommands {
max = 5,
permission = "citizens.waypoints.add")
public void add(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WaypointProvider provider = npc.getTrait(Waypoints.class).getCurrentProvider();
WaypointProvider provider = npc.getOrAddTrait(Waypoints.class).getCurrentProvider();
if (!(provider instanceof LinearWaypointProvider))
throw new CommandException();
List<Waypoint> waypoints = (List<Waypoint>) ((LinearWaypointProvider) provider).waypoints();
@ -88,7 +88,7 @@ public class WaypointCommands {
flags = "d",
permission = "citizens.waypoints.provider")
public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Waypoints waypoints = npc.getTrait(Waypoints.class);
Waypoints waypoints = npc.getOrAddTrait(Waypoints.class);
if (args.argsLength() == 1) {
if (args.hasFlag('d')) {
waypoints.describeProviders(sender);

View File

@ -46,7 +46,7 @@ public class CopierEditor extends Editor {
Location location = player.getLocation();
location.getChunk().load();
copy.teleport(location, TeleportCause.PLUGIN);
copy.getTrait(CurrentLocation.class).setLocation(location);
copy.getOrAddTrait(CurrentLocation.class).setLocation(location);
}
Messaging.sendTr(player, Messages.NPC_COPIED, npc.getName());

View File

@ -42,7 +42,7 @@ public class EndermanEquipper implements Equipper {
hand.setAmount(hand.getAmount() - 1);
equipper.getInventory().setItemInHand(hand);
}
npc.getTrait(Equipment.class).set(0, set);
npc.getOrAddTrait(Equipment.class).set(0, set);
} else {
MaterialData carried = ((Enderman) npc.getEntity()).getCarriedMaterial();
if (carried.getItemType() == Material.AIR) {
@ -61,7 +61,7 @@ public class EndermanEquipper implements Equipper {
hand.setAmount(hand.getAmount() - 1);
equipper.getInventory().setItemInHand(hand);
}
npc.getTrait(Equipment.class).set(0, set);
npc.getOrAddTrait(Equipment.class).set(0, set);
}
}
}

View File

@ -66,13 +66,13 @@ public class EquipmentEditor extends Editor {
if (hand.getType() == Material.AIR || hand.getAmount() <= 0) {
return;
}
ItemStack old = npc.getTrait(Equipment.class).get(finalSlot);
ItemStack old = npc.getOrAddTrait(Equipment.class).get(finalSlot);
if (old != null && old.getType() != Material.AIR) {
event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), old);
}
ItemStack newStack = hand.clone();
newStack.setAmount(1);
npc.getTrait(Equipment.class).set(finalSlot, newStack);
npc.getOrAddTrait(Equipment.class).set(finalSlot, newStack);
hand.setAmount(hand.getAmount() - 1);
event.getPlayer().getInventory().setItemInHand(hand);
}

View File

@ -19,7 +19,7 @@ public class GenericEquipper implements Equipper {
public void equip(Player equipper, NPC toEquip) {
// TODO: migrate to an inventory-GUI system
ItemStack hand = equipper.getInventory().getItemInHand();
Equipment trait = toEquip.getTrait(Equipment.class);
Equipment trait = toEquip.getOrAddTrait(Equipment.class);
EquipmentSlot slot = EquipmentSlot.HAND;
Material type = hand == null ? Material.AIR : hand.getType();
// First, determine the slot to edit

View File

@ -17,13 +17,13 @@ public class PigEquipper implements Equipper {
Pig pig = (Pig) toEquip.getEntity();
if (hand.getType() == Material.SADDLE) {
if (!pig.hasSaddle()) {
toEquip.getTrait(Saddle.class).toggle();
toEquip.getOrAddTrait(Saddle.class).toggle();
hand.setAmount(0);
Messaging.sendTr(equipper, Messages.SADDLED_SET, toEquip.getName());
}
} else if (pig.hasSaddle()) {
equipper.getWorld().dropItemNaturally(pig.getLocation(), new ItemStack(Material.SADDLE, 1));
toEquip.getTrait(Saddle.class).toggle();
toEquip.getOrAddTrait(Saddle.class).toggle();
Messaging.sendTr(equipper, Messages.SADDLED_STOPPED, toEquip.getName());
}
equipper.getInventory().setItemInHand(hand);

View File

@ -20,20 +20,20 @@ public class SheepEquipper implements Equipper {
ItemStack hand = equipper.getInventory().getItemInHand();
Sheep sheep = (Sheep) toEquip.getEntity();
if (hand.getType() == Material.SHEARS) {
Messaging.sendTr(equipper, toEquip.getTrait(SheepTrait.class).toggleSheared() ? Messages.SHEARED_SET
Messaging.sendTr(equipper, toEquip.getOrAddTrait(SheepTrait.class).toggleSheared() ? Messages.SHEARED_SET
: Messages.SHEARED_STOPPED, toEquip.getName());
} else if (hand.getType() == (SpigotUtil.isUsing1_13API() ? Material.INK_SAC : Material.valueOf("INK_SACK"))) {
Dye dye = (Dye) hand.getData();
if (sheep.getColor() == dye.getColor())
return;
DyeColor color = dye.getColor();
toEquip.getTrait(WoolColor.class).setColor(color);
toEquip.getOrAddTrait(WoolColor.class).setColor(color);
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(),
color.name().toLowerCase().replace("_", " "));
hand.setAmount(hand.getAmount() - 1);
} else {
toEquip.getTrait(WoolColor.class).setColor(DyeColor.WHITE);
toEquip.getOrAddTrait(WoolColor.class).setColor(DyeColor.WHITE);
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(), "white");
}
equipper.getInventory().setItemInHand(hand);

View File

@ -85,7 +85,7 @@ public class CitizensNPC extends AbstractNPC {
getEntity().isValid());
return false;
}
boolean keepSelected = getTrait(Spawned.class).shouldSpawn();
boolean keepSelected = getOrAddTrait(Spawned.class).shouldSpawn();
if (!keepSelected) {
data().remove("selectors");
}
@ -138,7 +138,7 @@ public class CitizensNPC extends AbstractNPC {
@Override
public Location getStoredLocation() {
return isSpawned() ? getEntity().getLocation() : getTrait(CurrentLocation.class).getLocation();
return isSpawned() ? getEntity().getLocation() : getOrAddTrait(CurrentLocation.class).getLocation();
}
@Override
@ -156,8 +156,8 @@ public class CitizensNPC extends AbstractNPC {
public void load(final DataKey root) {
super.load(root);
// Spawn the NPC
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) {
CurrentLocation spawnLocation = getOrAddTrait(CurrentLocation.class);
if (getOrAddTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) {
if (spawnLocation.getLocation() != null) {
spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN);
} else {
@ -245,7 +245,7 @@ public class CitizensNPC extends AbstractNPC {
at.getChunk().load();
}
getTrait(CurrentLocation.class).setLocation(at);
getOrAddTrait(CurrentLocation.class).setLocation(at);
entityController.spawn(at, this);
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
@ -275,8 +275,8 @@ public class CitizensNPC extends AbstractNPC {
NMS.setBodyYaw(getEntity(), at.getYaw());
// Set the spawned state
getTrait(CurrentLocation.class).setLocation(at);
getTrait(Spawned.class).setSpawned(true);
getOrAddTrait(CurrentLocation.class).setLocation(at);
getOrAddTrait(Spawned.class).setSpawned(true);
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at, reason);
Bukkit.getPluginManager().callEvent(spawnEvent);
@ -419,11 +419,11 @@ public class CitizensNPC extends AbstractNPC {
return;
}
getTrait(ScoreboardTrait.class).apply(team, nameVisibility);
getOrAddTrait(ScoreboardTrait.class).apply(team, nameVisibility);
}
private void updateFlyableState() {
EntityType type = isSpawned() ? getEntity().getType() : getTrait(MobType.class).getType();
EntityType type = isSpawned() ? getEntity().getType() : getOrAddTrait(MobType.class).getType();
if (type == null)
return;
if (!Util.isAlwaysFlyable(type))
@ -432,7 +432,7 @@ public class CitizensNPC extends AbstractNPC {
data().setPersistent(NPC.FLYABLE_METADATA, true);
}
if (!hasTrait(Gravity.class)) {
getTrait(Gravity.class).setEnabled(true);
getOrAddTrait(Gravity.class).setEnabled(true);
}
}

View File

@ -102,7 +102,7 @@ public class NPCSelector implements Listener, net.citizensnpcs.api.npc.NPCSelect
List<MetadataValue> selected = player.getMetadata("selected");
if (selected == null || selected.size() == 0 || selected.get(0).asInt() != npc.getId()) {
if (Util.matchesItemInHand(player, Setting.SELECTION_ITEM.asString())
&& npc.getTrait(Owner.class).isOwnedBy(player)) {
&& npc.getOrAddTrait(Owner.class).isOwnedBy(player)) {
player.removeMetadata("selected", plugin);
select(player, npc);
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), npc);

View File

@ -80,7 +80,7 @@ public class Skin {
Preconditions.checkNotNull(entity);
NPC npc = entity.getNPC();
SkinTrait skinTrait = npc.getTrait(SkinTrait.class);
SkinTrait skinTrait = npc.getOrAddTrait(SkinTrait.class);
// Use npc cached skin if available.
// If npc requires latest skin, cache is used for faster availability until the latest skin can be loaded.
String cachedName = npc.data().get(CACHED_SKIN_UUID_NAME_METADATA);
@ -103,7 +103,7 @@ public class Skin {
String defaultSkinName = ChatColor.stripColor(npc.getName()).toLowerCase();
if (npc.hasTrait(SkinTrait.class) && this.skinName.equals(defaultSkinName)
&& !npc.getTrait(SkinTrait.class).fetchDefaultSkin()) {
&& !npc.getOrAddTrait(SkinTrait.class).fetchDefaultSkin()) {
return false;
}
if (hasFetched) {
@ -371,7 +371,7 @@ public class Skin {
private static void setNPCSkinData(SkinnableEntity entity, String skinName, UUID skinId, Property skinProperty) {
NPC npc = entity.getNPC();
SkinTrait skinTrait = npc.getTrait(SkinTrait.class);
SkinTrait skinTrait = npc.getOrAddTrait(SkinTrait.class);
// cache skins for faster initial skin availability and
// for use when the latest skin is not required.

View File

@ -88,7 +88,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
return;
}
if (ownerRequired && !npc.getTrait(Owner.class).isOwnedBy(player)) {
if (ownerRequired && !npc.getOrAddTrait(Owner.class).isOwnedBy(player)) {
return;
}
NMS.mount(npc.getEntity(), player);

View File

@ -53,7 +53,7 @@ public class HologramTrait extends Trait {
private NPC createHologram(String line, double heightOffset) {
NPC hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line);
hologramNPC.addTrait(new ClickRedirectTrait(npc));
ArmorStandTrait trait = hologramNPC.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = hologramNPC.getOrAddTrait(ArmorStandTrait.class);
trait.setVisible(false);
trait.setSmall(true);
trait.setMarker(true);

View File

@ -25,8 +25,8 @@ public class OcelotModifiers extends Trait {
}
private void migrateToCat() {
npc.getTrait(CatTrait.class).setSitting(sitting);
npc.getTrait(CatTrait.class).setType(type);
npc.getOrAddTrait(CatTrait.class).setSitting(sitting);
npc.getOrAddTrait(CatTrait.class).setType(type);
}
@Override

View File

@ -62,7 +62,7 @@ public class Poses extends Trait {
private void assumePose(float yaw, float pitch) {
if (!npc.isSpawned()) {
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
npc.spawn(npc.getOrAddTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
}
Util.assumePose(npc.getEntity(), yaw, pitch);
}
@ -130,7 +130,7 @@ public class Poses extends Trait {
if (!hasPose(defaultPose))
return;
if (!npc.getNavigator().isNavigating()
&& (!npc.hasTrait(LookClose.class) || !npc.getTrait(LookClose.class).canSeeTarget())) {
&& (!npc.hasTrait(LookClose.class) || !npc.getOrAddTrait(LookClose.class).canSeeTarget())) {
assumePose(defaultPose);
}
}

View File

@ -32,7 +32,7 @@ public class DelayTrigger implements WaypointTrigger {
@Override
public void onWaypointReached(NPC npc, Location waypoint) {
if (delay > 0) {
scheduleTask(npc.getTrait(Waypoints.class).getCurrentProvider());
scheduleTask(npc.getOrAddTrait(Waypoints.class).getCurrentProvider());
}
}

View File

@ -230,7 +230,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -287,7 +287,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
g(0, 0);
}
@ -379,17 +379,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -435,7 +435,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -36,7 +36,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -36,7 +36,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -69,7 +69,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -103,7 +103,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();

View File

@ -43,14 +43,14 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.getTrait(ArmorStandTrait.class).setVisible(false);
holder.getOrAddTrait(ArmorStandTrait.class).setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
new BukkitRunnable() {

View File

@ -261,7 +261,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -347,7 +347,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
cA();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
g(0, 0);
}
@ -390,17 +390,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -447,7 +447,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -36,7 +36,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -36,7 +36,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -36,7 +36,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -36,7 +36,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -36,7 +36,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -37,7 +37,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -70,7 +70,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -101,7 +101,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -135,7 +135,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();

View File

@ -43,14 +43,14 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.getTrait(ArmorStandTrait.class).setVisible(false);
holder.getOrAddTrait(ArmorStandTrait.class).setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
new BukkitRunnable() {

View File

@ -281,7 +281,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -374,7 +374,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
Y();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
a(0, 0, 0);
}
@ -417,17 +417,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -474,7 +474,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -39,7 +39,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -206,7 +206,7 @@ public class HorseController extends MobEntityController {
public void M() {
super.M();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -206,7 +206,7 @@ public class HorseDonkeyController extends MobEntityController {
public void M() {
super.M();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -39,7 +39,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -206,7 +206,7 @@ public class HorseMuleController extends MobEntityController {
public void M() {
super.M();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -39,7 +39,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -209,7 +209,7 @@ public class HorseSkeletonController extends MobEntityController {
public void M() {
super.M();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -39,7 +39,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -209,7 +209,7 @@ public class HorseZombieController extends MobEntityController {
public void M() {
super.M();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -37,7 +37,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -39,7 +39,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -72,7 +72,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -103,7 +103,7 @@ public class Commands {
permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
ParrotTrait trait = npc.getOrAddTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
@ -130,7 +130,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -164,7 +164,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();

View File

@ -43,7 +43,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);

View File

@ -260,7 +260,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -344,7 +344,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
W();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
a(0, 0, 0);
}
@ -387,17 +387,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -474,7 +474,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -42,7 +42,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -209,7 +209,7 @@ public class HorseController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -209,7 +209,7 @@ public class HorseDonkeyController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -42,7 +42,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -209,7 +209,7 @@ public class HorseMuleController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -42,7 +42,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -210,7 +210,7 @@ public class HorseSkeletonController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -42,7 +42,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -210,7 +210,7 @@ public class HorseZombieController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -40,7 +40,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -179,7 +179,7 @@ public class PufferFishController extends MobEntityController {
if (npc != null) {
npc.update();
if (npc.hasTrait(PufferFishTrait.class)) {
setPuffState(npc.getTrait(PufferFishTrait.class).getPuffState());
setPuffState(npc.getOrAddTrait(PufferFishTrait.class).getPuffState());
}
}
}

View File

@ -43,7 +43,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -76,7 +76,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = EntityType.LLAMA)
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -107,7 +107,7 @@ public class Commands {
permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
ParrotTrait trait = npc.getOrAddTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
@ -134,7 +134,7 @@ public class Commands {
permission = "citizens.npc.phantom")
@Requirements(selected = true, ownership = true, types = EntityType.PHANTOM)
public void phantom(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PhantomTrait trait = npc.getTrait(PhantomTrait.class);
PhantomTrait trait = npc.getOrAddTrait(PhantomTrait.class);
String output = "";
if (args.hasValueFlag("size")) {
if (args.getFlagInteger("size") <= 0) {
@ -160,7 +160,7 @@ public class Commands {
permission = "citizens.npc.pufferfish")
@Requirements(selected = true, ownership = true, types = EntityType.PUFFERFISH)
public void pufferfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PufferFishTrait trait = npc.getTrait(PufferFishTrait.class);
PufferFishTrait trait = npc.getOrAddTrait(PufferFishTrait.class);
String output = "";
if (args.hasValueFlag("state")) {
int state = Math.min(Math.max(args.getFlagInteger("state"), 0), 3);
@ -182,7 +182,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -215,7 +215,7 @@ public class Commands {
permission = "citizens.npc.tropicalfish")
@Requirements(selected = true, ownership = true, types = EntityType.TROPICAL_FISH)
public void tropicalfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
TropicalFishTrait trait = npc.getTrait(TropicalFishTrait.class);
TropicalFishTrait trait = npc.getOrAddTrait(TropicalFishTrait.class);
String output = "";
if (args.hasValueFlag("body")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("body"));
@ -262,7 +262,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();

View File

@ -43,7 +43,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);

View File

@ -251,7 +251,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -348,7 +348,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
entityBaseTick();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
e(new Vec3D(0, 0, 0));
}
@ -391,17 +391,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -469,7 +469,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -45,7 +45,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -228,7 +228,7 @@ public class HorseController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -227,7 +227,7 @@ public class HorseDonkeyController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -227,7 +227,7 @@ public class HorseMuleController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -228,7 +228,7 @@ public class HorseSkeletonController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -228,7 +228,7 @@ public class HorseZombieController extends MobEntityController {
public void mobTick() {
super.mobTick();
if (npc != null) {
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -43,7 +43,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -233,7 +233,7 @@ public class PufferFishController extends MobEntityController {
}
super.tick();
if (npc != null && npc.hasTrait(PufferFishTrait.class)) {
setPuffState(npc.getTrait(PufferFishTrait.class).getPuffState());
setPuffState(npc.getOrAddTrait(PufferFishTrait.class).getPuffState());
}
}

View File

@ -45,7 +45,7 @@ public class TraderLlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -56,7 +56,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -91,7 +91,7 @@ public class Commands {
permission = "citizens.npc.cat")
@Requirements(selected = true, ownership = true, types = EntityType.CAT)
public void cat(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
CatTrait trait = npc.getTrait(CatTrait.class);
CatTrait trait = npc.getOrAddTrait(CatTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Cat.Type type = Util.matchEnum(Cat.Type.values(), args.getFlag("type"));
@ -139,7 +139,7 @@ public class Commands {
permission = "citizens.npc.fox")
@Requirements(selected = true, ownership = true, types = EntityType.FOX)
public void fox(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
FoxTrait trait = npc.getTrait(FoxTrait.class);
FoxTrait trait = npc.getOrAddTrait(FoxTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Fox.Type type = Util.matchEnum(Fox.Type.values(), args.getFlag("type"));
@ -181,7 +181,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = { EntityType.LLAMA, EntityType.TRADER_LLAMA })
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -212,7 +212,7 @@ public class Commands {
permission = "citizens.npc.mushroomcow")
@Requirements(selected = true, ownership = true, types = { EntityType.MUSHROOM_COW })
public void mushroomcow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
MushroomCowTrait trait = npc.getTrait(MushroomCowTrait.class);
MushroomCowTrait trait = npc.getOrAddTrait(MushroomCowTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("variant")) {
MushroomCow.Variant variant = Util.matchEnum(MushroomCow.Variant.values(), args.getFlag("variant"));
@ -240,7 +240,7 @@ public class Commands {
permission = "citizens.npc.panda")
@Requirements(selected = true, ownership = true, types = EntityType.PANDA)
public void panda(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PandaTrait trait = npc.getTrait(PandaTrait.class);
PandaTrait trait = npc.getOrAddTrait(PandaTrait.class);
String output = "";
if (args.hasValueFlag("gene")) {
Panda.Gene gene = Util.matchEnum(Panda.Gene.values(), args.getFlag("gene"));
@ -277,7 +277,7 @@ public class Commands {
permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
ParrotTrait trait = npc.getOrAddTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
@ -304,7 +304,7 @@ public class Commands {
permission = "citizens.npc.phantom")
@Requirements(selected = true, ownership = true, types = EntityType.PHANTOM)
public void phantom(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PhantomTrait trait = npc.getTrait(PhantomTrait.class);
PhantomTrait trait = npc.getOrAddTrait(PhantomTrait.class);
String output = "";
if (args.hasValueFlag("size")) {
if (args.getFlagInteger("size") <= 0) {
@ -330,7 +330,7 @@ public class Commands {
permission = "citizens.npc.pufferfish")
@Requirements(selected = true, ownership = true, types = EntityType.PUFFERFISH)
public void pufferfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PufferFishTrait trait = npc.getTrait(PufferFishTrait.class);
PufferFishTrait trait = npc.getOrAddTrait(PufferFishTrait.class);
String output = "";
if (args.hasValueFlag("state")) {
int state = Math.min(Math.max(args.getFlagInteger("state"), 0), 3);
@ -352,7 +352,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -386,7 +386,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
@ -408,7 +408,7 @@ public class Commands {
permission = "citizens.npc.tropicalfish")
@Requirements(selected = true, ownership = true, types = EntityType.TROPICAL_FISH)
public void tropicalfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
TropicalFishTrait trait = npc.getTrait(TropicalFishTrait.class);
TropicalFishTrait trait = npc.getOrAddTrait(TropicalFishTrait.class);
String output = "";
if (args.hasValueFlag("body")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("body"));
@ -454,7 +454,7 @@ public class Commands {
permission = "citizens.npc.villager")
@Requirements(selected = true, ownership = true, types = EntityType.VILLAGER)
public void villager(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
VillagerTrait trait = npc.getTrait(VillagerTrait.class);
VillagerTrait trait = npc.getOrAddTrait(VillagerTrait.class);
String output = "";
if (args.hasValueFlag("level")) {
if (args.getFlagInteger("level") < 0) {
@ -478,7 +478,7 @@ public class Commands {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Joiner.on(',').join(Profession.values()));
}
npc.getTrait(VillagerProfession.class).setProfession(parsed);
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);
output += Messaging.tr(Messages.PROFESSION_SET, npc.getName(), args.getFlag("profession"));
}
if (!output.isEmpty()) {

View File

@ -43,7 +43,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);

View File

@ -229,7 +229,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -348,7 +348,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
entityBaseTick();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
e(new Vec3D(0, 0, 0));
}
@ -392,17 +392,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -480,7 +480,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -45,7 +45,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -231,7 +231,7 @@ public class HorseController extends MobEntityController {
if (npc == null)
return;
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -229,7 +229,7 @@ public class HorseDonkeyController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -229,7 +229,7 @@ public class HorseMuleController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -230,7 +230,7 @@ public class HorseSkeletonController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -230,7 +230,7 @@ public class HorseZombieController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -43,7 +43,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -249,7 +249,7 @@ public class PufferFishController extends MobEntityController {
}
super.tick();
if (npc != null && npc.hasTrait(PufferFishTrait.class)) {
setPuffState(npc.getTrait(PufferFishTrait.class).getPuffState());
setPuffState(npc.getOrAddTrait(PufferFishTrait.class).getPuffState());
}
}

View File

@ -45,7 +45,7 @@ public class TraderLlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -59,7 +59,7 @@ public class Commands {
permission = "citizens.npc.bee")
@Requirements(selected = true, ownership = true, types = EntityType.BEE)
public void bee(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BeeTrait trait = npc.getTrait(BeeTrait.class);
BeeTrait trait = npc.getOrAddTrait(BeeTrait.class);
String output = "";
if (args.hasValueFlag("anger")) {
int anger = args.getFlagInteger("anger");
@ -95,7 +95,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -130,7 +130,7 @@ public class Commands {
permission = "citizens.npc.cat")
@Requirements(selected = true, ownership = true, types = EntityType.CAT)
public void cat(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
CatTrait trait = npc.getTrait(CatTrait.class);
CatTrait trait = npc.getOrAddTrait(CatTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Cat.Type type = Util.matchEnum(Cat.Type.values(), args.getFlag("type"));
@ -178,7 +178,7 @@ public class Commands {
permission = "citizens.npc.fox")
@Requirements(selected = true, ownership = true, types = EntityType.FOX)
public void fox(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
FoxTrait trait = npc.getTrait(FoxTrait.class);
FoxTrait trait = npc.getOrAddTrait(FoxTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Fox.Type type = Util.matchEnum(Fox.Type.values(), args.getFlag("type"));
@ -220,7 +220,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = { EntityType.LLAMA, EntityType.TRADER_LLAMA })
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -251,7 +251,7 @@ public class Commands {
permission = "citizens.npc.mushroomcow")
@Requirements(selected = true, ownership = true, types = { EntityType.MUSHROOM_COW })
public void mushroomcow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
MushroomCowTrait trait = npc.getTrait(MushroomCowTrait.class);
MushroomCowTrait trait = npc.getOrAddTrait(MushroomCowTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("variant")) {
MushroomCow.Variant variant = Util.matchEnum(MushroomCow.Variant.values(), args.getFlag("variant"));
@ -280,7 +280,7 @@ public class Commands {
permission = "citizens.npc.panda")
@Requirements(selected = true, ownership = true, types = EntityType.PANDA)
public void panda(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PandaTrait trait = npc.getTrait(PandaTrait.class);
PandaTrait trait = npc.getOrAddTrait(PandaTrait.class);
String output = "";
if (args.hasValueFlag("gene")) {
Panda.Gene gene = Util.matchEnum(Panda.Gene.values(), args.getFlag("gene"));
@ -321,7 +321,7 @@ public class Commands {
permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
ParrotTrait trait = npc.getOrAddTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
@ -348,7 +348,7 @@ public class Commands {
permission = "citizens.npc.phantom")
@Requirements(selected = true, ownership = true, types = EntityType.PHANTOM)
public void phantom(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PhantomTrait trait = npc.getTrait(PhantomTrait.class);
PhantomTrait trait = npc.getOrAddTrait(PhantomTrait.class);
String output = "";
if (args.hasValueFlag("size")) {
if (args.getFlagInteger("size") <= 0) {
@ -374,7 +374,7 @@ public class Commands {
permission = "citizens.npc.pufferfish")
@Requirements(selected = true, ownership = true, types = EntityType.PUFFERFISH)
public void pufferfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PufferFishTrait trait = npc.getTrait(PufferFishTrait.class);
PufferFishTrait trait = npc.getOrAddTrait(PufferFishTrait.class);
String output = "";
if (args.hasValueFlag("state")) {
int state = Math.min(Math.max(args.getFlagInteger("state"), 0), 3);
@ -396,7 +396,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -430,7 +430,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
@ -452,7 +452,7 @@ public class Commands {
permission = "citizens.npc.tropicalfish")
@Requirements(selected = true, ownership = true, types = EntityType.TROPICAL_FISH)
public void tropicalfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
TropicalFishTrait trait = npc.getTrait(TropicalFishTrait.class);
TropicalFishTrait trait = npc.getOrAddTrait(TropicalFishTrait.class);
String output = "";
if (args.hasValueFlag("body")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("body"));
@ -498,7 +498,7 @@ public class Commands {
permission = "citizens.npc.villager")
@Requirements(selected = true, ownership = true, types = EntityType.VILLAGER)
public void villager(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
VillagerTrait trait = npc.getTrait(VillagerTrait.class);
VillagerTrait trait = npc.getOrAddTrait(VillagerTrait.class);
String output = "";
if (args.hasValueFlag("level")) {
if (args.getFlagInteger("level") < 0) {
@ -522,7 +522,7 @@ public class Commands {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Joiner.on(',').join(Profession.values()));
}
npc.getTrait(VillagerProfession.class).setProfession(parsed);
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);
output += Messaging.tr(Messages.PROFESSION_SET, npc.getName(), args.getFlag("profession"));
}
if (!output.isEmpty()) {

View File

@ -43,7 +43,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);

View File

@ -243,7 +243,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -379,7 +379,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
entityBaseTick();
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
g(new Vec3D(0, 0, 0));
}
@ -423,17 +423,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -512,7 +512,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -45,7 +45,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -231,7 +231,7 @@ public class HorseController extends MobEntityController {
if (npc == null)
return;
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -229,7 +229,7 @@ public class HorseDonkeyController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseMuleController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -229,7 +229,7 @@ public class HorseMuleController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseSkeletonController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -230,7 +230,7 @@ public class HorseSkeletonController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -45,7 +45,7 @@ public class HorseZombieController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}
@ -230,7 +230,7 @@ public class HorseZombieController extends MobEntityController {
super.mobTick();
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
if (npc.hasTrait(Controllable.class) && npc.getOrAddTrait(Controllable.class).isEnabled()) {
riding = getBukkitEntity().getPassengers().size() > 0;
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());

View File

@ -43,7 +43,7 @@ public class LlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -249,7 +249,7 @@ public class PufferFishController extends MobEntityController {
}
super.tick();
if (npc != null && npc.hasTrait(PufferFishTrait.class)) {
setPuffState(npc.getTrait(PufferFishTrait.class).getPuffState());
setPuffState(npc.getOrAddTrait(PufferFishTrait.class).getPuffState());
}
}

View File

@ -45,7 +45,7 @@ public class TraderLlamaController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -59,7 +59,7 @@ public class Commands {
permission = "citizens.npc.bee")
@Requirements(selected = true, ownership = true, types = EntityType.BEE)
public void bee(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BeeTrait trait = npc.getTrait(BeeTrait.class);
BeeTrait trait = npc.getOrAddTrait(BeeTrait.class);
String output = "";
if (args.hasValueFlag("anger")) {
int anger = args.getFlagInteger("anger");
@ -95,7 +95,7 @@ public class Commands {
max = 1)
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON })
public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
BossBarTrait trait = npc.getTrait(BossBarTrait.class);
BossBarTrait trait = npc.getOrAddTrait(BossBarTrait.class);
if (args.hasValueFlag("color")) {
BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color"));
trait.setColor(color);
@ -130,7 +130,7 @@ public class Commands {
permission = "citizens.npc.cat")
@Requirements(selected = true, ownership = true, types = EntityType.CAT)
public void cat(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
CatTrait trait = npc.getTrait(CatTrait.class);
CatTrait trait = npc.getOrAddTrait(CatTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Cat.Type type = Util.matchEnum(Cat.Type.values(), args.getFlag("type"));
@ -178,7 +178,7 @@ public class Commands {
permission = "citizens.npc.fox")
@Requirements(selected = true, ownership = true, types = EntityType.FOX)
public void fox(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
FoxTrait trait = npc.getTrait(FoxTrait.class);
FoxTrait trait = npc.getOrAddTrait(FoxTrait.class);
String output = "";
if (args.hasValueFlag("type")) {
Fox.Type type = Util.matchEnum(Fox.Type.values(), args.getFlag("type"));
@ -220,7 +220,7 @@ public class Commands {
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = { EntityType.LLAMA, EntityType.TRADER_LLAMA })
public void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
LlamaTrait trait = npc.getTrait(LlamaTrait.class);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {
String colorRaw = args.getFlag("color", args.getFlag("colour"));
@ -251,7 +251,7 @@ public class Commands {
permission = "citizens.npc.mushroomcow")
@Requirements(selected = true, ownership = true, types = { EntityType.MUSHROOM_COW })
public void mushroomcow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
MushroomCowTrait trait = npc.getTrait(MushroomCowTrait.class);
MushroomCowTrait trait = npc.getOrAddTrait(MushroomCowTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("variant")) {
MushroomCow.Variant variant = Util.matchEnum(MushroomCow.Variant.values(), args.getFlag("variant"));
@ -280,7 +280,7 @@ public class Commands {
permission = "citizens.npc.panda")
@Requirements(selected = true, ownership = true, types = EntityType.PANDA)
public void panda(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PandaTrait trait = npc.getTrait(PandaTrait.class);
PandaTrait trait = npc.getOrAddTrait(PandaTrait.class);
String output = "";
if (args.hasValueFlag("gene")) {
Panda.Gene gene = Util.matchEnum(Panda.Gene.values(), args.getFlag("gene"));
@ -321,7 +321,7 @@ public class Commands {
permission = "citizens.npc.parrot")
@Requirements(selected = true, ownership = true, types = EntityType.PARROT)
public void parrot(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ParrotTrait trait = npc.getTrait(ParrotTrait.class);
ParrotTrait trait = npc.getOrAddTrait(ParrotTrait.class);
String output = "";
if (args.hasValueFlag("variant")) {
String variantRaw = args.getFlag("variant");
@ -348,7 +348,7 @@ public class Commands {
permission = "citizens.npc.phantom")
@Requirements(selected = true, ownership = true, types = EntityType.PHANTOM)
public void phantom(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PhantomTrait trait = npc.getTrait(PhantomTrait.class);
PhantomTrait trait = npc.getOrAddTrait(PhantomTrait.class);
String output = "";
if (args.hasValueFlag("size")) {
if (args.getFlagInteger("size") <= 0) {
@ -374,7 +374,7 @@ public class Commands {
permission = "citizens.npc.pufferfish")
@Requirements(selected = true, ownership = true, types = EntityType.PUFFERFISH)
public void pufferfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
PufferFishTrait trait = npc.getTrait(PufferFishTrait.class);
PufferFishTrait trait = npc.getOrAddTrait(PufferFishTrait.class);
String output = "";
if (args.hasValueFlag("state")) {
int state = Math.min(Math.max(args.getFlagInteger("state"), 0), 3);
@ -396,7 +396,7 @@ public class Commands {
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
ShulkerTrait trait = npc.getOrAddTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
@ -430,7 +430,7 @@ public class Commands {
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
@ -452,7 +452,7 @@ public class Commands {
permission = "citizens.npc.tropicalfish")
@Requirements(selected = true, ownership = true, types = EntityType.TROPICAL_FISH)
public void tropicalfish(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
TropicalFishTrait trait = npc.getTrait(TropicalFishTrait.class);
TropicalFishTrait trait = npc.getOrAddTrait(TropicalFishTrait.class);
String output = "";
if (args.hasValueFlag("body")) {
DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("body"));
@ -498,7 +498,7 @@ public class Commands {
permission = "citizens.npc.villager")
@Requirements(selected = true, ownership = true, types = EntityType.VILLAGER)
public void villager(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
VillagerTrait trait = npc.getTrait(VillagerTrait.class);
VillagerTrait trait = npc.getOrAddTrait(VillagerTrait.class);
String output = "";
if (args.hasValueFlag("level")) {
if (args.getFlagInteger("level") < 0) {
@ -522,7 +522,7 @@ public class Commands {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Joiner.on(',').join(Profession.values()));
}
npc.getTrait(VillagerProfession.class).setProfession(parsed);
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);
output += Messaging.tr(Messages.PROFESSION_SET, npc.getName(), args.getFlag("profession"));
}
if (!output.isEmpty()) {

View File

@ -43,7 +43,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);

View File

@ -231,7 +231,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public String getSkinName() {
String skinName = npc.getTrait(SkinTrait.class).getSkinName();
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
if (skinName == null) {
skinName = npc.getName();
}
@ -292,7 +292,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
boolean navigating = npc.getNavigator().isNavigating();
if (!navigating && getBukkitEntity() != null
&& (!npc.hasTrait(Gravity.class) || npc.getTrait(Gravity.class).hasGravity())
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
g(0, 0);
}
@ -357,17 +357,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public void setSkinName(String name) {
npc.getTrait(SkinTrait.class).setSkinName(name);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
}
@Override
public void setSkinName(String name, boolean forceUpdate) {
npc.getTrait(SkinTrait.class).setSkinName(name, forceUpdate);
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
}
@Override
public void setSkinPersistent(String skinName, String signature, String data) {
npc.getTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
}
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
@ -433,7 +433,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
this.cserver = (CraftServer) Bukkit.getServer();
npc.getTrait(Inventory.class);
npc.getOrAddTrait(Inventory.class);
}
@Override

View File

@ -35,7 +35,7 @@ public class HorseController extends MobEntityController {
@Override
public void spawn(Location at, NPC npc) {
npc.getTrait(HorseModifiers.class);
npc.getOrAddTrait(HorseModifiers.class);
super.spawn(at, npc);
}

View File

@ -42,7 +42,7 @@ public class PlayerAnimationImpl {
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class);
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);