Updated to 1.21 by switching to cosmos
This commit is contained in:
@@ -16,13 +16,10 @@ import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatPlugin extends JavaPlugin {
|
||||
|
||||
@@ -31,7 +28,6 @@ public class ChatPlugin extends JavaPlugin {
|
||||
private ChatAPI chatAPI;
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
private String messageChannel;
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
@Override
|
||||
@@ -44,7 +40,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
||||
if(serverConfig.GLOBALCHAT) {
|
||||
if (serverConfig.GLOBALCHAT) {
|
||||
registerCommand("globalchat", new GlobalChat());
|
||||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||
}
|
||||
@@ -56,7 +52,6 @@ public class ChatPlugin extends JavaPlugin {
|
||||
registerCommand("muteserver", new MuteServer());
|
||||
registerCommand("spy", new Spy());
|
||||
registerCommand("chatclear", new ChatClear());
|
||||
// registerCommand("chatparty", new ChatParty());
|
||||
registerCommand("p", new PartyChat());
|
||||
registerCommand("emotes", new Emotes());
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
@@ -66,7 +61,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||
}
|
||||
|
||||
messageChannel = Config.MESSAGECHANNEL;
|
||||
String messageChannel = Config.MESSAGECHANNEL;
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
||||
|
||||
@@ -88,23 +83,13 @@ public class ChatPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void registerCommand(String commandName, CommandExecutor commandExecutor) {
|
||||
getCommand(commandName).setExecutor(commandExecutor);
|
||||
}
|
||||
|
||||
public void registerCommand(String commandName, CommandExecutor commandExecutor, List<String> aliases) {
|
||||
PluginCommand command = getCommand(commandName);
|
||||
command.setAliases(aliases);
|
||||
command.setExecutor(commandExecutor);
|
||||
Objects.requireNonNull(getCommand(commandName)).setExecutor(commandExecutor);
|
||||
}
|
||||
|
||||
public static ChatPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ChatAPI getChatAPI() {
|
||||
return chatAPI;
|
||||
}
|
||||
|
||||
public ChatHandler getChatHandler() {
|
||||
return chatHandler;
|
||||
}
|
||||
@@ -125,7 +110,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
chatAPI.reloadConfig();
|
||||
chatAPI.reloadChatFilters();
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
|
||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config.").asComponent(), "command.chat.reloadchat");
|
||||
ALogger.info("Reloaded ChatPlugin config.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@ import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatChannel extends BukkitCommand {
|
||||
|
||||
CustomChannel channel;
|
||||
String command;
|
||||
ToggleableForCustomChannel toggleableForCustomChannel;
|
||||
private static List<ChatChannel> activeCommands = new ArrayList<>();
|
||||
private static final List<ChatChannel> activeCommands = new ArrayList<>();
|
||||
|
||||
public ChatChannel(CustomChannel channel) {
|
||||
super(channel.getChannelName().toLowerCase());
|
||||
@@ -33,15 +35,15 @@ public class ChatChannel extends BukkitCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length == 0 && player.hasPermission(channel.getPermission())) {
|
||||
if (args.length == 0 && player.hasPermission(channel.getPermission())) {
|
||||
player.sendRichMessage(Config.CUSTOM_CHANNEL_TOGGLED, TagResolver.resolver(
|
||||
Placeholder.unparsed("channel", channel.getChannelName()),
|
||||
Placeholder.component("status", toggleableForCustomChannel.toggle(player.getUniqueId())
|
||||
? Config.TOGGLED_ON : Config.TOGGLED_OFF)));
|
||||
? Config.TOGGLED_ON : Config.TOGGLED_OFF)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
@@ -9,26 +8,29 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatClear implements CommandExecutor {
|
||||
|
||||
private static final Component component = MiniMessage.miniMessage().deserialize("\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n");
|
||||
private static final Component component = MiniMessage.miniMessage().deserialize("\n".repeat(100));
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!sender.hasPermission("chat.command.clear-chat")) {
|
||||
sender.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this command.</red>"));
|
||||
sender.sendRichMessage("<red>You don't have permission to use this command.</red>");
|
||||
return true;
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (!player.hasPermission("chat.clear-bypass"))
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.hasPermission("chat.clear-bypass")) {
|
||||
player.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().sendMessage(miniMessage.deserialize(
|
||||
"<gold><player> cleared chat.</gold>",
|
||||
Placeholder.component("player",sender.name()))
|
||||
);
|
||||
"<gold><player> cleared chat.</gold>",
|
||||
Placeholder.component("player", sender.name()))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,22 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Continue implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user.getReplyContinueTarget() == null) return false;
|
||||
if(args.length == 0) return false; // todo error message or command info
|
||||
if (user.getReplyContinueTarget() == null) {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().continuePrivateMessage(player, user.getReplyContinueTarget(), message);
|
||||
|
||||
@@ -7,15 +7,18 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GlobalChat implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length == 0) return false;
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@ 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 com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ignore implements CommandExecutor {
|
||||
@@ -29,11 +27,13 @@ public class Ignore implements CommandExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
if (args.length > 1) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
String targetName = args[0];
|
||||
if (targetName.equals("?")) {
|
||||
new BukkitRunnable() {
|
||||
@@ -44,7 +44,7 @@ public class Ignore implements CommandExecutor {
|
||||
StringBuilder ignoredMessage = new StringBuilder();
|
||||
|
||||
if (userNames.isEmpty()) {
|
||||
player.sendMessage(Utility.parseMiniMessage("You don't have anyone ignored!")); //TODO load from config
|
||||
player.sendRichMessage("You don't have anyone ignored!"); //TODO load from config
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,21 +52,21 @@ public class Ignore implements CommandExecutor {
|
||||
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
|
||||
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
|
||||
|
||||
player.sendMessage(Utility.parseMiniMessage(ignoredMessage.toString()));
|
||||
player.sendRichMessage(ignoredMessage.toString());
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player targetPlayer = Bukkit.getPlayer(targetName);
|
||||
if(targetPlayer == null) { // can't ignore offline players
|
||||
if (targetPlayer == null) { // can't ignore offline players
|
||||
sender.sendMessage("You can't ignore offline players");
|
||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = targetPlayer.getUniqueId();
|
||||
if(targetPlayer.hasPermission("chat.ignorebypass") || target.equals(player.getUniqueId())) {
|
||||
if (targetPlayer.hasPermission("chat.ignorebypass") || target.equals(player.getUniqueId())) {
|
||||
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
@@ -74,9 +74,9 @@ public class Ignore implements CommandExecutor {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if(!chatUser.getIgnoredPlayers().contains(target)) {
|
||||
if (!chatUser.getIgnoredPlayers().contains(target)) {
|
||||
chatUser.addIgnoredPlayers(target);
|
||||
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
||||
Queries.ignoreUser(player.getUniqueId(), target);
|
||||
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
||||
sendPluginMessage("ignore", player, target);
|
||||
} else {
|
||||
|
||||
@@ -8,15 +8,18 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Message implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
if(args.length < 2) return false; // todo error message or command info
|
||||
if (args.length < 2) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setReplyContinueTarget(args[0]);
|
||||
|
||||
@@ -3,22 +3,22 @@ package com.alttd.chat.commands;
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MuteServer implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@@ -26,13 +26,13 @@ public class MuteServer implements CommandExecutor {
|
||||
public void run() {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this command.</red>"));
|
||||
sender.sendRichMessage("<red>You don't have permission to use this command.</red>");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatPlugin.getInstance().toggleServerMuted();
|
||||
|
||||
Component component;
|
||||
ComponentLike component;
|
||||
if (ChatPlugin.getInstance().serverMuted()) {
|
||||
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
||||
} else {
|
||||
|
||||
@@ -8,18 +8,22 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Reply implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user.getReplyTarget() == null) return false;
|
||||
if(args.length == 0) return false; // todo error message or command info
|
||||
if (user.getReplyTarget() == null) {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, user.getReplyTarget(), message);
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Spy implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
UUID uuid = player.getUniqueId();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
user.toggleSpy();
|
||||
sender.sendMessage(Utility.parseMiniMessage("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
|
||||
@@ -2,38 +2,31 @@ 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.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ToggleGlobalChat implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
//chatUser.toggleGc();
|
||||
ChatUserManager.getChatUser(uuid);
|
||||
Utility.flipPermission(uuid, Config.GCPERMISSION);
|
||||
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
||||
sender.sendMessage(Utility.parseMiniMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
sender.sendRichMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
|
||||
@@ -3,21 +3,17 @@ 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.listeners.PluginMessage;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -30,22 +26,20 @@ public class Unignore implements CommandExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
if (args.length > 1) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
String targetName = args[0];
|
||||
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
||||
if(target == null) {
|
||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if(chatUser.getIgnoredPlayers().contains(target)) {
|
||||
if (chatUser.getIgnoredPlayers().contains(target)) {
|
||||
chatUser.removeIgnoredPlayers(target);
|
||||
Queries.unIgnoreUser(player.getUniqueId(), target);
|
||||
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -28,16 +29,17 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
private final ChatPlugin plugin;
|
||||
|
||||
private final Component GCNOTENABLED;
|
||||
private final ComponentLike GCNOTENABLED;
|
||||
|
||||
public ChatHandler() {
|
||||
plugin = ChatPlugin.getInstance();
|
||||
@@ -45,68 +47,68 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
public void continuePrivateMessage(Player player, String target, String message) {
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// user.setReplyTarget(target);
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// user.setReplyTarget(target);
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.component("sendername", player.name()),
|
||||
Placeholder.parsed("receivername", target)
|
||||
);
|
||||
);
|
||||
|
||||
Component component = Utility.parseMiniMessage("<message>", placeholders);
|
||||
ComponentLike component = Utility.parseMiniMessage("<message>", placeholders);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
ModifiableString modifiableString = new ModifiableString(component.asComponent());
|
||||
// todo a better way for this
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||
GalaxyUtility.sendBlockedNotification("DM Language",
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
target);
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
target);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
component = modifiableString.component();
|
||||
|
||||
sendPrivateMessage(player, target, "privatemessage", component);
|
||||
Component spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
sendPrivateMessage(player, target, "privatemessage", component.asComponent());
|
||||
ComponentLike spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
pl.sendMessage(spymessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void privateMessage(Player player, String target, String message) {
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// user.setReplyTarget(target);
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// user.setReplyTarget(target);
|
||||
|
||||
Component messageComponent = parseMessageContent(player, message);
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("message", messageComponent),
|
||||
Placeholder.component("sendername", player.name()),
|
||||
Placeholder.parsed("receivername", target)
|
||||
);
|
||||
);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(messageComponent);
|
||||
// todo a better way for this
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||
GalaxyUtility.sendBlockedNotification("DM Language",
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
target);
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
target);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
messageComponent = modifiableString.component();
|
||||
|
||||
// Component component = Utility.parseMiniMessage("<message>", placeholders)
|
||||
// .replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand())).build());
|
||||
// Component component = Utility.parseMiniMessage("<message>", placeholders)
|
||||
// .replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand())).build());
|
||||
|
||||
sendPrivateMessage(player, target, "privatemessage", messageComponent);
|
||||
Component spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
ComponentLike spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
pl.sendMessage(spymessage);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +116,7 @@ public class ChatHandler {
|
||||
|
||||
public void globalChat(Player player, String message) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if(!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
|
||||
if (!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
|
||||
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
||||
return;
|
||||
}
|
||||
@@ -124,29 +126,29 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
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
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.GCONCOOLDOWN, Placeholder.parsed("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
|
||||
if (timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
|
||||
player.sendRichMessage(Config.GCONCOOLDOWN, Placeholder.parsed("cooldown", Config.GCCOOLDOWN - timeLeft + ""));
|
||||
return;
|
||||
}
|
||||
|
||||
Component senderName = user.getDisplayName();
|
||||
Component prefix = user.getPrefix();
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
ComponentLike prefix = user.getPrefix();
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", ServerName.getServerName())
|
||||
);
|
||||
);
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
|
||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders).asComponent();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
// todo a better way for this
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "globalchat")) {
|
||||
GalaxyUtility.sendBlockedNotification("GC Language",
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
return; // the message was blocked
|
||||
}
|
||||
component = modifiableString.component();
|
||||
@@ -157,7 +159,7 @@ public class ChatHandler {
|
||||
|
||||
public void chatChannel(Player player, CustomChannel channel, String message) {
|
||||
if (!player.hasPermission(channel.getPermission())) {
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this channel.</red>"));
|
||||
player.sendRichMessage("<red>You don't have permission to use this channel.</red>");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -167,22 +169,22 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
Component senderName = user.getDisplayName();
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", ServerName.getServerName()),
|
||||
Placeholder.parsed("channel", channel.getChannelName())
|
||||
);
|
||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
|
||||
);
|
||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders).asComponent();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
|
||||
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language",
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
ALogger.info("Refusing to send blocked chat message");
|
||||
return;
|
||||
}
|
||||
@@ -203,49 +205,48 @@ public class ChatHandler {
|
||||
out.writeUTF(message);
|
||||
out.writeUTF(GsonComponentSerializer.gson().serialize(
|
||||
itemComponent(player.getInventory().getItemInMainHand())
|
||||
));
|
||||
));
|
||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||
|
||||
|
||||
// if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||
//
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// Component senderName = user.getDisplayName();
|
||||
//
|
||||
// String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
||||
// if(updatedMessage == null) {
|
||||
// GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
||||
// return; // the message was blocked
|
||||
// }
|
||||
//
|
||||
// if(!player.hasPermission("chat.format")) {
|
||||
// updatedMessage = Utility.stripTokens(updatedMessage);
|
||||
// }
|
||||
//
|
||||
// if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replaceFirst("[i]", "<item>");
|
||||
//
|
||||
// updatedMessage = Utility.formatText(updatedMessage);
|
||||
//
|
||||
// List<Placeholder> Placeholders = new ArrayList<>(List.of(
|
||||
// Placeholder.miniMessage("sender", senderName),
|
||||
// Placeholder.miniMessage("sendername", senderName),
|
||||
// Placeholder.miniMessage("partyname", party.getPartyName()),
|
||||
// Placeholder.miniMessage("message", updatedMessage),
|
||||
// Placeholder.miniMessage("server", Bukkit.getServerName()),
|
||||
// Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
//
|
||||
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders);
|
||||
//// sendPartyMessage(player, party.getPartyId(), component);
|
||||
//
|
||||
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
// for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
// pl.sendMessage(spyMessage);
|
||||
// }
|
||||
// }
|
||||
// if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||
//
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
// Component senderName = user.getDisplayName();
|
||||
//
|
||||
// String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
||||
// if(updatedMessage == null) {
|
||||
// GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
||||
// return; // the message was blocked
|
||||
// }
|
||||
//
|
||||
// if(!player.hasPermission("chat.format")) {
|
||||
// updatedMessage = Utility.stripTokens(updatedMessage);
|
||||
// }
|
||||
//
|
||||
// if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replaceFirst("[i]", "<item>");
|
||||
//
|
||||
// updatedMessage = Utility.formatText(updatedMessage);
|
||||
//
|
||||
// List<Placeholder> Placeholders = new ArrayList<>(List.of(
|
||||
// Placeholder.miniMessage("sender", senderName),
|
||||
// Placeholder.miniMessage("sendername", senderName),
|
||||
// Placeholder.miniMessage("partyname", party.getPartyName()),
|
||||
// Placeholder.miniMessage("message", updatedMessage),
|
||||
// Placeholder.miniMessage("server", Bukkit.getServerName()),
|
||||
// Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
//
|
||||
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders);
|
||||
//// sendPartyMessage(player, party.getPartyId(), component);
|
||||
//
|
||||
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
// for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
// pl.sendMessage(spyMessage);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component, String message) {
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, ComponentLike component, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
ALogger.warn("Failed to send chat message from non existent player");
|
||||
@@ -254,9 +255,9 @@ public class ChatHandler {
|
||||
|
||||
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||
player.sendRichMessage("<red>Unable to send messages to <channel> in this server.</red>",
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()));
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()));
|
||||
ALogger.info(String.format("Not sending chat message due to [%s] not being in this channels config",
|
||||
ServerName.getServerName()));
|
||||
ServerName.getServerName()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -264,16 +265,18 @@ public class ChatHandler {
|
||||
.filter(p -> p.hasPermission(chatChannel.getPermission()));
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
if (chatChannel.isLocal()) {
|
||||
Location location = player.getLocation();
|
||||
stream = stream.filter(receiver -> {
|
||||
Player receiverPlayer = Bukkit.getPlayer(receiver.getUniqueId());
|
||||
if (receiverPlayer == null)
|
||||
if (receiverPlayer == null) {
|
||||
return false;
|
||||
if (!location.getWorld().getUID().equals(receiverPlayer.getLocation().getWorld().getUID()))
|
||||
}
|
||||
if (!location.getWorld().getUID().equals(receiverPlayer.getLocation().getWorld().getUID())) {
|
||||
return false;
|
||||
}
|
||||
return !(receiverPlayer.getLocation().distance(location) > Config.LOCAL_DISTANCE);
|
||||
});
|
||||
}
|
||||
@@ -285,9 +288,9 @@ public class ChatHandler {
|
||||
.filter(onlinePlayer -> onlinePlayer.hasPermission(Config.SPYPERMISSION))
|
||||
.filter(onlinePlayer -> !recipientUUIDs.contains(onlinePlayer.getUniqueId()))
|
||||
.forEach(onlinePlayer -> onlinePlayer.sendRichMessage(Config.CHANNEL_SPY,
|
||||
Placeholder.component("sender", player.name()),
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()),
|
||||
Placeholder.parsed("message", message)));
|
||||
Placeholder.component("sender", player.name()),
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()),
|
||||
Placeholder.parsed("message", message)));
|
||||
}
|
||||
|
||||
private void sendPluginMessage(Player player, String channel, Component component) {
|
||||
@@ -320,9 +323,11 @@ public class ChatHandler {
|
||||
|
||||
private boolean isMuted(Player player, String message, String prefix) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user == null) return false;
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
if (user.isMuted() || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
// if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
// if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
GalaxyUtility.sendBlockedNotification(prefix, player, Utility.parseMiniMessage(Utility.stripTokens(message)), "");
|
||||
return true;
|
||||
}
|
||||
@@ -331,11 +336,12 @@ public class ChatHandler {
|
||||
|
||||
public static Component itemComponent(ItemStack item) {
|
||||
Component component = Component.text("[i]", NamedTextColor.AQUA);
|
||||
if(item.getType().equals(Material.AIR))
|
||||
if (item.getType().equals(Material.AIR)) {
|
||||
return component.color(NamedTextColor.WHITE);
|
||||
}
|
||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||
if(dname) {
|
||||
component = component.append(item.getItemMeta().displayName());
|
||||
if (dname) {
|
||||
component = component.append(Objects.requireNonNull(item.getItemMeta().displayName()));
|
||||
} else {
|
||||
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
|
||||
}
|
||||
@@ -357,10 +363,12 @@ public class ChatHandler {
|
||||
int loc = sb.lastIndexOf(split);
|
||||
char charLoc = sb.charAt(loc);
|
||||
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
||||
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on")))
|
||||
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on"))) {
|
||||
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||
if (pos != splits.length - 1)
|
||||
}
|
||||
if (pos != splits.length - 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
@@ -379,7 +387,7 @@ public class ChatHandler {
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||
Component component = miniMessage.deserialize(rawMessage);
|
||||
for(ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
component = component.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.times(Config.EMOTELIMIT)
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -47,28 +48,32 @@ public class ChatListener implements Listener {
|
||||
this.chatLogHandler = chatLogHandler;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onChatCommandDecorate(AsyncChatCommandDecorateEvent event) {
|
||||
if (event.player() == null) return;
|
||||
if (event.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
Component message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onChatDecorate(AsyncChatDecorateEvent event) {
|
||||
if (event.player() == null) return;
|
||||
if (event.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
Component message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
|
||||
private final Component mention = MiniMessage.miniMessage().deserialize(Config.MENTIONPLAYERTAG);
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event) {
|
||||
event.setCancelled(true); //Always cancel the event because we do not want to deal with Microsoft's stupid bans
|
||||
@@ -86,12 +91,12 @@ public class ChatListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
Component input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(input);
|
||||
ModifiableString modifiableString = new ModifiableString(input.asComponent());
|
||||
|
||||
// todo a better way for this
|
||||
if(!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||
// todo a better way for this
|
||||
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||
if (!filterType.equals(FilterType.PUNISH)) {
|
||||
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||
return;
|
||||
@@ -105,9 +110,9 @@ public class ChatListener implements Listener {
|
||||
})) {
|
||||
event.setCancelled(true);
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
"");
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input), true);
|
||||
modifiableString.component(),
|
||||
"");
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input.asComponent()), true);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
@@ -116,7 +121,7 @@ public class ChatListener implements Listener {
|
||||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
|
||||
@@ -131,7 +136,7 @@ public class ChatListener implements Listener {
|
||||
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||
}
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input));
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input.asComponent()));
|
||||
}
|
||||
|
||||
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
||||
@@ -147,10 +152,10 @@ public class ChatListener implements Listener {
|
||||
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
|
||||
if (namePattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.match(namePattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
.once()
|
||||
.match(namePattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
||||
// modifiableString.replace(TextReplacementConfig.builder()
|
||||
// .once()
|
||||
@@ -161,24 +166,24 @@ public class ChatListener implements Listener {
|
||||
// });
|
||||
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.match(nickPattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
.once()
|
||||
.match(nickPattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull Component render(@NotNull Player player, @NotNull Component message) {
|
||||
public @NotNull ComponentLike render(@NotNull Player player, @NotNull Component message) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", user.getDisplayName()),
|
||||
@@ -187,12 +192,12 @@ public class ChatListener implements Listener {
|
||||
Placeholder.component("prefixall", user.getPrefixAll()),
|
||||
Placeholder.component("staffprefix", user.getStaffPrefix()),
|
||||
Placeholder.component("message", message)
|
||||
);
|
||||
);
|
||||
|
||||
return Utility.parseMiniMessage(Config.CHATFORMAT, placeholders);
|
||||
}
|
||||
|
||||
private Component parseMessageContent(Player player, String rawMessage) {
|
||||
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
||||
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
|
||||
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||
@@ -203,7 +208,7 @@ public class ChatListener implements Listener {
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||
Component component = miniMessage.deserialize(Utility.formatText(rawMessage));
|
||||
for(ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
component = component.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.times(Config.EMOTELIMIT)
|
||||
@@ -213,11 +218,11 @@ public class ChatListener implements Listener {
|
||||
|
||||
component = component
|
||||
.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.once()
|
||||
.matchLiteral("[i]")
|
||||
.replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
|
||||
.build());
|
||||
TextReplacementConfig.builder()
|
||||
.once()
|
||||
.matchLiteral("[i]")
|
||||
.replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
|
||||
.build());
|
||||
|
||||
return component;
|
||||
|
||||
|
||||
@@ -5,17 +5,18 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
@@ -50,8 +51,9 @@ public class PluginMessage implements PluginMessageListener {
|
||||
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
if (!user.getReplyContinueTarget().equalsIgnoreCase(target))
|
||||
if (!user.getReplyContinueTarget().equalsIgnoreCase(target)) {
|
||||
user.setReplyTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
case "privatemessageout": {
|
||||
@@ -67,13 +69,15 @@ public class PluginMessage implements PluginMessageListener {
|
||||
if (isTargetNotIgnored(chatUser, targetuuid)) {
|
||||
chatUser.setReplyTarget(target);
|
||||
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||
// ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
// user.setReplyTarget(target);
|
||||
// ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
// user.setReplyTarget(target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "globalchat": {
|
||||
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) break;
|
||||
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) {
|
||||
break;
|
||||
}
|
||||
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String message = in.readUTF();
|
||||
@@ -90,7 +94,7 @@ public class PluginMessage implements PluginMessageListener {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
||||
UUID targetUUID = UUID.fromString(in.readUTF());
|
||||
|
||||
if(!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
||||
if (!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
||||
chatUser.addIgnoredPlayers(targetUUID);
|
||||
}
|
||||
break;
|
||||
@@ -101,12 +105,14 @@ public class PluginMessage implements PluginMessageListener {
|
||||
break;
|
||||
}
|
||||
case "chatchannel": {
|
||||
if (ChatPlugin.getInstance().serverMuted()) break;
|
||||
if (ChatPlugin.getInstance().serverMuted()) {
|
||||
break;
|
||||
}
|
||||
|
||||
chatChannel(in);
|
||||
break;
|
||||
}
|
||||
case "tmppartyupdate" : {
|
||||
case "tmppartyupdate": {
|
||||
int id = Integer.parseInt(in.readUTF());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
@@ -128,8 +134,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||
@Override
|
||||
public void run() {
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if(user != null) {
|
||||
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
|
||||
if (user != null) {
|
||||
ComponentLike component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
@@ -152,8 +158,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||
@Override
|
||||
public void run() {
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if(user != null) {
|
||||
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
|
||||
if (user != null) {
|
||||
ComponentLike component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
@@ -171,7 +177,9 @@ public class PluginMessage implements PluginMessageListener {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
boolean mute = in.readBoolean();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
if (user == null) return;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
user.setMuted(mute);
|
||||
break;
|
||||
default:
|
||||
@@ -187,8 +195,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||
chatChannel = (CustomChannel) Channel.getChatChannel(in.readUTF());
|
||||
uuid = UUID.fromString(in.readUTF());
|
||||
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
||||
} catch (Exception e) { //Idk the exception for reading too far into in.readUTF()
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
ALogger.error("Failed to read ChatChannel message.", e);
|
||||
}
|
||||
|
||||
if (chatChannel == null) {
|
||||
|
||||
@@ -4,100 +4,21 @@ import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NickUtilities
|
||||
{
|
||||
public class NickUtilities {
|
||||
public static String stringRegen;
|
||||
|
||||
public static String applyColor(String message) {
|
||||
ChatColor hexColor1 = null;
|
||||
ChatColor hexColor2;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
boolean startsWithColor = false;
|
||||
boolean lastColorMatters = false;
|
||||
|
||||
if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
||||
String[] split = message.split(NickUtilities.stringRegen);
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
int nextIndex = 0;
|
||||
if (message.indexOf("}") <= 11) {
|
||||
startsWithColor = true;
|
||||
list.add(message.substring(0, message.indexOf("}") + 1));
|
||||
}
|
||||
for (String s : split) {
|
||||
nextIndex += s.length();
|
||||
int tmp = message.indexOf("}", nextIndex);
|
||||
if (tmp < message.length() && tmp>=0) {
|
||||
list.add(message.substring(nextIndex, tmp + 1));
|
||||
nextIndex = tmp + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int i;
|
||||
boolean firstLoop = true;
|
||||
if (startsWithColor) {
|
||||
i = -1;
|
||||
} else {
|
||||
i = 0;
|
||||
stringBuilder.append(split[i]);
|
||||
}
|
||||
|
||||
for (String s : list) {
|
||||
boolean lesser = s.contains("<");
|
||||
boolean bigger = s.contains(">");
|
||||
|
||||
if (bigger && lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
||||
} else if (bigger || lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
||||
} else {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
||||
}
|
||||
|
||||
if (firstLoop) {
|
||||
lastColorMatters = bigger;
|
||||
hexColor1 = hexColor2;
|
||||
firstLoop = false;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lesser && lastColorMatters) {
|
||||
stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
||||
} else {
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
|
||||
hexColor1 = hexColor2;
|
||||
lastColorMatters = bigger;
|
||||
i++;
|
||||
}
|
||||
if (split.length > i){
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
}
|
||||
return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String removeAllColors(String string) {
|
||||
|
||||
for (final String colorCodes : Config.NICK_ALLOWED_COLOR_CODESLIST) {
|
||||
@@ -111,34 +32,11 @@ public class NickUtilities
|
||||
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||
}
|
||||
|
||||
public static String hexGradient(Color color1, Color color2, String text){
|
||||
double r = color1.getRed();
|
||||
double g = color1.getGreen();
|
||||
double b = color1.getBlue();
|
||||
|
||||
double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
||||
double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
||||
double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (i > 0) {
|
||||
r = r - rDifference;
|
||||
g = g - gDifference;
|
||||
b = b - bDifference;
|
||||
}
|
||||
stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static void updateCache() {
|
||||
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()){
|
||||
Nicknames.getInstance().nickCacheUpdate.forEach(uuid ->{
|
||||
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()) {
|
||||
Nicknames.getInstance().nickCacheUpdate.forEach(uuid -> {
|
||||
Nick nick = Queries.getNick(uuid);
|
||||
if (nick == null){
|
||||
if (nick == null) {
|
||||
Nicknames.getInstance().NickCache.remove(uuid);
|
||||
} else {
|
||||
Nicknames.getInstance().NickCache.put(uuid, nick);
|
||||
@@ -174,13 +72,13 @@ public class NickUtilities
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Nick nick : Nicknames.getInstance().NickCache.values()){
|
||||
for (Nick nick : Nicknames.getInstance().NickCache.values()) {
|
||||
if (!nick.getUuid().equals(target.getUniqueId())
|
||||
&& ((nick.getCurrentNickNoColor() != null && nick.getCurrentNickNoColor().equalsIgnoreCase(cleanNick))
|
||||
|| (nick.getNewNickNoColor() != null && nick.getNewNickNoColor().equalsIgnoreCase(cleanNick)))){
|
||||
&& ((nick.getCurrentNickNoColor() != null && nick.getCurrentNickNoColor().equalsIgnoreCase(cleanNick))
|
||||
|| (nick.getNewNickNoColor() != null && nick.getNewNickNoColor().equalsIgnoreCase(cleanNick)))) {
|
||||
UUID uuid = nick.getUuid();
|
||||
UUID uniqueId = target.getUniqueId();
|
||||
if (uniqueId.equals(uuid)){
|
||||
if (uniqueId.equals(uuid)) {
|
||||
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
|
||||
}
|
||||
sender.sendRichMessage(Config.NICK_TAKEN);
|
||||
@@ -204,16 +102,16 @@ public class NickUtilities
|
||||
public static void bungeeMessageHandled(UUID uniqueId, Player player, String channel) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
out.writeUTF("NickName" + channel); // The channel name to check if this your data
|
||||
|
||||
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||
DataOutputStream msgout = new DataOutputStream(msgbytes);
|
||||
try {
|
||||
msgout.writeUTF(uniqueId.toString());
|
||||
} catch (IOException exception){
|
||||
exception.printStackTrace();
|
||||
} catch (IOException exception) {
|
||||
ALogger.error("Failed to write UUID to byte array", exception);
|
||||
return;
|
||||
}
|
||||
byte[] bytes = msgbytes.toByteArray();
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.alttd.chat.events.NickEvent;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -21,7 +22,6 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||
return true;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
@@ -60,10 +60,10 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
if (offlinePlayer.isOnline() || offlinePlayer.hasPlayedBefore()) {
|
||||
handleNick(player, offlinePlayer, args[2]);
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.SET_OTHERS)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.SET_OTHERS));
|
||||
}
|
||||
} else if (args.length > 3) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS));
|
||||
}
|
||||
break;
|
||||
case "review":
|
||||
@@ -72,7 +72,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
ChatPlugin.getInstance().getServer().getPluginManager().registerEvents(nicknamesGui, ChatPlugin.getInstance());
|
||||
nicknamesGui.openInventory(player);
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.REVIEW)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.REVIEW));
|
||||
}
|
||||
break;
|
||||
case "request":
|
||||
@@ -84,7 +84,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.REQUEST)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.REQUEST));
|
||||
}
|
||||
break;
|
||||
case "try":
|
||||
@@ -92,17 +92,17 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
LuckPerms api = ChatAPI.get().getLuckPerms();
|
||||
if (api != null) {
|
||||
if (NickUtilities.validNick(player, player, args[1])) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_TRYOUT,
|
||||
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
||||
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
||||
Placeholder.component("nick", Utility.applyColor(args[1])),
|
||||
Placeholder.unparsed("nickrequest", args[1])));
|
||||
sender.sendRichMessage(Config.NICK_TRYOUT,
|
||||
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
||||
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
||||
Placeholder.component("nick", Utility.applyColor(args[1])),
|
||||
Placeholder.unparsed("nickrequest", args[1]));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_NO_LUCKPERMS));
|
||||
sender.sendRichMessage(Config.NICK_NO_LUCKPERMS);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.TRY)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.TRY));
|
||||
}
|
||||
break;
|
||||
case "current":
|
||||
@@ -111,16 +111,16 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("nickname", chatUser.getDisplayName()),
|
||||
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
|
||||
);
|
||||
);
|
||||
player.sendRichMessage(Config.NICK_CURRENT, placeholders);
|
||||
}
|
||||
break;
|
||||
case "help":
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)
|
||||
+ "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>"));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL)
|
||||
+ "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>");
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Console commands are disabled.");
|
||||
@@ -131,7 +131,9 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
if (!sender.hasPermission("chat.command.nick")) return completions;
|
||||
if (!sender.hasPermission("chat.command.nick")) {
|
||||
return completions;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> choices = new ArrayList<>();
|
||||
@@ -191,15 +193,15 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
long waitTime = Config.NICK_WAIT_TIME;
|
||||
if (timeSinceLastChange > waitTime || player.hasPermission("chat.command.nick.bypasswaittime")) {
|
||||
if (nick.hasRequest()) {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_REQUEST_PLACED,
|
||||
Placeholder.component("oldrequestednick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("newrequestednick", Utility.applyColor(nickName))));
|
||||
player.sendRichMessage(Config.NICK_REQUEST_PLACED,
|
||||
Placeholder.component("oldrequestednick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("newrequestednick", Utility.applyColor(nickName)));
|
||||
}
|
||||
nick.setNewNick(nickName);
|
||||
nick.setRequestedDate(new Date().getTime());
|
||||
} else {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_TOO_SOON,
|
||||
Placeholder.unparsed("time", formatTime((timeSinceLastChange-waitTime)*-1))));
|
||||
player.sendRichMessage(Config.NICK_TOO_SOON,
|
||||
Placeholder.unparsed("time", formatTime((timeSinceLastChange - waitTime) * -1)));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -207,8 +209,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
Queries.newNicknameRequest(uniqueId, nickName);
|
||||
bungeeMessageRequest(player);
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_REQUESTED,
|
||||
Placeholder.component("nick", Utility.applyColor(nickName))));
|
||||
player.sendRichMessage(Config.NICK_REQUESTED,
|
||||
Placeholder.component("nick", Utility.applyColor(nickName)));
|
||||
}
|
||||
|
||||
private void bungeeMessageRequest(Player player) {
|
||||
@@ -216,8 +218,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
|
||||
UUID uniqueId = player.getUniqueId();
|
||||
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||
// out.writeUTF("ALL");
|
||||
out.writeUTF("NickNameRequest"); // The channel name to check if this your data
|
||||
|
||||
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||
@@ -225,7 +227,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
try {
|
||||
msgout.writeUTF(uniqueId.toString());
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
ALogger.error("Failed to write UUID to ByteArrayOutputStream", exception);
|
||||
return;
|
||||
}
|
||||
byte[] bytes = msgbytes.toByteArray();
|
||||
@@ -244,13 +246,13 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
long days = (timeInMillis / (1000 * 60 * 60 * 24));
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (days!=0) {
|
||||
if (days != 0) {
|
||||
stringBuilder.append(days).append(" days ");
|
||||
}
|
||||
if (days!=0 || hour!=0) {
|
||||
if (days != 0 || hour != 0) {
|
||||
stringBuilder.append(hour).append(" hours ");
|
||||
}
|
||||
if (days!=0 || hour!=0 || minute != 0) {
|
||||
if (days != 0 || hour != 0 || minute != 0) {
|
||||
stringBuilder.append(minute).append(" minutes and ");
|
||||
}
|
||||
stringBuilder.append(second).append(" seconds");
|
||||
@@ -262,22 +264,22 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
|
||||
try {
|
||||
if (target.isOnline()) {
|
||||
resetNick(target.getPlayer());
|
||||
resetNick(Objects.requireNonNull(target.getPlayer()));
|
||||
}
|
||||
Queries.removePlayerFromDataBase(target.getUniqueId());
|
||||
NickCache.remove(target.getUniqueId());
|
||||
nickCacheUpdate.add(target.getUniqueId());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error("Failed to remove nickname from database", e);
|
||||
}
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_RESET_OTHERS,
|
||||
Placeholder.unparsed("player", target.getName())));
|
||||
sender.sendRichMessage(Config.NICK_RESET_OTHERS,
|
||||
Placeholder.unparsed("player", Objects.requireNonNull(target.getName())));
|
||||
}
|
||||
|
||||
if (target.isOnline() && target.getPlayer() != null) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_RESET));
|
||||
target.getPlayer().sendRichMessage(Config.NICK_RESET);
|
||||
}
|
||||
|
||||
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), null, NickEvent.NickEventType.RESET);
|
||||
@@ -305,17 +307,19 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_CHANGED_OTHERS,
|
||||
Placeholder.unparsed("targetplayer", target.getName()),
|
||||
Placeholder.unparsed("nickname", nickName)));
|
||||
Placeholder.unparsed("targetplayer", Objects.requireNonNull(target.getName())),
|
||||
Placeholder.unparsed("nickname", nickName)));
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_TARGET_NICK_CHANGE,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())),
|
||||
Placeholder.unparsed("sendernick", getNick(sender)),
|
||||
Placeholder.unparsed("player", target.getName())));
|
||||
Objects.requireNonNull(target.getPlayer())
|
||||
.sendRichMessage(Config.NICK_TARGET_NICK_CHANGE,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())),
|
||||
Placeholder.unparsed("sendernick", getNick(sender)),
|
||||
Placeholder.unparsed("player", target.getName()));
|
||||
}
|
||||
} else if (target.isOnline()) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer()))));
|
||||
Objects.requireNonNull(target.getPlayer())
|
||||
.sendRichMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,8 +357,10 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
break;
|
||||
case REQUEST:
|
||||
if (sender.hasPermission("chat.command.nick.request")) {
|
||||
message.append("<gold>/nick request <nickname><white> - Requests a username to be reviewed by staff.\n" +
|
||||
" <gray>Try using <dark_gray>/nick try <nickname><gray> to see if you like the name, you can only change it once per day!\n");
|
||||
message.append("""
|
||||
<gold>/nick request <nickname><white> - Requests a username to be reviewed by staff.
|
||||
<gray>Try using <dark_gray>/nick try <nickname><gray> to see if you like the name, you can only change it once per day!
|
||||
""");
|
||||
}
|
||||
break;
|
||||
case REVIEW:
|
||||
@@ -381,8 +387,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
public void resetNick(final Player player) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setDisplayName(player.getName());
|
||||
player.displayName(user.getDisplayName());
|
||||
// updateCMIUser(player, null);
|
||||
player.displayName(user.getDisplayName().asComponent());
|
||||
// updateCMIUser(player, null);
|
||||
}
|
||||
|
||||
public String getNick(final Player player) {
|
||||
@@ -391,42 +397,13 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
public void setNick(final Player player, final String nickName) {
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setDisplayName(nickName);
|
||||
player.displayName(user.getDisplayName());
|
||||
// updateCMIUser(player, nickName);
|
||||
}
|
||||
|
||||
// public static String format(final String m) {
|
||||
// return NickUtilities.applyColor(m);
|
||||
// }
|
||||
|
||||
// public void updateCMIUser(Player player, String nickName) {
|
||||
// if (!isCMIEnabled())
|
||||
// return;
|
||||
//
|
||||
// CMIUser cmiUser = CMI.getInstance().getPlayerManager().getUser(player);
|
||||
// if (nickName == null){
|
||||
// cmiUser.setNickName(null, true);
|
||||
// } else {
|
||||
// cmiUser.setNickName(NickUtilities.applyColor(nickName), true);
|
||||
// }
|
||||
// cmiUser.updateDisplayName();
|
||||
// }
|
||||
|
||||
private Boolean isCMIEnabled = null;
|
||||
private Boolean isCMIEnabled() {
|
||||
if (!(isCMIEnabled == null))
|
||||
return isCMIEnabled;
|
||||
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("CMI");
|
||||
if (plugin != null && plugin.isEnabled())
|
||||
return isCMIEnabled = true;
|
||||
|
||||
return isCMIEnabled = false;
|
||||
player.displayName(user.getDisplayName().asComponent());
|
||||
}
|
||||
|
||||
public static Nicknames getInstance() {
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -29,7 +31,6 @@ import java.util.UUID;
|
||||
|
||||
public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
|
||||
@@ -54,9 +55,9 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
strippedNick = MiniMessage.miniMessage().stripTags(Nicknames.getInstance().getNick(player));
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
// final String strippedNick = CMIChatColor.stripColor(Nicknames.getInstance().getNick(player));
|
||||
// final String strippedNick = CMIChatColor.stripColor(Nicknames.getInstance().getNick(player));
|
||||
|
||||
// final String cmiNick = Util.CMIChatColor.deColorize(Nicknames.getInstance().getNick(player));
|
||||
// final String cmiNick = Util.CMIChatColor.deColorize(Nicknames.getInstance().getNick(player));
|
||||
|
||||
if (nickName == null) {
|
||||
Nicknames.getInstance().resetNick(player);
|
||||
@@ -75,8 +76,8 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
player.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_REQUESTS_ON_LOGIN,
|
||||
Placeholder.unparsed("amount", String.valueOf(i))));
|
||||
player.sendRichMessage(Config.NICK_REQUESTS_ON_LOGIN,
|
||||
Placeholder.unparsed("amount", String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +94,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
String subChannel = in.readUTF();
|
||||
ALogger.info(channel + ": " + subChannel);
|
||||
if (!subChannel.equals("NickNameRequest") && !subChannel.equals("NickNameAccepted")
|
||||
&& !subChannel.equals("NickNameDenied") && !subChannel.equals("NickNameSet")) {
|
||||
&& !subChannel.equals("NickNameDenied") && !subChannel.equals("NickNameSet")) {
|
||||
return;
|
||||
}
|
||||
UUID playerUUID;
|
||||
@@ -110,18 +111,18 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
name = offlinePlayer.getName() == null ? playerUUID.toString() : offlinePlayer.getName();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error("Failed to read plugin message", e);
|
||||
return;
|
||||
}
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
switch (subChannel) {
|
||||
case "NickNameRequest":
|
||||
Component component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
|
||||
ComponentLike component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
|
||||
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,
|
||||
"/nick review"))
|
||||
"/nick review"))
|
||||
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
miniMessage.deserialize("<gold>Click this text to review the request!")));
|
||||
miniMessage.deserialize("<gold>Click this text to review the request!")));
|
||||
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("chat.command.nick.review")) {
|
||||
@@ -138,8 +139,9 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
}
|
||||
break;
|
||||
case "NickNameAccepted":
|
||||
Component deserialize = miniMessage.deserialize("<green><name>'s nickname was accepted!",
|
||||
Placeholder.unparsed("name", name));
|
||||
|
||||
ComponentLike deserialize = Utility.parseMiniMessage("<green><name>'s nickname was accepted!",
|
||||
Placeholder.unparsed("name", name));
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("chat.command.nick.review")) {
|
||||
p.sendMessage(deserialize);
|
||||
@@ -153,14 +155,14 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
Player target = Bukkit.getPlayer(playerUUID);
|
||||
if (target != null && nick != null && nick.getCurrentNick() != null) {
|
||||
Nicknames.getInstance().setNick(target, nick.getCurrentNick());
|
||||
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
||||
target.sendRichMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "NickNameDenied":
|
||||
final Component messageDenied = miniMessage.deserialize("<red><name>'s nickname was denied",
|
||||
Placeholder.unparsed("name", name));
|
||||
Placeholder.unparsed("name", name));
|
||||
Nick nick = Nicknames.getInstance().NickCache.get(playerUUID);
|
||||
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
@@ -181,9 +183,11 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
if (offlinePlayer.isOnline()) {
|
||||
Player target = Bukkit.getPlayer(playerUUID);
|
||||
|
||||
if (target == null) break;
|
||||
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
||||
if (target == null) {
|
||||
break;
|
||||
}
|
||||
target.sendRichMessage(Config.NICK_NOT_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alttd.chat.events.NickEvent;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
@@ -40,7 +41,7 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
public NicknamesGui() {
|
||||
// Create a new inventory, with no owner (as this isn't a real inventory)
|
||||
inv = Bukkit.createInventory(null, 36, Utility.parseMiniMessage("Nicknames GUI"));
|
||||
inv = Bukkit.createInventory(null, 36, Utility.parseMiniMessage("Nicknames GUI").asComponent());
|
||||
|
||||
// Put the items into the inventory
|
||||
currentPage = 1;
|
||||
@@ -71,14 +72,14 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
if (currentPage != 1) {
|
||||
inv.setItem(28, createGuiItem(Material.PAPER, "§bPrevious page",
|
||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||
"§aPrevious page: %previousPage%".replace("%previousPage%", String.valueOf(currentPage - 1))));
|
||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||
"§aPrevious page: %previousPage%".replace("%previousPage%", String.valueOf(currentPage - 1))));
|
||||
}
|
||||
|
||||
if (hasNextPage) {
|
||||
inv.setItem(36, createGuiItem(Material.PAPER, "§bNext page",
|
||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||
"§aNext page: §b%nextPage%".replace("%nextPage%", String.valueOf(currentPage + 1))));
|
||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||
"§aNext page: §b%nextPage%".replace("%nextPage%", String.valueOf(currentPage + 1))));
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
@@ -92,10 +93,11 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
meta.setOwningPlayer(offlinePlayer);
|
||||
String name = offlinePlayer.getName();
|
||||
if (name == null)
|
||||
if (name == null) {
|
||||
meta.displayName(miniMessage.deserialize("UNKNOWN PLAYER NAME"));
|
||||
else
|
||||
} else {
|
||||
meta.displayName(miniMessage.deserialize(offlinePlayer.getName()));
|
||||
}
|
||||
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
@@ -132,30 +134,42 @@ public class NicknamesGui implements Listener {
|
||||
// Check for clicks on items
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getInventory() != inv) return;
|
||||
if (e.getInventory() != inv) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
final ItemStack clickedItem = e.getCurrentItem();
|
||||
|
||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) return;
|
||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if (clickedItem.getType().equals(Material.PAPER)) {
|
||||
String serialize = PlainTextComponentSerializer.plainText().serialize(clickedItem.getItemMeta().displayName());
|
||||
Component component = clickedItem.getItemMeta().displayName();
|
||||
if (component == null) {
|
||||
throw new IllegalStateException("Nicknames GUI: Item with no display name clicked!");
|
||||
}
|
||||
String serialize = PlainTextComponentSerializer.plainText().serialize(component);
|
||||
if (serialize.equals("Next Page")) {
|
||||
setItems(currentPage + 1);
|
||||
}
|
||||
} else if (clickedItem.getType().equals(Material.PLAYER_HEAD)) {
|
||||
SkullMeta meta = (SkullMeta) clickedItem.getItemMeta();
|
||||
ItemMeta itemMeta = clickedItem.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
SkullMeta meta = (SkullMeta) itemMeta;
|
||||
if (meta.hasEnchants()) {
|
||||
return;
|
||||
}
|
||||
OfflinePlayer owningPlayer = meta.getOwningPlayer();
|
||||
|
||||
if (owningPlayer == null) {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_USER_NOT_FOUND));
|
||||
p.sendRichMessage(Config.NICK_USER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -171,10 +185,15 @@ public class NicknamesGui implements Listener {
|
||||
} else {
|
||||
nick = Queries.getNick(uniqueId);
|
||||
}
|
||||
Component itemDisplayName = itemMeta.displayName();
|
||||
if (itemDisplayName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nick == null || !nick.hasRequest()) {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_ALREADY_HANDLED,
|
||||
Placeholder.component("targetplayer", clickedItem.getItemMeta().displayName())));
|
||||
p.sendRichMessage(Config.NICK_ALREADY_HANDLED,
|
||||
Placeholder.component("targetplayer", itemDisplayName))
|
||||
;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -187,20 +206,18 @@ public class NicknamesGui implements Listener {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), clickedItem.getItemMeta().getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||
nickEvent.callEvent();
|
||||
}
|
||||
}.runTask(ChatPlugin.getInstance());
|
||||
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_ACCEPTED,
|
||||
Placeholder.component("targetplayer", clickedItem.getItemMeta().displayName()),
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? clickedItem.getItemMeta().getDisplayName() : nick.getCurrentNick()))));
|
||||
p.sendRichMessage(Config.NICK_ACCEPTED,
|
||||
Placeholder.component("targetplayer", itemDisplayName),
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? itemMeta.getDisplayName() : nick.getCurrentNick())));
|
||||
|
||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getNewNick());
|
||||
// owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED // This message is also send when the plugin message is received
|
||||
// .replace("%nickname%", nick.getNewNick())));
|
||||
}
|
||||
|
||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Accepted");
|
||||
@@ -214,18 +231,16 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(clickedItem.getItemMeta().displayName());
|
||||
itemMeta.displayName(itemMeta.displayName());
|
||||
itemMeta.lore(clickedItem.lore());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE,
|
||||
Placeholder.component("playerName", clickedItem.getItemMeta().displayName())));
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
||||
}
|
||||
|
||||
} else if (e.isRightClick()) {
|
||||
Component displayName = clickedItem.getItemMeta().displayName();
|
||||
if (owningPlayer.hasPlayedBefore()) {
|
||||
Queries.denyNewNickname(uniqueId);
|
||||
|
||||
@@ -234,18 +249,18 @@ public class NicknamesGui implements Listener {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), clickedItem.getItemMeta().getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
||||
nickEvent.callEvent();
|
||||
}
|
||||
}.runTask(ChatPlugin.getInstance());
|
||||
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_DENIED,
|
||||
Placeholder.unparsed("targetplayer", owningPlayer.getName()),
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick()))));
|
||||
Placeholder.unparsed("targetplayer", owningPlayer.getName()),
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick()))));
|
||||
|
||||
if (Nicknames.getInstance().NickCache.containsKey(uniqueId)
|
||||
&& Nicknames.getInstance().NickCache.get(uniqueId).getCurrentNick() != null) {
|
||||
&& Nicknames.getInstance().NickCache.get(uniqueId).getCurrentNick() != null) {
|
||||
nick.setNewNick(null);
|
||||
nick.setRequestedDate(0);
|
||||
Nicknames.getInstance().NickCache.put(uniqueId, nick);
|
||||
@@ -255,31 +270,31 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
||||
owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED));
|
||||
owningPlayer.getPlayer().sendRichMessage(Config.NICK_NOT_CHANGED);
|
||||
}
|
||||
|
||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Denied");
|
||||
final Component messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
||||
Placeholder.unparsed("name", owningPlayer.getName()));
|
||||
final ComponentLike messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
||||
Placeholder.unparsed("name", owningPlayer.getName()));
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("chat.command.nick.review")) {
|
||||
p.sendMessage(messageDenied);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(displayName);
|
||||
itemMeta.displayName(itemDisplayName);
|
||||
itemMeta.lore(clickedItem.lore());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (displayName == null)
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.parsed("playerName", "UNKNOWN PLAYER NAME")));
|
||||
else
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("playerName", displayName)));
|
||||
if (itemDisplayName == null) {
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.parsed("player", "UNKNOWN PLAYER NAME"));
|
||||
} else {
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ package com.alttd.chat.util;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -16,40 +13,22 @@ import java.util.List;
|
||||
|
||||
public class GalaxyUtility {
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("prefix", prefix),
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
|
||||
Placeholder.parsed("target", (target.isEmpty() ? "tried to say:" : "-> " + target + ":")),
|
||||
Placeholder.parsed("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<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) {
|
||||
public static void sendBlockedNotification(String prefix, Player player, ComponentLike input, String target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("prefix", prefix),
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
|
||||
Placeholder.parsed("target", (target.isEmpty() ? "tried to say:" : "-> " + target + ":")),
|
||||
Placeholder.component("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
);
|
||||
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
Bukkit.getOnlinePlayers().forEach(a -> {
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<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>"));
|
||||
player.sendRichMessage("<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 addAdditionalChatCompletions(Player player) {
|
||||
|
||||
Reference in New Issue
Block a user