diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/Quests.java | 31 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/updater/Updater.java | 34 |
2 files changed, 39 insertions, 26 deletions
diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java index 7f5df19e..c2f9ac99 100644 --- a/src/main/java/com/leonardobishop/quests/Quests.java +++ b/src/main/java/com/leonardobishop/quests/Quests.java @@ -77,22 +77,33 @@ import java.util.ArrayList; public class Quests extends JavaPlugin { private static Quests instance; - private static Updater updater; + /** Handles anything to do with loaded quests */ private QuestManager questManager; - private QPlayerManager qPlayerManager; + /** Handles anything to do with task types */ private TaskTypeManager taskTypeManager; + /** Handles anything to do with players */ + private QPlayerManager qPlayerManager; + /** Checks and records ready plugin updates */ + private Updater updater; + /** Abstract title handle to allow for cross version compatibility */ private Title titleHandle; + /** Abstract item handle to allow for cross version compatibility */ private ItemGetter itemGetter; + /** Task which checks quests and marks them as complete if requirements are satisfied */ private QuestCompleter questCompleter; + /** Loads configurations and tracks errors */ private QuestsConfigLoader questsConfigLoader; + /** Quests logger to allow for configurable logging levels */ private QuestsLogger questsLogger; + /** Handles menu tracking and clicks */ private MenuController menuController; private IPlaceholderAPIHook placeholderAPIHook; private ICoreProtectHook coreProtectHook; + /** If true, the plugin should be inoperable */ private boolean brokenConfig = false; private BukkitTask questAutosaveTask; private BukkitTask questQueuePollTask; @@ -160,8 +171,8 @@ public class Quests extends JavaPlugin { qPlayerManager = new QPlayerManager(this); menuController = new MenuController(this); - dataGenerator(); - setupVersionSpecific(); + this.generateConfigurations(); + this.setupVersionSpecific(); Bukkit.getPluginCommand("quests").setExecutor(new CommandQuests(this)); Bukkit.getPluginManager().registerEvents(new EventPlayerJoin(this), this); @@ -266,7 +277,7 @@ public class Quests extends JavaPlugin { } catch (Throwable ignored) { } - updater = new Updater(this); + updater = new Updater(this, !ignoreUpdates); if (!ignoreUpdates) { Bukkit.getScheduler().runTaskAsynchronously(this, () -> { updater.check(); @@ -316,9 +327,7 @@ public class Quests extends JavaPlugin { } } if (autosaveTaskCancelled) { - questAutosaveTask = Bukkit.getScheduler().runTaskTimer(this, () -> { - new QuestsAutosaveRunnable(this); - }, autosaveInterval, autosaveInterval); + questAutosaveTask = Bukkit.getScheduler().runTaskTimer(this, () -> new QuestsAutosaveRunnable(this), autosaveInterval, autosaveInterval); } boolean queuePollTaskCancelled = true; @@ -386,7 +395,7 @@ public class Quests extends JavaPlugin { } } - private void dataGenerator() { + private void generateConfigurations() { File directory = new File(String.valueOf(this.getDataFolder())); if (!directory.exists() && !directory.isDirectory()) { directory.mkdir(); @@ -396,7 +405,6 @@ public class Quests extends JavaPlugin { if (!config.exists()) { try { config.createNewFile(); - //try (InputStream in = Quests.class.getClassLoader().getResourceAsStream("config.yml")) { try (InputStream in = this.getResource("config.yml")) { OutputStream out = new FileOutputStream(config); byte[] buffer = new byte[1024]; @@ -405,7 +413,6 @@ public class Quests extends JavaPlugin { out.write(buffer, 0, lenght); lenght = in.read(buffer); } - //ByteStreams.copy(in, out); BETA method, data losses ahead } catch (IOException e) { e.printStackTrace(); } @@ -432,7 +439,6 @@ public class Quests extends JavaPlugin { File file = new File(this.getDataFolder() + File.separator + "quests" + File.separator + name); try { file.createNewFile(); - //try (InputStream in = Quests.class.getClassLoader().getResourceAsStream("quests/" + name)) { try (InputStream in = this.getResource("quests/" + name)) { OutputStream out = new FileOutputStream(file); byte[] buffer = new byte[1024]; @@ -441,7 +447,6 @@ public class Quests extends JavaPlugin { out.write(buffer, 0, lenght); lenght = in.read(buffer); } - //ByteStreams.copy(in, out); BETA method, data losses ahead } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/com/leonardobishop/quests/updater/Updater.java b/src/main/java/com/leonardobishop/quests/updater/Updater.java index 5fa1a7e5..6bd28b49 100644 --- a/src/main/java/com/leonardobishop/quests/updater/Updater.java +++ b/src/main/java/com/leonardobishop/quests/updater/Updater.java @@ -14,46 +14,54 @@ import java.util.concurrent.TimeUnit; public class Updater { private static final int PROJECT_ID = 23696; - private final String installedVersion; private final Quests plugin; + private final boolean enabled; private String returnedVersion; private URL api; private boolean updateReady; private long lastCheck; - public Updater(Quests plugin) { + public Updater(Quests plugin, boolean enabled) { this.plugin = plugin; this.installedVersion = plugin.getDescription().getVersion(); + this.enabled = enabled; try { - this.api = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + PROJECT_ID); - } catch (MalformedURLException ignored) { - // shit + fan - } + this.api = new URL(getApiUrl()); + } catch (MalformedURLException ignored) { } } - public String getLink() { + public String getUpdateLink() { return "https://www.spigotmc.org/resources/" + PROJECT_ID; } + + public String getApiUrl() { + return "https://api.spigotmc.org/legacy/update.php?resource=" + PROJECT_ID; + } - public boolean check() { + public void check() { + if (!enabled) { + return; + } + // stop users from spamming the command and making needless requests if (lastCheck != 0 && TimeUnit.MINUTES.convert(System.currentTimeMillis() - lastCheck, TimeUnit.MILLISECONDS) < 10) { - return updateReady; + return; } try { lastCheck = System.currentTimeMillis(); URLConnection con = api.openConnection(); returnedVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); if (!returnedVersion.equals(installedVersion)) { - plugin.getQuestsLogger().info("A new version " + returnedVersion + " was found on Spigot (your version: " + installedVersion + "). Please update me! <3 - Link: " + getLink()); + plugin.getQuestsLogger().info("A new version " + returnedVersion + " was found on Spigot (your version: " + installedVersion + "). Please update me! <3 - Link: " + getUpdateLink()); updateReady = true; + } else { + updateReady = false; } } catch (IOException e) { - plugin.getQuestsLogger().warning("Failed to check for updates. You can check manually at " + getLink()); + plugin.getQuestsLogger().warning("Failed to check for updates. You can check manually at " + getUpdateLink()); // probably offline } - return false; } public boolean isUpdateReady() { @@ -61,6 +69,6 @@ public class Updater { } public String getMessage() { - return Messages.QUEST_UPDATER.getMessage().replace("{newver}", returnedVersion).replace("{oldver}", installedVersion).replace("{link}", getLink()); + return Messages.QUEST_UPDATER.getMessage().replace("{newver}", returnedVersion).replace("{oldver}", installedVersion).replace("{link}", getUpdateLink()); } }
\ No newline at end of file |
