Added updater

This commit is contained in:
ajgeiss0702
2021-09-07 15:37:48 -07:00
parent 64c403baca
commit 6dd2cf7fb1
15 changed files with 120 additions and 13 deletions
@@ -30,6 +30,7 @@ public class ManageCommand extends BaseCommand {
addSubCommand(new Send(main));
addSubCommand(new PermissionList(main));
addSubCommand(new Whitelist(main));
addSubCommand(new Update(main));
}
@@ -55,6 +55,8 @@ public class Reload extends SubCommand {
main.getQueueManager().reloadServers();
main.getMessages().reload();
main.getUpdater().setEnabled(main.getConfig().getBoolean("enable-updater"));
sender.sendMessage(getMessages().getComponent("commands.reload"));
}
@@ -0,0 +1,66 @@
package us.ajg0702.queue.commands.commands.manage;
import com.google.common.collect.ImmutableList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.spongepowered.configurate.ConfigurateException;
import us.ajg0702.queue.api.commands.ICommandSender;
import us.ajg0702.queue.commands.SubCommand;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;
import us.ajg0702.utils.common.Updater;
import java.util.ArrayList;
import java.util.List;
public class Update extends SubCommand {
final QueueMain main;
public Update(QueueMain main) {
this.main = main;
}
@Override
public String getName() {
return "update";
}
@Override
public ImmutableList<String> getAliases() {
return ImmutableList.of();
}
@Override
public String getPermission() {
return "ajqueue.manage.update";
}
@Override
public Messages getMessages() {
return main.getMessages();
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
Updater updater = main.getUpdater();
if(updater.isAlreadyDownloaded()) {
sender.sendMessage(getMessages().getComponent("updater.already-downloaded"));
return;
}
if(!updater.isUpdateAvailable()) {
sender.sendMessage(getMessages().getComponent("updater.no-update"));
return;
}
if(updater.downloadUpdate()) {
sender.sendMessage(getMessages().getComponent("updater.success"));
} else {
sender.sendMessage(getMessages().getComponent("updater.fail"));
}
}
@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
}
}
@@ -103,6 +103,16 @@ public class EventHandlerImpl implements EventHandler {
@Override
public void onPlayerJoin(AdaptedPlayer player) {
new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException ignored) {
}
if (main.getUpdater().isUpdateAvailable() && player.hasPermission("ajqueue.manage.update")) {
player.sendMessage(main.getMessages().getComponent("updater.update-available"));
}
}).start();
ImmutableList<QueuePlayer> queues = main.getQueueManager().findPlayerInQueues(player);
for(QueuePlayer queuePlayer : queues) {
queuePlayer.setPlayer(player);
@@ -9,6 +9,7 @@ import us.ajg0702.queue.common.utils.LogConverter;
import us.ajg0702.queue.logic.LogicGetterImpl;
import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages;
import us.ajg0702.utils.common.Updater;
import java.io.File;
import java.util.LinkedHashMap;
@@ -100,9 +101,15 @@ public class QueueMain extends AjQueueAPI {
return protocolNameManager;
}
private Updater updater;
public Updater getUpdater() {
return updater;
}
@Override
public void shutdown() {
taskManager.shutdown();
updater.shutdown();
}
@@ -150,6 +157,8 @@ public class QueueMain extends AjQueueAPI {
taskManager.rescheduleTasks();
updater = new Updater(logger, platformMethods.getPluginVersion(), isPremium() ? "ajQueuePlus" : "ajQueue", config.getBoolean("enable-updater"), isPremium() ? 79123 : 78266, dataFolder.getParentFile(), "ajQueue update");
}
private void constructMessages() {
@@ -227,6 +236,18 @@ public class QueueMain extends AjQueueAPI {
d.put("velocity-kick-message", "<red>You were kicked while trying to join {SERVER}: <white>{REASON}");
d.put("updater.update-available",
"<gray><strikethrough> <reset>\n" +
" <green>An update is available for ajQueue!\n" +
" <dark_green>You can download it by " +
"<click:run_command:/ajqueue update><bold>clicking here</bold>\n or running <gray>/ajQueue update</click>\n" +
"<gray><strikethrough> <reset>"
);
d.put("updater.no-update", "<red>There is not an update available");
d.put("updater.success", "<green>The update has been downloaded! Now just restart the server");
d.put("updater.fail", "<red>An error occurred while downloading the update. Check the console for more info.");
d.put("updater.already-downloaded", "<red>The update has already been downloaded.");
messages = new Messages(dataFolder, new LogConverter(logger), d);
}
}
+5 -2
View File
@@ -1,5 +1,5 @@
# Dont touch this number please
config-version: 27
config-version: 28
# This is the main config for ajQueue.
@@ -258,4 +258,7 @@ protocol-names:
# On velocity, should we end a player a message when they are kicked while trying to connect to a server with the queue?
# This has no effect on bungee, because the message is sent from bungee and theres no way to change that in ajQueue
# Default: false
velocity-kick-message: false
velocity-kick-message: false
# Should the updater be enabled?
enable-updater: true