diff --git a/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt b/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt index f71c8d2..2bf1062 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/Pobutils.kt @@ -2,6 +2,7 @@ package com.pobnellion.pobutils import com.pobnellion.pobutils.modules.CmdModule import com.pobnellion.pobutils.modules.ModuleBase +import com.pobnellion.pobutils.modules.disableExplosions.DisableExplosions import com.pobnellion.pobutils.modules.disableTrample.DisableTrample import com.pobnellion.pobutils.modules.formatChat.FormatChat import com.pobnellion.pobutils.modules.hub.Hub @@ -9,6 +10,7 @@ import com.pobnellion.pobutils.modules.noJoinMessage.NoJoinMessage import com.pobnellion.pobutils.modules.portals.Portals import com.pobnellion.pobutils.modules.sit.Sit import com.pobnellion.pobutils.modules.spawn.Spawn +import com.pobnellion.pobutils.modules.warp.Warp import org.bukkit.plugin.java.JavaPlugin @@ -21,15 +23,19 @@ class Pobutils : JavaPlugin() { } override fun onEnable() { - loadDefaultConfig() - - registerModule(Portals(this)) + registerModule(DisableExplosions(this)) + registerModule(DisableTrample(this)) + registerModule(FormatChat(this)) // TODO: test set format config + registerModule(Hub(this)) registerModule(NoJoinMessage(this)) + registerModule(Portals(this)) registerModule(Sit(this)) // TODO: maybe sit when right click stairs? registerModule(Spawn(this)) - registerModule(Hub(this)) - registerModule(DisableTrample(this)) - registerModule(FormatChat(this)) + registerModule(Warp(this)) + //snowballDamage + + config.options().copyDefaults(true) + saveConfig() CmdModule.register(this) @@ -54,42 +60,8 @@ class Pobutils : JavaPlugin() { } private fun registerModule(module: ModuleBase) { + config.addDefault("modules.${module.name}", false) availableModules[module.name] = module module.register() } - - private fun loadDefaultConfig() { - saveResource("config.yml", false) - - config.addDefault("modules.noJoinMessage", false) - config.addDefault("modules.portals", false) - config.addDefault("modules.sit", false) - config.addDefault("modules.spawn", false) - config.addDefault("modules.hub", false) - config.addDefault("modules.disableTrample", false) - - config.addDefault("modules.formatChat", false) - config.addDefault("modules.disableTNT", false) - - config.addDefault("modules.warp", false) - config.addDefault("modules.snowballDamage", false) - config.addDefault("modules.tabList", false) - - config.addDefault("data.spawn.location", "") - config.addDefault("data.spawn.spawnOnJoin", false) - config.addDefault("data.spawn.spawnOnDeath", false) - - // config.addDefault("data.spawn.spawnOnFirstJoin", false); - config.addDefault("data.portals", "") - config.addDefault("data.warps", "") - config.addDefault("data.formatChat.serverAlias", "?") - config.addDefault("data.formatChat.messageFormat", " : ") - config.addDefault("data.formatChat.formatMessageText", true) - - config.addDefault("settings.snowballDamage.damageExceptions", ArrayList()) - config.addDefault("settings.snowballDamage.snowmenDontHitEachother", true) - - config.options().copyDefaults(true) - saveConfig() - } } diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/CmdModule.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/CmdModule.kt index a8b1968..2e6b343 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/CmdModule.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/CmdModule.kt @@ -19,7 +19,7 @@ object CmdModule { .then(enable(plugin)) .then(disable(plugin)) .then(reload(plugin)) - .then(config(plugin)) + .then(config()) .build() plugin.lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS) {commands -> @@ -120,7 +120,7 @@ object CmdModule { }) } - private fun config(plugin: JavaPlugin) : LiteralArgumentBuilder { + private fun config() : LiteralArgumentBuilder { val configCommand = Commands.literal("config") .executes { ctx -> for ((name, _) in Pobutils.availableModules) { diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/ModuleBase.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/ModuleBase.kt index de629d2..d28366b 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/ModuleBase.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/ModuleBase.kt @@ -1,6 +1,5 @@ package com.pobnellion.pobutils.modules -import com.mojang.brigadier.builder.ArgumentBuilder import com.mojang.brigadier.builder.LiteralArgumentBuilder import io.papermc.paper.command.brigadier.CommandSourceStack import org.bukkit.plugin.java.JavaPlugin diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/CmdDisableExplosionsConfig.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/CmdDisableExplosionsConfig.kt new file mode 100644 index 0000000..1c9fffd --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/CmdDisableExplosionsConfig.kt @@ -0,0 +1,35 @@ +package com.pobnellion.pobutils.modules.disableExplosions + +import com.mojang.brigadier.Command +import com.mojang.brigadier.arguments.BoolArgumentType +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +object CmdDisableExplosionsConfig { + fun configCmd(plugin: JavaPlugin, disableExplosions: DisableExplosions) : LiteralArgumentBuilder { + return Commands.literal(disableExplosions.name) + .then(Commands.literal("igniteTnt") + .then(Commands.argument("shouldIgniteTnt", BoolArgumentType.bool()) + .executes { ctx -> + val shouldIgniteTnt = BoolArgumentType.getBool(ctx, "shouldIgniteTnt") + disableExplosions.igniteTnt = shouldIgniteTnt + plugin.config.set("data.disableExplosions.igniteTnt", shouldIgniteTnt) + plugin.saveConfig() + ctx.source.sender.sendMessage(Component.text("igniteTnt set to: $shouldIgniteTnt", NamedTextColor.YELLOW)) + return@executes Command.SINGLE_SUCCESS + })) + .executes { ctx -> + ctx.source.sender.sendMessage("DisableExplosions config:") + + ctx.source.sender.sendMessage(Component.text("igniteTnt: ", NamedTextColor.YELLOW) + .append(Component.text(disableExplosions.igniteTnt.toString(), NamedTextColor.WHITE))) + + return@executes Command.SINGLE_SUCCESS + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/DisableExplosions.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/DisableExplosions.kt new file mode 100644 index 0000000..8a32b7b --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/disableExplosions/DisableExplosions.kt @@ -0,0 +1,47 @@ +package com.pobnellion.pobutils.modules.disableExplosions + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.pobnellion.pobutils.Pobutils +import com.pobnellion.pobutils.modules.ModuleBase +import io.papermc.paper.command.brigadier.CommandSourceStack +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityExplodeEvent +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +class DisableExplosions(plugin: JavaPlugin) : ModuleBase(plugin), Listener { + override val name: String = "disableExplosions" + var igniteTnt: Boolean = false + + override fun register() { + plugin.server.pluginManager.registerEvents(this, plugin) + } + + override fun reload() { + plugin.reloadConfig() + onEnable() + } + + override fun onDisable() { } + + override fun onEnable() { + igniteTnt = plugin.config.getBoolean("data.disableExplosions.igniteTnt") + } + + override fun configCmd(): LiteralArgumentBuilder? { + return CmdDisableExplosionsConfig.configCmd(plugin, this) + } + + @EventHandler + fun onExplosion(event: EntityExplodeEvent) { + if (!Pobutils.isEnabled(this.name)) + return + + if (igniteTnt) + event.blockList().removeIf { block -> block.type != Material.TNT } + else + event.blockList().clear() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/CmdFormatChatConfig.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/CmdFormatChatConfig.kt index af8205b..7f848ae 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/CmdFormatChatConfig.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/CmdFormatChatConfig.kt @@ -21,6 +21,7 @@ object CmdFormatChatConfig { plugin.config.set("data.formatChat.serverAlias", alias) formatChat.serverAlias = alias plugin.saveConfig() + ctx.source.sender.sendMessage(Component.text("serverAlias set to: $alias", NamedTextColor.YELLOW)) return@executes Command.SINGLE_SUCCESS })) .then(Commands.literal("messageFormat")) @@ -30,6 +31,7 @@ object CmdFormatChatConfig { plugin.config.set("data.formatChat.messageFormat", format) formatChat.messageFormat = format plugin.saveConfig() + ctx.source.sender.sendMessage(Component.text("messageFormat set to: $format", NamedTextColor.YELLOW)) return@executes Command.SINGLE_SUCCESS }) .then(Commands.literal("formatMessageText") @@ -39,19 +41,24 @@ object CmdFormatChatConfig { plugin.config.set("data.formatChat.formatMessageText", shouldFormat) formatChat.formatMessageText = shouldFormat plugin.saveConfig() + ctx.source.sender.sendMessage(Component.text("formatMessageText set to: $shouldFormat", NamedTextColor.YELLOW)) return@executes Command.SINGLE_SUCCESS })) .executes { ctx -> + val serverAlias = plugin.config.getString("data.formatChat.serverAlias", "?")!! + val messageFormat = plugin.config.getString("data.formatChat.messageFormat", formatChat.defaultFormat)!! + val formatMessageText = plugin.config.getBoolean("data.formatChat.formatMessageText", true) + ctx.source.sender.sendMessage("FormatChat config:") ctx.source.sender.sendMessage(Component.text("serverAlias: ", NamedTextColor.YELLOW) - .append(Component.text(formatChat.serverAlias, NamedTextColor.WHITE))) + .append(Component.text(serverAlias, NamedTextColor.WHITE))) ctx.source.sender.sendMessage(Component.text("messageFormat: ", NamedTextColor.YELLOW) - .append(Component.text(formatChat.messageFormat, NamedTextColor.WHITE))) + .append(Component.text(messageFormat, NamedTextColor.WHITE))) ctx.source.sender.sendMessage(Component.text("formatMessageText: ", NamedTextColor.YELLOW) - .append(Component.text(formatChat.formatMessageText.toString(), NamedTextColor.WHITE))) + .append(Component.text(formatMessageText.toString(), NamedTextColor.WHITE))) return@executes Command.SINGLE_SUCCESS } diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/FormatChat.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/FormatChat.kt index 5ad0b78..5d17001 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/FormatChat.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/FormatChat.kt @@ -15,6 +15,7 @@ class FormatChat(plugin: JavaPlugin) : ModuleBase(plugin), Listener { override val name: String = "formatChat" lateinit var serverAlias: String lateinit var messageFormat: String + val defaultFormat: String = " : " var formatMessageText: Boolean = false val renderer: Renderer = Renderer(this) @@ -30,9 +31,9 @@ class FormatChat(plugin: JavaPlugin) : ModuleBase(plugin), Listener { override fun onDisable() { } override fun onEnable() { - serverAlias = plugin.config.getString("data.formatChat.serverAlias")!! - messageFormat = plugin.config.getString("data.formatChat.messageFormat")!! - formatMessageText = plugin.config.getBoolean("data.formatChat.formatMessageText") + serverAlias = plugin.config.getString("data.formatChat.serverAlias", "?")!! + messageFormat = plugin.config.getString("data.formatChat.messageFormat", defaultFormat)!! + formatMessageText = plugin.config.getBoolean("data.formatChat.formatMessageText", true) } override fun configCmd() : LiteralArgumentBuilder? { diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/Renderer.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/Renderer.kt index 7c72a03..82dad97 100644 --- a/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/Renderer.kt +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/formatChat/Renderer.kt @@ -12,6 +12,7 @@ import org.bukkit.entity.Player class Renderer(val formatChat: FormatChat) : ChatRenderer { override fun render(source: Player, sourceDisplayName: Component, message: Component, viewer: Audience): Component { + // Removes at the start of the message return message } diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/warp/CmdWarp.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/CmdWarp.kt new file mode 100644 index 0000000..3f27a19 --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/CmdWarp.kt @@ -0,0 +1,43 @@ +package com.pobnellion.pobutils.modules.warp + +import com.mojang.brigadier.Command +import com.mojang.brigadier.arguments.StringArgumentType +import com.pobnellion.pobutils.Pobutils +import io.papermc.paper.command.brigadier.Commands +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +object CmdWarp { + fun register(plugin: JavaPlugin, warp: Warp) { + val command = Commands.literal("warp") + .requires { source -> Pobutils.isEnabled(warp.name) && source.sender is Player } + .then(Commands.argument("warp", StringArgumentType.string()) + .suggests { ctx, builder -> + for (name in warp.warps.keys) + builder.suggest(name) + + return@suggests builder.buildFuture() + } + .executes { ctx -> + val warpName = StringArgumentType.getString(ctx, "warp") + + val warpLocation = warp.warps[warpName] + + if (warpLocation == null) + ctx.source.sender.sendMessage(Component.text("No warp named '$warpName'", NamedTextColor.RED)) + else + (ctx.source.sender as Player).teleport(warpLocation) + + 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/warp/CmdWarpConfig.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/CmdWarpConfig.kt new file mode 100644 index 0000000..84882e3 --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/CmdWarpConfig.kt @@ -0,0 +1,123 @@ +package com.pobnellion.pobutils.modules.warp + +import com.mojang.brigadier.Command +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands +import io.papermc.paper.command.brigadier.argument.ArgumentTypes +import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +object CmdWarpConfig { + fun configCmd(plugin: JavaPlugin, warp: Warp) : LiteralArgumentBuilder { + return Commands.literal("warp") + .requires { source -> source.sender is Player } + .then(add(plugin, warp)) + .then(update(plugin, warp)) + .then(remove(plugin, warp)) + .executes { ctx -> + ctx.source.sender.sendMessage("Warps:") + + val warpNames = plugin.config.getConfigurationSection("data.warps")?.getKeys(false) + + if (warpNames == null) + return@executes Command.SINGLE_SUCCESS + + for (warpName in warpNames) { + val location = plugin.config.getLocation("data.warps.$warpName")!! + + ctx.source.sender.sendMessage(Component.text("$warpName:", NamedTextColor.YELLOW) + .append(Component.text("${location.x} ${location.y} ${location.z}"))) + } + + return@executes Command.SINGLE_SUCCESS + } + } + + private fun add(plugin: JavaPlugin, warp: Warp) : LiteralArgumentBuilder { + return Commands.literal("add") + .then(Commands.argument("name", StringArgumentType.word()) + .then(Commands.argument("location", ArgumentTypes.blockPosition()) + .executes { ctx -> + val name = StringArgumentType.getString(ctx, "name") + val position = ctx.getArgument("location", BlockPositionResolver::class.java).resolve(ctx.source) + val location = position.toLocation((ctx.source.sender as Player).world) + + if (plugin.config.get("data.warps.$name") != null) { + ctx.source.sender.sendMessage(Component.text("A warp called $name already exists!", NamedTextColor.RED)) + return@executes Command.SINGLE_SUCCESS + } + + plugin.config.set("data.warps.$name", location) + plugin.saveConfig() + + warp.warps[name] = location + + ctx.source.sender.sendMessage(Component.text("Created warp '$name'", NamedTextColor.YELLOW)) + + return@executes Command.SINGLE_SUCCESS + })) + } + + private fun update(plugin: JavaPlugin, warp: Warp) : LiteralArgumentBuilder { + return Commands.literal("update") + .then(Commands.argument("name", StringArgumentType.word()) + .suggests { ctx, builder -> + val warpNames = plugin.config.getConfigurationSection("data.warps")?.getKeys(false) + warpNames?.forEach { name -> builder.suggest(name) } + return@suggests builder.buildFuture() + } + .then(Commands.argument("location", ArgumentTypes.blockPosition()) + .executes { ctx -> + val name = StringArgumentType.getString(ctx, "name") + val position = ctx.getArgument("location", BlockPositionResolver::class.java).resolve(ctx.source) + val location = position.toLocation((ctx.source.sender as Player).world) + + if (plugin.config.get("data.warps.$name") == null) { + ctx.source.sender.sendMessage(Component.text("Could not find a warp called $name!", NamedTextColor.RED)) + return@executes Command.SINGLE_SUCCESS + } + + plugin.config.set("data.warps.$name", location) + plugin.saveConfig() + + warp.warps[name] = location + + ctx.source.sender.sendMessage(Component.text("Updated warp '$name'", NamedTextColor.YELLOW)) + + return@executes Command.SINGLE_SUCCESS + })) + } + + private fun remove(plugin: JavaPlugin, warp: Warp) : LiteralArgumentBuilder { + return Commands.literal("remove") + .then(Commands.argument("name", StringArgumentType.word()) + .suggests { ctx, builder -> + val warpNames = plugin.config.getConfigurationSection("data.warps")?.getKeys(false) + warpNames?.forEach { name -> builder.suggest(name) } + return@suggests builder.buildFuture() + } + .executes { ctx -> + val name = StringArgumentType.getString(ctx, "name") + + if (plugin.config.get("data.warps.$name") == null) { + ctx.source.sender.sendMessage(Component.text("Could not find a warp called $name!", NamedTextColor.RED)) + return@executes Command.SINGLE_SUCCESS + } + + plugin.config.set("data.warps.$name", null) + plugin.saveConfig() + + warp.warps.remove(name) + + ctx.source.sender.sendMessage(Component.text("Removed warp '$name'", NamedTextColor.YELLOW)) + + return@executes Command.SINGLE_SUCCESS + }) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/pobnellion/pobutils/modules/warp/Warp.kt b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/Warp.kt new file mode 100644 index 0000000..dbe091d --- /dev/null +++ b/src/main/kotlin/com/pobnellion/pobutils/modules/warp/Warp.kt @@ -0,0 +1,39 @@ +package com.pobnellion.pobutils.modules.warp + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.pobnellion.pobutils.modules.ModuleBase +import io.papermc.paper.command.brigadier.CommandSourceStack +import org.bukkit.Location +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +class Warp(plugin: JavaPlugin) : ModuleBase(plugin) { + override val name: String = "warp" + val warps: MutableMap = mutableMapOf() + + override fun register() { + CmdWarp.register(plugin, this) + } + + override fun reload() { + warps.clear() + plugin.reloadConfig() + onEnable() + } + + override fun onDisable() { } + + override fun onEnable() { + val warpNames = plugin.config.getConfigurationSection("data.warps")?.getKeys(false) + + if (warpNames == null) + return + + for (warpName in warpNames) + warps[warpName] = plugin.config.getLocation("data.warps.$warpName")!! + } + + override fun configCmd(): LiteralArgumentBuilder? { + return CmdWarpConfig.configCmd(plugin, this) + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index 788472d..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,27 +0,0 @@ -modules: - noJoinMessage: true - sit: true - spawn: false - portals: false - warp: false - hub: true - disableTNT: false - tabList: false - formatChat: true - disableTrample: false - snowballDamage: false -data: - spawn: - location: '' - spawnOnJoin: false - spawnOnDeath: false - portals: '' - warps: '' - formatChat: - serverAlias: '?' - messageFormat: ' : ' - formatMessageText: true -settings: - snowballDamage: - damageExceptions: [] - snowmenDontHitEachother: true \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d24b28d..21ce0e5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,7 +8,7 @@ authors: [ Bizink ] commands: module: description: configure a module - usage: /module + usage: /module permission: pobutils.admin spawn: @@ -16,11 +16,6 @@ commands: usage: /spawn permission: pobutils.user - setspawn: - description: Set spawn location - usage: /setspawn [location] - permission: pobutils.admin - sit: description: Sit down for a while buddy usage: /sit @@ -28,12 +23,12 @@ commands: portal: description: add or remove a portal to another server - usage: /portal [x1] [y1] [z1] [x2] [y2] [z2] [destinationServer] + usage: /portal [name] [x1] [y1] [z1] [x2] [y2] [z2] [destinationServer] permission: pobutils.admin warp: description: list or go to warps - usage: /warp [add|del|list|warpName] [warpName] [x] [y] [z] [yaw] [pitch] + usage: /warp permission: pobutils.user hub: