Skip to content

Commit

Permalink
Add update notifier (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Nov 15, 2023
1 parent 280e1b8 commit e193e1e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ version = "1.2.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://jitpack.io")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
}

dependencies {
implementation("com.github.TechnicJelle:UpdateCheckerJava:2.2")
compileOnly(dependencyNotation = "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")
compileOnly(dependencyNotation = "net.kyori:adventure-api:4.14.0")
compileOnly(dependencyNotation = "net.kyori:adventure-platform-bukkit:4.3.1")
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/armamc/plugincontrol/PluginControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.armamc.plugincontrol.managers.ConfigManager;
import com.armamc.plugincontrol.managers.MessageManager;
import com.armamc.plugincontrol.managers.PluginsManager;
import com.technicjelle.UpdateChecker;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -21,6 +22,7 @@ public void onEnable() {
registerConfig();
registerCommands();
registerTask();
registerUpdateNotifier();
}

@Override
Expand Down Expand Up @@ -55,6 +57,14 @@ private void registerTask() {
Bukkit.getScheduler().runTaskLater(this, pluginsManager::checkPlugins, 20L);
}

private void registerUpdateNotifier() {
if (configManager.isUpdateNotifierEnabled()) {
UpdateChecker updateChecker = new UpdateChecker("SrBedrock", "PluginControl", "1.1.1");
updateChecker.checkAsync();
updateChecker.logUpdateMessage(getLogger());
}
}

@Contract(pure = true)
public ConfigManager getConfigManager() {
return configManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public List<String> getServerPlugins() {
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).toList().stream().map(Plugin::getName).toList();
}

// update
public boolean isUpdateNotifierEnabled() {
return config.getBoolean("update-notifier", false);
}

// enabled
public boolean isEnabled() {
if (config.getString(ENABLED) == null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
update-notifier: false
enabled: false
# Action to take if all listed plugins are not enabled.
# log-to-console
# disallow-player-login
# shutdown-server
action: log-to-console
plugins: []
groups: {}
plugins: [ ]
groups: { }

0 comments on commit e193e1e

Please sign in to comment.