From b4146b4e0f35016156288dc6c4c84d6a067f8a35 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Wed, 4 Sep 2019 11:54:12 +0200 Subject: [PATCH] Suggestions for /h and Multiverse support for /c --- build.gradle | 4 +++ .../kotlin/net/trivernis/superutils/Main.kt | 24 +++++++++++------ .../trivernis/superutils/commands/CommandC.kt | 15 ++++++++--- .../trivernis/superutils/commands/CommandH.kt | 26 ++++++++++++++++--- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 958efdd..6638cb1 100644 --- a/build.gradle +++ b/build.gradle @@ -30,12 +30,16 @@ repositories { maven { url "https://ci.ender.zone/plugin/repository/everything/" } + maven { + url "http://repo.onarandombox.com/content/repositories/multiverse/" + } } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compileOnly "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT" compileOnly 'net.ess3:EssentialsX:2.16.1' + compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.0.0' compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } diff --git a/src/main/kotlin/net/trivernis/superutils/Main.kt b/src/main/kotlin/net/trivernis/superutils/Main.kt index 2b950a1..193608f 100644 --- a/src/main/kotlin/net/trivernis/superutils/Main.kt +++ b/src/main/kotlin/net/trivernis/superutils/Main.kt @@ -1,6 +1,7 @@ package net.trivernis.superutils import com.earth2me.essentials.Essentials +import com.onarandombox.MultiverseCore.MultiverseCore import net.trivernis.superutils.commands.CommandC import net.trivernis.superutils.commands.CommandH import org.bukkit.plugin.java.JavaPlugin @@ -11,17 +12,13 @@ class Main : JavaPlugin() { * Executed on plugin enable */ override fun onEnable() { - val c = getCommand("c") - if (c != null) { - c.setExecutor(CommandC()) - } + logger.info("SuperUtils enabled.") + getCommand("c")?.setExecutor(CommandC(getMultiverseCore())) val essentials = getEssentials() if (essentials != null) { - val h = getCommand("h") - if (h != null) { - h.setExecutor(CommandH(essentials)) - } + logger.info("Registering short forms for Essentials plugin features.") + getCommand("h")?.setExecutor(CommandH(essentials)) } } @@ -42,4 +39,15 @@ class Main : JavaPlugin() { else null; } + + /** + * Returns instance of multiverse plugin + */ + private fun getMultiverseCore(): MultiverseCore? { + val multiverseCore = server.pluginManager.getPlugin("Multiverse-Core") + return if (multiverseCore != null && multiverseCore is MultiverseCore) + multiverseCore + else + null + } } diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandC.kt index 83cc8e3..df4de25 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.onarandombox.MultiverseCore.MultiverseCore import org.bukkit.GameMode import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -7,7 +8,7 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import org.bukkit.potion.PotionEffectType -class CommandC: CommandExecutor { +class CommandC(private var multiverseCore: MultiverseCore?): CommandExecutor { /** * Sets the users gamemode to spectator with nightvision or back to survival */ @@ -18,10 +19,16 @@ class CommandC: CommandExecutor { sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255)) } else { sender.removePotionEffect(PotionEffectType.NIGHT_VISION) - sender.gameMode = GameMode.SURVIVAL + if (multiverseCore != null) { + // get the multiverse gamemode of the world + val worldGameMode: GameMode = multiverseCore!!.mvWorldManager.getMVWorld(sender.world).gameMode + sender.gameMode = worldGameMode + } else { + sender.gameMode = GameMode.SURVIVAL + } } - return true; + return true } - return false; + return false } } \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt index 42e5bfa..a408d4a 100644 --- a/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandH.kt @@ -6,10 +6,26 @@ import org.bukkit.Location import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter import org.bukkit.entity.Player import org.bukkit.event.player.PlayerTeleportEvent -class CommandH(private var essentials: Essentials) : CommandExecutor { +class CommandH(private var essentials: Essentials) : CommandExecutor, TabCompleter { + + /** + * Tab completion suggestions for homes + */ + 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() + } else { + essentials.getUser(sender).homes + } + } else { + emptyList().toMutableList() + } + } /** * Teleports the user to the default home or a specified one @@ -23,8 +39,12 @@ class CommandH(private var essentials: Essentials) : CommandExecutor { } else { essUser.getHome("home") } - essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND) - essUser.sendMessage("You have been teleported home.") + if (userHome != null) { + essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND) + essUser.sendMessage("You have been teleported home.") + } else { + essUser.sendMessage("The specified home was not found.") + } return true } return false