Move global admin chat to ChatHandler
This commit is contained in:
parent
d8a4490358
commit
595bff765a
|
|
@ -59,6 +59,7 @@ public class VelocityChat {
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
new ALogger(logger);
|
new ALogger(logger);
|
||||||
Config.init(getDataDirectory());
|
Config.init(getDataDirectory());
|
||||||
|
new DatabaseConnection();
|
||||||
Queries.createTables();
|
Queries.createTables();
|
||||||
|
|
||||||
ChatUserManager.initialize(); // loads all the users from the db and adds them.
|
ChatUserManager.initialize(); // loads all the users from the db and adds them.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.events.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;
|
||||||
|
|
@ -9,6 +10,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import com.velocitypowered.api.command.BrigadierCommand;
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
|
||||||
public class GlobalAdminChat {
|
public class GlobalAdminChat {
|
||||||
|
|
@ -20,7 +22,7 @@ public class GlobalAdminChat {
|
||||||
.then(RequiredArgumentBuilder
|
.then(RequiredArgumentBuilder
|
||||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
proxyServer.getEventManager().fire(new GlobalAdminChatEvent(context.getSource(), context.getArgument("message", String.class)));
|
VelocityChat.getPlugin().getChatHandler().globalAdminChat(context.getSource(), context.getArgument("message", String.class));
|
||||||
return 1;
|
return 1;
|
||||||
}) // TODO call in the same way as gc?
|
}) // TODO call in the same way as gc?
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@ package com.alttd.chat.handlers;
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.data.ChatUser;
|
import com.alttd.chat.data.ChatUser;
|
||||||
|
import com.alttd.chat.events.GlobalAdminChatEvent;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
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;
|
||||||
|
|
@ -89,6 +92,33 @@ public class ChatHandler {
|
||||||
recipient.sendMessage(receiverMessage);
|
recipient.sendMessage(receiverMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||||
|
String senderName = Config.CONSOLENAME;
|
||||||
|
String serverName = "Altitude";
|
||||||
|
if (commandSource instanceof Player) {
|
||||||
|
Player sender = (Player) commandSource;
|
||||||
|
senderName = sender.getUsername();
|
||||||
|
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||||
|
}
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
|
||||||
|
message = Utility.parseColors(message);
|
||||||
|
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
|
map.put("sender", senderName);
|
||||||
|
//map.put("message", event.getMessage());
|
||||||
|
map.put("message", Utility.parseColors(message));
|
||||||
|
map.put("server", serverName);
|
||||||
|
|
||||||
|
Component component = miniMessage.parse(Config.GACFORMAT, map);
|
||||||
|
|
||||||
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||||
|
target.sendMessage(component);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructs a mail object and notifies all involved players about it
|
* constructs a mail object and notifies all involved players about it
|
||||||
* / mail send playerA,playerB,playerC message
|
* / mail send playerA,playerB,playerC message
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user