StatusAPI/src/main/java/net/viper/status/UpdateListener.java gelöscht
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
package net.viper.status;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Listener: Benachrichtigt OP-Spieler beim Login, falls ein Update bekannt ist oder führt
|
||||
* asynchronen Einzelcheck durch und benachrichtigt den Spieler danach.
|
||||
*/
|
||||
public class UpdateListener implements Listener {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final UpdateChecker checker;
|
||||
private final String[] notifyPerms = new String[] { "statusapi.update.notify", "statusapi.notify", "bungeecord.command.alert" };
|
||||
|
||||
public UpdateListener(Plugin plugin, UpdateChecker checker) {
|
||||
this.plugin = plugin;
|
||||
this.checker = checker;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
// Only notify players with the notify permission(s)
|
||||
boolean hasPerm = false;
|
||||
for (String perm : notifyPerms) {
|
||||
if (player.hasPermission(perm)) { hasPerm = true; break; }
|
||||
}
|
||||
if (!hasPerm) return;
|
||||
|
||||
String currentVersion = plugin.getDescription() != null ? plugin.getDescription().getVersion() : "0.0.0";
|
||||
|
||||
// If we already have a cached update and it's newer -> notify immediately
|
||||
if (checker.isUpdateAvailable(currentVersion)) {
|
||||
String lv = checker.getLatestVersion();
|
||||
String url = checker.getLatestUrl();
|
||||
player.sendMessage(new TextComponent("§6[StatusAPI] §eNeue Version verfügbar: §a" + lv));
|
||||
player.sendMessage(new TextComponent("§eDownload: §b" + url));
|
||||
return;
|
||||
}
|
||||
|
||||
// No cached update yet -> run an async check for this player and notify if found
|
||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
|
||||
// perform network call
|
||||
checker.checkNow();
|
||||
|
||||
if (checker.isUpdateAvailable(currentVersion)) {
|
||||
String lv = checker.getLatestVersion();
|
||||
String url = checker.getLatestUrl();
|
||||
|
||||
// ensure player is still online before sending message
|
||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(player.getUniqueId());
|
||||
if (p != null) {
|
||||
p.sendMessage(new TextComponent("§6[StatusAPI] §eNeue Version verfügbar: §a" + lv));
|
||||
p.sendMessage(new TextComponent("§eDownload: §b" + url));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user