Skip to content

Commit

Permalink
+ Added an UpdateChecker.kt
Browse files Browse the repository at this point in the history
+ Bump version to v1.0.2
  • Loading branch information
TheLeCrafter committed Dec 5, 2021
1 parent de4417a commit 318d215
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "dev.thelecrafter.plugins.ambientstars"
version = "1.0.1"
version = "1.0.2"
val versionType: String = "stable"

repositories {
Expand All @@ -25,13 +25,15 @@ dependencies {
implementation("io.papermc:paperlib:1.0.7")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0")
implementation("io.github.classgraph:classgraph:4.8.137")
implementation("org.kohsuke:github-api:1.301")
}

tasks.shadowJar {
minimize()
relocate("org.jetbrains", "$group.org.jetbrains")
relocate("org.reflections", "$group.org.reflections")
relocate("io.papermc.lib", "$group.io.papermc.lib")
relocate("org.kohsuke", "$group.org.kohsuke")
archiveFileName.set("${project.name}-$versionType.jar")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.thelecrafter.plugins.ambientstars

import dev.thelecrafter.plugins.ambientstars.commands.ReloadCommand
import dev.thelecrafter.plugins.ambientstars.utils.EventCollector
import dev.thelecrafter.plugins.ambientstars.utils.UpdateChecker
import io.papermc.lib.PaperLib
import org.bukkit.Bukkit
import org.bukkit.command.CommandExecutor
Expand Down Expand Up @@ -43,6 +44,7 @@ class AmbientStarsPlugin : JavaPlugin() {
override fun onEnable() {
getInstance = this
getLogger = logger
UpdateChecker.checkForUpdates()
PaperLib.suggestPaper(getInstance, Level.WARNING)
getInstance.saveDefaultConfig()
getDefaultConfig = YamlConfiguration.loadConfiguration(getTextResource("config.yml")!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.thelecrafter.plugins.ambientstars.utils

import dev.thelecrafter.plugins.ambientstars.AmbientStarsPlugin
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.kohsuke.github.GHRelease
import org.kohsuke.github.GHRepository
import org.kohsuke.github.GitHub
import java.util.logging.Level

class UpdateChecker : Listener {

companion object {
private var upToDate: Boolean = true

fun checkForUpdates() {
val version: String = "v" + AmbientStarsPlugin.getInstance.description.version
val gitHub: GitHub = GitHub.connectAnonymously()
val repository: GHRepository = gitHub.getRepository("TheLeCrafter/ambientstars")!!
val latestRelease: GHRelease = repository.latestRelease
if (!latestRelease.isDraft && !latestRelease.isPrerelease) {
if (version != latestRelease.tagName) {
upToDate = false
AmbientStarsPlugin.getLogger.log(Level.WARNING, "The plugin is not up to date! Download the latest release at https://github.com/TheLeCrafter/ambientstars/releases")
}
} else AmbientStarsPlugin.getLogger.log(Level.WARNING, "Couldn't check the latest release because it's a draft/pre release! Check yourself at https://github.com/TheLeCrafter/ambientstars/releases")
}

fun getUpToDate(): Boolean {
return upToDate
}
}

@EventHandler
fun sendUpdateMessageOnOPJoin(event: PlayerJoinEvent) {
if (event.player.isOp || event.player.hasPermission("*")) {
if (!getUpToDate()) {
event.player.sendMessage(Component.text("[AmbientStars] The plugin is not up to date! Download the latest release ").color(NamedTextColor.YELLOW).append(Component.text("here").decorate(TextDecoration.UNDERLINED).color(NamedTextColor.BLUE).clickEvent(
ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/TheLeCrafter/ambientstars/releases")).hoverEvent(HoverEvent.showText(
Component.text("Opens https://github.com/TheLeCrafter/ambientstars/releases").color(NamedTextColor.GRAY)))))
}
}
}

}

0 comments on commit 318d215

Please sign in to comment.