mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-29 05:36:13 +01:00
Use old Gson location if needed
This commit is contained in:
parent
cc88e6b6ea
commit
7f94e2115e
@ -1,12 +1,12 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -1053,6 +1053,13 @@ public class YAMLSection {
|
||||
* @return JSON
|
||||
*/
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(get(), Map.class);
|
||||
try {
|
||||
Class<?> gson = Class.forName(((Util.getDespiteException(() -> Class.forName("com.google.gson.Gson") != null, false)?"":"org.bukkit.craftbukkit.libs.")) + "com.google.gson.Gson");
|
||||
//Class<?> gson = com.google.gson.Gson.class;
|
||||
return (String) gson.getMethod("toJson", Object.class, Type.class).invoke(gson.newInstance(), get(), Map.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Encryption;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
@ -270,11 +270,11 @@ public final class AES implements net.ME1312.SubServers.Client.Bukkit.Network.Ci
|
||||
* @param data Encrypted Data Array
|
||||
* @return JSON Data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("deprecation")
|
||||
public YAMLSection decrypt(String key, byte[] data) throws Exception {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
decrypt(key, new ByteArrayInputStream(data), bytes);
|
||||
return new YAMLSection(new Gson().fromJson(new String(bytes.toByteArray(), StandardCharsets.UTF_8), Map.class));
|
||||
return new YAMLSection(SubAPI.getInstance().getInternals().parseJSON(new String(bytes.toByteArray(), StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
@ -66,8 +64,8 @@ public final class SubDataClient {
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection decrypt(String key, byte[] data) {
|
||||
return new YAMLSection(new Gson().fromJson(new String(data, StandardCharsets.UTF_8), Map.class));
|
||||
public YAMLSection decrypt(String key, byte[] data) throws Exception {
|
||||
return new YAMLSection(plugin.parseJSON(new String(data, StandardCharsets.UTF_8)));
|
||||
}
|
||||
};
|
||||
|
||||
@ -144,14 +142,18 @@ public final class SubDataClient {
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (JsonParseException | YAMLException e) {
|
||||
new IllegalPacketException("Unknown Packet Format: " + input).printStackTrace();
|
||||
} catch (IllegalPacketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
Class<?> gsone = Class.forName(((Util.getDespiteException(() -> Class.forName("com.google.gson.JsonParseException") != null, false)?"":"org.bukkit.craftbukkit.libs.")) + "com.google.gson.JsonParseException");
|
||||
//Class<?> gsone = com.google.gson.JsonParseException.class;
|
||||
if (e instanceof YAMLException || gsone.isInstance(e)) {
|
||||
new IllegalPacketException("Unknown Packet Format: " + input).printStackTrace();
|
||||
} else {
|
||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
|
@ -1,29 +1,22 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.VersionType;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
@ -61,7 +54,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage("");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
YAMLSection tags = new YAMLSection(plugin.parseJSON("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
|
||||
List<Version> versions = new LinkedList<Version>();
|
||||
|
||||
Version updversion = plugin.version;
|
||||
@ -86,69 +79,69 @@ public final class SubCommand implements CommandExecutor {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
if (Util.getDespiteException(() -> Class.forName("org.spigotmc.SpigotConfig") != null, false) && sender instanceof Player) {
|
||||
net.md_5.bungee.api.chat.TextComponent div = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Command.List.Divider"));
|
||||
if (sender instanceof Player) {
|
||||
TextComponent div = new TextComponent(plugin.api.getLang("SubServers", "Command.List.Divider"));
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Group-Header"));
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
List<net.md_5.bungee.api.chat.TextComponent> hoverm = new LinkedList<net.md_5.bungee.api.chat.TextComponent>();
|
||||
net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(" ");
|
||||
net.md_5.bungee.api.chat.TextComponent message = new net.md_5.bungee.api.chat.TextComponent(group);
|
||||
net.md_5.bungee.api.chat.TextComponent hover = new net.md_5.bungee.api.chat.TextComponent(group + '\n');
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
TextComponent message = new TextComponent(group);
|
||||
TextComponent hover = new TextComponent(group + '\n');
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.GOLD);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GOLD);
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getKeys().size())));
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open Server 1 " + group));
|
||||
message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()])));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open Server 1 " + group));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
msg.addExtra(message);
|
||||
msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
hoverm = new LinkedList<net.md_5.bungee.api.chat.TextComponent>();
|
||||
message = new net.md_5.bungee.api.chat.TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display"));
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display") + '\n');
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display"));
|
||||
hover = new TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display") + '\n');
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getKeys().contains("enabled")) {
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server));
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n');
|
||||
hover = new TextComponent(server + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())) + '\n');
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())) + '\n');
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n');
|
||||
hover = new TextComponent(server + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n');
|
||||
hover = new TextComponent(server + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
} else {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n');
|
||||
hover = new TextComponent(server + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
}
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() != 0) {
|
||||
@ -158,42 +151,42 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("groups").getSection(group).getSection(server).getList("incompatible").get(ii).asString();
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled"))?"":"\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled"))?"":"\n"));
|
||||
}
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled")) {
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address"));
|
||||
} else {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]);
|
||||
}
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server));
|
||||
} else {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("servers").getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address"));
|
||||
} else {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]);
|
||||
}
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()])));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
if (i != 0) msg.addExtra(div);
|
||||
msg.addExtra(message);
|
||||
i++;
|
||||
}
|
||||
if (i == 0) msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
if (i == 0) msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
((Player) sender).spigot().sendMessage(msg);
|
||||
i = 0;
|
||||
sent = true;
|
||||
@ -203,85 +196,85 @@ public final class SubCommand implements CommandExecutor {
|
||||
}
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Host-Header"));
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
List<net.md_5.bungee.api.chat.TextComponent> hoverm = new LinkedList<net.md_5.bungee.api.chat.TextComponent>();
|
||||
net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(" ");
|
||||
net.md_5.bungee.api.chat.TextComponent message = new net.md_5.bungee.api.chat.TextComponent(data.getSection("hosts").getSection(host).getString("display"));
|
||||
net.md_5.bungee.api.chat.TextComponent hover = new net.md_5.bungee.api.chat.TextComponent(data.getSection("hosts").getSection(host).getString("display") + '\n');
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
TextComponent message = new TextComponent(data.getSection("hosts").getSection(host).getString("display"));
|
||||
TextComponent hover = new TextComponent(data.getSection("hosts").getSection(host).getString("display") + '\n');
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(host + '\n');
|
||||
hover = new TextComponent(host + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getKeys().size())));
|
||||
} else {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
hoverm.add(hover);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(host + '\n');
|
||||
hover = new TextComponent(host + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled"));
|
||||
}
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("hosts").getSection(host).getString("address"));
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getString("address"));
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
}
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open Host/ " + host));
|
||||
message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()])));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open Host/ " + host));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
msg.addExtra(message);
|
||||
msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
hoverm = new LinkedList<net.md_5.bungee.api.chat.TextComponent>();
|
||||
message = new net.md_5.bungee.api.chat.TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"));
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display") + '\n');
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + subserver));
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"));
|
||||
hover = new TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display") + '\n');
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + subserver));
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(subserver + '\n');
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())) + '\n');
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())) + '\n');
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GREEN);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(subserver + '\n');
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(subserver + '\n');
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
} else {
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.RED);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(subserver + '\n');
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
}
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() != 0) {
|
||||
@ -291,52 +284,52 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").get(ii).asString();
|
||||
}
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled"))?"":"\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled"))?"":"\n"));
|
||||
}
|
||||
if (!data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled")) {
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address"));
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address"));
|
||||
} else {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":").length - 1]);
|
||||
}
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + subserver));
|
||||
message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()])));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + subserver));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
if (i != 0) msg.addExtra(div);
|
||||
msg.addExtra(message);
|
||||
i++;
|
||||
}
|
||||
if (i == 0) msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
if (i == 0) msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
((Player) sender).spigot().sendMessage(msg);
|
||||
i = 0;
|
||||
sent = true;
|
||||
}
|
||||
if (!sent) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Server-Header"));
|
||||
net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(" ");
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
List<net.md_5.bungee.api.chat.TextComponent> hoverm = new LinkedList<net.md_5.bungee.api.chat.TextComponent>();
|
||||
net.md_5.bungee.api.chat.TextComponent message = new net.md_5.bungee.api.chat.TextComponent(data.getSection("servers").getSection(server).getString("display"));
|
||||
net.md_5.bungee.api.chat.TextComponent hover = new net.md_5.bungee.api.chat.TextComponent(data.getSection("servers").getSection(server).getString("display") + '\n');
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent message = new TextComponent(data.getSection("servers").getSection(server).getString("display"));
|
||||
TextComponent hover = new TextComponent(data.getSection("servers").getSection(server).getString("display") + '\n');
|
||||
message.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("servers").getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address"));
|
||||
} else {
|
||||
hover = new net.md_5.bungee.api.chat.TextComponent('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]);
|
||||
}
|
||||
hover.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()])));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
if (i != 0) msg.addExtra(div);
|
||||
msg.addExtra(message);
|
||||
i++;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.InternalUIHandler;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLConfig;
|
||||
@ -10,17 +9,11 @@ import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.VersionType;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Cipher;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
@ -76,7 +69,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
config = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
|
||||
if (new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client").exists()) {
|
||||
FileReader reader = new FileReader(new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client"));
|
||||
config.get().getSection("Settings").set("SubData", new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class)));
|
||||
config.get().getSection("Settings").set("SubData", new YAMLSection(parseJSON(Util.readAll(reader))));
|
||||
config.save();
|
||||
reader.close();
|
||||
new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client").delete();
|
||||
@ -95,7 +88,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
new Metrics(this);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
try {
|
||||
YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
YAMLSection tags = new YAMLSection(parseJSON("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
|
||||
List<Version> versions = new LinkedList<Version>();
|
||||
|
||||
Version updversion = version;
|
||||
@ -111,7 +104,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
if (updcount > 0) Bukkit.getLogger().info("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||
} catch (Exception e) {}
|
||||
}, 0, TimeUnit.DAYS.toSeconds(2) * 20);
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -162,4 +155,22 @@ public final class SubPlugin extends JavaPlugin {
|
||||
}
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use reflection to access Gson for parsing
|
||||
*
|
||||
* @param json JSON to parse
|
||||
* @return JSON as a map
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, ?> parseJSON(String json) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException {
|
||||
Class<?> gson = Class.forName(((Util.getDespiteException(() -> Class.forName("com.google.gson.Gson") != null, false)?"":"org.bukkit.craftbukkit.libs.")) + "com.google.gson.Gson");
|
||||
//Class<?> gson = com.google.gson.Gson.class;
|
||||
return (Map<String, ?>) gson.getMethod("fromJson", String.class, Class.class).invoke(gson.newInstance(), json, Map.class);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user