Suggestions for /h and Multiverse support for /c

master
Trivernis 5 years ago
parent b3bdcaa822
commit b4146b4e0f

@ -30,12 +30,16 @@ repositories {
maven { maven {
url "https://ci.ender.zone/plugin/repository/everything/" url "https://ci.ender.zone/plugin/repository/everything/"
} }
maven {
url "http://repo.onarandombox.com/content/repositories/multiverse/"
}
} }
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT" compileOnly "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT"
compileOnly 'net.ess3:EssentialsX:2.16.1' compileOnly 'net.ess3:EssentialsX:2.16.1'
compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
} }

@ -1,6 +1,7 @@
package net.trivernis.superutils package net.trivernis.superutils
import com.earth2me.essentials.Essentials import com.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore
import net.trivernis.superutils.commands.CommandC import net.trivernis.superutils.commands.CommandC
import net.trivernis.superutils.commands.CommandH import net.trivernis.superutils.commands.CommandH
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
@ -11,17 +12,13 @@ class Main : JavaPlugin() {
* Executed on plugin enable * Executed on plugin enable
*/ */
override fun onEnable() { override fun onEnable() {
val c = getCommand("c") logger.info("SuperUtils enabled.")
if (c != null) { getCommand("c")?.setExecutor(CommandC(getMultiverseCore()))
c.setExecutor(CommandC())
}
val essentials = getEssentials() val essentials = getEssentials()
if (essentials != null) { if (essentials != null) {
val h = getCommand("h") logger.info("Registering short forms for Essentials plugin features.")
if (h != null) { getCommand("h")?.setExecutor(CommandH(essentials))
h.setExecutor(CommandH(essentials))
}
} }
} }
@ -42,4 +39,15 @@ class Main : JavaPlugin() {
else else
null; 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 package net.trivernis.superutils.commands
import com.onarandombox.MultiverseCore.MultiverseCore
import org.bukkit.GameMode import org.bukkit.GameMode
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandExecutor
@ -7,7 +8,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffectType 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 * 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)) sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255))
} else { } else {
sender.removePotionEffect(PotionEffectType.NIGHT_VISION) 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
} }
} }

@ -6,10 +6,26 @@ import org.bukkit.Location
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent 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 * Teleports the user to the default home or a specified one
@ -23,8 +39,12 @@ class CommandH(private var essentials: Essentials) : CommandExecutor {
} else { } else {
essUser.getHome("home") essUser.getHome("home")
} }
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND) if (userHome != null) {
essUser.sendMessage("You have been teleported home.") 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 true
} }
return false return false

Loading…
Cancel
Save