File tree 3 files changed +41
-2
lines changed
src/main/kotlin/dev/themeinerlp/attollo 3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,10 @@ bukkit {
77
77
description = " Allows the player to use the plugin"
78
78
default = Default .TRUE
79
79
}
80
+ register(" attollo.update" ) {
81
+ description = " Allows the player to see update notifications"
82
+ default = Default .OP
83
+ }
80
84
}
81
85
commands {
82
86
register(" attollo" ) {
Original file line number Diff line number Diff line change 1
1
package dev.themeinerlp.attollo
2
2
3
3
import dev.themeinerlp.attollo.listener.AttolloListener
4
+ import dev.themeinerlp.attollo.listener.UpdateCheckerListener
4
5
import org.bukkit.Material
5
6
import org.bukkit.plugin.java.JavaPlugin
6
7
7
8
open class Attollo : JavaPlugin () {
8
9
9
-
10
10
lateinit var elevatorBlock: Material
11
+
11
12
override fun onLoad () {
12
13
saveDefaultConfig()
13
14
}
@@ -23,6 +24,7 @@ open class Attollo : JavaPlugin() {
23
24
elevatorBlock = material ? : Material .DAYLIGHT_DETECTOR
24
25
logger.info(" Using elevatorBlock: $elevatorBlock " )
25
26
server.pluginManager.registerEvents(AttolloListener (this ), this )
27
+ server.pluginManager.registerEvents(UpdateCheckerListener (this ), this )
26
28
}
27
29
28
- }
30
+ }
Original file line number Diff line number Diff line change
1
+ package dev.themeinerlp.attollo.listener
2
+
3
+ import dev.themeinerlp.attollo.Attollo
4
+ import org.bukkit.event.EventHandler
5
+ import org.bukkit.event.Listener
6
+ import org.bukkit.event.player.PlayerJoinEvent
7
+ import java.net.URI
8
+
9
+ class UpdateCheckerListener (private val attollo : Attollo ) : Listener {
10
+
11
+ @EventHandler
12
+ fun onJoin (event : PlayerJoinEvent ) {
13
+ val player = event.player
14
+ if (player.hasPermission(" attollo.update" )) {
15
+ attollo.server.scheduler.runTaskAsynchronously(attollo, Runnable {
16
+ val latestVersion = getLatestVersion()
17
+ if (attollo.description.version != latestVersion) {
18
+ player.sendMessage(
19
+ " §aAn update for Attollo is available! Version: $latestVersion " ,
20
+ " §aYou can download it at: https://hangar.papermc.io/OneLiteFeather/Attollo"
21
+ )
22
+ }
23
+ })
24
+ }
25
+ }
26
+
27
+ private fun getLatestVersion (): String {
28
+ val url = URI .create(" https://hangar.papermc.io/api/v1/projects/Attollo/latestrelease" ).toURL()
29
+ val reader = url.openStream().bufferedReader()
30
+ val content = reader.use { it.readText() }
31
+ return content
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments