68 lines
2.3 KiB
Java
68 lines
2.3 KiB
Java
package de.jatitv.commandguiv2.Spigot.system;
|
|
|
|
import de.jatitv.commandguiv2.Spigot.Main;
|
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
|
|
import java.io.*;
|
|
|
|
public class Bungee_Sender_Reciver implements PluginMessageListener {
|
|
|
|
public static void sendToBungee(CommandSender sender, String information, Boolean console) {
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
DataOutputStream output = new DataOutputStream(stream);
|
|
try {
|
|
if (console) {
|
|
output.writeUTF("cgui-Console");
|
|
} else {
|
|
if (sender instanceof Player) {
|
|
output.writeUTF(sender.getName());
|
|
} else {
|
|
output.writeUTF("cgui-Console");
|
|
}
|
|
}
|
|
output.writeUTF(information);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (sender instanceof Player) {
|
|
Player player = (Player) sender;
|
|
player.sendPluginMessage(Main.plugin, "cgui:bungee", stream.toByteArray());
|
|
}else {
|
|
for(Player player : Bukkit.getOnlinePlayers()){
|
|
player.sendPluginMessage(Main.plugin, "cgui:bungee", stream.toByteArray());
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
|
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(message));
|
|
send.debug(Main.plugin,"stream: "+stream.toString());
|
|
try {
|
|
String subChannel = stream.readUTF();
|
|
String input = stream.readUTF();
|
|
send.debug(Main.plugin,"subChannel: " +subChannel);
|
|
send.debug(Main.plugin,"input: " +input);
|
|
switch (subChannel) {
|
|
case "join":
|
|
Main.bungeejoinplayers.add(input);
|
|
break;
|
|
case "left":
|
|
Main.bungeejoinplayers.remove(input);
|
|
break;
|
|
case "clear":
|
|
Main.bungeejoinplayers.clear();
|
|
break;
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|