improve trusted plugin
This commit is contained in:
parent
592cbe2b0d
commit
42ca7d0009
1 changed files with 25 additions and 11 deletions
|
@ -7,40 +7,53 @@ import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class TrustedPlugin extends PlayersPlugin.PlayerListener {
|
public class TrustedPlugin extends PlayersPlugin.PlayerListener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
@Getter private final List<String> trusted;
|
@Getter private final List<String> list;
|
||||||
|
|
||||||
public TrustedPlugin (Bot bot) {
|
public TrustedPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
this.trusted = bot.config().trusted();
|
this.list = bot.config().trusted();
|
||||||
|
|
||||||
bot.players().addListener(this);
|
bot.players().addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast (Component message) {
|
public void broadcast (Component message, UUID exceptTarget) {
|
||||||
for (Bot allBot : bot.allBots()) {
|
for (Bot bot : bot.allBots()) {
|
||||||
if (!allBot.loggedIn()) continue;
|
if (!bot.loggedIn()) continue;
|
||||||
|
|
||||||
|
for (String player : list) {
|
||||||
|
final MutablePlayerListEntry entry = bot.players().getEntry(player);
|
||||||
|
|
||||||
|
if (entry == null) continue;
|
||||||
|
|
||||||
|
if (entry.profile().getId() == exceptTarget) continue;
|
||||||
|
|
||||||
for (String player : trusted) {
|
|
||||||
final Component component = Component.translatable(
|
final Component component = Component.translatable(
|
||||||
"[%s] [%s] %s",
|
"[%s] [%s] %s",
|
||||||
Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW),
|
Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW),
|
||||||
Component.text(bot.serverName()).color(NamedTextColor.GRAY),
|
Component.text(this.bot.serverName()).color(NamedTextColor.GRAY),
|
||||||
message.color(NamedTextColor.WHITE)
|
message.color(NamedTextColor.WHITE)
|
||||||
).color(NamedTextColor.DARK_GRAY);
|
).color(NamedTextColor.DARK_GRAY);
|
||||||
|
|
||||||
allBot.chat().tellraw(component, player);
|
bot.chat().tellraw(component, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void broadcast (Component message) { broadcast(message, null); }
|
||||||
|
|
||||||
|
// these can be used in servereval
|
||||||
|
public void broadcast (String message) { broadcast(Component.text(message), null); }
|
||||||
|
public void broadcast (String message, UUID exceptTarget) { broadcast(Component.text(message), exceptTarget); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerJoined (MutablePlayerListEntry target) {
|
public void playerJoined (MutablePlayerListEntry target) {
|
||||||
if (!trusted.contains(target.profile().getName())) return;
|
if (!list.contains(target.profile().getName())) return;
|
||||||
|
|
||||||
bot.chat().tellraw(
|
bot.chat().tellraw(
|
||||||
Component.empty()
|
Component.empty()
|
||||||
|
@ -54,13 +67,14 @@ public class TrustedPlugin extends PlayersPlugin.PlayerListener {
|
||||||
Component.translatable(
|
Component.translatable(
|
||||||
"Trusted player %s is now online",
|
"Trusted player %s is now online",
|
||||||
Component.text(target.profile().getName()).color(NamedTextColor.GREEN)
|
Component.text(target.profile().getName()).color(NamedTextColor.GREEN)
|
||||||
)
|
),
|
||||||
|
target.profile().getId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerLeft (MutablePlayerListEntry target) {
|
public void playerLeft (MutablePlayerListEntry target) {
|
||||||
if (!trusted.contains(target.profile().getName())) return;
|
if (!list.contains(target.profile().getName())) return;
|
||||||
|
|
||||||
broadcast(
|
broadcast(
|
||||||
Component.translatable(
|
Component.translatable(
|
||||||
|
|
Loading…
Reference in a new issue