Skip to content

Commit

Permalink
Refactoring deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
Rincewind34 committed Jun 25, 2020
1 parent 7c07d9d commit d741407
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
@@ -1,12 +1,12 @@
package net.citizensnpcs.api.ai.speech;

import org.bukkit.Bukkit;

import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.speech.event.NPCSpeechEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Speech;

import org.bukkit.Bukkit;

/**
* Simple implementation of {@link SpeechController} which allows a NPC to speak with any registered {@link VocalChord}.
*
Expand All @@ -20,7 +20,7 @@ public SimpleSpeechController(NPC npc) {

@Override
public void speak(SpeechContext context) {
speak(context, npc.getTrait(Speech.class).getDefaultVocalChord());
speak(context, npc.getOrAddTrait(Speech.class).getDefaultVocalChord());
}

@Override
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void process(CommandSender sender, CommandContext context, Annotation ins
}

if (requirements.ownership() && npc != null && !sender.hasPermission("citizens.admin")
&& !npc.getTrait(Owner.class).isOwnedBy(sender)) {
&& !npc.getOrAddTrait(Owner.class).isOwnedBy(sender)) {
throw new RequirementMissingException(Messaging.tr(CommandMessages.MUST_BE_OWNER));
}

Expand All @@ -67,7 +67,7 @@ public void process(CommandSender sender, CommandContext context, Annotation ins
}
types.removeAll(Sets.newHashSet(requirements.excludedTypes()));

EntityType type = npc.getTrait(MobType.class).getType();
EntityType type = npc.getOrAddTrait(MobType.class).getType();
if (!types.contains(type)) {
throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE,
type.name().toLowerCase().replace('_', ' ')));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/citizensnpcs/api/trait/trait/Inventory.java
Expand Up @@ -61,7 +61,7 @@ public void inventoryCloseEvent(InventoryCloseEvent event) {
for (int i = 0; i < contents.length; i++) {
this.contents[i] = contents[i];
if (i == 0) {
npc.getTrait(Equipment.class).setItemInHand(contents[i]);
npc.getOrAddTrait(Equipment.class).setItemInHand(contents[i]);
}
}
if (npc.getEntity() instanceof InventoryHolder) {
Expand Down Expand Up @@ -164,7 +164,7 @@ private void saveContents(Entity entity) {
contents = ((InventoryHolder) entity).getInventory().getContents();
}
if (entity instanceof Player) {
npc.getTrait(Equipment.class).setItemInHand(contents[0]);
npc.getOrAddTrait(Equipment.class).setItemInHand(contents[0]);
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public void setItem(int slot, ItemStack item) {
throw new IndexOutOfBoundsException();
}
if (slot == 0) {
npc.getTrait(Equipment.class).setItemInHand(item);
npc.getOrAddTrait(Equipment.class).setItemInHand(item);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/citizensnpcs/api/util/Placeholders.java
Expand Up @@ -17,7 +17,7 @@ public static String replace(String text, CommandSender sender, NPC npc) {
if (npc == null) {
return text;
}
text = text.replace("<owner>", npc.getTrait(Owner.class).getOwner());
text = text.replace("<owner>", npc.getOrAddTrait(Owner.class).getOwner());
text = text.replace("<npc>", npc.getName());
text = text.replace("<id>", Integer.toString(npc.getId()));
return text;
Expand Down

0 comments on commit d741407

Please sign in to comment.