Cleanup and use new method

This commit is contained in:
fullwall 2022-07-28 23:34:03 +08:00
parent 748af9f9bd
commit 7f993e2c1d
3 changed files with 9 additions and 20 deletions

View File

@ -14,11 +14,9 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
public class Chat implements VocalChord {
public final String VOCAL_CHORD_NAME = "chat";
@Override
public String getName() {
return VOCAL_CHORD_NAME;
return "chat";
}
@Override

View File

@ -5,7 +5,6 @@ import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import com.google.common.base.Preconditions;
@ -14,7 +13,7 @@ import net.citizensnpcs.api.ai.speech.Talkable;
import net.citizensnpcs.api.ai.speech.VocalChord;
public class CitizensSpeechFactory implements SpeechFactory {
Map<String, Class<? extends VocalChord>> registered = new HashMap<String, Class<? extends VocalChord>>();
private final Map<String, Class<? extends VocalChord>> registered = new HashMap<String, Class<? extends VocalChord>>();
@Override
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
@ -50,10 +49,11 @@ public class CitizensSpeechFactory implements SpeechFactory {
@Override
public String getVocalChordName(Class<? extends VocalChord> clazz) {
// Get the name of a VocalChord class that has been registered
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet())
if (vocalChord.getValue() == clazz)
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet()) {
if (vocalChord.getValue() == clazz) {
return vocalChord.getKey();
}
}
return null;
}
@ -70,11 +70,6 @@ public class CitizensSpeechFactory implements SpeechFactory {
return new TalkableEntity(entity);
}
@Override
public Talkable newTalkableEntity(LivingEntity entity) {
return newTalkableEntity((Entity) entity);
}
@Override
public void register(Class<? extends VocalChord> clazz, String name) {
Preconditions.checkNotNull(name, "info cannot be null");

View File

@ -14,7 +14,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
public class TalkableEntity implements Talkable {
Entity entity;
private final Entity entity;
public TalkableEntity(Entity entity) {
this.entity = entity;
@ -24,10 +24,6 @@ public class TalkableEntity implements Talkable {
entity = npc.getEntity();
}
public TalkableEntity(Player player) {
entity = player;
}
/**
* Used to compare a LivingEntity to this TalkableEntity
*
@ -66,8 +62,8 @@ public class TalkableEntity implements Talkable {
}
private void talk(NPC npc, String message) {
if (entity instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(entity)) {
Messaging.sendWithNPC(entity, message, npc);
if (!CitizensAPI.getNPCRegistry().isNPC(entity)) {
Messaging.sendWithNPCColorless(entity, message, npc);
}
}