Refactor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.commands.GlobalAdminChat;
|
||||
import com.alttd.chat.commands.GlobalChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handlers.ChatHandler;
|
||||
import com.alttd.chat.handlers.ServerHandler;
|
||||
@@ -83,6 +84,7 @@ public class VelocityChat {
|
||||
|
||||
public void loadCommands() {
|
||||
new GlobalAdminChat(server);
|
||||
new GlobalChat(server);
|
||||
// all (proxy)commands go here
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.mojang.brigadier.arguments.StringArgumentType;
|
||||
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;
|
||||
|
||||
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.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
@@ -39,10 +39,8 @@ public class Message {
|
||||
Player receiver = playerOptional.get();
|
||||
proxyServer.getEventManager().fire(new PrivateMessageEvent(context.getSource(), receiver, context.getArgument("message", String.class))).thenAccept((event) -> {
|
||||
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;
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
@@ -27,7 +26,7 @@ public class SendMail {
|
||||
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||
.suggests((context, builder) -> {
|
||||
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());
|
||||
}
|
||||
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||
@@ -43,13 +42,53 @@ public class SendMail {
|
||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||
.executes(context -> {
|
||||
// todo construct the mail and notify the player if online?
|
||||
VelocityChat.getPlugin().getChatHandler().sendMail();
|
||||
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();
|
||||
|
||||
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||
|
||||
@@ -68,8 +68,8 @@ public final class ServerConfig {
|
||||
|
||||
/** DO NOT EDIT ANYTHING ABOVE **/
|
||||
|
||||
public boolean GLOBALCHAT = true; // TODO change to false on release
|
||||
public boolean JOINLEAVEMSSAGES = 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 set to false on lobby
|
||||
private void ServerSettings() {
|
||||
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
||||
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.alttd.chat.api;
|
||||
package com.alttd.chat.events;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.alttd.chat.api;
|
||||
package com.alttd.chat.events;
|
||||
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
@@ -1,44 +1,111 @@
|
||||
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.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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 receiverName;
|
||||
CommandSource commandSource = event.getSender();
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) event.getSender();
|
||||
Player sender = (Player) commandSource;
|
||||
senderName = sender.getUsername();
|
||||
//plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
|
||||
} else {
|
||||
senderName = Config.CONSOLENAME;
|
||||
}
|
||||
receiverName = event.getRecipient().getUsername();
|
||||
receiverName = recipient.getUsername();
|
||||
|
||||
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.put("sender", senderName);
|
||||
map.put("receiver", receiverName);
|
||||
map.put("message", event.getMessage());
|
||||
map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
|
||||
map.put("message", message);
|
||||
// map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
|
||||
|
||||
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, map);
|
||||
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, map);
|
||||
|
||||
event.getSender().sendMessage(senderMessage);
|
||||
event.getRecipient().sendMessage(receiverMessage);
|
||||
commandSource.sendMessage(senderMessage);
|
||||
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.data.ServerWrapper;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,10 +35,10 @@ public class ServerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGlobalChat(String message) {
|
||||
public void sendGlobalChat(Component message) {
|
||||
servers.stream()
|
||||
.filter(serverWrapper -> serverWrapper.globalChat())
|
||||
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(MiniMessage.get().parse(message)));
|
||||
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(message));
|
||||
}
|
||||
|
||||
public List<ServerWrapper> getServers()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.api.PrivateMessageEvent;
|
||||
import com.alttd.chat.events.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.events.PrivateMessageEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
@@ -33,7 +33,8 @@ public class PluginMessageListener {
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
switch (channel) {
|
||||
case "globalchat":
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
||||
// todo this is obsolete
|
||||
//VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
||||
break;
|
||||
default:
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
|
||||
Reference in New Issue
Block a user