Skip to content

Commit 5ec82fb

Browse files
committed
Commit
1 parent dd927c5 commit 5ec82fb

3 files changed

Lines changed: 31 additions & 40 deletions

File tree

src/main/java/me/nik/combatplus/handlers/UpdateChecker.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package me.nik.combatplus.handlers;
22

33
import me.nik.combatplus.CombatPlus;
4-
import me.nik.combatplus.listeners.UpdateReminder;
54
import me.nik.combatplus.managers.MsgType;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.Listener;
7+
import org.bukkit.event.player.PlayerJoinEvent;
68
import org.bukkit.scheduler.BukkitRunnable;
79

8-
import javax.net.ssl.HttpsURLConnection;
910
import java.io.BufferedReader;
1011
import java.io.IOException;
1112
import java.io.InputStreamReader;
1213
import java.net.URL;
14+
import java.net.URLConnection;
1315

14-
public class UpdateChecker extends BukkitRunnable {
16+
public class UpdateChecker extends BukkitRunnable implements Listener {
1517

1618
private final CombatPlus plugin;
1719

@@ -24,18 +26,32 @@ public UpdateChecker(CombatPlus plugin) {
2426
@Override
2527
public void run() {
2628
try {
27-
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=76788").openConnection();
28-
String version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
29-
30-
if (!plugin.getDescription().getVersion().equalsIgnoreCase(version)) {
31-
newVersion = version;
32-
plugin.consoleMessage(MsgType.UPDATE_REMINDER.getMessage().replaceAll("%current%", plugin.getDescription().getVersion()).replaceAll("%new%", newVersion));
33-
plugin.registerEvent(new UpdateReminder(plugin, this));
34-
} else {
35-
plugin.consoleMessage(MsgType.CONSOLE_UPDATE_NOT_FOUND.getMessage());
36-
}
37-
} catch (IOException ignored) {
29+
newVersion = readLines();
30+
} catch (IOException e) {
31+
plugin.getLogger().warning("Couldn't check for updates, Is the server connected to the internet?");
3832
}
33+
34+
if (!plugin.getDescription().getVersion().equals(newVersion)) {
35+
plugin.consoleMessage(MsgType.UPDATE_REMINDER.getMessage().replaceAll("%current%", plugin.getDescription().getVersion()).replaceAll("%new%", newVersion));
36+
plugin.getServer().getPluginManager().registerEvents(this, plugin);
37+
} else {
38+
plugin.consoleMessage(MsgType.CONSOLE_UPDATE_NOT_FOUND.getMessage());
39+
}
40+
}
41+
42+
private String readLines() throws IOException {
43+
URLConnection connection = new URL("https://raw.githubusercontent.com/NikV2/CombatPlus/master/version.txt").openConnection();
44+
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
45+
46+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
47+
48+
return reader.readLine();
49+
}
50+
51+
@EventHandler
52+
public void onJoin(PlayerJoinEvent e) {
53+
if (!e.getPlayer().hasPermission("cp.admin")) return;
54+
e.getPlayer().sendMessage(MsgType.UPDATE_REMINDER.getMessage().replaceAll("%current%", plugin.getDescription().getVersion()).replaceAll("%new%", newVersion));
3955
}
4056

4157
public String getNewVersion() {

src/main/java/me/nik/combatplus/listeners/UpdateReminder.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.4.10

0 commit comments

Comments
 (0)