mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 10:39:05 +00:00
Added DiscordSRV Bungee route
This commit is contained in:
parent
6d438f9372
commit
b730be11f5
@ -41,6 +41,7 @@ import mineverse.Aust1n46.chat.listeners.SignListener;
|
||||
import mineverse.Aust1n46.chat.alias.AliasInfo;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
|
||||
import mineverse.Aust1n46.chat.channel.ChatChannel;
|
||||
//import mineverse.Aust1n46.chat.command.CCommand;
|
||||
import mineverse.Aust1n46.chat.command.MineverseCommand;
|
||||
@ -662,13 +663,32 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendDiscordSRVPluginMessage(String chatChannel, String message) {
|
||||
if(onlinePlayers.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Player host = onlinePlayers.iterator().next().getPlayer();
|
||||
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(byteOutStream);
|
||||
try {
|
||||
out.writeUTF("DiscordSRV");
|
||||
out.writeUTF(chatChannel);
|
||||
out.writeUTF(message);
|
||||
host.sendPluginMessage(plugin, MineverseChat.PLUGIN_MESSAGING_CHANNEL, byteOutStream.toByteArray());
|
||||
out.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] inputStream) {
|
||||
if(!channel.equals(MineverseChat.PLUGIN_MESSAGING_CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(message));
|
||||
DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(inputStream));
|
||||
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||
System.out.println(msgin.available() + " size on receiving end");
|
||||
}
|
||||
@ -680,46 +700,65 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
String senderName = msgin.readUTF();
|
||||
UUID senderUUID = UUID.fromString(msgin.readUTF());
|
||||
int hash = msgin.readInt();
|
||||
String consoleChat = msgin.readUTF();
|
||||
boolean hasJSON = msgin.readBoolean();
|
||||
String globalJSON = "";
|
||||
if(hasJSON) {
|
||||
globalJSON = msgin.readUTF();
|
||||
String format = msgin.readUTF();
|
||||
String chat = msgin.readUTF();
|
||||
String consoleChat = format + chat;
|
||||
String globalJSON = msgin.readUTF();
|
||||
|
||||
if(!ChatChannel.isChannel(chatchannel)) {
|
||||
return;
|
||||
}
|
||||
if(ChatChannel.isChannel(chatchannel) && ChatChannel.getChannel(chatchannel).getBungee()) {
|
||||
Bukkit.getConsoleSender().sendMessage(consoleChat);
|
||||
for(MineverseChatPlayer p : MineverseChat.onlinePlayers) {
|
||||
if(p.isListening(ChatChannel.getChannel(chatchannel).getName())) {
|
||||
if(!p.getBungeeToggle() && MineverseChatAPI.getOnlineMineverseChatPlayer(senderName) == null) {
|
||||
continue;
|
||||
}
|
||||
ChatChannel chatChannelObject = ChatChannel.getChannel(chatchannel);
|
||||
|
||||
PacketContainer packet = null;
|
||||
if(hasJSON) {
|
||||
String json = Format.formatModerationGUI(globalJSON, p.getPlayer(), senderName, chatchannel, hash);
|
||||
WrappedChatComponent chatComponent = WrappedChatComponent.fromJson(json);
|
||||
packet = Format.createPacketPlayOutChat(chatComponent);
|
||||
}
|
||||
if(!chatChannelObject.getBungee()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(plugin.getConfig().getBoolean("ignorechat", false)) {
|
||||
if(!p.getIgnores().contains(senderUUID)) {
|
||||
// System.out.println("Chat sent");
|
||||
if(hasJSON) {
|
||||
Format.sendPacketPlayOutChat(p.getPlayer(), packet);
|
||||
}
|
||||
else {
|
||||
p.getPlayer().sendMessage(consoleChat);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(hasJSON) {
|
||||
Set<Player> recipients = new HashSet<Player>();
|
||||
for(MineverseChatPlayer p : MineverseChat.onlinePlayers) {
|
||||
if(p.isListening(chatChannelObject.getName())) {
|
||||
recipients.add(p.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Create VentureChatEvent
|
||||
VentureChatEvent ventureChatEvent = new VentureChatEvent(onlinePlayers.iterator().next(), chatChannelObject, recipients, format, chat, globalJSON, hash, false);
|
||||
//Fire event and wait for other plugin listeners to act on it
|
||||
Bukkit.getServer().getPluginManager().callEvent(ventureChatEvent);
|
||||
}
|
||||
});
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(consoleChat);
|
||||
for(MineverseChatPlayer p : MineverseChat.onlinePlayers) {
|
||||
if(p.isListening(chatChannelObject.getName())) {
|
||||
if(!p.getBungeeToggle() && MineverseChatAPI.getOnlineMineverseChatPlayer(senderName) == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String json = Format.formatModerationGUI(globalJSON, p.getPlayer(), senderName, chatchannel, hash);
|
||||
WrappedChatComponent chatComponent = WrappedChatComponent.fromJson(json);
|
||||
PacketContainer packet = Format.createPacketPlayOutChat(chatComponent);
|
||||
|
||||
if(plugin.getConfig().getBoolean("ignorechat", false)) {
|
||||
if(!p.getIgnores().contains(senderUUID)) {
|
||||
// System.out.println("Chat sent");
|
||||
Format.sendPacketPlayOutChat(p.getPlayer(), packet);
|
||||
}
|
||||
else {
|
||||
p.getPlayer().sendMessage(consoleChat);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Format.sendPacketPlayOutChat(p.getPlayer(), packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(subchannel.equals("DiscordSRV")) {
|
||||
String chatchannel = msgin.readUTF();
|
||||
String message = msgin.readUTF();
|
||||
if(ChatChannel.isChannel(chatchannel) && ChatChannel.getChannel(chatchannel).getBungee()) {
|
||||
for(MineverseChatPlayer p : MineverseChat.onlinePlayers) {
|
||||
p.getPlayer().sendMessage(Format.FormatStringAll(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,22 +157,17 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
String senderUUID = in.readUTF();
|
||||
boolean bungeeToggle = in.readBoolean();
|
||||
int hash = in.readInt();
|
||||
String consoleChat = in.readUTF();
|
||||
boolean hasJSON = in.readBoolean();
|
||||
String json = "";
|
||||
if(hasJSON) {
|
||||
json = in.readUTF();
|
||||
}
|
||||
String format = in.readUTF();
|
||||
String chat = in.readUTF();
|
||||
String json = in.readUTF();
|
||||
out.writeUTF("Chat");
|
||||
out.writeUTF(chatchannel);
|
||||
out.writeUTF(senderName);
|
||||
out.writeUTF(senderUUID);
|
||||
out.writeInt(hash);
|
||||
out.writeUTF(consoleChat);
|
||||
out.writeBoolean(hasJSON);
|
||||
if(hasJSON) {
|
||||
out.writeUTF(json);
|
||||
}
|
||||
out.writeUTF(format);
|
||||
out.writeUTF(chat);
|
||||
out.writeUTF(json);
|
||||
for(String send : getProxy().getServers().keySet()) {
|
||||
if(getProxy().getServers().get(send).getPlayers().size() > 0) {
|
||||
if(!bungeeToggle && !getProxy().getServers().get(send).getName().equalsIgnoreCase(ser.getInfo().getName())) {
|
||||
@ -182,6 +177,18 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(subchannel.equals("DiscordSRV")) {
|
||||
String chatchannel = in.readUTF();
|
||||
String message = in.readUTF();
|
||||
out.writeUTF("DiscordSRV");
|
||||
out.writeUTF(chatchannel);
|
||||
out.writeUTF(message);
|
||||
for(String send : getProxy().getServers().keySet()) {
|
||||
if(getProxy().getServers().get(send).getPlayers().size() > 0) {
|
||||
getProxy().getServers().get(send).sendData(MineverseChatBungee.PLUGIN_MESSAGING_CHANNEL, outstream.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(subchannel.equals("Chwho")) {
|
||||
String identifier = in.readUTF();
|
||||
if(identifier.equals("Get")) {
|
||||
|
@ -467,6 +467,7 @@ public class ChatListener implements Listener {
|
||||
MineverseChatPlayer mcp = event.getMineverseChatPlayer();
|
||||
ChatChannel channel = event.getChannel();
|
||||
Set<Player> recipients = event.getRecipients();
|
||||
String format = event.getFormat();
|
||||
String chat = event.getChat();
|
||||
String consoleChat = event.getConsoleChat();
|
||||
String globalJSON = event.getGlobalJSON();
|
||||
@ -512,17 +513,16 @@ public class ChatListener implements Listener {
|
||||
out.writeUTF(mcp.getUUID().toString());
|
||||
out.writeBoolean(mcp.getBungeeToggle());
|
||||
out.writeInt(hash);
|
||||
out.writeUTF(consoleChat);
|
||||
out.writeUTF(format);
|
||||
out.writeUTF(chat);
|
||||
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||
System.out.println(out.size() + " size bytes without json");
|
||||
}
|
||||
out.writeBoolean(true);
|
||||
out.writeUTF(globalJSON);
|
||||
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||
System.out.println(out.size() + " bytes size with json");
|
||||
}
|
||||
mcp.getPlayer().sendPluginMessage(plugin, MineverseChat.PLUGIN_MESSAGING_CHANNEL, byteOutStream.toByteArray());
|
||||
|
||||
out.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user