Fixed world save message

master
Trivernis 5 years ago
parent c2ba86b660
commit f165e11cee

@ -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 org.bukkit.Server import org.bukkit.Server
import org.bukkit.configuration.file.FileConfiguration import org.bukkit.configuration.file.FileConfiguration
@ -12,6 +13,7 @@ import org.bukkit.event.world.WorldSaveEvent
import org.bukkit.potion.PotionEffectType import org.bukkit.potion.PotionEffectType
class EventListener(private val config: FileConfiguration, private val essentials: Essentials?, class EventListener(private val config: FileConfiguration, private val essentials: Essentials?,
private val multiverseCore: MultiverseCore?,
private val commandC: CommandC, private val server: Server): Listener { private val commandC: CommandC, private val server: Server): Listener {
/** /**
* Removes the night vision effect from the player if given by /c command * 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) { @EventHandler fun onWorldSave(event: WorldSaveEvent) {
if (config.getBoolean("save-notification")) { if (config.getBoolean("save-notification")) {
if (multiverseCore != null) {
if (multiverseCore.mvWorldManager.firstSpawnWorld.name == event.world.name) {
server.broadcastMessage("The world has been saved.") 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.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore import com.onarandombox.MultiverseCore.MultiverseCore
import net.trivernis.superutils.commands.CommandC import net.trivernis.superutils.commands.*
import net.trivernis.superutils.commands.CommandH
import net.trivernis.superutils.commands.CommandReload
import net.trivernis.superutils.commands.CommandWp
import org.bukkit.configuration.file.FileConfiguration import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Minecart import org.bukkit.entity.Minecart
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
@ -19,8 +16,9 @@ class SuperUtils : JavaPlugin() {
configure() configure()
val essentials = getEssentials() val essentials = getEssentials()
val commandC = CommandC(getMultiverseCore(), essentials) 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("superutils reload")?.setExecutor(CommandReload(this))
getCommand("scheduleshutdown")?.setExecutor(CommandScheduleShutdown(this))
getCommand("c")?.setExecutor(commandC) getCommand("c")?.setExecutor(commandC)
if (essentials != null) { 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: superutils.wp
permission-message: You do not have permission! permission-message: You do not have permission!
usage: /wp {warp} usage: /wp {warp}
scheduleshutdown:
description: schedule a restart
permission: superutils.scheduleshutdown
permission-message: You do not have permission!
usage: /schedulerestart {seconds}
permissions: permissions:
superutils.reload: superutils.reload:
description: Allows reload command description: Allows reload command
@ -38,6 +43,9 @@ permissions:
superutils.wp: superutils.wp:
description: Allow wp command description: Allow wp command
default: op default: op
superutils.scheduleshutdown:
description: Allow scheduleshutdown command
default: op
superutils.*: superutils.*:
description: Wildcard permission description: Wildcard permission
default: op default: op

Loading…
Cancel
Save