Citizens2/main/src/main/java/net/citizensnpcs/trait/waypoint/triggers/ChatTrigger.java

53 lines
1.5 KiB
Java
Raw Normal View History

package net.citizensnpcs.trait.waypoint.triggers;
import java.util.Collection;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
2022-12-03 17:59:16 +01:00
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.util.Messaging;
public class ChatTrigger implements WaypointTrigger {
@Persist(required = true)
private List<String> lines;
@Persist
private double radius = -1;
public ChatTrigger() {
}
public ChatTrigger(double radius, Collection<String> chatLines) {
this.radius = radius;
lines = Lists.newArrayList(chatLines);
}
@Override
public String description() {
return String.format("[[Chat]] [radius %f, %s]", radius, Joiner.on(", ").join(lines));
}
@Override
public void onWaypointReached(NPC npc, Location waypoint) {
2023-03-25 14:47:42 +01:00
if (radius <= 0) {
for (Player player : npc.getEntity().getWorld().getPlayers()) {
2022-12-03 17:59:16 +01:00
for (String line : lines) {
Messaging.send(player, line);
2022-12-03 17:59:16 +01:00
}
}
} else {
2024-03-23 16:46:09 +01:00
for (Player player : CitizensAPI.getLocationLookup().getNearbyVisiblePlayers(npc.getEntity(), radius)) {
2022-12-03 17:59:16 +01:00
for (String line : lines) {
Messaging.send(player, line);
}
}
}
}
}