mirror of
https://github.com/arcadiadevs/hubcore.git
synced 2024-11-25 06:45:11 +01:00
Fixes
This commit is contained in:
parent
3a938c8e61
commit
9ed2083928
@ -121,10 +121,7 @@ public class PsHubCore extends JavaPlugin {
|
||||
|
||||
// Initialize ServerCache
|
||||
serverCache = new ServerCache(serversController);
|
||||
|
||||
// Create ServerCache refreshing task
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(serverCache, 1, getConfig().getInt("cache.cache-time"), TimeUnit.SECONDS);
|
||||
serverCache.runTaskTimerAsynchronously(this, 0, getConfig().getLong("cache.cache-time") * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,20 +1,23 @@
|
||||
package os.arcadiadevs.playerservers.hubcore.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import os.arcadiadevs.playerservers.hubcore.controllers.ServersController;
|
||||
import os.arcadiadevs.playerservers.hubcore.models.CachedServer;
|
||||
|
||||
public class ServerCache implements Runnable {
|
||||
public class ServerCache extends BukkitRunnable {
|
||||
|
||||
@Getter
|
||||
private final HashSet<CachedServer> servers;
|
||||
private final List<CachedServer> servers;
|
||||
|
||||
private final ServersController serversController;
|
||||
|
||||
public ServerCache(ServersController serversController) {
|
||||
this.serversController = serversController;
|
||||
this.servers = new HashSet<>();
|
||||
this.servers = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ public class SelectorGui {
|
||||
menu.setAutomaticPaginationEnabled(true);
|
||||
menu.setBlockDefaultInteractions(true);
|
||||
|
||||
final var servers = useCache
|
||||
var servers = useCache
|
||||
?
|
||||
PsHubCore.getInstance()
|
||||
.getServerCache()
|
||||
@ -48,9 +48,7 @@ public class SelectorGui {
|
||||
.getServersController()
|
||||
.getServers();
|
||||
|
||||
List<Server> filteredServers = new ArrayList<>(servers);
|
||||
|
||||
filteredServers.sort(Comparator.comparing(s -> {
|
||||
servers.sort(Comparator.comparing(s -> {
|
||||
final ServerPinger.PingResult info = s.getInfo();
|
||||
if (info == null || info.status() != ServerStatus.ONLINE) {
|
||||
return 1;
|
||||
@ -58,15 +56,11 @@ public class SelectorGui {
|
||||
return 0;
|
||||
}));
|
||||
|
||||
List<Server> filteredServersByPlayers = new ArrayList<>(filteredServers);
|
||||
if (instance.getConfig().getBoolean("gui.selector.menu.sort-by-players")) {
|
||||
servers.sort(Comparator.comparing(s -> s.getInfo().players() != null ? -s.getInfo().players() : 0));
|
||||
}
|
||||
|
||||
filteredServersByPlayers.sort(Comparator.comparing(s -> s.getInfo().players() != null ? -s.getInfo().players() : 0));
|
||||
|
||||
final var serversPage = instance.getConfig().getBoolean("gui.selector.menu.sort-by-players")
|
||||
? filteredServersByPlayers
|
||||
: filteredServers;
|
||||
|
||||
serversPage.forEach(server -> {
|
||||
servers.forEach(server -> {
|
||||
final var onlinexMaterial =
|
||||
XMaterial.matchXMaterial(instance.getConfig().getString("gui.selector.menu.online.block"))
|
||||
.orElse(XMaterial.PLAYER_HEAD).parseItem();
|
||||
|
Loading…
Reference in New Issue
Block a user