Compare commits

...
2 Commits
Author SHA1 Message Date
Andre601 9feb3dfac6 Bump version 2024-10-02 13:43:45 +02:00
Andre601 5961d0dca0 Don't log errors when fetching servers (+ misc changes) 2024-10-02 13:43:05 +02:00
14 changed files with 95 additions and 56 deletions

No files matched your search

@@ -41,6 +41,7 @@ import com.alessiodp.libby.Library;
import de.myzelyam.api.vanish.BungeeVanishAPI;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
@@ -51,10 +52,14 @@ import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
public class BungeeCordCore extends Plugin implements PluginCore<Favicon>{
private final PluginLogger logger = new BungeeLogger(this);
private final Map<String, ServerPing> fetchedServers = new ConcurrentHashMap<>();
private boolean successfulLoad = false;
@@ -91,6 +96,7 @@ public class BungeeCordCore extends Plugin implements PluginCore<Favicon>{
@Override
public void onDisable(){
core.disable();
getProxy().getScheduler().cancel(this);
}
@Override
@@ -142,6 +148,11 @@ public class BungeeCordCore extends Plugin implements PluginCore<Favicon>{
libraryManager.loadLibrary(lib);
}
@Override
public void startScheduler(){
getProxy().getScheduler().schedule(this, this::fetchServers, 0, 10, TimeUnit.SECONDS);
}
@Override
public AdvancedServerList<Favicon> getCore(){
return core;
@@ -200,6 +211,10 @@ public class BungeeCordCore extends Plugin implements PluginCore<Favicon>{
return players.size();
}
public Map<String, ServerPing> getFetchedServers(){
return fetchedServers;
}
private boolean loadLibs(){
try{
if(libraryManager == null){
@@ -215,4 +230,14 @@ public class BungeeCordCore extends Plugin implements PluginCore<Favicon>{
return false;
}
}
private void fetchServers(){
fetchedServers.clear();
getProxy().getServers().forEach((name, server) -> server.ping((ping, throwable) -> {
if(throwable != null)
return;
fetchedServers.put(name, ping);
}));
}
}
@@ -10,20 +10,14 @@ import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
public class BungeeProxyPlaceholders extends PlaceholderProvider{
private final Map<String, ServerPing> serverStates = new ConcurrentHashMap<>();
private final BungeeCordCore plugin;
private BungeeProxyPlaceholders(BungeeCordCore plugin){
super("proxy");
this.plugin = plugin;
plugin.getProxy().getScheduler().schedule(plugin, this::fetchServerStates, 0, 10, TimeUnit.SECONDS);
}
public static BungeeProxyPlaceholders init(BungeeCordCore plugin){
@@ -36,7 +30,7 @@ public class BungeeProxyPlaceholders extends PlaceholderProvider{
if(args.length < 2)
return null;
ServerPing ping = serverStates.get(args[1]);
ServerPing ping = plugin.getFetchedServers().get(args[1]);
return switch(args[0]){
case "status" -> ping == null ? "offline" : "online";
@@ -64,16 +58,4 @@ public class BungeeProxyPlaceholders extends PlaceholderProvider{
default -> null;
};
}
private void fetchServerStates(){
serverStates.clear();
plugin.getProxy().getServers().forEach((name, server) -> server.ping((ping, throwable) -> {
if(throwable != null){
plugin.getPluginLogger().warn("Encountered an exception while fetching status of Server %s", throwable, name);
return;
}
serverStates.put(name, ping);
}));
}
}
@@ -177,6 +177,10 @@ public class AdvancedServerList<F>{
getPlugin().getPluginLogger().info("Loading bStats metrics. Disable it in the global config under /plugins/bstats/");
plugin.loadMetrics();
getPlugin().getPluginLogger().info("Metrics loaded!");
getPlugin().getPluginLogger().info("Enabling Schedulers...");
plugin.startScheduler();
getPlugin().getPluginLogger().info("Schedulers enabled.");
getPlugin().getPluginLogger().info("AdvancedServerList is ready!");
@@ -29,14 +29,14 @@ import java.util.Locale;
public abstract class PluginCommand{
private final String argument;
private final String name;
public PluginCommand(String argument){
this.argument = argument;
public PluginCommand(String name){
this.name = name;
}
public String name(){
return argument;
return name;
}
public String permission(){
@@ -46,6 +46,8 @@ public interface PluginCore<F>{
void downloadLibrary(String groupId, String artifactId, String version);
void startScheduler();
AdvancedServerList<F> getCore();
Path getFolderPath();
@@ -114,8 +114,6 @@ public class PlayerHandler{
}catch(IOException ex){
logger.warn("Encountered IOException while saving cached players to playercache.json!", ex);
}
}
public void addPlayer(String ip, String name, UUID uuid){
@@ -60,8 +60,19 @@ public class ProfileManager{
String maxPlayersCount = resolve(defEntry, entry, ProfileEntry::maxPlayersCount);
String onlinePlayersCount = resolve(defEntry, entry, ProfileEntry::onlinePlayersCount);
return new ProfileEntry(motd, players, playerCountText, favicon, hidePlayersEnabled, extraPlayersEnabled,
maxPlayersEnabled, onlinePlayersEnabled, extraPlayersCount, maxPlayersCount, onlinePlayersCount);
return new ProfileEntry.Builder()
.motd(motd)
.players(players)
.playerCountText(playerCountText)
.favicon(favicon)
.hidePlayersEnabled(hidePlayersEnabled)
.extraPlayersEnabled(extraPlayersEnabled)
.maxPlayersEnabled(maxPlayersEnabled)
.onlinePlayersEnabled(onlinePlayersEnabled)
.extraPlayersCount(extraPlayersCount)
.maxPlayersCount(maxPlayersCount)
.onlinePlayersCount(onlinePlayersCount)
.build();
}
public static ServerListProfile resolveProfile(AdvancedServerList<?> core, GenericPlayer player, GenericServer server){
@@ -149,6 +149,11 @@ public class PaperCore extends JavaPlugin implements PluginCore<CachedServerIcon
libraryManager.loadLibrary(lib);
}
@Override
public void startScheduler(){
// Unused
}
@Override
public AdvancedServerList<CachedServerIcon> getCore(){
return core;
+1 -1
View File
@@ -37,7 +37,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.version>5.0.2</plugin.version>
<plugin.version>5.0.3</plugin.version>
<plugin.description>Create multiple Server lists based on conditions.</plugin.description>
<api.version>4.0.0</api.version>
@@ -47,6 +47,8 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.scheduler.ScheduledTask;
import com.velocitypowered.api.util.Favicon;
import de.myzelyam.api.vanish.VelocityVanishAPI;
import org.bstats.charts.SimplePie;
@@ -59,10 +61,14 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
public class VelocityCore implements PluginCore<Favicon>{
private final Logger logger = LoggerFactory.getLogger("AdvancedServerList");
private final Map<String, ServerPing> fetchedServers = new ConcurrentHashMap<>();
private final PluginLogger pluginLogger;
private final ProxyServer proxy;
@@ -74,6 +80,8 @@ public class VelocityCore implements PluginCore<Favicon>{
private VelocityLibraryManager<VelocityCore> libraryManager = null;
private ScheduledTask scheduledTask = null;
@Inject
public VelocityCore(ProxyServer proxy, @DataDirectory Path path, Metrics.Factory metrics){
this.pluginLogger = new VelocityLogger(this, this.logger);
@@ -92,6 +100,8 @@ public class VelocityCore implements PluginCore<Favicon>{
@Subscribe
public void pluginDisable(ProxyShutdownEvent event){
core.disable();
if(scheduledTask != null)
scheduledTask.cancel();
}
@Override
@@ -147,6 +157,13 @@ public class VelocityCore implements PluginCore<Favicon>{
libraryManager.loadLibrary(lib);
}
@Override
public void startScheduler(){
scheduledTask = getProxy().getScheduler().buildTask(this, this::fetchServers)
.repeat(10, TimeUnit.SECONDS)
.schedule();
}
@Override
public AdvancedServerList<Favicon> getCore(){
return core;
@@ -210,4 +227,18 @@ public class VelocityCore implements PluginCore<Favicon>{
return players.size();
}
public Map<String, ServerPing> getFetchedServers(){
return fetchedServers;
}
private void fetchServers(){
fetchedServers.clear();
getProxy().getAllServers().forEach(server -> server.ping().whenComplete((ping, throwable) -> {
if(throwable != null)
return;
fetchedServers.put(server.getServerInfo().getName(), ping);
}));
}
}
@@ -7,22 +7,14 @@ import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.velocity.VelocityCore;
import com.velocitypowered.api.proxy.server.ServerPing;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class VelocityProxyPlaceholders extends PlaceholderProvider{
private final Map<String, ServerPing> serverStates = new ConcurrentHashMap<>();
private final VelocityCore plugin;
private VelocityProxyPlaceholders(VelocityCore plugin){
super("proxy");
this.plugin = plugin;
plugin.getProxy().getScheduler().buildTask(plugin, this::fetchServerStates)
.repeat(Duration.ofSeconds(10))
.schedule();
}
public static VelocityProxyPlaceholders init(VelocityCore plugin){
@@ -35,7 +27,7 @@ public class VelocityProxyPlaceholders extends PlaceholderProvider{
if(args.length < 2)
return null;
ServerPing ping = serverStates.get(args[1]);
ServerPing ping = plugin.getFetchedServers().get(args[1]);
return switch(args[0]){
case "status" -> ping == null ? "offline" : "online";
case "motd" -> {
@@ -67,16 +59,4 @@ public class VelocityProxyPlaceholders extends PlaceholderProvider{
default -> null;
};
}
private void fetchServerStates(){
serverStates.clear();
plugin.getProxy().getAllServers().forEach(server -> server.ping().whenComplete((ping, throwable) -> {
if(throwable != null){
plugin.getPluginLogger().warn("Encountered an exception while fetching status of Server %s", throwable, server.getServerInfo().getName());
return;
}
serverStates.put(server.getServerInfo().getName(), ping);
}));
}
}
@@ -53,7 +53,7 @@ public class VersionUploader{
if(args.length == 0){
LOGGER.warn("MISSING ARGUMENT!");
LOGGER.warn("COMMAND USAGE: java -jar VersionUploader.jar [--dryrun] --all | --modrinth | --hangar");
LOGGER.warn("COMMAND USAGE: java -jar VersionUploader.jar --all | --modrinth | --hangar [--dryrun]");
System.exit(1);
return;
}
@@ -84,7 +84,7 @@ public class VersionUploader{
}
default -> {
LOGGER.warn("Unknown argument '{}' provided.", args[0]);
LOGGER.warn("COMMAND USAGE: java -jar VersionUploader.jar [--dryrun] --all | --modrinth | --hangar");
LOGGER.warn("COMMAND USAGE: java -jar VersionUploader.jar --all | --modrinth | --hangar [--dryrun]");
System.exit(1);
return;
}
@@ -50,9 +50,9 @@ public class CodebergReleaseFetcher{
public static CodebergRelease fetch(){
String tag = System.getenv("CI_COMMIT_TAG");
String codbergToken = System.getenv("CODEBERG_API_TOKEN");
String codebergToken = System.getenv("CODEBERG_API_TOKEN");
if(tag == null || codbergToken == null || tag.isEmpty() || codbergToken.isEmpty()){
if(tag == null || codebergToken == null || tag.isEmpty() || codebergToken.isEmpty()){
LOGGER.warn("Cannot fetch release data. Either Tag or Codeberg token was null/empty.");
return null;
}
@@ -64,7 +64,7 @@ public class CodebergReleaseFetcher{
.url(url)
.header("User-Agent", "VersionUploader-CodebergReleaseFetcher/v1.0.0")
.header("Accept", "application/json")
.header("Authorization", "token " + codbergToken)
.header("Authorization", "token " + codebergToken)
.build();
try(Response response = CLIENT.newCall(request).execute()){
@@ -25,8 +25,8 @@
package ch.andre601.advancedserverlist.versionuploader.modrinth;
import ch.andre601.advancedserverlist.versionuploader.ReleaseHolder;
import ch.andre601.advancedserverlist.versionuploader.PlatformInfo;
import ch.andre601.advancedserverlist.versionuploader.ReleaseHolder;
import ch.andre601.advancedserverlist.versionuploader.VersionUploader;
import ch.andre601.advancedserverlist.versionuploader.data.CodebergRelease;
import com.google.gson.Gson;
@@ -143,7 +143,8 @@ public class ModrinthVersionUploader{
String url = versionUrl + projectVersion.getId();
logger.info("Created new release!");
logger.info("Link: {}", url);
logger.info("Link: {}", url);
logger.info("Platform: {}", platforms.get(index).getPlatform());
releaseHolder.addRelease(
"modrinth",