Moved Util to Utility

This commit is contained in:
Teriuihi 2021-07-30 23:22:38 +02:00
parent 85dd526617
commit e7d508d8d1
6 changed files with 52 additions and 41 deletions

View File

@ -13,6 +13,7 @@ import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.awt.*;
@ -186,4 +187,39 @@ public class Utility {
: miniMessage.parse(stringBuilder.toString());
}
public static void noPermission(CommandSender sender) {
sender.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this command.</red>")); //TODO config?
}
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
+ Utility.getDisplayName(player.getUniqueId())
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
+ input + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
}
public static void sendMutedNotification(String prefix, Player player, String input) {
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
+ Utility.getDisplayName(player.getUniqueId())
+ " tried to say: "
+ input + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
}
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
}
}

View File

@ -41,6 +41,7 @@ public class ChatPlugin extends JavaPlugin {
registerCommand("reply", new Reply());
registerCommand("ignore", new Ignore());
registerCommand("unignore", new Unignore());
registerCommand("muteserver", new MuteServer());
messageChannel = Config.MESSAGECHANNEL;
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
@ -77,4 +78,12 @@ public class ChatPlugin extends JavaPlugin {
public boolean serverGlobalChatEnabled() {
return serverConfig.GLOBALCHAT;
}
public boolean serverMuted() {
return serverConfig.MUTED;
}
public void toggleServerMuted() {
serverConfig.MUTED = !serverConfig.MUTED;
}
}

View File

@ -6,7 +6,6 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import litebans.api.Database;
@ -42,7 +41,7 @@ public class ChatHandler {
user.setReplyTarget(target);
String updatedMessage = RegexManager.replaceText(player, message); // todo a better way for this
if(updatedMessage == null) {
Utils.sendBlockedNotification("DM Language", player, message, target);
Utility.sendBlockedNotification("DM Language", player, message, target);
return; // the message was blocked
}
@ -77,8 +76,8 @@ public class ChatHandler {
return;
}
if (Database.get().isPlayerMuted(player.getUniqueId(), null)) {
Utils.sendBlockedNotification("Muted" ,player, message, "");
if (Database.get().isPlayerMuted(player.getUniqueId(), null) || ChatPlugin.getInstance().serverMuted()) {
Utility.sendMutedNotification("GC Muted", player, message);
return;
}
@ -93,7 +92,7 @@ public class ChatHandler {
String updatedMessage = RegexManager.replaceText(player, message); // todo a better way for this
if(updatedMessage == null) {
Utils.sendBlockedNotification("GC Language", player, message, "");
Utility.sendBlockedNotification("GC Language", player, message, "");
return; // the message was blocked
}
@ -119,6 +118,7 @@ public class ChatHandler {
private void sendPluginMessage(Player player, String channel, Component component) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(channel);
out.writeUTF(player.getUniqueId().toString());
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
}

View File

@ -6,7 +6,6 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience;
@ -40,7 +39,7 @@ public class ChatListener implements Listener, ChatRenderer {
message = RegexManager.replaceText(event.getPlayer(), message); // todo a better way for this
if(message == null) {
event.setCancelled(true);
Utils.sendBlockedNotification("Language", player, input, "");
Utility.sendBlockedNotification("Language", player, input, "");
return; // the message was blocked
}

View File

@ -1,11 +1,9 @@
package com.alttd.chat.listeners;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.bukkit.event.EventHandler;
@ -14,7 +12,6 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.List;
import java.util.UUID;
public class PlayerListener implements Listener {
@ -47,7 +44,7 @@ public class PlayerListener implements Listener {
message = RegexManager.replaceText(event.getPlayer(), message); // todo a better way for this
if (message == null) {
Utils.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
Utility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
}
component = message == null ? Component.empty() : Component.text(message);

View File

@ -1,30 +0,0 @@
package com.alttd.chat.util;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class Utils {
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
+ Utility.getDisplayName(player.getUniqueId())
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
+ input + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
}
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
}
}