Give update info on command update
This commit is contained in:
parent
714c37d1c3
commit
88c9546a88
@ -2,6 +2,7 @@ package me.libraryaddict.disguise.commands.libsdisguises;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -51,7 +52,7 @@ public class LDUpdate implements LDCommand {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean result;
|
||||
PluginInformation result;
|
||||
|
||||
if (force) {
|
||||
result = checker.grabLatestSnapshot();
|
||||
@ -59,15 +60,21 @@ public class LDUpdate implements LDCommand {
|
||||
result = checker.grabSnapshotBuild();
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
if (result == null) {
|
||||
sender.sendMessage(LibsMsg.UPDATE_FAILED.get());
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
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());
|
||||
|
@ -112,7 +112,7 @@ public class LibsPremium {
|
||||
//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()})) {
|
||||
Class c = cl.loadClass(LibsPremium.class.getName());
|
||||
|
||||
@ -166,8 +166,8 @@ public class LibsPremium {
|
||||
|
||||
String pluginVersion = config.getString("version");
|
||||
|
||||
return new PluginInformation(userId, resourceId, downloadId, premium, pluginVersion, pluginBuildNumber,
|
||||
pluginBuildDate);
|
||||
return new PluginInformation(file.length(), userId, resourceId, downloadId, premium, pluginVersion,
|
||||
pluginBuildNumber, pluginBuildDate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ public class LibsPremium {
|
||||
if (bisectHosted = new BisectHosting().isBisectHosted("LibsDisguises")) {
|
||||
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;
|
||||
} else {
|
||||
@ -305,8 +305,9 @@ public class LibsPremium {
|
||||
buildNo = "#" + buildNo;
|
||||
}
|
||||
|
||||
pluginInformation = new PluginInformation(getUserID(), getResourceID(), getDownloadID(),
|
||||
isPremium(getResourceID(), getUserID()), version, buildNo, pluginBuildDate);
|
||||
pluginInformation = new PluginInformation(LibsDisguises.getInstance().getFile().length(), getUserID(),
|
||||
getResourceID(), getDownloadID(), isPremium(getResourceID(), getUserID()), version, buildNo,
|
||||
pluginBuildDate);
|
||||
}
|
||||
|
||||
if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) {
|
||||
|
@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
|
||||
|
||||
@ -31,38 +32,38 @@ public class UpdateChecker {
|
||||
this.resourceID = resourceID;
|
||||
}
|
||||
|
||||
public boolean grabSnapshotBuild() {
|
||||
public PluginInformation grabSnapshotBuild() {
|
||||
if (getLatestSnapshot() == 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
if (lastDownload == -1) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (getLatestSnapshot() == lastDownload) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return grabSnapshotBuild(getLatestSnapshot());
|
||||
}
|
||||
|
||||
public boolean grabSnapshotBuild(int buildNo) {
|
||||
boolean result = grabSnapshotBuild(
|
||||
public PluginInformation grabSnapshotBuild(int buildNo) {
|
||||
PluginInformation result = grabSnapshotBuild(
|
||||
"https://ci.md-5.net/job/LibsDisguises/" + buildNo + "/artifact/target/LibsDisguises.jar");
|
||||
|
||||
if (result) {
|
||||
if (result != null) {
|
||||
lastDownload = buildNo;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean grabLatestSnapshot() {
|
||||
boolean result = grabSnapshotBuild(
|
||||
public PluginInformation grabLatestSnapshot() {
|
||||
PluginInformation result = grabSnapshotBuild(
|
||||
"https://ci.md-5.net/job/LibsDisguises/lastSuccessfulBuild/artifact/target/LibsDisguises.jar");
|
||||
|
||||
if (result) {
|
||||
if (result != null) {
|
||||
lastDownload = LibsDisguises.getInstance().getBuildNumber();
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ public class UpdateChecker {
|
||||
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);
|
||||
lastDownload = -1;
|
||||
|
||||
@ -101,7 +102,8 @@ public class UpdateChecker {
|
||||
}
|
||||
|
||||
DisguiseUtilities.getLogger().info("Download success!");
|
||||
return true;
|
||||
|
||||
return LibsPremium.getInformation(dest);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Failed, set the last download back to previous build
|
||||
@ -111,7 +113,7 @@ public class UpdateChecker {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkSnapshotUpdate(int buildNumber) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.libraryaddict.disguise.utilities.plugin;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@ -7,6 +9,8 @@ import java.util.Date;
|
||||
* Created by libraryaddict on 20/06/2019.
|
||||
*/
|
||||
public class PluginInformation {
|
||||
@Getter
|
||||
private long size;
|
||||
private String userID;
|
||||
private String resourceID;
|
||||
private String downloadID;
|
||||
@ -15,8 +19,9 @@ public class PluginInformation {
|
||||
private String buildNumber;
|
||||
private String buildDate;
|
||||
|
||||
public PluginInformation(String userID, String resourceID, String downloadID, boolean premium, String version,
|
||||
String buildNumber, String buildDate) {
|
||||
public PluginInformation(long size, String userID, String resourceID, String downloadID, boolean premium,
|
||||
String version, String buildNumber, String buildDate) {
|
||||
this.size = size;
|
||||
this.userID = userID;
|
||||
this.resourceID = resourceID;
|
||||
this.downloadID = downloadID;
|
||||
@ -65,6 +70,7 @@ public class PluginInformation {
|
||||
}
|
||||
|
||||
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_FAILED(ChatColor.RED + "LibsDisguises update failed! Check console for errors."),
|
||||
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..."),
|
||||
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!"),
|
||||
|
Loading…
Reference in New Issue
Block a user