From 5b5cdd03956ba54903c2409899ef5dab5c99a527 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 27 Apr 2020 17:03:11 +1200 Subject: [PATCH] Improve update system and info --- .../commands/LibsDisguisesCommand.java | 1 + .../commands/libsdisguises/LDChangelog.java | 60 +++++++++++++++++++ .../commands/libsdisguises/LDUpdate.java | 26 +------- .../utilities/translations/LibsMsg.java | 7 ++- 4 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDChangelog.java diff --git a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index 709b9cec..d5b6adb4 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -23,6 +23,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { getCommands().add(new LDHelp(this)); getCommands().add(new LDReload()); getCommands().add(new LDUpdate()); + getCommands().add(new LDChangelog()); getCommands().add(new LDCount()); getCommands().add(new LDConfig()); getCommands().add(new LDPermTest()); diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDChangelog.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDChangelog.java new file mode 100644 index 00000000..a1e92921 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDChangelog.java @@ -0,0 +1,60 @@ +package me.libraryaddict.disguise.commands.libsdisguises; + +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.updates.UpdateChecker; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.util.Collections; +import java.util.List; + +/** + * Created by libraryaddict on 27/04/2020. + */ +public class LDChangelog implements LDCommand { + @Override + public List getTabComplete() { + return Collections.singletonList("changelog"); + } + + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + + @Override + public String getPermission() { + return "libsdisguises.update"; + } + + @Override + public void onCommand(CommandSender sender, String[] args) { + UpdateChecker checker = LibsDisguises.getInstance().getUpdateChecker(); + + if (checker.isDownloading()) { + sender.sendMessage(LibsMsg.UPDATE_IN_PROGRESS.get()); + return; + } + + if (checker.getUpdate() == null) { + sender.sendMessage(LibsMsg.UPDATE_REQUIRED.get()); + return; + } + + if (!checker.getUpdate().isReleaseBuild()) { + sender.sendMessage( + ChatColor.GOLD + "You are on build " + (LibsDisguises.getInstance().isNumberedBuild() ? "#" : "") + + LibsDisguises.getInstance().getBuildNo()); + } + + for (String msg : checker.getUpdate().getChangelog()) { + sender.sendMessage(ChatColor.GOLD + msg); + } + } + + @Override + public LibsMsg getHelp() { + return LibsMsg.LD_COMMAND_CHANGELOG; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java index 8ab99626..445de532 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java @@ -23,7 +23,7 @@ public class LDUpdate implements LDCommand { // Update by download // Update check // Update to latest dev build - return Arrays.asList("update", "update dev", "update release", "changelog", "update!"); + return Arrays.asList("update", "update dev", "update release", "update!"); } @Override @@ -31,25 +31,6 @@ public class LDUpdate implements LDCommand { return "libsdisguises.update"; } - private void doChangelog(CommandSender sender) { - UpdateChecker checker = LibsDisguises.getInstance().getUpdateChecker(); - - if (checker.getUpdate() == null) { - sender.sendMessage(LibsMsg.UPDATE_REQUIRED.get()); - return; - } - - if (!checker.getUpdate().isReleaseBuild()) { - sender.sendMessage( - ChatColor.GOLD + "You are on build " + (LibsDisguises.getInstance().isNumberedBuild() ? "#" : "") + - LibsDisguises.getInstance().getBuildNo()); - } - - for (String msg : checker.getUpdate().getChangelog()) { - sender.sendMessage(ChatColor.GOLD + msg); - } - } - @Override public void onCommand(CommandSender sender, String[] args) { UpdateChecker checker = LibsDisguises.getInstance().getUpdateChecker(); @@ -59,11 +40,6 @@ public class LDUpdate implements LDCommand { return; } - if (args[0].equalsIgnoreCase("changelog")) { - doChangelog(sender); - return; - } - boolean releaseBuilds = checker.isUsingReleaseBuilds(); if (args.length > 1) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java index c075a2cb..a15a62c9 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java @@ -313,7 +313,10 @@ public enum LibsMsg { LD_COMMAND_CONFIG(ChatColor.BLUE + "/libsdisguises config - " + ChatColor.AQUA + "Tells you what's not normal in your config"), LD_COMMAND_UPDATE(ChatColor.BLUE + "/libsdisguises update - " + ChatColor.AQUA + - "Update's the plugin, doing 'update!' will force an update. Server must be restarted to install update."), + "'update' will fetch an update, 'update dev' will fetch a dev build update, 'update release' will fetch a" + + " release build update and 'update!' will download that update!"), + LD_COMMAND_CHANGELOG(ChatColor.BLUE + "/libsdisguises changelog - " + ChatColor.AQUA + + "Gives you the changelog of the current update fetched"), LD_COMMAND_JSON(ChatColor.BLUE + "/libsdisguises json - " + ChatColor.AQUA + "Turns the current held item into a string format"), LD_COMMAND_MODS(ChatColor.BLUE + "/libsdisguises mods - " + ChatColor.AQUA + @@ -327,7 +330,7 @@ public enum LibsMsg { LD_COMMAND_DEBUG(ChatColor.BLUE + "/libsdisguises debug - " + ChatColor.AQUA + "Used to help debug scoreboard issues on a player disguise"); - private String string; + private final String string; LibsMsg(String string) { this.string = string;