Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.warfight.api.utils.bungee;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.ConnectException;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import org.bukkit.entity.Player;
- import com.google.common.io.ByteArrayDataOutput;
- import com.google.common.io.ByteStreams;
- import fr.warfight.api.API;
- /**
- * @author MrJuiceboy
- */
- public class BungeeUtils
- {
- private static API pl;
- public BungeeUtils(final API pl)
- {
- BungeeUtils.pl = pl;
- pl.getServer().getMessenger().registerOutgoingPluginChannel(pl, "BungeeCord");
- }
- public static void sendPlayer(Player p, String server)
- {
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(b);
- try
- {
- out.writeUTF("Connect");
- out.writeUTF(server);
- }catch(IOException eee){}
- p.sendPluginMessage(pl, "BungeeCord", b.toByteArray());
- }
- public static Object getCountPlayerBungeeServer(String server) {
- if (server == null) {
- server = "ALL";
- }
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF("PlayerCount");
- out.writeUTF(server);
- return server;
- }
- public static Object getCountPlayerServer(String ip, int port) {
- String returnString = null;
- try {
- Socket socket = new Socket();
- socket.setSoTimeout(100);
- socket.connect(new InetSocketAddress(ip, port), 1 * 1000);
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- DataInputStream in = new DataInputStream(socket.getInputStream());
- out.write(0xFE);
- StringBuilder str = new StringBuilder();
- int b;
- while ((b = in.read()) != -1){
- if (b != 0 && b > 16 && b != 255 && b != 23 && b != 24){
- str.append((char) b);
- }
- }
- socket.close();
- String[] data = str.toString().split("§");
- return Integer.parseInt(data[1]);
- } catch (ConnectException e) {
- returnString = "§4N/A§6";
- } catch (UnknownHostException e) {
- returnString = "§4N/A§6";
- } catch (IOException e) {
- returnString = "§4N/A§6";
- }
- return returnString;
- }
- public static String getMotdServer(String ip, int port) {
- String returnString = null;
- try {
- Socket socket = new Socket();
- socket.setSoTimeout(100);
- socket.connect(new InetSocketAddress(ip, port), 1 * 1000);
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- DataInputStream in = new DataInputStream(socket.getInputStream());
- out.write(0xFE);
- int b;
- StringBuffer str = new StringBuffer();
- while ((b = in .read()) != -1) {
- if (b != 0 && b > 16 && b != 255 && b != 23 && b != 24) {
- str.append((char) b);
- }
- }
- String[] data = str.toString().split("§");
- String serverMotd = data[0];
- returnString = String.format(serverMotd);
- socket.close();
- } catch (ConnectException e) {
- returnString = "§c§lHors Ligne";
- } catch (UnknownHostException e) {
- returnString = "§c§lHors Ligne";
- } catch (IOException e) {
- returnString = "§c§lHors Ligne";
- }
- return returnString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement