diff --git a/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt b/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt index 46da7d9..d734523 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt @@ -2,7 +2,9 @@ package com.pobnellion.pobutils import com.pobnellion.pobutils.modules.CmdModule 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.sit.Sit import org.bukkit.plugin.java.JavaPlugin @@ -20,6 +22,8 @@ class Pobutils : JavaPlugin() { CmdModule.register(this) registerModule(Portals(this)) + registerModule(NoJoinMessage(this)) + registerModule(Sit(this)) logger.info("Registered ${availableModules.size} modules: [${availableModules.keys.joinToString()}]") @@ -47,9 +51,11 @@ class Pobutils : JavaPlugin() { saveResource("config.yml", false) config.addDefault("modules.noJoinMessage", false) - config.addDefault("modules.sit", false) - config.addDefault("modules.spawn", false) config.addDefault("modules.portals", false) + + config.addDefault("modules.sit", false) + + config.addDefault("modules.spawn", false) config.addDefault("modules.warp", false) config.addDefault("modules.hub", false) config.addDefault("modules.disableTNT", false) diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/noJoinMessage/NoJoinMessage.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/noJoinMessage/NoJoinMessage.kt new file mode 100644 index 0000000..474b928 --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/noJoinMessage/NoJoinMessage.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/portals/CmdPortal.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/portals/CmdPortal.kt index e46edae..0e83fb6 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/portals/CmdPortal.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/portals/CmdPortal.kt @@ -21,7 +21,7 @@ object CmdPortal { fun register(plugin: JavaPlugin, portals: Portals) { val command = Commands.literal("portal") .requires { source -> - Pobutils.isEnabled("portals") && + Pobutils.isEnabled(portals.name) && source.sender.hasPermission("pobutils.admin") && source.sender is Player } diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/portals/Portals.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/portals/Portals.kt index e6fdac4..a69d0f6 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/portals/Portals.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/portals/Portals.kt @@ -4,7 +4,6 @@ import com.google.common.io.ByteStreams import com.pobnellion.pobutils.Pobutils import com.pobnellion.pobutils.modules.ModuleBase import io.papermc.paper.math.BlockPosition -import org.bukkit.Bukkit import org.bukkit.Location import org.bukkit.NamespacedKey import org.bukkit.attribute.Attribute @@ -21,14 +20,12 @@ import org.bukkit.plugin.messaging.PluginMessageListener @Suppress("UnstableApiUsage") class Portals(plugin: JavaPlugin) : ModuleBase(plugin), Listener, PluginMessageListener { - val portals: MutableList = mutableListOf() + val portals: MutableSet = mutableSetOf() val portalCooldowns: MutableMap = mutableMapOf() override val name: String = "portals" override fun register() { - Bukkit.getPluginManager().registerEvents(this, plugin) plugin.server.pluginManager.registerEvents(this, plugin) - CmdPortal.register(plugin, this) } diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/sit/CmdSit.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/sit/CmdSit.kt new file mode 100644 index 0000000..ca765a0 --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/sit/CmdSit.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/sit/Sit.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/sit/Sit.kt new file mode 100644 index 0000000..2cff8c3 --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/sit/Sit.kt @@ -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 = 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() + } +} \ No newline at end of file