mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2025-01-20 21:21:37 +01:00
Smarter packetevents updating, and lets not be so urgent about updating
This commit is contained in:
parent
8027652ea1
commit
39565991f1
@ -14,7 +14,7 @@ net-kyori-adventure-text-serializer-gson = "4.17.0"
|
||||
net-kyori-adventure-text-serializer-json = "4.17.0"
|
||||
net-md-v5-bungeecord-chat = "1.16-R0.4"
|
||||
org-spigotmc-spigot-latest = "1.21-R0.1-SNAPSHOT"
|
||||
com-retro-packetevents-version = "2.4.0"
|
||||
com-retro-packetevents-version = "2.5.0-SNAPSHOT"
|
||||
lombok-version = "1.18.34"
|
||||
shadow-version = "8.1.1"
|
||||
junit-version = "4.13.2"
|
||||
|
@ -459,8 +459,6 @@ public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
getLogger().severe("!! May I have your attention please !!");
|
||||
|
||||
if (isPacketEventsUpdateDownloaded()) {
|
||||
getLogger().severe(
|
||||
"An update for PacketEvents has been downloaded and will be installed when the server restarts. When possible, " +
|
||||
@ -472,12 +470,6 @@ public class LibsDisguises extends JavaPlugin {
|
||||
getLogger().severe("https://www.spigotmc.org/resources/packetevents-api.80279/");
|
||||
getLogger().severe("Or! Use /ld packetevents - To have Lib's Disguises download the latest release from Modrinth");
|
||||
}
|
||||
|
||||
if (timesRun++ > 0) {
|
||||
getLogger().severe("This message is on repeat due to the sheer number of people who don't see this.");
|
||||
}
|
||||
|
||||
getLogger().severe("!! May I have your attention please !!");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2912,18 +2912,17 @@ public class DisguiseUtilities {
|
||||
public static void sendPacketEventsUpdateMessage(CommandSender p, String version, String requiredPacketEvents) {
|
||||
// If we already automatically updated PE
|
||||
if (LibsDisguises.getInstance().isPacketEventsUpdateDownloaded()) {
|
||||
// No need to be urgent about it if server uptime is less than a day and player is not an op
|
||||
if (!p.isOp() && LibsDisguises.getInstance().getServerStarted() + TimeUnit.DAYS.toMillis(1) > System.currentTimeMillis()) {
|
||||
return;
|
||||
}
|
||||
// If they are an op, give a 12 hour grace period
|
||||
if (p.isOp() && LibsDisguises.getInstance().getServerStarted() + TimeUnit.HOURS.toMillis(12) > System.currentTimeMillis()) {
|
||||
/*// Grace period of an absurd value, because some people leave the servers up this long
|
||||
int daysGracePeriod = p.isOp() ? 14 : 31;
|
||||
|
||||
// If the grace period hasn't elapsed since server startup, don't send any messages
|
||||
if (LibsDisguises.getInstance().getServerStarted() + TimeUnit.DAYS.toMillis(daysGracePeriod) > System.currentTimeMillis()) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(ChatColor.RED +
|
||||
"Please ask the server owner to restart the server, an update for PacketEvents has been downloaded and is pending a " +
|
||||
"server restart to install.");
|
||||
"[LibsDisguises] Please ask the server owner to restart the server, an update for PacketEvents has been downloaded and is pending a " +
|
||||
"server restart to install.");*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise.utilities.updates;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.util.PEVersions;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
@ -24,6 +25,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.security.CodeSource;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -56,14 +58,29 @@ public class PacketEventsUpdater {
|
||||
* Returns the min required version, as in any older version will just not work.
|
||||
*/
|
||||
public static String getMinimumPacketEventsVersion() {
|
||||
// Unfortunately PacketEvents does not have build info, so we'll hope you are using the latest snapshot if we fallback to that
|
||||
// Edit, it now includes build time which we'll use at a later point in the future
|
||||
|
||||
// At time of writing, release is 2.4.0, and snapshot builds are all "2.5.0-SNAPSHOT"
|
||||
// This means we'll always fail a release check!
|
||||
return "2.5.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* PacketEvents must have a build timestamp of this or more recent
|
||||
*/
|
||||
public static Instant getMinimumPacketEventsBuildTimestamp() {
|
||||
// As taken from the most recent packetevents compiled jar
|
||||
return Instant.ofEpochMilli(1723957995204L);
|
||||
}
|
||||
|
||||
public static boolean isPacketEventsOutdated(Instant requiredTime) {
|
||||
try {
|
||||
return PEVersions.BUILD_TIMESTAMP.isBefore(requiredTime);
|
||||
} catch (Throwable ignored) {
|
||||
// If error is thrown, then the field is missing and we're definitely outdated
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isNotBukkitPlugin(String name) {
|
||||
return !name.toLowerCase(Locale.ENGLISH).matches(".*(bukkit|spigot|paper).*");
|
||||
}
|
||||
@ -330,6 +347,7 @@ public class PacketEventsUpdater {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isOlderThan(PacketEventsUpdater.getMinimumPacketEventsVersion(), packetEventsVersion);
|
||||
return isOlderThan(PacketEventsUpdater.getMinimumPacketEventsVersion(), packetEventsVersion) ||
|
||||
isPacketEventsOutdated(getMinimumPacketEventsBuildTimestamp());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user