Commit 0084a18b authored by Linus K.'s avatar Linus K.
Browse files

Add random motds

parent 81f0d95b
......@@ -56,12 +56,14 @@ class Plugin: JavaPlugin() {
pm.registerEvents(ColoredSignsListener(), this)
pm.registerEvents(KillCatsListener(), this)
pm.registerEvents(CoordHudListener(), this)
pm.registerEvents(RandomMotdListener(), this)
}
fun registerSchedulers() {
AutoFarmerListener.initScheduler(this)
KillCatsListener.initializeScheduler(this)
CoordHudListener.initializeScheduler(this)
RandomMotdListener.initializeScheduler(this)
}
override fun onDisable() {
......
package me.linuscde.mcplugins.autosyston.listeners
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.server.ServerListPingEvent
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
import java.util.*
class RandomMotdListener: Listener {
companion object {
val SENTENCES = arrayListOf<String>()
val SENTENCES_URL = URL("https://cosmos-ink.net/random_sentences.txt")
val RNG = Random()
fun updateSentences() {
val br = BufferedReader(InputStreamReader(SENTENCES_URL.openStream()))
val newList = arrayListOf<String>()
br.forEachLine { sentence ->
if(!(sentence.trim().isBlank() || sentence.trim().startsWith("#")))
newList.add(sentence.trim())
}
br.close()
SENTENCES.clear()
SENTENCES.addAll(newList)
}
fun initializeScheduler(plugin: org.bukkit.plugin.Plugin) {
Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, { updateSentences() }, 0, 20*60*30) // every 30 min
}
}
@EventHandler
fun onServerListPing(e: ServerListPingEvent) {
if(SENTENCES.isEmpty()) return
e.motd = SENTENCES[RNG.nextInt(SENTENCES.size)]
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte Frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close