mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-12 19:30:50 +01:00
Cleanup and use new method
This commit is contained in:
parent
748af9f9bd
commit
7f993e2c1d
@ -14,11 +14,9 @@ import net.citizensnpcs.api.npc.NPC;
|
|||||||
import net.citizensnpcs.api.util.Messaging;
|
import net.citizensnpcs.api.util.Messaging;
|
||||||
|
|
||||||
public class Chat implements VocalChord {
|
public class Chat implements VocalChord {
|
||||||
public final String VOCAL_CHORD_NAME = "chat";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return VOCAL_CHORD_NAME;
|
return "chat";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ import net.citizensnpcs.api.ai.speech.Talkable;
|
|||||||
import net.citizensnpcs.api.ai.speech.VocalChord;
|
import net.citizensnpcs.api.ai.speech.VocalChord;
|
||||||
|
|
||||||
public class CitizensSpeechFactory implements SpeechFactory {
|
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
|
@Override
|
||||||
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
|
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
|
||||||
@ -50,10 +49,11 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
|||||||
@Override
|
@Override
|
||||||
public String getVocalChordName(Class<? extends VocalChord> clazz) {
|
public String getVocalChordName(Class<? extends VocalChord> clazz) {
|
||||||
// Get the name of a VocalChord class that has been registered
|
// Get the name of a VocalChord class that has been registered
|
||||||
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet())
|
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet()) {
|
||||||
if (vocalChord.getValue() == clazz)
|
if (vocalChord.getValue() == clazz) {
|
||||||
return vocalChord.getKey();
|
return vocalChord.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,11 +70,6 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
|||||||
return new TalkableEntity(entity);
|
return new TalkableEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Talkable newTalkableEntity(LivingEntity entity) {
|
|
||||||
return newTalkableEntity((Entity) entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(Class<? extends VocalChord> clazz, String name) {
|
public void register(Class<? extends VocalChord> clazz, String name) {
|
||||||
Preconditions.checkNotNull(name, "info cannot be null");
|
Preconditions.checkNotNull(name, "info cannot be null");
|
||||||
|
@ -14,7 +14,7 @@ import net.citizensnpcs.api.npc.NPC;
|
|||||||
import net.citizensnpcs.api.util.Messaging;
|
import net.citizensnpcs.api.util.Messaging;
|
||||||
|
|
||||||
public class TalkableEntity implements Talkable {
|
public class TalkableEntity implements Talkable {
|
||||||
Entity entity;
|
private final Entity entity;
|
||||||
|
|
||||||
public TalkableEntity(Entity entity) {
|
public TalkableEntity(Entity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
@ -24,10 +24,6 @@ public class TalkableEntity implements Talkable {
|
|||||||
entity = npc.getEntity();
|
entity = npc.getEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TalkableEntity(Player player) {
|
|
||||||
entity = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to compare a LivingEntity to this TalkableEntity
|
* Used to compare a LivingEntity to this TalkableEntity
|
||||||
*
|
*
|
||||||
@ -66,8 +62,8 @@ public class TalkableEntity implements Talkable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void talk(NPC npc, String message) {
|
private void talk(NPC npc, String message) {
|
||||||
if (entity instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(entity)) {
|
if (!CitizensAPI.getNPCRegistry().isNPC(entity)) {
|
||||||
Messaging.sendWithNPC(entity, message, npc);
|
Messaging.sendWithNPCColorless(entity, message, npc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user