mirror of
https://github.com/arcadiadevs/hubcore.git
synced 2024-11-22 06:15:14 +01:00
General improvements and fixes
This commit is contained in:
parent
68842155a0
commit
6c673a19bc
@ -11,12 +11,12 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
|
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
|
||||||
import os.arcadiadevs.playerservers.hubcore.utils.ColorUtils;
|
import os.arcadiadevs.playerservers.hubcore.utils.ChatUtil;
|
||||||
import os.arcadiadevs.playerservers.hubcore.utils.GUIUtils;
|
import os.arcadiadevs.playerservers.hubcore.utils.GUIUtils;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static os.arcadiadevs.playerservers.hubcore.utils.ColorUtils.translate;
|
import static os.arcadiadevs.playerservers.hubcore.utils.ChatUtil.translate;
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class ClickEvent implements Listener {
|
public class ClickEvent implements Listener {
|
||||||
@ -35,7 +35,6 @@ public class ClickEvent implements Listener {
|
|||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -46,22 +45,6 @@ public class ClickEvent implements Listener {
|
|||||||
if (e.getCurrentItem() != null && e.getCurrentItem().getItemMeta() != null
|
if (e.getCurrentItem() != null && e.getCurrentItem().getItemMeta() != null
|
||||||
&& e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(translate(PSHubCore.getInstance().getConfig().getString("compass-name"))))
|
&& e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(translate(PSHubCore.getInstance().getConfig().getString("compass-name"))))
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
||||||
else if (e.getView().getTitle().equalsIgnoreCase(translate("&aServer Selector"))) {
|
|
||||||
if (e.getCurrentItem() != null && e.getCurrentItem().getItemMeta() != null && e.getCurrentItem().getItemMeta().getLore() != null) {
|
|
||||||
if (e.getCurrentItem().getType() == XMaterial.EMERALD_BLOCK.parseMaterial()) {
|
|
||||||
String UUID = e.getCurrentItem().getItemMeta().getLore().get(1).split(" ")[1].replaceAll("§7", "");
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF("Connect");
|
|
||||||
out.writeUTF(UUID);
|
|
||||||
|
|
||||||
p.sendPluginMessage(PSHubCore.getInstance(), "BungeeCord", out.toByteArray());
|
|
||||||
e.getWhoClicked().closeInventory();
|
|
||||||
} else if (e.getCurrentItem().getType() == XMaterial.REDSTONE_BLOCK.parseMaterial())
|
|
||||||
p.sendMessage(ColorUtils.translate("&9PlayerServers> &7Oops, the server you tried to connect to is offline."));
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -13,7 +13,7 @@ import os.arcadiadevs.playerservers.hubcore.database.DataBase;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static os.arcadiadevs.playerservers.hubcore.utils.ColorUtils.translate;
|
import static os.arcadiadevs.playerservers.hubcore.utils.ChatUtil.translate;
|
||||||
|
|
||||||
public class JoinEvent implements Listener {
|
public class JoinEvent implements Listener {
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package os.arcadiadevs.playerservers.hubcore.utils;
|
||||||
|
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
|
||||||
|
|
||||||
|
public class BungeeUtil {
|
||||||
|
|
||||||
|
public static void connectPlayer(InventoryClickEvent event, Player player, String server) {
|
||||||
|
if (event.getCurrentItem().getType() == XMaterial.REDSTONE_BLOCK.parseMaterial()) {
|
||||||
|
player.sendMessage(ChatUtil.translate("&9PlayerServers> &7Oops, the server you tried to connect to is offline."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF("Connect");
|
||||||
|
out.writeUTF(server);
|
||||||
|
|
||||||
|
player.sendPluginMessage(PSHubCore.getInstance(), "BungeeCord", out.toByteArray());
|
||||||
|
event.getWhoClicked().closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,7 +2,7 @@ package os.arcadiadevs.playerservers.hubcore.utils;
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
public class ColorUtils {
|
public class ChatUtil {
|
||||||
|
|
||||||
public static String translate(String text) {
|
public static String translate(String text) {
|
||||||
return ChatColor.translateAlternateColorCodes('&', text);
|
return ChatColor.translateAlternateColorCodes('&', text);
|
@ -5,7 +5,6 @@ import com.samjakob.spigui.SGMenu;
|
|||||||
import com.samjakob.spigui.buttons.SGButton;
|
import com.samjakob.spigui.buttons.SGButton;
|
||||||
import com.samjakob.spigui.item.ItemBuilder;
|
import com.samjakob.spigui.item.ItemBuilder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
|
import os.arcadiadevs.playerservers.hubcore.PSHubCore;
|
||||||
import os.arcadiadevs.playerservers.hubcore.database.DataBase;
|
import os.arcadiadevs.playerservers.hubcore.database.DataBase;
|
||||||
@ -26,47 +25,65 @@ public class GUIUtils {
|
|||||||
final PingUtil pu = new PingUtil();
|
final PingUtil pu = new PingUtil();
|
||||||
final PSHubCore PSH = PSHubCore.getInstance();
|
final PSHubCore PSH = PSHubCore.getInstance();
|
||||||
|
|
||||||
final SGMenu menu = PSH.spiGUI.create(ChatColor.GREEN + "Server Selector " + ChatColor.GRAY + "(Page {currentPage}/{maxPage})", 5);
|
final SGMenu menu = PSH.spiGUI.create(ChatUtil.translate("&aServer Selector"), 5);
|
||||||
final Map<String, Object> map = PSH.multinode.getTable("servers").toMap();
|
final Map<String, Object> map = PSHubCore.getInstance().multinode.getTable("servers").toMap();
|
||||||
|
|
||||||
menu.setAutomaticPaginationEnabled(true);
|
menu.setAutomaticPaginationEnabled(true);
|
||||||
|
menu.setBlockDefaultInteractions(true);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PSH, () -> {
|
new Thread(() -> {
|
||||||
for (DBInfoStructure is : db.getServersInfo()) {
|
final var servers = db.getServersInfo();
|
||||||
if (pu.isOnline(PSH.getConfig().getBoolean("multi-node") ? map.get(is.getNode()).toString() : "127.0.0.1", is.getPort())) {
|
|
||||||
|
|
||||||
final PingInfoStructure pus = pu.getData(Integer.parseInt(is.getPort()));
|
// Sort servers by pu.isOnline(server)
|
||||||
|
servers.sort((s1, s2) -> {
|
||||||
|
final var pingUtil1 = new PingUtil(map.get(s1.getNode()).toString().split(" ")[0].replaceAll(":8080", ""), s1.getPort());
|
||||||
|
final var pingUtil2 = new PingUtil(map.get(s2.getNode()).toString().split(" ")[0].replaceAll(":8080", ""), s2.getPort());
|
||||||
|
|
||||||
menu.setButton(0, menu.getInventory().firstEmpty(), new SGButton(
|
final var p1 = pingUtil1.isOnline();
|
||||||
new ItemBuilder(Objects.requireNonNull(XMaterial.EMERALD_BLOCK.parseMaterial()))
|
final var p2 = pingUtil2.isOnline();
|
||||||
.name(translate("&a" + is.getPlayerName() + "'s server"))
|
|
||||||
.lore(
|
if (p1 && !p2) {
|
||||||
translate("&7UUID: &a" + is.getServerID().split("-")[0]),
|
return -1;
|
||||||
translate("&7Port: &a" + is.getPort()),
|
} else if (!p1 && p2) {
|
||||||
translate(String.format("&cOnline: &7%d/%d", pus.getOnline(), pus.getMax())),
|
return 1;
|
||||||
translate("&7MOTD: &a" + pus.getMOTD())
|
} else {
|
||||||
)
|
return 0;
|
||||||
.build()
|
}
|
||||||
));
|
});
|
||||||
}
|
|
||||||
|
servers.forEach(server -> {
|
||||||
|
final var pingUtil = new PingUtil(map.get(server.getNode()).toString().split(" ")[0].replaceAll(":8080", ""), server.getPort());
|
||||||
|
|
||||||
|
final var itemBuilder = new ItemBuilder(Objects.requireNonNull(
|
||||||
|
pingUtil.isOnline() ? XMaterial.EMERALD_BLOCK.parseMaterial() : XMaterial.REDSTONE_BLOCK.parseMaterial()
|
||||||
|
));
|
||||||
|
|
||||||
|
final ItemStack item;
|
||||||
|
|
||||||
|
if (pingUtil.isOnline()) {
|
||||||
|
item = itemBuilder
|
||||||
|
.name(ChatUtil.translate("&a" + server.getPlayerName() + "'s server"))
|
||||||
|
.lore(
|
||||||
|
ChatUtil.translate("&7UUID: &a" + server.getServerId().split("-")[0]),
|
||||||
|
ChatUtil.translate("&7Port: &a" + server.getPort()),
|
||||||
|
ChatUtil.translate(String.format("&7Online: &a%d/%d", pingUtil.getData().getOnline(), pingUtil.getData().getMax())),
|
||||||
|
ChatUtil.translate("&7MOTD: &a" + pingUtil.getData().getMOTD())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
} else {
|
||||||
|
item = itemBuilder
|
||||||
|
.name(ChatUtil.translate("&c" + server.getPlayerName() + "'s server"))
|
||||||
|
.lore(
|
||||||
|
ChatUtil.translate("&7UUID: &c" + server.getServerId().split("-")[0]),
|
||||||
|
ChatUtil.translate("&7Port: &c" + server.getPort())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (DBInfoStructure is : db.getServersInfo()) {
|
menu.setButton(0, menu.getInventory().firstEmpty(), new SGButton(item).withListener(listener -> BungeeUtil.connectPlayer(listener, player, server.getServerId())));
|
||||||
if (!pu.isOnline(PSH.getConfig().getBoolean("multi-node") ? map.get(is.getNode()).toString() : "127.0.0.1", is.getPort())) {
|
});
|
||||||
|
|
||||||
menu.setButton(0, menu.getInventory().firstEmpty(), new SGButton(
|
Bukkit.getScheduler().runTask(PSHubCore.getInstance(), () -> player.openInventory(menu.getInventory()));
|
||||||
new ItemBuilder(Objects.requireNonNull(XMaterial.REDSTONE_BLOCK.parseMaterial()))
|
}).start();
|
||||||
.name(translate("&c" + is.getPlayerName() + "'s server"))
|
|
||||||
.lore(
|
|
||||||
translate("&7Status: &cOffline"),
|
|
||||||
translate("&7UUID: &c" + is.getServerID().split("-")[0]),
|
|
||||||
translate("&7Port: &c" + is.getPort())
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTask(PSH, () -> player.openInventory(menu.getInventory()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user