Changed to class for every command

master
Trivernis 5 years ago
parent cacca65d43
commit b3bdcaa822

@ -1,49 +1,40 @@
package net.trivernis.superutils package net.trivernis.superutils
import com.earth2me.essentials.Essentials import com.earth2me.essentials.Essentials
import com.earth2me.essentials.Trade import net.trivernis.superutils.commands.CommandC
import org.bukkit.GameMode import net.trivernis.superutils.commands.CommandH
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffectType
class Main : JavaPlugin() { class Main : JavaPlugin() {
/**
* Executed on plugin enable
*/
override fun onEnable() { override fun onEnable() {
val c = getCommand("c")
} if (c != null) {
c.setExecutor(CommandC())
override fun onDisable() {
} }
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() val essentials = getEssentials()
if (essentials != null) { if (essentials != null) {
val essUser = essentials.getUser(sender); val h = getCommand("h")
val userHome = essUser.getHome("home"); if (h != null) {
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND); h.setExecutor(CommandH(essentials))
essUser.sendMessage("You have been teleported home.");
} }
} }
} }
return false;
/**
* Executed on plugin disable
*/
override fun onDisable() {
} }
/**
* Returns instance of the essentials plugin
*/
private fun getEssentials(): Essentials? { private fun getEssentials(): Essentials? {
val essentials = server.pluginManager.getPlugin("Essentials"); val essentials = server.pluginManager.getPlugin("Essentials");
return if (essentials != null && essentials is 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