mirror of
https://github.com/unmojang/OnlineModeFix.git
synced 2025-09-09 23:41:24 -04:00
Added server icons.
This commit is contained in:
parent
1743e725c4
commit
d0e65c9031
@ -1,5 +1,5 @@
|
|||||||
name: MineOnlineBroadcast
|
name: MineOnlineBroadcast
|
||||||
version: 1.1.0
|
version: 1.1.1
|
||||||
description: Lists a server on mineonline.codie.gg/servers
|
description: Lists a server on mineonline.codie.gg/servers
|
||||||
author: codieradical
|
author: codieradical
|
||||||
authors: [Codie]
|
authors: [Codie]
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
import gg.codie.common.input.EColorCodeColor;
|
import gg.codie.common.input.EColorCodeColor;
|
||||||
import gg.codie.minecraft.server.MinecraftColorCodeProvider;
|
import gg.codie.minecraft.server.MinecraftColorCodeProvider;
|
||||||
|
import gg.codie.mineonline.api.MineOnlineAPI;
|
||||||
import gg.codie.mineonline.discord.DiscordChatBridge;
|
import gg.codie.mineonline.discord.DiscordChatBridge;
|
||||||
import gg.codie.mineonline.discord.IMessageRecievedListener;
|
import gg.codie.mineonline.discord.IMessageRecievedListener;
|
||||||
import gg.codie.mineonline.discord.IShutdownListener;
|
import gg.codie.mineonline.discord.IShutdownListener;
|
||||||
import gg.codie.mineonline.discord.MinotarAvatarProvider;
|
import gg.codie.mineonline.discord.MinotarAvatarProvider;
|
||||||
import gg.codie.mineonline.plugin.ProxyThread;
|
import gg.codie.mineonline.plugin.ProxyThread;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import javax.imageio.IIOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -16,7 +21,9 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -35,6 +42,7 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
boolean initialized;
|
boolean initialized;
|
||||||
String serverName = "Minecraft Server";
|
String serverName = "Minecraft Server";
|
||||||
private MineOnlineConfig mineOnlineConfig;
|
private MineOnlineConfig mineOnlineConfig;
|
||||||
|
String serverUUID;
|
||||||
|
|
||||||
public void launchProxy() throws IOException {
|
public void launchProxy() throws IOException {
|
||||||
ServerSocket serverSocket = new ServerSocket(0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
@ -83,81 +91,6 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
return result.toUpperCase();
|
return result.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void listServer(
|
|
||||||
String ip,
|
|
||||||
String port,
|
|
||||||
int users,
|
|
||||||
int maxUsers,
|
|
||||||
String name,
|
|
||||||
boolean onlineMode,
|
|
||||||
String md5,
|
|
||||||
boolean whitelisted,
|
|
||||||
String[] playerNames,
|
|
||||||
String motd,
|
|
||||||
boolean dontListPlayers,
|
|
||||||
boolean useBetaEvolutionsAuth
|
|
||||||
) {
|
|
||||||
HttpURLConnection connection = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{MineOnlineBroadcast.class.getProtectionDomain().getCodeSource().getLocation()});
|
|
||||||
|
|
||||||
Class jsonObjectClass = classLoader.loadClass("org.json.JSONObject");
|
|
||||||
|
|
||||||
Constructor jsonObjectConstructor = jsonObjectClass.getConstructor();
|
|
||||||
Method jsonObjectPut = jsonObjectClass.getMethod("put", String.class, Object.class);
|
|
||||||
Method jsonObjectToString = jsonObjectClass.getMethod("toString");
|
|
||||||
|
|
||||||
Object jsonObject = jsonObjectConstructor.newInstance();
|
|
||||||
if (ip != null)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "ip", ip);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "port", port);
|
|
||||||
if (users > -1 && !dontListPlayers)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "users", users);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "max", maxUsers);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "name", name);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "onlinemode", onlineMode);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "md5", md5);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "whitelisted", whitelisted);
|
|
||||||
if (!dontListPlayers)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "players", playerNames);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "motd", motd);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "dontListPlayers", dontListPlayers);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "useBetaEvolutionsAuth", useBetaEvolutionsAuth);
|
|
||||||
|
|
||||||
String json = (String) jsonObjectToString.invoke(jsonObject);
|
|
||||||
|
|
||||||
URL url = new URL("https://mineonline.codie.gg/api/servers");
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
connection.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
|
||||||
connection.getOutputStream().flush();
|
|
||||||
connection.getOutputStream().close();
|
|
||||||
|
|
||||||
InputStream is = connection.getInputStream();
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
|
||||||
|
|
||||||
StringBuilder response = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
response.append(line);
|
|
||||||
response.append('\r');
|
|
||||||
}
|
|
||||||
rd.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
@ -208,7 +141,27 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
|
|
||||||
String[] playerNames = etc.getServer().getPlayerList().stream().map(player -> player.getName()).collect(Collectors.toList()).toArray(new String[users]);
|
String[] playerNames = etc.getServer().getPlayerList().stream().map(player -> player.getName()).collect(Collectors.toList()).toArray(new String[users]);
|
||||||
|
|
||||||
listServer(
|
String serverIcon = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedImage serverIconBufferedImage = ImageIO.read(new File(System.getProperty("user.dir") + File.separator + "server-icon.png"));
|
||||||
|
if (serverIconBufferedImage.getHeight() <= 64 && serverIconBufferedImage.getWidth() <= 64) {
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
ImageIO.write(serverIconBufferedImage, "png", bos);
|
||||||
|
byte[] bytes = bos.toByteArray();
|
||||||
|
Base64.Encoder encoder = Base64.getEncoder();
|
||||||
|
serverIcon = encoder.encodeToString(bytes);
|
||||||
|
serverIcon = serverIcon.replace(System.lineSeparator(), "");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IIOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
serverUUID = MineOnlineAPI.listServer(
|
||||||
ip,
|
ip,
|
||||||
port,
|
port,
|
||||||
users,
|
users,
|
||||||
@ -220,10 +173,11 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
playerNames,
|
playerNames,
|
||||||
motd,
|
motd,
|
||||||
dontListPlayers,
|
dontListPlayers,
|
||||||
useBetaEvolutionsAuth
|
useBetaEvolutionsAuth,
|
||||||
|
serverIcon
|
||||||
);
|
);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
//ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
// ignore.
|
// ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,7 +217,6 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
String discordWebhookURL = mineOnlineConfig.getConfigString("discord-webhook-url");
|
String discordWebhookURL = mineOnlineConfig.getConfigString("discord-webhook-url");
|
||||||
serverName = mineOnlineConfig.getConfigString("server-name");
|
serverName = mineOnlineConfig.getConfigString("server-name");
|
||||||
|
|
||||||
|
|
||||||
if (discordToken != null && discordChannelID != null) { // Create the discord bot if token and channel are present
|
if (discordToken != null && discordChannelID != null) { // Create the discord bot if token and channel are present
|
||||||
discord = new DiscordChatBridge(new MinotarAvatarProvider(), discordChannelID, discordToken, discordWebhookURL, new IMessageRecievedListener() {
|
discord = new DiscordChatBridge(new MinotarAvatarProvider(), discordChannelID, discordToken, discordWebhookURL, new IMessageRecievedListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -350,6 +303,14 @@ public class MineOnlineBroadcast extends Plugin {
|
|||||||
if (!initialized)
|
if (!initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (serverUUID != null) {
|
||||||
|
try {
|
||||||
|
MineOnlineAPI.deleteServerListing(serverUUID);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unregister();
|
unregister();
|
||||||
if (discord != null)
|
if (discord != null)
|
||||||
discord.shutdown();
|
discord.shutdown();
|
||||||
|
119
src/gg/codie/mineonline/api/MineOnlineAPI.java
Normal file
119
src/gg/codie/mineonline/api/MineOnlineAPI.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package gg.codie.mineonline.api;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class MineOnlineAPI {
|
||||||
|
public static void deleteServerListing(String uuid) throws IOException {
|
||||||
|
HttpURLConnection connection;
|
||||||
|
|
||||||
|
URL url = new URL("https://mineonline.codie.gg/api/servers/" + uuid);
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("DELETE");
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
if (connection != null)
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String listServer(
|
||||||
|
String ip,
|
||||||
|
String port,
|
||||||
|
int users,
|
||||||
|
int maxUsers,
|
||||||
|
String name,
|
||||||
|
boolean onlineMode,
|
||||||
|
String md5,
|
||||||
|
boolean whitelisted,
|
||||||
|
String[] playerNames,
|
||||||
|
String motd,
|
||||||
|
boolean dontListPlayers,
|
||||||
|
boolean useBetaEvolutionsAuth,
|
||||||
|
String serverIcon
|
||||||
|
) {
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
URLClassLoader classLoader = new URLClassLoader(new URL[]{MineOnlineAPI.class.getProtectionDomain().getCodeSource().getLocation()});
|
||||||
|
|
||||||
|
Class jsonObjectClass = classLoader.loadClass("org.json.JSONObject");
|
||||||
|
|
||||||
|
Constructor jsonObjectConstructor = jsonObjectClass.getConstructor();
|
||||||
|
Method jsonObjectPut = jsonObjectClass.getMethod("put", String.class, Object.class);
|
||||||
|
Method jsonObjectHas = jsonObjectClass.getMethod("has", String.class);
|
||||||
|
Method jsonObjectGetString = jsonObjectClass.getMethod("getString", String.class);
|
||||||
|
Method jsonObjectToString = jsonObjectClass.getMethod("toString");
|
||||||
|
|
||||||
|
Object jsonObject = jsonObjectConstructor.newInstance();
|
||||||
|
if (ip != null)
|
||||||
|
jsonObjectPut.invoke(jsonObject, "ip", ip);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "port", port);
|
||||||
|
if (users > -1 && !dontListPlayers)
|
||||||
|
jsonObjectPut.invoke(jsonObject, "users", users);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "max", maxUsers);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "name", name);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "onlinemode", onlineMode);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "md5", md5.toUpperCase());
|
||||||
|
jsonObjectPut.invoke(jsonObject, "whitelisted", whitelisted);
|
||||||
|
if (!dontListPlayers)
|
||||||
|
jsonObjectPut.invoke(jsonObject, "players", playerNames);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "motd", motd);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "dontListPlayers", dontListPlayers);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "useBetaEvolutionsAuth", useBetaEvolutionsAuth);
|
||||||
|
jsonObjectPut.invoke(jsonObject, "serverIcon", serverIcon);
|
||||||
|
|
||||||
|
String json = (String) jsonObjectToString.invoke(jsonObject);
|
||||||
|
|
||||||
|
URL url = new URL("https://mineonline.codie.gg/api/servers");
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
connection.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
||||||
|
connection.getOutputStream().flush();
|
||||||
|
connection.getOutputStream().close();
|
||||||
|
|
||||||
|
InputStream is = connection.getInputStream();
|
||||||
|
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
response.append('\r');
|
||||||
|
}
|
||||||
|
rd.close();
|
||||||
|
|
||||||
|
|
||||||
|
jsonObjectConstructor = jsonObjectClass.getConstructor(String.class);
|
||||||
|
|
||||||
|
Object resObject = jsonObjectConstructor.newInstance(response.toString());
|
||||||
|
if ((boolean)jsonObjectHas.invoke(resObject, "uuid")) {
|
||||||
|
return (String)jsonObjectGetString.invoke(resObject, "uuid");
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
if (connection != null)
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package gg.codie.mineonline.plugin.bukkit;
|
|||||||
|
|
||||||
import gg.codie.common.input.EColorCodeColor;
|
import gg.codie.common.input.EColorCodeColor;
|
||||||
import gg.codie.minecraft.server.MinecraftColorCodeProvider;
|
import gg.codie.minecraft.server.MinecraftColorCodeProvider;
|
||||||
|
import gg.codie.mineonline.api.MineOnlineAPI;
|
||||||
import gg.codie.mineonline.discord.DiscordChatBridge;
|
import gg.codie.mineonline.discord.DiscordChatBridge;
|
||||||
import gg.codie.mineonline.discord.IMessageRecievedListener;
|
import gg.codie.mineonline.discord.IMessageRecievedListener;
|
||||||
import gg.codie.mineonline.discord.IShutdownListener;
|
import gg.codie.mineonline.discord.IShutdownListener;
|
||||||
@ -12,16 +13,14 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import javax.imageio.IIOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -36,6 +35,7 @@ public class MineOnlineBroadcastPlugin extends JavaPlugin {
|
|||||||
ProxyThread proxyThread;
|
ProxyThread proxyThread;
|
||||||
DiscordChatBridge discord;
|
DiscordChatBridge discord;
|
||||||
private MineOnlineConfig mineOnlineConfig;
|
private MineOnlineConfig mineOnlineConfig;
|
||||||
|
String serverUUID;
|
||||||
|
|
||||||
public void launchProxy() throws IOException {
|
public void launchProxy() throws IOException {
|
||||||
ServerSocket serverSocket = new ServerSocket(0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
@ -74,79 +74,6 @@ public class MineOnlineBroadcastPlugin extends JavaPlugin {
|
|||||||
return complete.digest();
|
return complete.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void listServer(
|
|
||||||
String ip,
|
|
||||||
String port,
|
|
||||||
int users,
|
|
||||||
int maxUsers,
|
|
||||||
String name,
|
|
||||||
boolean onlineMode,
|
|
||||||
String md5,
|
|
||||||
boolean whitelisted,
|
|
||||||
String[] playerNames,
|
|
||||||
String motd,
|
|
||||||
boolean dontListPlayers,
|
|
||||||
boolean useBetaEvolutionsAuth
|
|
||||||
) {
|
|
||||||
HttpURLConnection connection = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{MineOnlineBroadcastPlugin.class.getProtectionDomain().getCodeSource().getLocation()});
|
|
||||||
|
|
||||||
Class jsonObjectClass = classLoader.loadClass("org.json.JSONObject");
|
|
||||||
|
|
||||||
Constructor jsonObjectConstructor = jsonObjectClass.getConstructor();
|
|
||||||
Method jsonObjectPut = jsonObjectClass.getMethod("put", String.class, Object.class);
|
|
||||||
Method jsonObjectToString = jsonObjectClass.getMethod("toString");
|
|
||||||
|
|
||||||
Object jsonObject = jsonObjectConstructor.newInstance();
|
|
||||||
if (ip != null)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "ip", ip);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "port", port);
|
|
||||||
if (users > -1 && !dontListPlayers)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "users", users);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "max", maxUsers);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "name", name);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "onlinemode", onlineMode);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "md5", md5);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "whitelisted", whitelisted);
|
|
||||||
if (!dontListPlayers)
|
|
||||||
jsonObjectPut.invoke(jsonObject, "players", playerNames);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "motd", motd);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "dontListPlayers", dontListPlayers);
|
|
||||||
jsonObjectPut.invoke(jsonObject, "useBetaEvolutionsAuth", useBetaEvolutionsAuth);
|
|
||||||
|
|
||||||
String json = (String) jsonObjectToString.invoke(jsonObject);
|
|
||||||
|
|
||||||
URL url = new URL("https://mineonline.codie.gg/api/servers");
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
connection.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
|
|
||||||
connection.getOutputStream().flush();
|
|
||||||
connection.getOutputStream().close();
|
|
||||||
|
|
||||||
InputStream is = connection.getInputStream();
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
|
|
||||||
|
|
||||||
StringBuilder response = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
response.append(line);
|
|
||||||
response.append('\r');
|
|
||||||
}
|
|
||||||
rd.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (connection != null)
|
|
||||||
connection.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
initialize();
|
initialize();
|
||||||
@ -189,7 +116,27 @@ public class MineOnlineBroadcastPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
String[] playerNames = Arrays.stream(getServer().getOnlinePlayers()).map(Player::getName).collect(Collectors.toList()).toArray(new String[users]);
|
String[] playerNames = Arrays.stream(getServer().getOnlinePlayers()).map(Player::getName).collect(Collectors.toList()).toArray(new String[users]);
|
||||||
|
|
||||||
listServer(
|
String serverIcon = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedImage serverIconBufferedImage = ImageIO.read(new File(System.getProperty("user.dir") + File.separator + "server-icon.png"));
|
||||||
|
if (serverIconBufferedImage.getHeight() <= 64 && serverIconBufferedImage.getWidth() <= 64) {
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
ImageIO.write(serverIconBufferedImage, "png", bos);
|
||||||
|
byte[] bytes = bos.toByteArray();
|
||||||
|
Base64.Encoder encoder = Base64.getEncoder();
|
||||||
|
serverIcon = encoder.encodeToString(bytes);
|
||||||
|
serverIcon = serverIcon.replace(System.lineSeparator(), "");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IIOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
serverUUID = MineOnlineAPI.listServer(
|
||||||
ip,
|
ip,
|
||||||
port,
|
port,
|
||||||
users,
|
users,
|
||||||
@ -201,7 +148,8 @@ public class MineOnlineBroadcastPlugin extends JavaPlugin {
|
|||||||
playerNames,
|
playerNames,
|
||||||
motd,
|
motd,
|
||||||
dontListPlayers,
|
dontListPlayers,
|
||||||
useBetaEvolutionsAuth
|
useBetaEvolutionsAuth,
|
||||||
|
serverIcon
|
||||||
);
|
);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// ignore.
|
// ignore.
|
||||||
@ -308,14 +256,16 @@ public class MineOnlineBroadcastPlugin extends JavaPlugin {
|
|||||||
this.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, this.listener, Event.Priority.Highest, this);
|
this.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, this.listener, Event.Priority.Highest, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void unregister() {
|
|
||||||
// if(registeredListener != null)
|
|
||||||
// etc.getLoader().removeListener(registeredListener);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
//unregister();
|
if (serverUUID != null) {
|
||||||
|
try {
|
||||||
|
MineOnlineAPI.deleteServerListing(serverUUID);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (discord != null)
|
if (discord != null)
|
||||||
discord.shutdown();
|
discord.shutdown();
|
||||||
broadcastThread.interrupt();
|
broadcastThread.interrupt();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user