Plugin.kt 1.8 KB
Newer Older
Linus K.'s avatar
Linus K. committed
1
2
package me.linuscde.mcplugins.autosyston

Linus K.'s avatar
Linus K. committed
3
import me.linuscde.mcplugins.autosyston.commands.SleepVote
Linus K.'s avatar
Linus K. committed
4
5
import me.linuscde.mcplugins.autosyston.listeners.*
import org.bukkit.Bukkit
Linus K.'s avatar
Linus K. committed
6
import org.bukkit.command.TabCompleter
Linus K.'s avatar
Linus K. committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import org.bukkit.plugin.java.JavaPlugin
import java.io.File
import java.util.logging.Level

class Plugin: JavaPlugin() {

    companion object {
        lateinit var instance: Plugin
            private set

        val pluginDir: File
            get() {
                val dir = File("plugins/${instance.name}")
                if(!dir.exists()) dir.mkdirs();
                return dir
            }

        val prefix: String by lazy {
            "§a[§2§o${instance.name}§r§a]§f"
        }
    }

    override fun onEnable() {
        instance = this
        registerCommands()
        registerTabCompleters()
        registerListeners()
        registerSchedulers()

        //Bukkit.getScheduler().scheduleSyncRepeatingTask(this, { saveConfig() }, 20*60*5, 20*60*5)

        logger.log(Level.INFO, "Plugin enabled")
    }

Linus K.'s avatar
Linus K. committed
41
42
43
    fun registerCommands() {
        getCommand("sleepvote")?.setExecutor(SleepVote())
    }
Linus K.'s avatar
Linus K. committed
44
45

    fun registerTabCompleters() {
Linus K.'s avatar
Linus K. committed
46
47
48
        for (commandName in arrayOf("sleepvote")) {
            getCommand(commandName)?.tabCompleter =  getCommand(commandName)?.executor as TabCompleter
        }
Linus K.'s avatar
Linus K. committed
49
50
51
52
53
    }

    fun registerListeners() {
        val pm = Bukkit.getPluginManager()
        pm.registerEvents(AutoFarmerListener(), this)
Linus K.'s avatar
Linus K. committed
54
        pm.registerEvents(ColoredSignsListener(), this)
55
        pm.registerEvents(KillCatsListener(), this)
Linus K.'s avatar
Linus K. committed
56
57
58
59
    }

    fun registerSchedulers() {
        AutoFarmerListener.initScheduler(this)
60
        KillCatsListener.initializeScheduler(this)
Linus K.'s avatar
Linus K. committed
61
62
63
64
65
66
67
    }

    override fun onDisable() {
        //saveConfig()
        logger.log(Level.INFO, "Plugin disabled")
    }
}