Suggestions for /h and Multiverse support for /c

master
Trivernis 5 years ago
parent b3bdcaa822
commit b4146b4e0f

@ -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"
}

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

@ -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)
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 false;
return true
}
return false
}
}

@ -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<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()
} else {
essentials.getUser(sender).homes
}
} else {
emptyList<String>().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")
}
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

Loading…
Cancel
Save