Changed main class name and added events

- added event listener for advancement payout
- added config for payout configuration
- changed Main to SuperUtils
master
Trivernis 5 years ago
parent ed04cd011a
commit 3de6072d3a

@ -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())
}
}
}
}

@ -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()
}
}

@ -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<Player> = emptyList<Player>().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

@ -19,7 +19,8 @@ class CommandH(private var essentials: Essentials) : CommandExecutor, TabComplet
override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array<out String>): MutableList<String> {
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
}

@ -18,7 +18,7 @@ class CommandWp(private val essentials: Essentials): CommandExecutor, TabComplet
override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array<out String>): MutableList<String> {
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)
if (essentials.warps.list.find { it.equals(args[0], ignoreCase = true) }?.isNotEmpty() == true) {
val warp = essentials.warps.getWarp(args.first())
if (warp != null) {
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")
}

@ -1,4 +1,4 @@
main: net.trivernis.superutils.Main
main: net.trivernis.superutils.SuperUtils
name: SuperUtils
version: '1.0 SNAPSHOT'
description: Utility commands plugin.

Loading…
Cancel
Save