Loader.kt 3.07 KB
Newer Older
Moritz Sokoll's avatar
Moritz Sokoll committed
1
2
3
4
5
6
7
8
9
10
11
package main

import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
Moritz Sokoll's avatar
Moritz Sokoll committed
12
import org.bukkit.event.player.AsyncPlayerChatEvent
Moritz Sokoll's avatar
Moritz Sokoll committed
13
import org.bukkit.event.player.PlayerJoinEvent
Moritz Sokoll's avatar
Moritz Sokoll committed
14
import org.bukkit.event.player.PlayerQuitEvent
Moritz Sokoll's avatar
Moritz Sokoll committed
15
16
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.java.JavaPlugin
Moritz Sokoll's avatar
Moritz Sokoll committed
17
18
import org.bukkit.scoreboard.DisplaySlot
import org.bukkit.scoreboard.Scoreboard
Moritz Sokoll's avatar
Moritz Sokoll committed
19
20
21
22
23
24
25
26
27
28
import java.sql.Time
import java.time.Instant

public class Loader : JavaPlugin(), Listener, CommandExecutor {
    override fun onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this)
    }

    @EventHandler
    public fun joinEvent(event: PlayerJoinEvent) {
Moritz Sokoll's avatar
Moritz Sokoll committed
29
        event.joinMessage = "§2>>§7 " + event.player.displayName
Moritz Sokoll's avatar
Moritz Sokoll committed
30
        val players = Bukkit.getOnlinePlayers()
Moritz Sokoll's avatar
Moritz Sokoll committed
31
32
33
34
35
        for (p in players) {
            event.player.sendMessage("Currently there are " + players.size + " players online!")
        }
    }

Moritz Sokoll's avatar
Moritz Sokoll committed
36
37
38
39
40
41
42
43
44
45
    @EventHandler
    public fun leaveEvent(event: PlayerQuitEvent) {
        event.quitMessage = "§4<<§7 " + event.player.displayName
    }

    @EventHandler
    public fun chatEvent(event: AsyncPlayerChatEvent) {
        event.format = "§3" + event.player.displayName + ":§7 " + event.message
    }

Moritz Sokoll's avatar
Moritz Sokoll committed
46
47
48
49
50
51
52
53
54
    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        if (sender is Player) {
            when(command.name){
                "whoami" -> {
                    sender.sendMessage("name: " + sender.name)
                    sender.sendMessage("uuid: " + sender.uniqueId)
                }
                "permissions" -> {
                    if (args.isEmpty()) {
Moritz Sokoll's avatar
Moritz Sokoll committed
55
56
                        sender.effectivePermissions.forEach {
                            sender.sendMessage(it.permission)
Moritz Sokoll's avatar
Moritz Sokoll committed
57
                        }
Moritz Sokoll's avatar
Moritz Sokoll committed
58
59
60
61
62
                    } else {
                        val name = args[0]
                        server.onlinePlayers
                                .filter { it.name == name }
                                .firstOrNull()?.effectivePermissions?.forEach { sender.sendMessage(it.permission) }
Moritz Sokoll's avatar
Moritz Sokoll committed
63
64
65

                    }
                }
Moritz Sokoll's avatar
Moritz Sokoll committed
66
67
68
69
70
71
                "nick" -> {
                    if (args.joinToString(" ") == "") {
                        sender.sendMessage("§4nickname cant be empty")
                    }
                    else {
                        sender.setDisplayName(args.joinToString(" "))
Moritz Sokoll's avatar
Moritz Sokoll committed
72
                        sender.setPlayerListName(args.joinToString(" "))
Moritz Sokoll's avatar
Moritz Sokoll committed
73
74
75
76
77
                        sender.sendMessage("§2You are now nicked")
                    }
                }
                "unnick" -> {
                    sender.setDisplayName(sender.name)
Moritz Sokoll's avatar
Moritz Sokoll committed
78
                    sender.setPlayerListName(sender.name)
Moritz Sokoll's avatar
Moritz Sokoll committed
79
                    sender.sendMessage("§4You are not nicked anymore!")
Moritz Sokoll's avatar
Moritz Sokoll committed
80
81
82
83
84
85
86
                }
            }
        }
        return true
    }

}