Made global chat async and added uuid to it everywhere
This commit is contained in:
parent
a36ac260f1
commit
a9be164979
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
|
@ -9,20 +8,24 @@ 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
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if(args.length == 0) return false;
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().globalChat(player, message);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatPlugin.getInstance().getChatHandler().globalChat(player, message);
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class PluginMessage implements PluginMessageListener {
|
|||
break;
|
||||
}
|
||||
case "globalchat": {
|
||||
if (ChatPlugin.getInstance().serverGlobalChatEnabled()) {
|
||||
if (ChatPlugin.getInstance().serverGlobalChatEnabled() && !ChatPlugin.getInstance().serverMuted()) {
|
||||
String uuidString = in.readUTF();
|
||||
if (!uuidString.matches("\\b[0-9a-f]{8}\\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\\b[0-9a-f]{12}\\b")) {
|
||||
Bukkit.broadcast(GsonComponentSerializer.gson().deserialize(uuidString), Config.GCPERMISSION);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import com.velocitypowered.api.command.CommandSource;
|
|||
|
||||
public class GlobalAdminChatEvent {
|
||||
private final CommandSource sender;
|
||||
private final String uuid;
|
||||
private final String message;
|
||||
|
||||
public GlobalAdminChatEvent(CommandSource sender, String message) {
|
||||
public GlobalAdminChatEvent(CommandSource sender, String uuid, String message) {
|
||||
this.sender = sender;
|
||||
this.uuid = uuid;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
|
@ -15,6 +17,10 @@ public class GlobalAdminChatEvent {
|
|||
return sender;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ServerHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public void sendGlobalChat(String message) {
|
||||
public void sendGlobalChat(String uuid, String message) {
|
||||
// Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
servers.stream()
|
||||
|
|
@ -47,6 +47,7 @@ public class ServerHandler {
|
|||
.forEach(registeredServer -> {
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("globalchat");
|
||||
buf.writeUTF(uuid);
|
||||
buf.writeUTF(message);
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class PluginMessageListener {
|
|||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
switch (channel) {
|
||||
case "globalchat":
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "globaladminchat":
|
||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user