From a478bbab78be75fa37a0cfaed4e4810ab6169e05 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Fri, 6 Sep 2019 00:21:52 +0200 Subject: [PATCH] Fixed error message on success --- .../net/trivernis/superutils/EventListener.kt | 2 +- .../net/trivernis/superutils/SuperUtils.kt | 3 ++- .../trivernis/superutils/commands/CommandC.kt | 14 +++++++++++--- .../superutils/commands/CommandReload.kt | 17 +++++++++++++++++ .../trivernis/superutils/commands/CommandWp.kt | 9 +++++++-- src/main/resources/plugin.yml | 8 ++++++++ 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/net/trivernis/superutils/commands/CommandReload.kt diff --git a/src/main/kotlin/net/trivernis/superutils/EventListener.kt b/src/main/kotlin/net/trivernis/superutils/EventListener.kt index 4df3ca1..e3f2386 100644 --- a/src/main/kotlin/net/trivernis/superutils/EventListener.kt +++ b/src/main/kotlin/net/trivernis/superutils/EventListener.kt @@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerAdvancementDoneEvent import org.bukkit.event.player.PlayerGameModeChangeEvent import org.bukkit.potion.PotionEffectType -class EventListener(private val config: FileConfiguration, private val essentials: Essentials?, private val commandC: CommandC,): Listener { +class EventListener(private val config: FileConfiguration, private val essentials: Essentials?, private val commandC: CommandC): Listener { /** * Removes the night vision effect from the player if given by /c command */ diff --git a/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt index 8b3e53d..c72a0b4 100644 --- a/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt +++ b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt @@ -4,6 +4,7 @@ import com.earth2me.essentials.Essentials import com.onarandombox.MultiverseCore.MultiverseCore import net.trivernis.superutils.commands.CommandC import net.trivernis.superutils.commands.CommandH +import net.trivernis.superutils.commands.CommandReload import net.trivernis.superutils.commands.CommandWp import org.bukkit.configuration.file.FileConfiguration import org.bukkit.entity.Minecart @@ -19,6 +20,7 @@ class SuperUtils : JavaPlugin() { val essentials = getEssentials() val commandC = CommandC(getMultiverseCore(), essentials) server.pluginManager.registerEvents(EventListener(config, essentials, commandC), this) + getCommand("reload")?.setExecutor(CommandReload(this)) getCommand("c")?.setExecutor(commandC) if (essentials != null) { @@ -60,6 +62,5 @@ class SuperUtils : JavaPlugin() { private fun configure() { config.addDefault("advancement-payout", 50) config.options().copyDefaults(true) - saveConfig() } } diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt index de1f826..9ce0758 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt @@ -17,11 +17,19 @@ class CommandC(private var multiverseCore: MultiverseCore?, private var essentia override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { if (sender is Player && command.testPermission(sender)) { if (sender.gameMode != GameMode.SPECTATOR) { - sender.gameMode = GameMode.SPECTATOR - sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255)) if (essentials != null) { val commandCost = essentials!!.settings.getCommandCost("c") - essentials!!.getUser(sender).takeMoney(commandCost) + val essUser = essentials!!.getUser(sender) + if ((essUser.money - commandCost) > essentials!!.settings.minMoney) { + sender.gameMode = GameMode.SPECTATOR + sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255)) + essUser.takeMoney(commandCost) + } else { + sender.sendMessage("You do not have enough money for this command") + } + } else { + sender.gameMode = GameMode.SPECTATOR + sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255)) } } else { sender.removePotionEffect(PotionEffectType.NIGHT_VISION) diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandReload.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandReload.kt new file mode 100644 index 0000000..4e4f85b --- /dev/null +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandReload.kt @@ -0,0 +1,17 @@ +package net.trivernis.superutils.commands + +import net.trivernis.superutils.SuperUtils +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender + +class CommandReload(val superUtils: SuperUtils): CommandExecutor { + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (command.testPermission(sender)) { + superUtils.reloadConfig() + sender.sendMessage("Config for superutils reloaded.") + } + return true + } + +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt index a8d3068..3ac438d 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt @@ -36,8 +36,13 @@ class CommandWp(private val essentials: Essentials): CommandExecutor, TabComplet if (essentials.warps.list.find { it.equals(args[0], ignoreCase = true) }?.isNotEmpty() == true) { val warp = essentials.warps.getWarp(args.first()) val teleportCost = Trade(essentials.settings.getCommandCost("warp"), essentials) - essUser.teleport.teleport(warp.block.location, teleportCost, PlayerTeleportEvent.TeleportCause.COMMAND) - return true + if ((essUser.money - teleportCost.money) > essentials.settings.minMoney) { + essUser.teleport.teleport(warp.block.location, teleportCost, PlayerTeleportEvent.TeleportCause.COMMAND) + return true + } else { + sender.sendMessage("You do not have enough money for this command.") + return true + } } else { sender.sendMessage("Warp \"${args.first()}\" not found") } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cb4e489..2b96130 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,6 +5,11 @@ description: Utility commands plugin. author: Trivernis website: trivernis.net commands: + reload: + description: reloads the config of the plugin + permission: superutils.reload + permission-message: You do not have permission to reload the configuration! + usage: /reload c: description: spectator night vision permission: superutils.c @@ -21,6 +26,9 @@ commands: permission-message: You do not have permission! usage: /wp {warp} permissions: + superutils.reload: + description: Allows reload command + default: op superutils.c: description: Allows c command default: op