Give update info on command update
This commit is contained in:
		| @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.commands.libsdisguises; | |||||||
|  |  | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.utilities.UpdateChecker; | import me.libraryaddict.disguise.utilities.UpdateChecker; | ||||||
|  | import me.libraryaddict.disguise.utilities.plugin.PluginInformation; | ||||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; | import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| @@ -51,7 +52,7 @@ public class LDUpdate implements LDCommand { | |||||||
|         new BukkitRunnable() { |         new BukkitRunnable() { | ||||||
|             @Override |             @Override | ||||||
|             public void run() { |             public void run() { | ||||||
|                 boolean result; |                 PluginInformation result; | ||||||
|  |  | ||||||
|                 if (force) { |                 if (force) { | ||||||
|                     result = checker.grabLatestSnapshot(); |                     result = checker.grabLatestSnapshot(); | ||||||
| @@ -59,15 +60,21 @@ public class LDUpdate implements LDCommand { | |||||||
|                     result = checker.grabSnapshotBuild(); |                     result = checker.grabSnapshotBuild(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if (!result) { |                 if (result == null) { | ||||||
|                     sender.sendMessage(LibsMsg.UPDATE_FAILED.get()); |                     sender.sendMessage(LibsMsg.UPDATE_FAILED.get()); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 sender.sendMessage(LibsMsg.UPDATE_SUCCESS.get()); // Update success, please restart to update |                 sender.sendMessage(LibsMsg.UPDATE_SUCCESS.get()); // Update success, please restart to update | ||||||
|  |                 sender.sendMessage(LibsMsg.UPDATE_INFO | ||||||
|  |                         .get(result.getVersion(), result.getBuildNumber(), result.getParsedBuildDate().toString(), | ||||||
|  |                                 result.getSize() / 1024)); | ||||||
|  |  | ||||||
|                 if (sender instanceof Player) { |                 if (sender instanceof Player) { | ||||||
|                     Bukkit.getConsoleSender().sendMessage(LibsMsg.UPDATE_SUCCESS.get()); |                     Bukkit.getConsoleSender().sendMessage(LibsMsg.UPDATE_SUCCESS.get()); | ||||||
|  |                     sender.sendMessage(LibsMsg.UPDATE_INFO | ||||||
|  |                             .get(result.getVersion(), result.getBuildNumber(), result.getParsedBuildDate().toString(), | ||||||
|  |                                     result.getSize() / 1024)); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }.runTaskAsynchronously(LibsDisguises.getInstance()); |         }.runTaskAsynchronously(LibsDisguises.getInstance()); | ||||||
|   | |||||||
| @@ -112,7 +112,7 @@ public class LibsPremium { | |||||||
|         //return premiumVersion.equals(currentVersion); |         //return premiumVersion.equals(currentVersion); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static PluginInformation getInformation(File file) throws Exception { |     public static PluginInformation getInformation(File file) throws Exception { | ||||||
|         try (URLClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()})) { |         try (URLClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()})) { | ||||||
|             Class c = cl.loadClass(LibsPremium.class.getName()); |             Class c = cl.loadClass(LibsPremium.class.getName()); | ||||||
|  |  | ||||||
| @@ -166,8 +166,8 @@ public class LibsPremium { | |||||||
|  |  | ||||||
|             String pluginVersion = config.getString("version"); |             String pluginVersion = config.getString("version"); | ||||||
|  |  | ||||||
|             return new PluginInformation(userId, resourceId, downloadId, premium, pluginVersion, pluginBuildNumber, |             return new PluginInformation(file.length(), userId, resourceId, downloadId, premium, pluginVersion, | ||||||
|                     pluginBuildDate); |                     pluginBuildNumber, pluginBuildDate); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -243,7 +243,7 @@ public class LibsPremium { | |||||||
|             if (bisectHosted = new BisectHosting().isBisectHosted("LibsDisguises")) { |             if (bisectHosted = new BisectHosting().isBisectHosted("LibsDisguises")) { | ||||||
|                 DisguiseUtilities.getLogger().info("Hosted by BisectHosting! Premium enabled!"); |                 DisguiseUtilities.getLogger().info("Hosted by BisectHosting! Premium enabled!"); | ||||||
|  |  | ||||||
|                 paidInformation = new PluginInformation("0", "32453", "0", true, "0", "#0", "0"); |                 paidInformation = new PluginInformation(0, "0", "32453", "0", true, "0", "#0", "0"); | ||||||
|  |  | ||||||
|                 thisPluginIsPaidFor = true; |                 thisPluginIsPaidFor = true; | ||||||
|             } else { |             } else { | ||||||
| @@ -305,8 +305,9 @@ public class LibsPremium { | |||||||
|                 buildNo = "#" + buildNo; |                 buildNo = "#" + buildNo; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             pluginInformation = new PluginInformation(getUserID(), getResourceID(), getDownloadID(), |             pluginInformation = new PluginInformation(LibsDisguises.getInstance().getFile().length(), getUserID(), | ||||||
|                     isPremium(getResourceID(), getUserID()), version, buildNo, pluginBuildDate); |                     getResourceID(), getDownloadID(), isPremium(getResourceID(), getUserID()), version, buildNo, | ||||||
|  |                     pluginBuildDate); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) { |         if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) { | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
|  | import me.libraryaddict.disguise.utilities.plugin.PluginInformation; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; | import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; | ||||||
|  |  | ||||||
| @@ -31,38 +32,38 @@ public class UpdateChecker { | |||||||
|         this.resourceID = resourceID; |         this.resourceID = resourceID; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean grabSnapshotBuild() { |     public PluginInformation grabSnapshotBuild() { | ||||||
|         if (getLatestSnapshot() == 0) { |         if (getLatestSnapshot() == 0) { | ||||||
|             throw new IllegalArgumentException(); |             throw new IllegalArgumentException(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (lastDownload == -1) { |         if (lastDownload == -1) { | ||||||
|             return false; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (getLatestSnapshot() == lastDownload) { |         if (getLatestSnapshot() == lastDownload) { | ||||||
|             return false; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return grabSnapshotBuild(getLatestSnapshot()); |         return grabSnapshotBuild(getLatestSnapshot()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean grabSnapshotBuild(int buildNo) { |     public PluginInformation grabSnapshotBuild(int buildNo) { | ||||||
|         boolean result = grabSnapshotBuild( |         PluginInformation result = grabSnapshotBuild( | ||||||
|                 "https://ci.md-5.net/job/LibsDisguises/" + buildNo + "/artifact/target/LibsDisguises.jar"); |                 "https://ci.md-5.net/job/LibsDisguises/" + buildNo + "/artifact/target/LibsDisguises.jar"); | ||||||
|  |  | ||||||
|         if (result) { |         if (result != null) { | ||||||
|             lastDownload = buildNo; |             lastDownload = buildNo; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean grabLatestSnapshot() { |     public PluginInformation grabLatestSnapshot() { | ||||||
|         boolean result = grabSnapshotBuild( |         PluginInformation result = grabSnapshotBuild( | ||||||
|                 "https://ci.md-5.net/job/LibsDisguises/lastSuccessfulBuild/artifact/target/LibsDisguises.jar"); |                 "https://ci.md-5.net/job/LibsDisguises/lastSuccessfulBuild/artifact/target/LibsDisguises.jar"); | ||||||
|  |  | ||||||
|         if (result) { |         if (result != null) { | ||||||
|             lastDownload = LibsDisguises.getInstance().getBuildNumber(); |             lastDownload = LibsDisguises.getInstance().getBuildNumber(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -77,7 +78,7 @@ public class UpdateChecker { | |||||||
|         return lastDownload; |         return lastDownload; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean grabSnapshotBuild(String urlString) { |     public PluginInformation grabSnapshotBuild(String urlString) { | ||||||
|         DisguiseUtilities.getLogger().info("Now downloading latest build of Lib's Disguises from " + urlString); |         DisguiseUtilities.getLogger().info("Now downloading latest build of Lib's Disguises from " + urlString); | ||||||
|         lastDownload = -1; |         lastDownload = -1; | ||||||
|  |  | ||||||
| @@ -101,7 +102,8 @@ public class UpdateChecker { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             DisguiseUtilities.getLogger().info("Download success!"); |             DisguiseUtilities.getLogger().info("Download success!"); | ||||||
|             return true; |  | ||||||
|  |             return LibsPremium.getInformation(dest); | ||||||
|         } |         } | ||||||
|         catch (Exception ex) { |         catch (Exception ex) { | ||||||
|             // Failed, set the last download back to previous build |             // Failed, set the last download back to previous build | ||||||
| @@ -111,7 +113,7 @@ public class UpdateChecker { | |||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void checkSnapshotUpdate(int buildNumber) { |     public void checkSnapshotUpdate(int buildNumber) { | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.utilities.plugin; | package me.libraryaddict.disguise.utilities.plugin; | ||||||
|  |  | ||||||
|  | import lombok.Getter; | ||||||
|  |  | ||||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||||
| import java.util.Date; | import java.util.Date; | ||||||
|  |  | ||||||
| @@ -7,6 +9,8 @@ import java.util.Date; | |||||||
|  * Created by libraryaddict on 20/06/2019. |  * Created by libraryaddict on 20/06/2019. | ||||||
|  */ |  */ | ||||||
| public class PluginInformation { | public class PluginInformation { | ||||||
|  |     @Getter | ||||||
|  |     private long size; | ||||||
|     private String userID; |     private String userID; | ||||||
|     private String resourceID; |     private String resourceID; | ||||||
|     private String downloadID; |     private String downloadID; | ||||||
| @@ -15,8 +19,9 @@ public class PluginInformation { | |||||||
|     private String buildNumber; |     private String buildNumber; | ||||||
|     private String buildDate; |     private String buildDate; | ||||||
|  |  | ||||||
|     public PluginInformation(String userID, String resourceID, String downloadID, boolean premium, String version, |     public PluginInformation(long size, String userID, String resourceID, String downloadID, boolean premium, | ||||||
|             String buildNumber, String buildDate) { |             String version, String buildNumber, String buildDate) { | ||||||
|  |         this.size = size; | ||||||
|         this.userID = userID; |         this.userID = userID; | ||||||
|         this.resourceID = resourceID; |         this.resourceID = resourceID; | ||||||
|         this.downloadID = downloadID; |         this.downloadID = downloadID; | ||||||
| @@ -65,6 +70,7 @@ public class PluginInformation { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isLegit() { |     public boolean isLegit() { | ||||||
|         return getUserID().matches("[0-9]+") && !getUserID().equals("12345") && getResourceID().equals("32453") && getDownloadID().matches("-?[0-9]+"); |         return getUserID().matches("[0-9]+") && !getUserID().equals("12345") && getResourceID().equals("32453") && | ||||||
|  |                 getDownloadID().matches("-?[0-9]+"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -148,6 +148,7 @@ public enum LibsMsg { | |||||||
|     UPDATE_ON_LATEST(ChatColor.RED + "You are already on the latest version of LibsDisguises!"), |     UPDATE_ON_LATEST(ChatColor.RED + "You are already on the latest version of LibsDisguises!"), | ||||||
|     UPDATE_FAILED(ChatColor.RED + "LibsDisguises update failed! Check console for errors."), |     UPDATE_FAILED(ChatColor.RED + "LibsDisguises update failed! Check console for errors."), | ||||||
|     UPDATE_SUCCESS(ChatColor.DARK_GREEN + "LibsDisguises update success! Restart server to update!"), |     UPDATE_SUCCESS(ChatColor.DARK_GREEN + "LibsDisguises update success! Restart server to update!"), | ||||||
|  |     UPDATE_INFO(ChatColor.DARK_GREEN + "Lib's Disguises v%s, build %b, built %s and size %skb"), | ||||||
|     UPDATE_IN_PROGRESS(ChatColor.DARK_GREEN + "LibsDisguises is now downloading an update..."), |     UPDATE_IN_PROGRESS(ChatColor.DARK_GREEN + "LibsDisguises is now downloading an update..."), | ||||||
|     NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), |     NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"), | ||||||
|     NO_MODS_LISTENING(ChatColor.RED + "This server is not listening for mods!"), |     NO_MODS_LISTENING(ChatColor.RED + "This server is not listening for mods!"), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user