mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 20:55:44 +01:00
Add line of sight check to lookclose
This commit is contained in:
parent
60db622b68
commit
ac106a6c50
@ -4,20 +4,21 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.citizensnpcs.api.ai.speech.SpeechFactory;
|
||||
import net.citizensnpcs.api.ai.speech.Talkable;
|
||||
import net.citizensnpcs.api.ai.speech.VocalChord;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.citizensnpcs.api.ai.speech.SpeechFactory;
|
||||
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>>();
|
||||
|
||||
@Override
|
||||
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
|
||||
Preconditions.checkNotNull(clazz, "class cannot be null");
|
||||
// Return a new instance of the VocalChord specified
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
@ -31,8 +32,9 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
||||
|
||||
@Override
|
||||
public VocalChord getVocalChord(String name) {
|
||||
Preconditions.checkNotNull(name, "name cannot be null");
|
||||
// Check if VocalChord name is a registered type
|
||||
if (isRegistered(name))
|
||||
if (isRegistered(name)) {
|
||||
// Return a new instance of the VocalChord specified
|
||||
try {
|
||||
return registered.get(name.toLowerCase()).newInstance();
|
||||
@ -41,6 +43,7 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -56,6 +59,7 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
||||
|
||||
@Override
|
||||
public boolean isRegistered(String name) {
|
||||
Preconditions.checkNotNull(name, "name cannot be null");
|
||||
return registered.containsKey(name.toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -49,14 +49,18 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
super("lookclose");
|
||||
}
|
||||
|
||||
private boolean canSee(Player player) {
|
||||
return realisticLooking && npc.getEntity() instanceof LivingEntity
|
||||
? ((LivingEntity) npc.getEntity()).hasLineOfSight(player)
|
||||
: player != null && player.isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the target can be seen. Will use realistic line of sight if {@link #setRealisticLooking(boolean)}
|
||||
* is true.
|
||||
*/
|
||||
public boolean canSeeTarget() {
|
||||
return realisticLooking && npc.getEntity() instanceof LivingEntity
|
||||
? ((LivingEntity) npc.getEntity()).hasLineOfSight(lookingAt)
|
||||
: lookingAt != null && lookingAt.isValid();
|
||||
return canSee(lookingAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,7 +124,7 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
|
||||
private boolean isInvisible(Player player) {
|
||||
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
||||
|| isPluginVanished(player);
|
||||
|| isPluginVanished(player) || !canSee(player);
|
||||
}
|
||||
|
||||
private boolean isPluginVanished(Player player) {
|
||||
@ -138,8 +142,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
|
||||
private boolean isValid(Player entity) {
|
||||
return entity.isOnline() && entity.isValid() && entity.getWorld() == npc.getEntity().getWorld()
|
||||
&& !isInvisible(entity)
|
||||
&& entity.getLocation(PLAYER_LOCATION).distanceSquared(NPC_LOCATION) < range * range;
|
||||
&& entity.getLocation(PLAYER_LOCATION).distanceSquared(NPC_LOCATION) < range * range
|
||||
&& !isInvisible(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user