Changed to class for every command

master
Trivernis 5 years ago
parent cacca65d43
commit b3bdcaa822

@ -1,49 +1,40 @@
package net.trivernis.superutils
import com.earth2me.essentials.Essentials
import com.earth2me.essentials.Trade
import org.bukkit.GameMode
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent
import net.trivernis.superutils.commands.CommandC
import net.trivernis.superutils.commands.CommandH
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffectType
class Main : JavaPlugin() {
/**
* Executed on plugin enable
*/
override fun onEnable() {
}
override fun onDisable() {
val c = getCommand("c")
if (c != null) {
c.setExecutor(CommandC())
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
if (sender is Player) {
if (command.name.equals("c", ignoreCase = true) && sender.hasPermission("superutils.c")) {
if (sender.gameMode != GameMode.SPECTATOR) {
sender.gameMode = GameMode.SPECTATOR
sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255))
} else {
sender.removePotionEffect(PotionEffectType.NIGHT_VISION)
sender.gameMode = GameMode.SURVIVAL
}
return true
} else if (command.name.equals("h", ignoreCase = true) && sender.hasPermission("superutils.h")) {
val essentials = getEssentials()
if (essentials != null) {
val essUser = essentials.getUser(sender);
val userHome = essUser.getHome("home");
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND);
essUser.sendMessage("You have been teleported home.");
val h = getCommand("h")
if (h != null) {
h.setExecutor(CommandH(essentials))
}
}
}
return false;
/**
* Executed on plugin disable
*/
override fun onDisable() {
}
/**
* Returns instance of the essentials plugin
*/
private fun getEssentials(): Essentials? {
val essentials = server.pluginManager.getPlugin("Essentials");
return if (essentials != null && essentials is Essentials)

@ -0,0 +1,27 @@
package net.trivernis.superutils.commands
import org.bukkit.GameMode
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffectType
class CommandC: CommandExecutor {
/**
* Sets the users gamemode to spectator with nightvision or back to survival
*/
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): 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))
} else {
sender.removePotionEffect(PotionEffectType.NIGHT_VISION)
sender.gameMode = GameMode.SURVIVAL
}
return true;
}
return false;
}
}

@ -0,0 +1,32 @@
package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials
import com.earth2me.essentials.UserData
import org.bukkit.Location
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent
class CommandH(private var essentials: Essentials) : CommandExecutor {
/**
* Teleports the user to the default home or a specified one
*/
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player && command.testPermission(sender)) {
val essUser = essentials.getUser(sender)
val userHome: Location
userHome = if (args.isNotEmpty()) {
essUser.getHome(args[0])
} else {
essUser.getHome("home")
}
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND)
essUser.sendMessage("You have been teleported home.")
return true
}
return false
}
}
Loading…
Cancel
Save