Removed Bukkit stuff I missed from the general use API

This commit is contained in:
Teriuihi 2021-07-31 23:27:29 +02:00
parent 59a6edd4f6
commit e253894a77
6 changed files with 46 additions and 45 deletions

View File

@ -9,9 +9,6 @@ import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
@ -179,40 +176,4 @@ public class Utility {
return stringBuilder.length()==0 ? miniMessage.parse(message)
: 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(), player.getName())
+ (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(), player.getName())
+ " 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

@ -24,7 +24,7 @@ public class MuteServer implements CommandExecutor {
public void run() {
UUID uuid = ((Player) sender).getUniqueId();
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
Utility.noPermission(sender);
sender.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this command.</red>"));
return;
}
ChatPlugin.getInstance().toggleServerMuted();

View File

@ -5,6 +5,7 @@ import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
@ -41,7 +42,7 @@ public class ChatHandler {
user.setReplyTarget(target);
String updatedMessage = RegexManager.replaceText(player, message); // todo a better way for this
if(updatedMessage == null) {
Utility.sendBlockedNotification("DM Language", player, message, target);
GalaxyUtility.sendBlockedNotification("DM Language", player, message, target);
return; // the message was blocked
}
@ -77,7 +78,16 @@ public class ChatHandler {
}
if (Database.get().isPlayerMuted(player.getUniqueId(), null) || ChatPlugin.getInstance().serverMuted()) {
Utility.sendMutedNotification("GC Muted", player, message);
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[GC Muted] "
+ Utility.getDisplayName(player.getUniqueId(), player.getName())
+ " tried to say: "
+ message + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
return;
}
@ -92,7 +102,7 @@ public class ChatHandler {
String updatedMessage = RegexManager.replaceText(player, message); // todo a better way for this
if(updatedMessage == null) {
Utility.sendBlockedNotification("GC Language", player, message, "");
GalaxyUtility.sendBlockedNotification("GC Language", player, message, "");
return; // the message was blocked
}

View File

@ -5,6 +5,7 @@ import com.alttd.chat.handler.ChatHandler;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility;
import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent;
@ -39,7 +40,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);
Utility.sendBlockedNotification("Language", player, input, "");
GalaxyUtility.sendBlockedNotification("Language", player, input, "");
return; // the message was blocked
}

View File

@ -3,6 +3,7 @@ package com.alttd.chat.listeners;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
@ -44,7 +45,7 @@ public class PlayerListener implements Listener {
message = RegexManager.replaceText(event.getPlayer(), message); // todo a better way for this
if (message == null) {
Utility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
GalaxyUtility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
}
component = message == null ? Component.empty() : Component.text(message);

View File

@ -0,0 +1,28 @@
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 GalaxyUtility {
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(), player.getName())
+ (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);
}
}