Sit (untested) and NoJoinMessage
This commit is contained in:
@ -2,7 +2,9 @@ package com.pobnellion.pobutils
|
|||||||
|
|
||||||
import com.pobnellion.pobutils.modules.CmdModule
|
import com.pobnellion.pobutils.modules.CmdModule
|
||||||
import com.pobnellion.pobutils.modules.ModuleBase
|
import com.pobnellion.pobutils.modules.ModuleBase
|
||||||
|
import com.pobnellion.pobutils.modules.noJoinMessage.NoJoinMessage
|
||||||
import com.pobnellion.pobutils.modules.portals.Portals
|
import com.pobnellion.pobutils.modules.portals.Portals
|
||||||
|
import com.pobnellion.pobutils.modules.sit.Sit
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
|
|
||||||
@ -20,6 +22,8 @@ class Pobutils : JavaPlugin() {
|
|||||||
CmdModule.register(this)
|
CmdModule.register(this)
|
||||||
|
|
||||||
registerModule(Portals(this))
|
registerModule(Portals(this))
|
||||||
|
registerModule(NoJoinMessage(this))
|
||||||
|
registerModule(Sit(this))
|
||||||
|
|
||||||
logger.info("Registered ${availableModules.size} modules: [${availableModules.keys.joinToString()}]")
|
logger.info("Registered ${availableModules.size} modules: [${availableModules.keys.joinToString()}]")
|
||||||
|
|
||||||
@ -47,9 +51,11 @@ class Pobutils : JavaPlugin() {
|
|||||||
saveResource("config.yml", false)
|
saveResource("config.yml", false)
|
||||||
|
|
||||||
config.addDefault("modules.noJoinMessage", false)
|
config.addDefault("modules.noJoinMessage", false)
|
||||||
config.addDefault("modules.sit", false)
|
|
||||||
config.addDefault("modules.spawn", false)
|
|
||||||
config.addDefault("modules.portals", false)
|
config.addDefault("modules.portals", false)
|
||||||
|
|
||||||
|
config.addDefault("modules.sit", false)
|
||||||
|
|
||||||
|
config.addDefault("modules.spawn", false)
|
||||||
config.addDefault("modules.warp", false)
|
config.addDefault("modules.warp", false)
|
||||||
config.addDefault("modules.hub", false)
|
config.addDefault("modules.hub", false)
|
||||||
config.addDefault("modules.disableTNT", false)
|
config.addDefault("modules.disableTNT", false)
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
package com.pobnellion.pobutils.modules.noJoinMessage
|
||||||
|
|
||||||
|
import com.pobnellion.pobutils.Pobutils
|
||||||
|
import com.pobnellion.pobutils.modules.ModuleBase
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
|
class NoJoinMessage(plugin: JavaPlugin) : ModuleBase(plugin), Listener {
|
||||||
|
override val name: String = "noJoinMessage"
|
||||||
|
|
||||||
|
override fun register() {
|
||||||
|
plugin.server.pluginManager.registerEvents(this, plugin)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reload() {}
|
||||||
|
override fun onDisable() {}
|
||||||
|
override fun onEnable() {}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onPlayerJoin(event: PlayerJoinEvent) {
|
||||||
|
if (Pobutils.isEnabled(this.name))
|
||||||
|
event.joinMessage(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onPlayerLeave(event: PlayerQuitEvent) {
|
||||||
|
if (Pobutils.isEnabled(this.name))
|
||||||
|
event.quitMessage(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ object CmdPortal {
|
|||||||
fun register(plugin: JavaPlugin, portals: Portals) {
|
fun register(plugin: JavaPlugin, portals: Portals) {
|
||||||
val command = Commands.literal("portal")
|
val command = Commands.literal("portal")
|
||||||
.requires { source ->
|
.requires { source ->
|
||||||
Pobutils.isEnabled("portals") &&
|
Pobutils.isEnabled(portals.name) &&
|
||||||
source.sender.hasPermission("pobutils.admin") &&
|
source.sender.hasPermission("pobutils.admin") &&
|
||||||
source.sender is Player
|
source.sender is Player
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import com.google.common.io.ByteStreams
|
|||||||
import com.pobnellion.pobutils.Pobutils
|
import com.pobnellion.pobutils.Pobutils
|
||||||
import com.pobnellion.pobutils.modules.ModuleBase
|
import com.pobnellion.pobutils.modules.ModuleBase
|
||||||
import io.papermc.paper.math.BlockPosition
|
import io.papermc.paper.math.BlockPosition
|
||||||
import org.bukkit.Bukkit
|
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.attribute.Attribute
|
import org.bukkit.attribute.Attribute
|
||||||
@ -21,14 +20,12 @@ import org.bukkit.plugin.messaging.PluginMessageListener
|
|||||||
|
|
||||||
@Suppress("UnstableApiUsage")
|
@Suppress("UnstableApiUsage")
|
||||||
class Portals(plugin: JavaPlugin) : ModuleBase(plugin), Listener, PluginMessageListener {
|
class Portals(plugin: JavaPlugin) : ModuleBase(plugin), Listener, PluginMessageListener {
|
||||||
val portals: MutableList<Portal> = mutableListOf()
|
val portals: MutableSet<Portal> = mutableSetOf()
|
||||||
val portalCooldowns: MutableMap<Player, Location> = mutableMapOf()
|
val portalCooldowns: MutableMap<Player, Location> = mutableMapOf()
|
||||||
override val name: String = "portals"
|
override val name: String = "portals"
|
||||||
|
|
||||||
override fun register() {
|
override fun register() {
|
||||||
Bukkit.getPluginManager().registerEvents(this, plugin)
|
|
||||||
plugin.server.pluginManager.registerEvents(this, plugin)
|
plugin.server.pluginManager.registerEvents(this, plugin)
|
||||||
|
|
||||||
CmdPortal.register(plugin, this)
|
CmdPortal.register(plugin, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.pobnellion.pobutils.modules.sit
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command
|
||||||
|
import com.pobnellion.pobutils.Pobutils
|
||||||
|
import io.papermc.paper.command.brigadier.Commands
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
|
object CmdSit {
|
||||||
|
fun register(plugin: JavaPlugin, sit: Sit) {
|
||||||
|
val command = Commands.literal("sit")
|
||||||
|
.requires { source -> Pobutils.isEnabled(sit.name) && source.sender is Player }
|
||||||
|
.executes { ctx ->
|
||||||
|
sit.sit(ctx.source.sender as Player)
|
||||||
|
return@executes Command.SINGLE_SUCCESS
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
|
||||||
|
plugin.lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS) { commands ->
|
||||||
|
commands.registrar().register(command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/main/kotlin/com/pobnellion/pobutils/modules/sit/Sit.kt
Normal file
61
src/main/kotlin/com/pobnellion/pobutils/modules/sit/Sit.kt
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.pobnellion.pobutils.modules.sit
|
||||||
|
|
||||||
|
import com.pobnellion.pobutils.Pobutils
|
||||||
|
import com.pobnellion.pobutils.modules.ModuleBase
|
||||||
|
import org.bukkit.entity.Entity
|
||||||
|
import org.bukkit.entity.EntityType
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.entity.EntityDismountEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
|
class Sit(plugin: JavaPlugin) : ModuleBase(plugin), Listener {
|
||||||
|
override val name: String = "sit"
|
||||||
|
private val sittingPlayers: MutableMap<Player, Entity> = mutableMapOf()
|
||||||
|
|
||||||
|
override fun register() {
|
||||||
|
plugin.server.pluginManager.registerEvents(this, plugin)
|
||||||
|
CmdSit.register(plugin, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reload() {
|
||||||
|
onDisable()
|
||||||
|
onEnable()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEnable() { }
|
||||||
|
|
||||||
|
override fun onDisable() {
|
||||||
|
for ((_, seat) in sittingPlayers)
|
||||||
|
seat.remove()
|
||||||
|
|
||||||
|
sittingPlayers.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sit(player: Player) {
|
||||||
|
val seat = player.world.spawnEntity(player.location, EntityType.TEXT_DISPLAY)
|
||||||
|
seat.addScoreboardTag("seat")
|
||||||
|
seat.addPassenger(player)
|
||||||
|
sittingPlayers[player] = seat
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onPlayerDismount(event: EntityDismountEvent) {
|
||||||
|
if (event.entity !is Player || !Pobutils.isEnabled(this.name))
|
||||||
|
return
|
||||||
|
|
||||||
|
val player = event.entity as Player
|
||||||
|
if (sittingPlayers.containsKey(player))
|
||||||
|
sittingPlayers[player]?.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onPlayerLeave(event: PlayerQuitEvent) {
|
||||||
|
if (!Pobutils.isEnabled(this.name) || !sittingPlayers.containsKey(event.player))
|
||||||
|
return
|
||||||
|
|
||||||
|
sittingPlayers[event.player]?.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user