mirror of
https://github.com/arcadiadevs/hubcore.git
synced 2024-11-26 06:55:10 +01:00
Drastically optimized GUIs with effective cache
This commit is contained in:
parent
ce5e3193c8
commit
b2d909ea6a
9
pom.xml
9
pom.xml
@ -43,31 +43,26 @@
|
|||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>5.0.1</version>
|
<version>5.0.1</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.36</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.36</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.moandjiezana.toml</groupId>
|
<groupId>com.moandjiezana.toml</groupId>
|
||||||
<artifactId>toml4j</artifactId>
|
<artifactId>toml4j</artifactId>
|
||||||
<version>0.7.2</version>
|
<version>0.7.2</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cryptomorin</groupId>
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
<artifactId>XSeries</artifactId>
|
<artifactId>XSeries</artifactId>
|
||||||
<version>8.8.0</version>
|
<version>8.8.0</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
@ -83,8 +78,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<groupId>PlayerServersHubCore</groupId>
|
<groupId>PSHubCore</groupId>
|
||||||
<artifactId>PlayerServersHubCore</artifactId>
|
<artifactId>PSHubCore</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,11 +1,9 @@
|
|||||||
package os.arcadiadevs.playerservers.hubcore;
|
package os.arcadiadevs.playerservers.hubcore;
|
||||||
|
|
||||||
import com.moandjiezana.toml.Toml;
|
|
||||||
import com.samjakob.spigui.SpiGUI;
|
import com.samjakob.spigui.SpiGUI;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.Configuration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import os.arcadiadevs.playerservers.hubcore.commands.CommandManager;
|
import os.arcadiadevs.playerservers.hubcore.commands.CommandManager;
|
||||||
@ -19,7 +17,6 @@ import os.arcadiadevs.playerservers.hubcore.placeholders.PlayerCount;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -71,7 +68,7 @@ public class PSHubCore extends JavaPlugin {
|
|||||||
|
|
||||||
// Create ServerCache refreshing task
|
// Create ServerCache refreshing task
|
||||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
executor.scheduleAtFixedRate(serverCache, 1, getConfig().getInt("gui.selector.menu.cache-time"), TimeUnit.SECONDS);
|
executor.scheduleAtFixedRate(serverCache, 1, getConfig().getInt("cache-time"), TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMultiNodeConfig() throws IOException {
|
private void createMultiNodeConfig() throws IOException {
|
||||||
|
@ -23,8 +23,9 @@ public class Server {
|
|||||||
private String playerName;
|
private String playerName;
|
||||||
private String node;
|
private String node;
|
||||||
private Integer port;
|
private Integer port;
|
||||||
@Setter
|
|
||||||
private PingInfoStructure cachedData;
|
@Setter private PingInfoStructure cachedData;
|
||||||
|
@Setter private ServerStatus cachedStatus;
|
||||||
|
|
||||||
public String getShortId() {
|
public String getShortId() {
|
||||||
return serverId.split("-")[0];
|
return serverId.split("-")[0];
|
||||||
|
@ -28,7 +28,10 @@ public class ServerCache implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
servers.forEach(server -> server.setCachedData(server.getData()));
|
servers.forEach(server -> {
|
||||||
|
server.setCachedData(server.getData());
|
||||||
|
server.setCachedStatus(server.getServerStatus());
|
||||||
|
});
|
||||||
|
|
||||||
servers.sort((s1, s2) -> {
|
servers.sort((s1, s2) -> {
|
||||||
final var p1 = s1.getServerStatus() == ServerStatus.ONLINE;
|
final var p1 = s1.getServerStatus() == ServerStatus.ONLINE;
|
||||||
|
@ -32,30 +32,34 @@ public class GUIUtils {
|
|||||||
final var servers = PSHubCore.getInstance().getServerCache().getServers();
|
final var servers = PSHubCore.getInstance().getServerCache().getServers();
|
||||||
|
|
||||||
servers.forEach(server -> {
|
servers.forEach(server -> {
|
||||||
final var itemBuilder = new ItemBuilder(server.getServerStatus() == ServerStatus.ONLINE ? onlineXMaterial : offlineXMaterial);
|
final var itemBuilder = new ItemBuilder(server.getCachedStatus() == ServerStatus.ONLINE ? onlineXMaterial : offlineXMaterial);
|
||||||
|
|
||||||
var lore = PSH.getConfig().getStringList(server.getServerStatus() == ServerStatus.ONLINE ? "gui.selector.menu.online.lore" : "gui.selector.menu.offline.lore");
|
var lore = PSH.getConfig().getStringList(server.getCachedStatus() == ServerStatus.ONLINE ? "gui.selector.menu.online.lore" : "gui.selector.menu.offline.lore");
|
||||||
|
|
||||||
|
System.out.println("test1");
|
||||||
|
|
||||||
lore = lore.stream()
|
lore = lore.stream()
|
||||||
.map(s -> s.replaceAll("%server%", server.getPlayerName()))
|
.map(s -> s.replaceAll("%server%", server.getPlayerName()))
|
||||||
.map(s -> s.replaceAll("%status%", server.getServerStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
.map(s -> s.replaceAll("%status%", server.getCachedStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
||||||
.map(s -> s.replaceAll("%players%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0"))
|
.map(s -> s.replaceAll("%players%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0"))
|
||||||
.map(s -> s.replaceAll("%maxplayers%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0"))
|
.map(s -> s.replaceAll("%maxplayers%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0"))
|
||||||
.map(s -> s.replaceAll("%port%", server.getPort() + ""))
|
.map(s -> s.replaceAll("%port%", server.getPort() + ""))
|
||||||
.map(s -> s.replaceAll("%motd%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline"))
|
.map(s -> s.replaceAll("%motd%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline"))
|
||||||
.map(s -> s.replaceAll("%node%", server.getNode()))
|
.map(s -> s.replaceAll("%node%", server.getNode()))
|
||||||
.map(s -> s.replaceAll("%owner%", server.getPlayerName()))
|
.map(s -> s.replaceAll("%owner%", server.getPlayerName()))
|
||||||
.map(s -> s.replaceAll("%ip%", server.getHostname()))
|
.map(s -> s.replaceAll("%ip%", server.getHostname()))
|
||||||
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
|
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
|
||||||
|
|
||||||
|
System.out.println("test2");
|
||||||
|
|
||||||
var item = itemBuilder
|
var item = itemBuilder
|
||||||
.name(ChatUtil.translate(PSH.getConfig().getString(server.getServerStatus() == ServerStatus.ONLINE ? "gui.selector.menu.online.name" : "gui.selector.menu.offline.name")
|
.name(ChatUtil.translate(PSH.getConfig().getString(server.getCachedStatus() == ServerStatus.ONLINE ? "gui.selector.menu.online.name" : "gui.selector.menu.offline.name")
|
||||||
.replaceAll("%server%", server.getPlayerName())
|
.replaceAll("%server%", server.getPlayerName())
|
||||||
.replaceAll("%status%", server.getServerStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
.replaceAll("%status%", server.getCachedStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
||||||
.replaceAll("%players%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0")
|
.replaceAll("%players%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0")
|
||||||
.replaceAll("%maxplayers%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0")
|
.replaceAll("%maxplayers%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0")
|
||||||
.replaceAll("%port%", server.getPort() + "")
|
.replaceAll("%port%", server.getPort() + "")
|
||||||
.replaceAll("%motd%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline")
|
.replaceAll("%motd%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline")
|
||||||
.replaceAll("%node%", server.getNode())
|
.replaceAll("%node%", server.getNode())
|
||||||
.replaceAll("%owner%", server.getPlayerName())
|
.replaceAll("%owner%", server.getPlayerName())
|
||||||
.replaceAll("%ip%", server.getHostname())
|
.replaceAll("%ip%", server.getHostname())
|
||||||
@ -63,6 +67,8 @@ public class GUIUtils {
|
|||||||
.lore(lore)
|
.lore(lore)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
System.out.println("test3");
|
||||||
|
|
||||||
menu.setButton(0, menu.getInventory().firstEmpty(), new SGButton(item).withListener(listener -> BungeeUtil.connectPlayer(listener, player, server.getPlayerName())));
|
menu.setButton(0, menu.getInventory().firstEmpty(), new SGButton(item).withListener(listener -> BungeeUtil.connectPlayer(listener, player, server.getPlayerName())));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,22 +110,22 @@ public class GUIUtils {
|
|||||||
|
|
||||||
final var server = new Server(player);
|
final var server = new Server(player);
|
||||||
|
|
||||||
var lore = PSH.getConfig().getStringList(server.getServerStatus() == ServerStatus.ONLINE ? "gui.player-menu.menu.info.online.lore" : "gui.player-menu.menu.info.offline.lore");
|
var lore = PSH.getConfig().getStringList(server.getCachedStatus() == ServerStatus.ONLINE ? "gui.player-menu.menu.info.online.lore" : "gui.player-menu.menu.info.offline.lore");
|
||||||
|
|
||||||
lore = lore.stream()
|
lore = lore.stream()
|
||||||
.map(s -> s.replaceAll("%server%", server.getPlayerName()))
|
.map(s -> s.replaceAll("%server%", server.getPlayerName()))
|
||||||
.map(s -> s.replaceAll("%status%", server.getServerStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
.map(s -> s.replaceAll("%status%", server.getCachedStatus() == ServerStatus.ONLINE ? "&aOnline" : "&cOffline"))
|
||||||
.map(s -> s.replaceAll("%players%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0"))
|
.map(s -> s.replaceAll("%players%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getOnline() + "" : "0"))
|
||||||
.map(s -> s.replaceAll("%maxplayers%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0"))
|
.map(s -> s.replaceAll("%maxplayers%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMax() + "" : "0"))
|
||||||
.map(s -> s.replaceAll("%port%", server.getPort() + ""))
|
.map(s -> s.replaceAll("%port%", server.getPort() + ""))
|
||||||
.map(s -> s.replaceAll("%motd%", server.getServerStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline"))
|
.map(s -> s.replaceAll("%motd%", server.getCachedStatus() == ServerStatus.ONLINE ? server.getCachedData().getMOTD() : "&cOffline"))
|
||||||
.map(s -> s.replaceAll("%node%", server.getNode()))
|
.map(s -> s.replaceAll("%node%", server.getNode()))
|
||||||
.map(s -> s.replaceAll("%owner%", server.getPlayerName()))
|
.map(s -> s.replaceAll("%owner%", server.getPlayerName()))
|
||||||
.map(s -> s.replaceAll("%ip%", server.getHostname()))
|
.map(s -> s.replaceAll("%ip%", server.getHostname()))
|
||||||
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
|
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
|
||||||
|
|
||||||
final var itemPlayer = new ItemBuilder(XMaterial.OAK_SIGN.parseMaterial())
|
final var itemPlayer = new ItemBuilder(XMaterial.OAK_SIGN.parseMaterial())
|
||||||
.name(ChatUtil.translate(PSH.getConfig().getString(server.getServerStatus() == ServerStatus.ONLINE ? "gui.player-menu.menu.info.online.name" : "gui.player-menu.menu.info.offline.name")
|
.name(ChatUtil.translate(PSH.getConfig().getString(server.getCachedStatus() == ServerStatus.ONLINE ? "gui.player-menu.menu.info.online.name" : "gui.player-menu.menu.info.offline.name")
|
||||||
.replaceAll("%server%", server.getPlayerName())))
|
.replaceAll("%server%", server.getPlayerName())))
|
||||||
.lore(lore)
|
.lore(lore)
|
||||||
.build();
|
.build();
|
||||||
@ -139,7 +145,7 @@ public class GUIUtils {
|
|||||||
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.delete.confirmation.decline.lore"))
|
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.delete.confirmation.decline.lore"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (server.getServerStatus() == ServerStatus.ONLINE) {
|
if (server.getCachedStatus() == ServerStatus.ONLINE) {
|
||||||
final var itemJoin = new ItemBuilder(XMaterial.OAK_DOOR.parseMaterial())
|
final var itemJoin = new ItemBuilder(XMaterial.OAK_DOOR.parseMaterial())
|
||||||
.name(ChatUtil.translate(PSH.getConfig().getString("gui.player-menu.menu.join.name")))
|
.name(ChatUtil.translate(PSH.getConfig().getString("gui.player-menu.menu.join.name")))
|
||||||
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.join.lore"))
|
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.join.lore"))
|
||||||
@ -162,7 +168,7 @@ public class GUIUtils {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.getServerStatus() == ServerStatus.OFFLINE) {
|
if (server.getCachedStatus() == ServerStatus.OFFLINE) {
|
||||||
final var itemStart = new ItemBuilder(XMaterial.EMERALD_BLOCK.parseMaterial())
|
final var itemStart = new ItemBuilder(XMaterial.EMERALD_BLOCK.parseMaterial())
|
||||||
.name(ChatUtil.translate(PSH.getConfig().getString("gui.player-menu.menu.start.name")))
|
.name(ChatUtil.translate(PSH.getConfig().getString("gui.player-menu.menu.start.name")))
|
||||||
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.start.lore"))
|
.lore(PSH.getConfig().getStringList("gui.player-menu.menu.start.lore"))
|
||||||
|
Loading…
Reference in New Issue
Block a user