diff --git a/src/main/kotlin/net/trivernis/superutils/EventListener.kt b/src/main/kotlin/net/trivernis/superutils/EventListener.kt new file mode 100644 index 0000000..4df3ca1 --- /dev/null +++ b/src/main/kotlin/net/trivernis/superutils/EventListener.kt @@ -0,0 +1,34 @@ +package net.trivernis.superutils + +import com.earth2me.essentials.Essentials +import net.trivernis.superutils.commands.CommandC +import org.bukkit.configuration.file.FileConfiguration +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +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 { + /** + * Removes the night vision effect from the player if given by /c command + */ + @EventHandler fun onPlayerGameModeChange(event: PlayerGameModeChangeEvent) { + if (commandC.spectatorPlayers.contains(event.player)) { + event.player.removePotionEffect(PotionEffectType.NIGHT_VISION) + commandC.spectatorPlayers.remove(event.player) + } + } + + /** + * Rewardes player advancements. + */ + @EventHandler fun onPlayerAdvancement(event: PlayerAdvancementDoneEvent) { + if (essentials != null) { + val payout = config.getDouble("advancement-payout") + if (payout > 0) { + essentials.getUser(event.player).giveMoney(payout.toBigDecimal()) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/superutils/Main.kt b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt similarity index 74% rename from src/main/kotlin/net/trivernis/superutils/Main.kt rename to src/main/kotlin/net/trivernis/superutils/SuperUtils.kt index bc19fa5..8b3e53d 100644 --- a/src/main/kotlin/net/trivernis/superutils/Main.kt +++ b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt @@ -5,17 +5,22 @@ import com.onarandombox.MultiverseCore.MultiverseCore import net.trivernis.superutils.commands.CommandC import net.trivernis.superutils.commands.CommandH import net.trivernis.superutils.commands.CommandWp +import org.bukkit.configuration.file.FileConfiguration +import org.bukkit.entity.Minecart import org.bukkit.plugin.java.JavaPlugin -class Main : JavaPlugin() { +class SuperUtils : JavaPlugin() { /** * Executed on plugin enable */ override fun onEnable() { - getCommand("c")?.setExecutor(CommandC(getMultiverseCore())) - + configure() val essentials = getEssentials() + val commandC = CommandC(getMultiverseCore(), essentials) + server.pluginManager.registerEvents(EventListener(config, essentials, commandC), this) + getCommand("c")?.setExecutor(commandC) + if (essentials != null) { logger.info("Registering short forms for Essentials plugin features.") getCommand("h")?.setExecutor(CommandH(essentials)) @@ -51,4 +56,10 @@ class Main : JavaPlugin() { else null } + + 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 7a5c164..de1f826 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt @@ -1,5 +1,6 @@ package net.trivernis.superutils.commands +import com.earth2me.essentials.Essentials import com.onarandombox.MultiverseCore.MultiverseCore import org.bukkit.GameMode import org.bukkit.command.Command @@ -8,7 +9,8 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import org.bukkit.potion.PotionEffectType -class CommandC(private var multiverseCore: MultiverseCore?): CommandExecutor { +class CommandC(private var multiverseCore: MultiverseCore?, private var essentials: Essentials?): CommandExecutor { + var spectatorPlayers: HashSet = emptyList().toHashSet() /** * Sets the users gamemode to spectator with nightvision or back to survival */ @@ -17,14 +19,20 @@ class CommandC(private var multiverseCore: MultiverseCore?): CommandExecutor { 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) + } } else { sender.removePotionEffect(PotionEffectType.NIGHT_VISION) if (multiverseCore != null) { // get the multiverse gamemode of the world val worldGameMode: GameMode = multiverseCore!!.mvWorldManager.getMVWorld(sender.world).gameMode sender.gameMode = worldGameMode + spectatorPlayers.add(sender) } else { sender.gameMode = GameMode.SURVIVAL + spectatorPlayers.remove(sender) } } return true diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt index 1a11813..83a243b 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt @@ -19,7 +19,8 @@ class CommandH(private var essentials: Essentials) : CommandExecutor, TabComplet override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array): MutableList { return if (sender is Player && command.testPermission(sender)) { if (args.isNotEmpty()) { - essentials.getUser(sender).homes.filter {it.contains(args.first())}.toMutableList() + essentials.getUser(sender).homes + .filter {it.indexOf(args[0], ignoreCase = true) == 0}.toMutableList() } else { essentials.getUser(sender).homes } diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt index 17d06bd..a8d3068 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandWp.kt @@ -18,7 +18,7 @@ class CommandWp(private val essentials: Essentials): CommandExecutor, TabComplet override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array): MutableList { if (sender is Player) { return if (args.isNotEmpty()) { - essentials.warps.list.filter{it.contains(args.first(), ignoreCase = true)}.toMutableList() + essentials.warps.list.filter { it.indexOf(args[0], ignoreCase = true) == 0 }.toMutableList() } else { essentials.warps.list.toMutableList() } @@ -33,10 +33,11 @@ class CommandWp(private val essentials: Essentials): CommandExecutor, TabComplet if (sender is Player) { if (args.isNotEmpty()) { val essUser: User = essentials.getUser(sender) - val warp = essentials.warps.getWarp(args.first()) - if (warp != null) { + 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 } else { sender.sendMessage("Warp \"${args.first()}\" not found") } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 42e0200..cb4e489 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ -main: net.trivernis.superutils.Main +main: net.trivernis.superutils.SuperUtils name: SuperUtils version: '1.0 SNAPSHOT' description: Utility commands plugin.