Fixed world save message

master
Trivernis 5 years ago
parent c2ba86b660
commit f165e11cee

@ -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 org.bukkit.Server
import org.bukkit.configuration.file.FileConfiguration
@ -12,6 +13,7 @@ import org.bukkit.event.world.WorldSaveEvent
import org.bukkit.potion.PotionEffectType
class EventListener(private val config: FileConfiguration, private val essentials: Essentials?,
private val multiverseCore: MultiverseCore?,
private val commandC: CommandC, private val server: Server): Listener {
/**
* Removes the night vision effect from the player if given by /c command
@ -36,11 +38,21 @@ class EventListener(private val config: FileConfiguration, private val essential
}
/**
* Broadcasts that the world has been saved
* Broadcasts that the world has been saved.
* If multiverse core is used, the message is broadcasted for the spawn world.
* Else it is broadcasted for the world with the name "world"
*/
@EventHandler fun onWorldSave(event: WorldSaveEvent) {
if (config.getBoolean("save-notification")) {
server.broadcastMessage("The world has been saved.")
if (multiverseCore != null) {
if (multiverseCore.mvWorldManager.firstSpawnWorld.name == event.world.name) {
server.broadcastMessage("The world has been saved.")
}
} else {
if (event.world.name == "world") {
server.broadcastMessage("The world has been saved.")
}
}
}
}
}

@ -2,10 +2,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 net.trivernis.superutils.commands.CommandReload
import net.trivernis.superutils.commands.CommandWp
import net.trivernis.superutils.commands.*
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Minecart
import org.bukkit.plugin.java.JavaPlugin
@ -19,8 +16,9 @@ class SuperUtils : JavaPlugin() {
configure()
val essentials = getEssentials()
val commandC = CommandC(getMultiverseCore(), essentials)
server.pluginManager.registerEvents(EventListener(config, essentials, commandC, server), this)
server.pluginManager.registerEvents(EventListener(config, essentials, getMultiverseCore(), commandC, server), this)
getCommand("superutils reload")?.setExecutor(CommandReload(this))
getCommand("scheduleshutdown")?.setExecutor(CommandScheduleShutdown(this))
getCommand("c")?.setExecutor(commandC)
if (essentials != null) {

@ -0,0 +1,31 @@
package net.trivernis.superutils.commands
import java.lang.Double.parseDouble
import net.trivernis.superutils.SuperUtils
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import java.lang.NumberFormatException
class CommandScheduleShutdown(private val superUtils: SuperUtils): CommandExecutor {
/**
* Command that schedules a server shutdown.
*/
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
var scheduling: Double = 60.0 // 10 seconds to shutdown
if (!args.isNullOrEmpty()) {
try {
scheduling = parseDouble(args[0])
} catch (e: NumberFormatException) {
sender.sendMessage("Invalid number format for timing")
return false
}
}
sender.server.scheduler.scheduleSyncDelayedTask(superUtils, {
sender.server.shutdown()
}, (20*scheduling).toLong())
sender.server.broadcastMessage("Server shutdown in $scheduling seconds!")
return true
}
}

@ -25,6 +25,11 @@ commands:
permission: superutils.wp
permission-message: You do not have permission!
usage: /wp {warp}
scheduleshutdown:
description: schedule a restart
permission: superutils.scheduleshutdown
permission-message: You do not have permission!
usage: /schedulerestart {seconds}
permissions:
superutils.reload:
description: Allows reload command
@ -38,6 +43,9 @@ permissions:
superutils.wp:
description: Allow wp command
default: op
superutils.scheduleshutdown:
description: Allow scheduleshutdown command
default: op
superutils.*:
description: Wildcard permission
default: op

Loading…
Cancel
Save