|
1 | | -/* |
2 | | - * This file is part of BungeeBlockVersion. |
3 | | - * |
4 | | - * BungeeBlockVersion is free software: you can redistribute it and/or modify |
5 | | - * it under the terms of the GNU General Public License as published by |
6 | | - * the Free Software Foundation, either version 3 of the License, or |
7 | | - * (at your option) any later version. |
8 | | - * |
9 | | - * BungeeBlockVersion is distributed in the hope that it will be useful, |
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | - * GNU General Public License for more details. |
13 | | - * |
14 | | - * You should have received a copy of the GNU General Public License |
15 | | - * along with BungeeBlockVersion. If not, see <https://www.gnu.org/licenses/>. |
16 | | - */ |
17 | | - |
18 | | -package lol.hyper.bungeeblockversion; |
19 | | - |
20 | | -import lol.hyper.bungeeblockversion.commands.CommandReload; |
21 | | -import lol.hyper.bungeeblockversion.events.JoinEvent; |
22 | | -import lol.hyper.bungeeblockversion.tools.ConfigHandler; |
23 | | -import lol.hyper.githubreleaseapi.GitHubRelease; |
24 | | -import lol.hyper.githubreleaseapi.GitHubReleaseAPI; |
25 | | -import net.kyori.adventure.platform.bungeecord.BungeeAudiences; |
26 | | -import net.kyori.adventure.text.minimessage.MiniMessage; |
27 | | -import net.md_5.bungee.api.ProxyServer; |
28 | | -import net.md_5.bungee.api.plugin.Listener; |
29 | | -import net.md_5.bungee.api.plugin.Plugin; |
30 | | -import org.bstats.bungeecord.Metrics; |
31 | | - |
32 | | -import java.io.IOException; |
33 | | -import java.util.HashMap; |
34 | | -import java.util.Map; |
35 | | -import java.util.logging.Logger; |
36 | | - |
37 | | -public final class BungeeBlockVersion extends Plugin implements Listener { |
38 | | - |
39 | | - public final Logger logger = this.getLogger(); |
40 | | - |
41 | | - public ConfigHandler configHandler; |
42 | | - public JoinEvent joinEvent; |
43 | | - public final MiniMessage miniMessage = MiniMessage.miniMessage(); |
44 | | - private BungeeAudiences adventure; |
45 | | - |
46 | | - public Map<Integer, String> versions = new HashMap<>(); |
47 | | - |
48 | | - @Override |
49 | | - public void onEnable() { |
50 | | - this.adventure = BungeeAudiences.create(this); |
51 | | - joinEvent = new JoinEvent(this); |
52 | | - configHandler = new ConfigHandler(this); |
53 | | - configHandler.loadConfig(); |
54 | | - getProxy().getPluginManager().registerCommand(this, new CommandReload("bbvreload", this)); |
55 | | - ProxyServer.getInstance().getPluginManager().registerListener(this, joinEvent); |
56 | | - |
57 | | - new Metrics(this, 9392); |
58 | | - ProxyServer.getInstance().getScheduler().runAsync(this, this::checkForUpdates); |
59 | | - } |
60 | | - |
61 | | - public void checkForUpdates() { |
62 | | - GitHubReleaseAPI api; |
63 | | - try { |
64 | | - api = new GitHubReleaseAPI("BungeeBlockVersion", "hyperdefined"); |
65 | | - } catch (IOException e) { |
66 | | - logger.warning("Unable to check updates!"); |
67 | | - e.printStackTrace(); |
68 | | - return; |
69 | | - } |
70 | | - GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion()); |
71 | | - GitHubRelease latest = api.getLatestVersion(); |
72 | | - if (current == null) { |
73 | | - logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!"); |
74 | | - return; |
75 | | - } |
76 | | - int buildsBehind = api.getBuildsBehind(current); |
77 | | - if (buildsBehind == 0) { |
78 | | - logger.info("You are running the latest version."); |
79 | | - } else { |
80 | | - logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind."); |
81 | | - } |
82 | | - } |
83 | | - |
84 | | - public BungeeAudiences getAdventure() { |
85 | | - if (this.adventure == null) { |
86 | | - throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); |
87 | | - } |
88 | | - return this.adventure; |
89 | | - } |
90 | | -} |
| 1 | +/* |
| 2 | + * This file is part of BungeeBlockVersion. |
| 3 | + * |
| 4 | + * BungeeBlockVersion is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * BungeeBlockVersion is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with BungeeBlockVersion. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package lol.hyper.bungeeblockversion; |
| 19 | + |
| 20 | +import lol.hyper.bungeeblockversion.commands.CommandReload; |
| 21 | +import lol.hyper.bungeeblockversion.events.JoinEvent; |
| 22 | +import lol.hyper.bungeeblockversion.tools.ConfigHandler; |
| 23 | +import lol.hyper.githubreleaseapi.GitHubRelease; |
| 24 | +import lol.hyper.githubreleaseapi.GitHubReleaseAPI; |
| 25 | +import net.kyori.adventure.platform.bungeecord.BungeeAudiences; |
| 26 | +import net.kyori.adventure.text.minimessage.MiniMessage; |
| 27 | +import net.md_5.bungee.api.ProxyServer; |
| 28 | +import net.md_5.bungee.api.plugin.Listener; |
| 29 | +import net.md_5.bungee.api.plugin.Plugin; |
| 30 | +import org.bstats.bungeecord.Metrics; |
| 31 | + |
| 32 | +import java.io.IOException; |
| 33 | +import java.util.HashMap; |
| 34 | +import java.util.Map; |
| 35 | +import java.util.logging.Logger; |
| 36 | + |
| 37 | +public final class BungeeBlockVersion extends Plugin implements Listener { |
| 38 | + |
| 39 | + public final Logger logger = this.getLogger(); |
| 40 | + |
| 41 | + public ConfigHandler configHandler; |
| 42 | + public JoinEvent joinEvent; |
| 43 | + public final MiniMessage miniMessage = MiniMessage.miniMessage(); |
| 44 | + private BungeeAudiences adventure; |
| 45 | + |
| 46 | + public Map<Integer, String> versions = new HashMap<>(); |
| 47 | + |
| 48 | + @Override |
| 49 | + public void onEnable() { |
| 50 | + this.adventure = BungeeAudiences.create(this); |
| 51 | + joinEvent = new JoinEvent(this); |
| 52 | + configHandler = new ConfigHandler(this); |
| 53 | + configHandler.loadConfig(); |
| 54 | + getProxy().getPluginManager().registerCommand(this, new CommandReload("bbvreload", this)); |
| 55 | + ProxyServer.getInstance().getPluginManager().registerListener(this, joinEvent); |
| 56 | + |
| 57 | + new Metrics(this, 9392); |
| 58 | + ProxyServer.getInstance().getScheduler().runAsync(this, this::checkForUpdates); |
| 59 | + } |
| 60 | + |
| 61 | + public void checkForUpdates() { |
| 62 | + GitHubReleaseAPI api; |
| 63 | + try { |
| 64 | + api = new GitHubReleaseAPI("BungeeBlockVersion", "hyperdefined"); |
| 65 | + } catch (IOException e) { |
| 66 | + logger.warning("Unable to check updates!"); |
| 67 | + e.printStackTrace(); |
| 68 | + return; |
| 69 | + } |
| 70 | + GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion()); |
| 71 | + GitHubRelease latest = api.getLatestVersion(); |
| 72 | + if (current == null) { |
| 73 | + logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!"); |
| 74 | + return; |
| 75 | + } |
| 76 | + int buildsBehind = api.getBuildsBehind(current); |
| 77 | + if (buildsBehind == 0) { |
| 78 | + logger.info("You are running the latest version."); |
| 79 | + } else { |
| 80 | + logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind."); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public BungeeAudiences getAdventure() { |
| 85 | + if (this.adventure == null) { |
| 86 | + throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); |
| 87 | + } |
| 88 | + return this.adventure; |
| 89 | + } |
| 90 | +} |
0 commit comments