fixes
This commit is contained in:
@@ -2,12 +2,14 @@ package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.commands.*;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.config.ServerConfig;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.handler.ChatHandler;
|
||||
import com.alttd.chat.listeners.ChatListener;
|
||||
import com.alttd.chat.listeners.PlayerListener;
|
||||
import com.alttd.chat.listeners.PluginMessage;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -20,6 +22,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
private String messageChannel;
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -28,9 +31,12 @@ public class ChatPlugin extends JavaPlugin {
|
||||
chatAPI = new ChatImplementation();
|
||||
chatHandler = new ChatHandler();
|
||||
DatabaseConnection.initialize();
|
||||
serverConfig = new ServerConfig(Bukkit.getServerName());
|
||||
registerListener(new PlayerListener(), new ChatListener());
|
||||
registerCommand("globalchat", new GlobalChat());
|
||||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||
if(serverConfig.GLOBALCHAT) {
|
||||
registerCommand("globalchat", new GlobalChat());
|
||||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||
}
|
||||
registerCommand("message", new Message());
|
||||
registerCommand("reply", new Reply());
|
||||
registerCommand("ignore", new Ignore());
|
||||
@@ -67,4 +73,8 @@ public class ChatPlugin extends JavaPlugin {
|
||||
public ChatHandler getChatHandler() {
|
||||
return chatHandler;
|
||||
}
|
||||
|
||||
public boolean serverGlobalChatEnabled() {
|
||||
return serverConfig.GLOBALCHAT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import jdk.jshell.execution.Util;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -13,6 +16,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ToggleGlobalChat implements CommandExecutor {
|
||||
|
||||
@@ -24,10 +28,12 @@ public class ToggleGlobalChat implements CommandExecutor {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
||||
chatUser.toggleGc();
|
||||
Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
||||
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
//chatUser.toggleGc();
|
||||
Utility.flipPermission(uuid, Config.GCPERMISSION);
|
||||
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
||||
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
|
||||
@@ -6,6 +6,7 @@ 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 net.kyori.adventure.text.Component;
|
||||
@@ -40,7 +41,7 @@ public class ChatHandler {
|
||||
user.setReplyTarget(target);
|
||||
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(updatedMessage == null) {
|
||||
Utility.sendBlockedNotification("DM Language", player, message, target);
|
||||
Utils.sendBlockedNotification("DM Language", player, message, target);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
@@ -53,22 +54,29 @@ public class ChatHandler {
|
||||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("message", updatedMessage),
|
||||
Template.of("sendername", player.getName()),
|
||||
Template.of("receivername", target),
|
||||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
Component component = miniMessage.parse("<message>", templates);
|
||||
|
||||
sendPrivateMessage(player, target, "privatemessage", component);
|
||||
Component spymessage = miniMessage.parse(Config.MESSAGESPY, templates);
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission("chat.social-spy")) { // todo add a toggle for social spy
|
||||
pl.sendMessage(spymessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void globalChat(Player player, String message) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if(user == null) return;
|
||||
if(!user.isGcOn()) {
|
||||
if(!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
|
||||
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
||||
return;
|
||||
}
|
||||
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
|
||||
if(timeLeft <= Config.GCCOOLDOWN || player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
|
||||
if(timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
|
||||
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
|
||||
return;
|
||||
}
|
||||
@@ -78,7 +86,7 @@ public class ChatHandler {
|
||||
|
||||
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(updatedMessage == null) {
|
||||
Utility.sendBlockedNotification("GC Language", player, message, "");
|
||||
Utils.sendBlockedNotification("GC Language", player, message, "");
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -39,7 +40,7 @@ public class ChatListener implements Listener, ChatRenderer {
|
||||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(message == null) {
|
||||
event.setCancelled(true);
|
||||
Utility.sendBlockedNotification("Language", player, input, "");
|
||||
Utils.sendBlockedNotification("Language", player, input, "");
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -46,7 +47,7 @@ public class PlayerListener implements Listener {
|
||||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
|
||||
if (message == null) {
|
||||
Utility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
|
||||
Utils.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
|
||||
}
|
||||
|
||||
component = message == null ? Component.empty() : Component.text(message);
|
||||
|
||||
@@ -24,35 +24,20 @@ public class PluginMessage implements PluginMessageListener {
|
||||
}
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
String subChannel = in.readUTF();
|
||||
UUID uuid;String target; Player p;
|
||||
switch (subChannel) {
|
||||
case "privatemessagesend":
|
||||
uuid = UUID.fromString(in.readUTF());
|
||||
target = in.readUTF();
|
||||
p = Bukkit.getPlayer(uuid);
|
||||
case "privatemessage":
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String target = in.readUTF();
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if(p != null) {
|
||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
user.setReplyTarget(target);
|
||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||
Component spymessage = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission("chat.social-spy")) { // todo add a toggle for social spy
|
||||
pl.sendMessage(spymessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "privatemessagesreceived":
|
||||
uuid = UUID.fromString(in.readUTF());
|
||||
target = in.readUTF();
|
||||
p = Bukkit.getPlayer(uuid);
|
||||
if(p != null) {
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
user.setReplyTarget(target);
|
||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||
}
|
||||
break;
|
||||
case "globalchat":
|
||||
if(ChatPlugin.getInstance().serverGlobalChatEnabled())
|
||||
Bukkit.broadcast(GsonComponentSerializer.gson().deserialize(in.readUTF()), Config.GCPERMISSION);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user