mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 09:37:37 +00:00
Add caching to the updater
This commit is contained in:
parent
bbb41aa052
commit
bb92805fa5
@ -10,7 +10,6 @@ import dev.plex.PlexBase;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@ -7,7 +7,6 @@ import dev.morphia.query.experimental.filters.Filters;
|
|||||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL fetching utilities for players
|
* SQL fetching utilities for players
|
||||||
|
@ -35,7 +35,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||||
send(sender, mmString("<light_purple>Built by: <gold>" + Plex.build.author + " <light_purple>on <gold>" + Plex.build.date));
|
send(sender, mmString("<light_purple>Built by: <gold>" + Plex.build.author + " <light_purple>on <gold>" + Plex.build.date));
|
||||||
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||||
plugin.getUpdateChecker().getUpdateStatusMessage(sender);
|
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("reload"))
|
if (args[0].equalsIgnoreCase("reload"))
|
||||||
|
@ -3,7 +3,6 @@ package dev.plex.module;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.module.exception.ModuleLoadException;
|
import dev.plex.module.exception.ModuleLoadException;
|
||||||
//import dev.plex.module.loader.CustomClassLoader;
|
|
||||||
import dev.plex.module.loader.LibraryLoader;
|
import dev.plex.module.loader.LibraryLoader;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -7,8 +7,6 @@ import dev.plex.listener.PlexListener;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
//import dev.plex.module.loader.CustomClassLoader;
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package dev.plex.module;
|
package dev.plex.module;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class PlexModuleFile
|
public class PlexModuleFile
|
||||||
|
@ -4,6 +4,20 @@ import com.google.common.collect.Lists;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
import dev.plex.module.PlexModuleFile;
|
import dev.plex.module.PlexModuleFile;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||||
import org.eclipse.aether.RepositorySystem;
|
import org.eclipse.aether.RepositorySystem;
|
||||||
@ -29,18 +43,6 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
//TODO: doesn't work
|
//TODO: doesn't work
|
||||||
|
|
||||||
public class LibraryLoader {
|
public class LibraryLoader {
|
||||||
|
@ -17,7 +17,7 @@ public class UpdateCheckerService extends AbstractService
|
|||||||
{
|
{
|
||||||
if (!newVersion)
|
if (!newVersion)
|
||||||
{
|
{
|
||||||
if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender()))
|
if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender(), false))
|
||||||
{
|
{
|
||||||
newVersion = true;
|
newVersion = true;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,16 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
public class UpdateChecker extends PlexBase
|
public class UpdateChecker extends PlexBase
|
||||||
{
|
{
|
||||||
private static final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Plex/";
|
/*
|
||||||
|
* -4 = Never checked for updates
|
||||||
|
* -3 = Likely rate limited
|
||||||
|
* -2 = Unknown commit
|
||||||
|
* -1 = Error occurred
|
||||||
|
* 0 = Up to date
|
||||||
|
* > 0 = Number of commits behind
|
||||||
|
*/
|
||||||
|
private final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Plex/";
|
||||||
|
private int distance = -4;
|
||||||
|
|
||||||
// Adapted from Paper
|
// Adapted from Paper
|
||||||
private int fetchDistanceFromGitHub(@Nonnull String repo, @Nonnull String branch, @Nonnull String hash)
|
private int fetchDistanceFromGitHub(@Nonnull String repo, @Nonnull String branch, @Nonnull String hash)
|
||||||
@ -31,6 +40,10 @@ public class UpdateChecker extends PlexBase
|
|||||||
{
|
{
|
||||||
return -2; // Unknown commit
|
return -2; // Unknown commit
|
||||||
}
|
}
|
||||||
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN)
|
||||||
|
{
|
||||||
|
return -3; // Rate limited likely
|
||||||
|
}
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8)))
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8)))
|
||||||
{
|
{
|
||||||
JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
|
JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
|
||||||
@ -55,10 +68,27 @@ public class UpdateChecker extends PlexBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUpdateStatusMessage(CommandSender sender)
|
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached)
|
||||||
|
{
|
||||||
|
// If it's -4, it hasn't checked for updates yet
|
||||||
|
if (distance == -4)
|
||||||
{
|
{
|
||||||
int distance;
|
|
||||||
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
|
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
|
||||||
|
PlexLog.debug("Never checked for updates, checking now...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the request isn't asked to be cached, fetch it
|
||||||
|
if (!cached)
|
||||||
|
{
|
||||||
|
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
|
||||||
|
PlexLog.debug("We have checked for updates before, but this request was not asked to be cached.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexLog.debug("We have checked for updates before, using cache.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (distance)
|
switch (distance)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user