Refactor
This commit is contained in:
parent
74fc459156
commit
4b79d6909f
|
|
@ -184,9 +184,14 @@ public final class Config {
|
||||||
|
|
||||||
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message></gray></white>";
|
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message></gray></white>";
|
||||||
public static String GCPERMISSION = "proxy.globalchat";
|
public static String GCPERMISSION = "proxy.globalchat";
|
||||||
|
public static List<String> GCALIAS = new ArrayList<>();
|
||||||
|
public static String GCNOTENABLED = "You don't have global chat enabled.";
|
||||||
private static void globalChat() {
|
private static void globalChat() {
|
||||||
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
||||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||||
|
GCALIAS.clear();
|
||||||
|
GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global"));
|
||||||
|
GCNOTENABLED = getString("commands.globalchat.not-enabled", GCNOTENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.alttd.chat.managers;
|
||||||
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.config.RegexConfig;
|
import com.alttd.chat.config.RegexConfig;
|
||||||
import com.alttd.chat.objects.ChatFilterType;
|
import com.alttd.chat.objects.FilterType;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
|
@ -12,6 +12,7 @@ import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
// TODO rebuild this class, All regexes go in a single list where we use the ChatFilter object and a matcher
|
||||||
public class RegexManager {
|
public class RegexManager {
|
||||||
|
|
||||||
private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>();
|
private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>();
|
||||||
|
|
@ -23,9 +24,9 @@ public class RegexManager {
|
||||||
// maiby a REGEXobject and a list<Regex> would be better here?
|
// maiby a REGEXobject and a list<Regex> would be better here?
|
||||||
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
|
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
|
||||||
RegexConfig regexConfig = new RegexConfig(node.getString());
|
RegexConfig regexConfig = new RegexConfig(node.getString());
|
||||||
if (ChatFilterType.getType(regexConfig.TYPE) == ChatFilterType.BLOCK) {
|
if (FilterType.getType(regexConfig.TYPE) == FilterType.BLOCK) {
|
||||||
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
|
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
|
||||||
} else if (ChatFilterType.getType(regexConfig.TYPE) == ChatFilterType.REPLACE) {
|
} else if (FilterType.getType(regexConfig.TYPE) == FilterType.REPLACE) {
|
||||||
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
|
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@ package com.alttd.chat.objects;
|
||||||
public class ChatFilter {
|
public class ChatFilter {
|
||||||
|
|
||||||
private final String regex;
|
private final String regex;
|
||||||
private final ChatFilterType type;
|
private final FilterType type;
|
||||||
private String replacement = "";
|
private String replacement = "";
|
||||||
|
|
||||||
public ChatFilter(String regex, ChatFilterType type) {
|
public ChatFilter(String regex, FilterType type) {
|
||||||
this.regex = regex;
|
this.regex = regex;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatFilter(String regex, ChatFilterType type, String replacement) {
|
public ChatFilter(String regex, FilterType type, String replacement) {
|
||||||
this.regex = regex;
|
this.regex = regex;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.replacement = replacement;
|
this.replacement = replacement;
|
||||||
|
|
@ -21,7 +21,7 @@ public class ChatFilter {
|
||||||
return regex;
|
return regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatFilterType getType() {
|
public FilterType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,6 @@ public class ChatUser {
|
||||||
|
|
||||||
private LinkedList<Mail> mails;
|
private LinkedList<Mail> mails;
|
||||||
|
|
||||||
/**
|
|
||||||
* Not all of the objects are relevant to proxy or server, so the saving should only update if the value has been changed?
|
|
||||||
*/
|
|
||||||
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) {
|
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.partyId = partyId;
|
this.partyId = partyId;
|
||||||
|
|
@ -37,9 +34,9 @@ public class ChatUser {
|
||||||
prefix = Utility.getPrefix(uuid, true);
|
prefix = Utility.getPrefix(uuid, true);
|
||||||
staffPrefix = Utility.getStaffPrefix(uuid);
|
staffPrefix = Utility.getStaffPrefix(uuid);
|
||||||
|
|
||||||
prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api
|
prefixAll = Utility.getPrefix(uuid, false);
|
||||||
// a boolean is lighter then a permission check, it's what I'd suggest doing here
|
|
||||||
toggleGc = toggle_Gc;//Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is...
|
toggleGc = toggle_Gc;
|
||||||
replyTarget = null;
|
replyTarget = null;
|
||||||
mails = new LinkedList<>(); // todo load mails
|
mails = new LinkedList<>(); // todo load mails
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +55,7 @@ public class ChatUser {
|
||||||
|
|
||||||
public void togglePartyChat() {
|
public void togglePartyChat() {
|
||||||
toggledPartyChat = !toggledPartyChat;
|
toggledPartyChat = !toggledPartyChat;
|
||||||
Queries.setPartyChatState(toggledPartyChat, uuid); //TODO: Async pls
|
Queries.setPartyChatState(toggledPartyChat, uuid); //TODO: Async pls - no CompleteableFuture<>!
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ForceTp() {
|
public boolean ForceTp() {
|
||||||
|
|
@ -67,7 +64,7 @@ public class ChatUser {
|
||||||
|
|
||||||
public void toggleForceTp() {
|
public void toggleForceTp() {
|
||||||
forceTp = !forceTp;
|
forceTp = !forceTp;
|
||||||
Queries.setForceTpState(forceTp, uuid); //TODO: Async pls
|
Queries.setForceTpState(forceTp, uuid); //TODO: Async pls - no CompleteableFuture<>!
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
|
|
@ -121,4 +118,8 @@ public class ChatUser {
|
||||||
public LinkedList<Mail> getMails() {
|
public LinkedList<Mail> getMails() {
|
||||||
return mails;
|
return mails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMail(Mail mail) {
|
||||||
|
mails.add(mail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
public enum ChatFilterType {
|
public enum FilterType {
|
||||||
REPLACE("replace"),
|
REPLACE("replace"),
|
||||||
BLOCK("block");
|
BLOCK("block");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
ChatFilterType(String name) {
|
FilterType(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatFilterType getType(String name) {
|
public static FilterType getType(String name) {
|
||||||
for (ChatFilterType type : ChatFilterType.values()) {
|
for (FilterType type : FilterType.values()) {
|
||||||
if (type.name.equalsIgnoreCase(name)) {
|
if (type.name.equalsIgnoreCase(name)) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
// Todo this is only needed to get some special usecases eg [i] -> get and return the item the player is holding over a SYNCRONIZED connection:/
|
||||||
public class ChatPlugin extends JavaPlugin {
|
public class ChatPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private static ChatPlugin instance;
|
private static ChatPlugin instance;
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
package com.alttd.chat.commands;
|
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
|
||||||
import org.apache.commons.lang.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 java.util.Objects;
|
|
||||||
|
|
||||||
public class GlobalChat implements CommandExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if(!(sender instanceof Player)) { // must be a player
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length == 0) return false;
|
|
||||||
if(args[0].equalsIgnoreCase("togglegc")) {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Objects.requireNonNull(ChatUserManager.getChatUser(((Player) sender).getUniqueId())).toggleGc();
|
|
||||||
}
|
|
||||||
}.runTask(ChatPlugin.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = StringUtils.join(args, " ", 0, args.length);
|
|
||||||
ChatPlugin.getInstance().getChatHandler().globalChat(player, message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -27,80 +27,7 @@ public class ChatHandler {
|
||||||
plugin = ChatPlugin.getInstance();
|
plugin = ChatPlugin.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void globalChat(Player player, String message) {
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
|
||||||
if(user == null) return;
|
|
||||||
if(!user.isGcOn()) {
|
|
||||||
player.sendMessage();// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check if the player has global chat enabled, if not warn them
|
|
||||||
String senderName, prefix = "";
|
|
||||||
|
|
||||||
senderName = player.getDisplayName(); // TODO this can be a component
|
|
||||||
// can also be cached in the chatuser object?
|
|
||||||
prefix = plugin.getChatAPI().getPrefix(player.getUniqueId());
|
|
||||||
|
|
||||||
MiniMessage miniMessage = MiniMessage.get();
|
|
||||||
message = Utility.parseColors(message);
|
|
||||||
if(!player.hasPermission("chat.format"))
|
|
||||||
message = miniMessage.stripTokens(message);
|
|
||||||
if(message.contains("[i]"))
|
|
||||||
message = message.replace("[i]", "<[i]>");
|
|
||||||
|
|
||||||
List<Template> templates = new ArrayList<>(List.of(
|
|
||||||
Template.of("sender", senderName),
|
|
||||||
Template.of("prefix", prefix),
|
|
||||||
Template.of("message", message),
|
|
||||||
Template.of("server", Bukkit.getServerName())/*,
|
|
||||||
Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/));
|
|
||||||
|
|
||||||
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
|
||||||
|
|
||||||
//todo make a method for this, it'll be used more then onc
|
|
||||||
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF("globalchat");
|
|
||||||
out.writeUTF(miniMessage.serialize(component));
|
|
||||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start - move these to util
|
|
||||||
public Component itemComponent(ItemStack item) {
|
|
||||||
Component component = Component.text("[i]");
|
|
||||||
if(item.getType().equals(Material.AIR))
|
|
||||||
return component;
|
|
||||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
|
||||||
if(dname) {
|
|
||||||
component = component.append(item.getItemMeta().displayName());
|
|
||||||
} else {
|
|
||||||
component = Component.text(materialToName(item.getType()));
|
|
||||||
}
|
|
||||||
component = component.hoverEvent(item.asHoverEvent());
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String materialToName(Material m) {
|
|
||||||
if (m.equals(Material.TNT)) {
|
|
||||||
return "TNT";
|
|
||||||
}
|
|
||||||
String orig = m.toString().toLowerCase();
|
|
||||||
String[] splits = orig.split("_");
|
|
||||||
StringBuilder sb = new StringBuilder(orig.length());
|
|
||||||
int pos = 0;
|
|
||||||
for (String split : splits) {
|
|
||||||
sb.append(split);
|
|
||||||
int loc = sb.lastIndexOf(split);
|
|
||||||
char charLoc = sb.charAt(loc);
|
|
||||||
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
|
||||||
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on")))
|
|
||||||
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
|
||||||
if (pos != splits.length - 1)
|
|
||||||
sb.append(' ');
|
|
||||||
++pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
// end - move these to util
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,45 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/* // todo implement AdvancedChatFilter for this like this
|
||||||
|
// send pluginmessage to backend server and return a shatteredcomponent to be reparsed by proxy
|
||||||
|
// Start - move these to util
|
||||||
|
public Component itemComponent(ItemStack item) {
|
||||||
|
Component component = Component.text("[i]");
|
||||||
|
if(item.getType().equals(Material.AIR))
|
||||||
|
return component;
|
||||||
|
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||||
|
if(dname) {
|
||||||
|
component = component.append(item.getItemMeta().displayName());
|
||||||
|
} else {
|
||||||
|
component = Component.text(materialToName(item.getType()));
|
||||||
|
}
|
||||||
|
component = component.hoverEvent(item.asHoverEvent());
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String materialToName(Material m) {
|
||||||
|
if (m.equals(Material.TNT)) {
|
||||||
|
return "TNT";
|
||||||
|
}
|
||||||
|
String orig = m.toString().toLowerCase();
|
||||||
|
String[] splits = orig.split("_");
|
||||||
|
StringBuilder sb = new StringBuilder(orig.length());
|
||||||
|
int pos = 0;
|
||||||
|
for (String split : splits) {
|
||||||
|
sb.append(split);
|
||||||
|
int loc = sb.lastIndexOf(split);
|
||||||
|
char charLoc = sb.charAt(loc);
|
||||||
|
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
||||||
|
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on")))
|
||||||
|
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||||
|
if (pos != splits.length - 1)
|
||||||
|
sb.append(' ');
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
// end - move these to util
|
||||||
|
}*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.chat;
|
package com.alttd.chat;
|
||||||
|
|
||||||
import com.alttd.chat.commands.GlobalAdminChat;
|
import com.alttd.chat.commands.GlobalAdminChat;
|
||||||
|
import com.alttd.chat.commands.GlobalChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.handlers.ChatHandler;
|
import com.alttd.chat.handlers.ChatHandler;
|
||||||
import com.alttd.chat.handlers.ServerHandler;
|
import com.alttd.chat.handlers.ServerHandler;
|
||||||
|
|
@ -83,6 +84,7 @@ public class VelocityChat {
|
||||||
|
|
||||||
public void loadCommands() {
|
public void loadCommands() {
|
||||||
new GlobalAdminChat(server);
|
new GlobalAdminChat(server);
|
||||||
|
new GlobalChat(server);
|
||||||
// all (proxy)commands go here
|
// all (proxy)commands go here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
import com.alttd.chat.events.GlobalAdminChatEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.VelocityChat;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
|
||||||
|
public class GlobalChat {
|
||||||
|
|
||||||
|
public GlobalChat(ProxyServer proxyServer) {
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("globalchat")
|
||||||
|
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
|
||||||
|
.requires(ctx -> ctx instanceof Player) // players only can use this
|
||||||
|
.then(RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
|
.executes(context -> {
|
||||||
|
VelocityChat.getPlugin().getChatHandler().globalChat((Player) context.getSource(), context.getArgument("message", String.class));
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> 0) // todo info message /usage
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
|
for (String alias : Config.GCALIAS) {
|
||||||
|
metaBuilder.aliases(alias);
|
||||||
|
}
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.VelocityChat;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.node.Node;
|
||||||
|
|
||||||
|
public class GlobalChatToggle {
|
||||||
|
|
||||||
|
// todo q - can this be implemented in /gc toggle or /gc true/false
|
||||||
|
public GlobalChatToggle(ProxyServer proxyServer) {
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("toggleglobalchat")
|
||||||
|
.requires(ctx -> ctx instanceof Player)
|
||||||
|
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
|
||||||
|
.then(RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
|
.executes(context -> {
|
||||||
|
LuckPerms luckPerms = VelocityChat.getPlugin().API().getLuckPerms();
|
||||||
|
Player player = (Player) context;
|
||||||
|
luckPerms.getUserManager().modifyUser(player.getUniqueId(), user -> {
|
||||||
|
if(player.hasPermission(Config.GCPERMISSION)) { //TODO THIS MUST BE A CONSTANT FROM CONFIG?
|
||||||
|
user.data().add(Node.builder(Config.GCPERMISSION).build());
|
||||||
|
} else {
|
||||||
|
user.data().remove(Node.builder(Config.GCPERMISSION).build());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> 0)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
metaBuilder.aliases("togglegc");
|
||||||
|
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.chat.events.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
@ -39,10 +39,8 @@ public class Message {
|
||||||
Player receiver = playerOptional.get();
|
Player receiver = playerOptional.get();
|
||||||
proxyServer.getEventManager().fire(new PrivateMessageEvent(context.getSource(), receiver, context.getArgument("message", String.class))).thenAccept((event) -> {
|
proxyServer.getEventManager().fire(new PrivateMessageEvent(context.getSource(), receiver, context.getArgument("message", String.class))).thenAccept((event) -> {
|
||||||
if(event.getResult() == ResultedEvent.GenericResult.allowed()) {
|
if(event.getResult() == ResultedEvent.GenericResult.allowed()) {
|
||||||
VelocityChat.getPlugin().getChatHandler().privateMessage(event);
|
VelocityChat.getPlugin().getChatHandler().privateMessage(context.getSource(), receiver, context.getArgument("message", String.class));
|
||||||
}
|
}
|
||||||
// event has finished firing
|
|
||||||
// do some logic dependent on the result
|
|
||||||
});
|
});
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
|
@ -27,7 +26,7 @@ public class SendMail {
|
||||||
.<CommandSource, String>argument("player", StringArgumentType.string())
|
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||||
.suggests((context, builder) -> {
|
.suggests((context, builder) -> {
|
||||||
Collection<String> possibleValues = new ArrayList<>();
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
for (Player player : proxyServer.getAllPlayers()) {
|
for (Player player : proxyServer.getAllPlayers()) { // todo all chatplayers? this can be heavy
|
||||||
possibleValues.add(player.getGameProfile().getName());
|
possibleValues.add(player.getGameProfile().getName());
|
||||||
}
|
}
|
||||||
if(possibleValues.isEmpty()) return Suggestions.empty();
|
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||||
|
|
@ -43,13 +42,53 @@ public class SendMail {
|
||||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
// todo construct the mail and notify the player if online?
|
// todo construct the mail and notify the player if online?
|
||||||
|
VelocityChat.getPlugin().getChatHandler().sendMail();
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.executes(context -> 0)
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.executes(context -> 0)
|
.then(LiteralArgumentBuilder.<CommandSource>literal("list")
|
||||||
|
// TODO list read, unread, all?
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("read")
|
||||||
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
|
||||||
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
|
||||||
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("admin")
|
||||||
|
.requires(ctx -> ctx.hasPermission("command.proxy.mail.admin"))// TODO permission system? load permissions from config?
|
||||||
|
// TODO admin command, remove, edit?
|
||||||
|
.executes(context -> {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> {
|
||||||
|
// todo mail help message
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ public final class ServerConfig {
|
||||||
|
|
||||||
/** DO NOT EDIT ANYTHING ABOVE **/
|
/** DO NOT EDIT ANYTHING ABOVE **/
|
||||||
|
|
||||||
public boolean GLOBALCHAT = true; // TODO change to false on release
|
public boolean GLOBALCHAT = true; // TODO - @teri idk what servers need to have this enabled
|
||||||
public boolean JOINLEAVEMSSAGES = true; // TODO change to false on release
|
public boolean JOINLEAVEMSSAGES = true; // TODO set to false on lobby
|
||||||
private void ServerSettings() {
|
private void ServerSettings() {
|
||||||
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
||||||
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.api;
|
package com.alttd.chat.events;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.api;
|
package com.alttd.chat.events;
|
||||||
|
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
@ -1,44 +1,111 @@
|
||||||
package com.alttd.chat.handlers;
|
package com.alttd.chat.handlers;
|
||||||
|
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.chat.VelocityChat;
|
||||||
|
import com.alttd.chat.events.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ChatHandler {
|
public class ChatHandler {
|
||||||
|
|
||||||
public void privateMessage(PrivateMessageEvent event) {
|
public void globalChat(Player player, String message) {
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
if(user == null) return;
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
if(!user.isGcOn()) {
|
||||||
|
player.sendMessage(miniMessage.parse(Config.GCNOTENABLED));// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = Utility.parseColors(message);
|
||||||
|
if(!player.hasPermission("chat.format")) // Todo PR fix for '<3' to minimessage
|
||||||
|
message = miniMessage.stripTokens(message);
|
||||||
|
|
||||||
|
message = RegexManager.replaceText(message); // this filters the message TODO should staff be able to bypass filters?
|
||||||
|
|
||||||
|
List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
Template.of("sender", user.getDisplayName()),
|
||||||
|
Template.of("prefix", user.getPrefix()),
|
||||||
|
Template.of("message", message),
|
||||||
|
Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
||||||
|
/*,Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
||||||
|
));
|
||||||
|
|
||||||
|
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
||||||
|
|
||||||
|
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(component);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void privateMessage(CommandSource commandSource, Player recipient, String message) {
|
||||||
|
// todo get the chatUserinstance of both players and or console - @teri should console be able to /msg?
|
||||||
String senderName;
|
String senderName;
|
||||||
String receiverName;
|
String receiverName;
|
||||||
CommandSource commandSource = event.getSender();
|
|
||||||
if (commandSource instanceof Player) {
|
if (commandSource instanceof Player) {
|
||||||
Player sender = (Player) event.getSender();
|
Player sender = (Player) commandSource;
|
||||||
senderName = sender.getUsername();
|
senderName = sender.getUsername();
|
||||||
//plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
|
//plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
|
||||||
} else {
|
} else {
|
||||||
senderName = Config.CONSOLENAME;
|
senderName = Config.CONSOLENAME;
|
||||||
}
|
}
|
||||||
receiverName = event.getRecipient().getUsername();
|
receiverName = recipient.getUsername();
|
||||||
|
|
||||||
MiniMessage miniMessage = MiniMessage.get();
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
|
||||||
|
message = Utility.parseColors(message);
|
||||||
|
if(!commandSource.hasPermission("chat.format")) // Todo PR fix for '<3' to minimessage
|
||||||
|
message = miniMessage.stripTokens(message);
|
||||||
|
|
||||||
|
message = RegexManager.replaceText(message); // this filters the message TODO should staff be able to bypass filters?
|
||||||
|
|
||||||
|
// List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
// Template.of("sender", user.getDisplayName()),
|
||||||
|
// Template.of("prefix", user.getPrefix()),
|
||||||
|
// Template.of("message", message),
|
||||||
|
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
||||||
|
// /*,Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
||||||
|
// ));
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
map.put("sender", senderName);
|
map.put("sender", senderName);
|
||||||
map.put("receiver", receiverName);
|
map.put("receiver", receiverName);
|
||||||
map.put("message", event.getMessage());
|
map.put("message", message);
|
||||||
map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
|
// map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
|
||||||
|
|
||||||
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, map);
|
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, map);
|
||||||
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, map);
|
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, map);
|
||||||
|
|
||||||
event.getSender().sendMessage(senderMessage);
|
commandSource.sendMessage(senderMessage);
|
||||||
event.getRecipient().sendMessage(receiverMessage);
|
recipient.sendMessage(receiverMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructs a mail object and notifies all involved players about it
|
||||||
|
* / mail send playerA,playerB,playerC message
|
||||||
|
*/
|
||||||
|
public void sendMail() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message the messaged to be parsed by the chatfilter
|
||||||
|
* @param player the player invoking the message
|
||||||
|
* @return the message altered by the filters
|
||||||
|
*/
|
||||||
|
public String applyChatFilters(String message, Player player) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMail(CommandSource source, String message, List<Player> targets) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.ServerConfig;
|
import com.alttd.chat.config.ServerConfig;
|
||||||
import com.alttd.chat.data.ServerWrapper;
|
import com.alttd.chat.data.ServerWrapper;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -34,10 +35,10 @@ public class ServerHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendGlobalChat(String message) {
|
public void sendGlobalChat(Component message) {
|
||||||
servers.stream()
|
servers.stream()
|
||||||
.filter(serverWrapper -> serverWrapper.globalChat())
|
.filter(serverWrapper -> serverWrapper.globalChat())
|
||||||
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(MiniMessage.get().parse(message)));
|
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ServerWrapper> getServers()
|
public List<ServerWrapper> getServers()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
import com.alttd.chat.events.GlobalAdminChatEvent;
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.chat.events.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ public class PluginMessageListener {
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "globalchat":
|
case "globalchat":
|
||||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
// todo this is obsolete
|
||||||
|
//VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user