Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Added update checker.
Browse files Browse the repository at this point in the history
Former-commit-id: d6d77aa
  • Loading branch information
xishift committed Jul 13, 2020
1 parent 991248b commit 01a8948
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion files/version.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.1
5.0.2
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ishift</groupId>
<artifactId>EpicGuard</artifactId>
<version>5.0.1</version>
<version>5.0.2</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.ishift.epicguard.core.EpicGuard;
import me.ishift.epicguard.core.task.AttackResetTask;
import me.ishift.epicguard.core.task.CounterTask;
import me.ishift.epicguard.core.task.UpdateCheckerTask;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -33,7 +34,8 @@ public void onEnable() {

BukkitScheduler scheduler = Bukkit.getScheduler();
scheduler.runTaskTimerAsynchronously(this, new CounterTask(this.epicGuard), 20L, 20L);
scheduler.runTaskTimerAsynchronously(this, new AttackResetTask(this.epicGuard), 20L * 20L, 20L);
scheduler.runTaskTimerAsynchronously(this, new AttackResetTask(this.epicGuard), 20L, 20L * 20L);
scheduler.runTaskTimerAsynchronously(this, new UpdateCheckerTask(this.epicGuard), 20L, 1800L * 20L); // 30 minutes
scheduler.runTaskTimer(this, new ModuleTask(this), 20L * 5L, 20L);

this.getCommand("epicguard").setExecutor(new EpicGuardCommand(this.epicGuard));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.ishift.epicguard.core.config.MessagesConfiguration;
import me.ishift.epicguard.core.user.User;
import me.ishift.epicguard.core.util.ChatUtils;
import me.ishift.epicguard.core.util.UpdateChecker;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -25,6 +26,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
send(sender, "&8&m---------------------------------------------------");
send(sender, " &6&lEpicGuard &8(Spigot version)");
send(sender, " &7Version: &f" + this.epicGuard.getVersion());
if (UpdateChecker.isAvailable()) {
send(sender, "");
send(sender, " &7Update available: &c&n" + UpdateChecker.getRemoteVersion());
send(sender, " &c&ohttps://www.spigotmc.org/resources/72369/");
}
send(sender, "");
send(sender, " &8• &b/guard stats &7- show plugin statistics.");
send(sender, " &8• &b/guard notifications &7- enable actionbar notifications.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.ishift.epicguard.core.EpicGuard;
import me.ishift.epicguard.core.task.AttackResetTask;
import me.ishift.epicguard.core.task.CounterTask;
import me.ishift.epicguard.core.task.UpdateCheckerTask;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.api.scheduler.TaskScheduler;
Expand All @@ -23,7 +24,8 @@ public void onEnable() {

TaskScheduler scheduler = this.getProxy().getScheduler();
scheduler.schedule(this, new CounterTask(this.epicGuard), 1L, 1L, TimeUnit.SECONDS);
scheduler.schedule(this, new AttackResetTask(this.epicGuard), 20L, 20L, TimeUnit.SECONDS);
scheduler.schedule(this, new AttackResetTask(this.epicGuard), 1L, 20L, TimeUnit.SECONDS);
scheduler.schedule(this, new UpdateCheckerTask(this.epicGuard), 1L, 1800L, TimeUnit.SECONDS); // 30 minutes

PluginManager pm = this.getProxy().getPluginManager();
pm.registerListener(this, new PreLoginListener(this.epicGuard));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.ishift.epicguard.core.config.MessagesConfiguration;
import me.ishift.epicguard.core.user.User;
import me.ishift.epicguard.core.util.ChatUtils;
import me.ishift.epicguard.core.util.UpdateChecker;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand All @@ -25,6 +26,11 @@ public void execute(CommandSender sender, String[] args) {
send(sender, "&8&m---------------------------------------------------");
send(sender, " &6&lEpicGuard &8(Spigot version)");
send(sender, " &7Version: &f" + this.epicGuard.getVersion());
if (UpdateChecker.isAvailable()) {
send(sender, "");
send(sender, " &7Update available: &c&n" + UpdateChecker.getRemoteVersion());
send(sender, " &c&ohttps://www.spigotmc.org/resources/72369/");
}
send(sender, "");
send(sender, " &8• &b/guard stats &7- show plugin statistics.");
send(sender, " &8• &b/guard notifications &7- enable actionbar notifications.");
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/ishift/epicguard/core/task/UpdateCheckerTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.ishift.epicguard.core.task;

import me.ishift.epicguard.core.EpicGuard;
import me.ishift.epicguard.core.util.UpdateChecker;

public class UpdateCheckerTask implements Runnable {
private final EpicGuard epicGuard;

public UpdateCheckerTask(EpicGuard epicGuard) {
this.epicGuard = epicGuard;
}

@Override
public void run() {
UpdateChecker.checkForUpdates(this.epicGuard);

if (UpdateChecker.isAvailable()) {
this.epicGuard.getLogger().info("New update is available");
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/me/ishift/epicguard/core/util/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.ishift.epicguard.core.util;

import me.ishift.epicguard.core.EpicGuard;

public final class UpdateChecker {
private static final String CHECK_URL = "https://raw.githubusercontent.com/xishift/EpicGuard/master/files/version.info";
private static String remoteVersion;
private static boolean available;

public static void checkForUpdates(EpicGuard epicGuard) {
remoteVersion = URLUtils.readString(CHECK_URL);
int latest = Integer.parseInt(remoteVersion.replace(".", ""));
int current = Integer.parseInt(epicGuard.getVersion().replace(".", ""));

available = latest > current;
}

public static boolean isAvailable() {
return available;
}

public static String getRemoteVersion() {
return remoteVersion;
}

private UpdateChecker() {}
}

0 comments on commit 01a8948

Please sign in to comment.