improve filter (mabe)

This commit is contained in:
Chayapak 2023-06-19 16:27:43 +07:00
parent 2ae561b0cb
commit b537cabbe0
2 changed files with 51 additions and 3 deletions

View file

@ -37,6 +37,8 @@ public class FilterCommand implements Command {
public List<String> alias() { public List<String> alias() {
final List<String> aliases = new ArrayList<>(); final List<String> aliases = new ArrayList<>();
aliases.add("filterplayer"); aliases.add("filterplayer");
aliases.add("ban");
aliases.add("blacklist");
return aliases; return aliases;
} }

View file

@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.data.FilteredPlayer; import land.chipmunk.chayapak.chomens_bot.data.FilteredPlayer;
import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerMessage;
import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities; import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities;
import lombok.Getter; import lombok.Getter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -23,7 +24,19 @@ public class FilterPlugin extends PlayersPlugin.Listener {
bot.players().addListener(this); bot.players().addListener(this);
bot.executor().scheduleAtFixedRate(this::kick, 0, 5, TimeUnit.SECONDS); bot.chat().addListener(new ChatPlugin.Listener() {
@Override
public void commandSpyMessageReceived(PlayerMessage message) {
FilterPlugin.this.commandSpyMessageReceived(message);
}
@Override
public void playerMessageReceived(PlayerMessage message) {
FilterPlugin.this.playerMessageReceived(message);
}
});
bot.executor().scheduleAtFixedRate(this::kick, 0, 10, TimeUnit.SECONDS);
} }
private FilteredPlayer getPlayer (String name) { private FilteredPlayer getPlayer (String name) {
@ -73,11 +86,37 @@ public class FilterPlugin extends PlayersPlugin.Listener {
if (player == null) return; if (player == null) return;
bot.core().run("essentials:mute " + target.profile().getIdAsString() + " 10y"); deOp(target);
bot.core().run("minecraft:execute run deop " + UUIDUtilities.selector(target.profile().getId())); mute(target);
bot.exploits().kick(target.profile().getId()); bot.exploits().kick(target.profile().getId());
} }
public void commandSpyMessageReceived (PlayerMessage message) {
final FilteredPlayer player = getPlayer(message.sender().profile().getName());
if (player == null) return;
deOp(message.sender());
}
public void playerMessageReceived (PlayerMessage message) {
final FilteredPlayer player = getPlayer(message.sender().profile().getName());
if (player == null) return;
deOp(message.sender());
mute(message.sender());
}
private void mute (MutablePlayerListEntry target) {
bot.core().run("essentials:mute " + target.profile().getIdAsString() + " 10y");
}
private void deOp (MutablePlayerListEntry target) {
bot.core().run("minecraft:execute run deop " + UUIDUtilities.selector(target.profile().getId()));
}
public void kick () { public void kick () {
for (MutablePlayerListEntry target : bot.players().list()) { for (MutablePlayerListEntry target : bot.players().list()) {
final FilteredPlayer player = getPlayer(target.profile().getName()); final FilteredPlayer player = getPlayer(target.profile().getName());
@ -90,6 +129,13 @@ public class FilterPlugin extends PlayersPlugin.Listener {
public void add (String playerName, boolean regex, boolean ignoreCase) { public void add (String playerName, boolean regex, boolean ignoreCase) {
filteredPlayers.add(new FilteredPlayer(playerName, regex, ignoreCase)); filteredPlayers.add(new FilteredPlayer(playerName, regex, ignoreCase));
final MutablePlayerListEntry target = bot.players().getEntry(playerName); // fix not working for regex and ignorecase
if (target == null) return;
deOp(target);
mute(target);
} }
public FilteredPlayer remove (int index) { public FilteredPlayer remove (int index) {