From efb2388cd83efef2aa964f62c70cba61d5dc9f4d Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Tue, 23 Jun 2020 20:35:43 +0200
Subject: [PATCH] 9.0.0-SNAPSHOT1
---
CHANGELOG.md | 4 +
TODO.md | 4 +-
pom.xml | 17 ++-
.../jeff_media/ChestSort/ChestSortPlugin.java | 20 +--
.../ChestSort/ChestSortUpdateChecker.java | 122 ------------------
src/main/resources/plugin.yml | 2 +-
6 files changed, 30 insertions(+), 139 deletions(-)
delete mode 100644 src/main/java/de/jeff_media/ChestSort/ChestSortUpdateChecker.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b3a8f8..a282281 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,8 @@
# Changelog
+## 9.0.0-SNAPSHOT1
+- Using new universal Update (https://github.com/JEFF-Media-GbR/Spigot-UpdateChecker)
+- TODO: InvUnload integration (see TODO.md)
+
## 8.10.5
- Added reload command (/chestsort reload) with permission chestsort.reload
- ChestSort checks if Minepacks version is recent enough and, if not, disable the Minepacks hook.
diff --git a/TODO.md b/TODO.md
index a51cc84..79b4f5b 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,6 +1,6 @@
# Todo
-## Minepacks API check
-When using Minepacks, check if version is 2.3.8 or later and otherwise disable the hook
+## InvUnload integration
+Use InvUnload API to only put matching stuff into the chest when using left-click hotkey. On second click, everything is put into the chest.
## StackableItems
Make it configurable whether ItemStacks > 64 items will stay unsorted, or sorted and reverted back to stacks of 64 items
diff --git a/pom.xml b/pom.xml
index be51d41..e5c42b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
JeffChestSort
https://www.chestsort.de
Automatically sorts your chests!
- 8.10.5
+ 9.0.0-SNAPSHOT1
jar
@@ -87,6 +87,10 @@
pcgf-repo
https://repo.pcgamingfreaks.at/repository/maven-everything
+
+ jeff-media-gbr
+ https://repo.jeff-media.de/maven2
+
@@ -114,6 +118,17 @@
Minepacks-API
2.3.8
+
+ de.jeff_media
+ PluginUpdateChecker
+ 1.0
+
+
+ de.jeff_media
+ InvUnload
+ 4.2.0-SNAPSHOT3
+ compile
+
diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java
index 3e58bb9..fd912ae 100644
--- a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java
+++ b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java
@@ -42,6 +42,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
+import de.jeff_media.PluginUpdateChecker.PluginUpdateChecker;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -60,8 +61,7 @@ public class ChestSortPlugin extends JavaPlugin {
Map perPlayerSettings = new HashMap();
ChestSortMessages messages;
ChestSortOrganizer organizer;
- ChestSortUpdateChecker updateChecker;
- Integer updateCheckerTask;
+ PluginUpdateChecker updateChecker;
ChestSortListener listener;
ChestSortSettingsGUI settingsGUI;
ChestSortPermissionsHandler permissionsHandler;
@@ -417,8 +417,8 @@ public class ChestSortPlugin extends JavaPlugin {
if(reload) {
unregisterAllPlayers();
reloadConfig();
- if(updateCheckerTask != null) {
- getServer().getScheduler().cancelTask(updateCheckerTask);
+ if(updateChecker != null) {
+ updateChecker.stop();
}
}
@@ -448,7 +448,7 @@ public class ChestSortPlugin extends JavaPlugin {
messages = new ChestSortMessages(this);
organizer = new ChestSortOrganizer(this);
settingsGUI = new ChestSortSettingsGUI(this);
- updateChecker = new ChestSortUpdateChecker(this);
+ updateChecker = new PluginUpdateChecker(this, "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt", "https://chestsort.de", "https://chestsort.de/changelog", "https://chestsort.de/donate");
listener = new ChestSortListener(this);
api = new ChestSortAPI(this);
permissionsHandler = new ChestSortPermissionsHandler(this);
@@ -491,16 +491,10 @@ public class ChestSortPlugin extends JavaPlugin {
}
if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("true")) {
- updateCheckerTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- updateChecker.checkForUpdate();
- }
- }, 0L, updateCheckInterval * 20);
-
+ updateChecker.check(updateCheckInterval);
} // When set to on-startup, we check right now (delay 0)
else if (getConfig().getString("check-for-updates", "true").equalsIgnoreCase("on-startup")) {
- updateChecker.checkForUpdate();
+ updateChecker.check();
}
registerMetrics();
diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortUpdateChecker.java b/src/main/java/de/jeff_media/ChestSort/ChestSortUpdateChecker.java
deleted file mode 100644
index 60113ba..0000000
--- a/src/main/java/de/jeff_media/ChestSort/ChestSortUpdateChecker.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package de.jeff_media.ChestSort;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.function.Consumer;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitRunnable;
-import org.bukkit.scheduler.BukkitTask;
-
-
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.ComponentBuilder;
-import net.md_5.bungee.api.chat.HoverEvent;
-import net.md_5.bungee.api.chat.TextComponent;
-
-public class ChestSortUpdateChecker {
-
- // This checks for updates. A txt file is downloaded. If the txt file contains a
- // string that is unequal to the currently used plugin's version, a message is
- // printed in the console.
- // The listener will also ensure that OPs will be notified on join. When the
- // update checker could not complete the request, e.g. when the JEFF
- // Media GbR API server is offline, or if you have no internet connection, a
- // warning will be printed in the console.
-
- private ChestSortPlugin plugin;
-
- ChestSortUpdateChecker(ChestSortPlugin plugin) {
- this.plugin = plugin;
- }
-
- // This text file always contains a string with the latest version, e.g. 3.7.1
- final static String latestVersionLink = "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt";
- final static String downloadLink = "https://chestsort.de/download";
- final static String changelogLink = "https://chestsort.de/changelog";
- final static String donateLink = "https://chestsort.de/donate";
-
- private String currentVersion = "undefined";
- private String latestVersion = "undefined";
-
- private TextComponent createLink(String text, String link, net.md_5.bungee.api.ChatColor color) {
- // Hover text
- ComponentBuilder hoverCB = new ComponentBuilder(
- text+" Link: ").bold(true)
- .append(link).bold(false);
-
- TextComponent tc = new TextComponent(text);
- tc.setBold(true);
- tc.setColor(color);
- tc.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,link));
- tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,hoverCB.create()));
- return tc;
- }
-
- private void sendLinks(Player p) {
- TextComponent text = new TextComponent("");
-
- TextComponent download = createLink("Download",downloadLink,net.md_5.bungee.api.ChatColor.GOLD);
- TextComponent donate = createLink("Donate",donateLink,net.md_5.bungee.api.ChatColor.GOLD);
- TextComponent changelog = createLink("Changelog",changelogLink,net.md_5.bungee.api.ChatColor.GOLD);
-
- TextComponent placeholder = new TextComponent(" | ");
- placeholder.setColor(net.md_5.bungee.api.ChatColor.GRAY);
-
- text.addExtra(download);
- text.addExtra(placeholder);
- text.addExtra(donate);
- text.addExtra(placeholder);
- text.addExtra(changelog);
-
- p.spigot().sendMessage(text);
- }
-
- void sendUpdateMessage(Player p) {
- if (!latestVersion.equals("undefined")) {
- if (!currentVersion.equals(latestVersion)) {
- p.sendMessage(ChatColor.GRAY + "There is a new version of " + ChatColor.GOLD + "ChestSort"
- + ChatColor.GRAY + " available.");
- sendLinks(p);
- p.sendMessage(ChatColor.DARK_GRAY + "Your version: "+currentVersion + " | Latest version: "+ latestVersion);
- p.sendMessage("");
- }
- }
- }
-
- void checkForUpdate() {
- Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
- @Override
- public void run() {
- try {
- String userAgent = "ChestSort/"+plugin.getDescription().getVersion()+" (MC "+plugin.mcVersion+", "+plugin.getServer().getOnlinePlayers().size()+"/"+plugin.getServer().getOfflinePlayers().length+")";
- HttpURLConnection httpcon = (HttpURLConnection) new URL(latestVersionLink).openConnection();
- httpcon.addRequestProperty("User-Agent", userAgent);
- BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
- String inputLine = reader.readLine().trim();
- latestVersion = inputLine;
- currentVersion = plugin.getDescription().getVersion().trim();
-
- if (latestVersion.equals(currentVersion)) {
- plugin.getLogger().info("You are using the latest version of ChestSort.");
- } else {
- plugin.getLogger().warning("=================================================");
- plugin.getLogger().warning("There is a new version of ChestSort available!");
- plugin.getLogger().warning("Latest : " + inputLine);
- plugin.getLogger().warning("Current: " + currentVersion);
- plugin.getLogger().warning("Please update to the newest version. Download:");
- plugin.getLogger().warning(downloadLink);
- plugin.getLogger().warning("=================================================");
- }
- reader.close();
- } catch (Exception e) {
- plugin.getLogger().warning("Could not check for updates.");
- }
- }
- });
- }
-}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 437a219..6990206 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
main: de.jeff_media.ChestSort.ChestSortPlugin
name: ChestSort
-version: 8.10.5
+version: 9.0.0-SNAPSHOT1
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex