From f165e11cee6320c0d4aabaa5df2a042c9f7ed435 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Fri, 6 Sep 2019 17:28:48 +0200 Subject: [PATCH] Fixed world save message --- .../net/trivernis/superutils/EventListener.kt | 16 ++++++++-- .../net/trivernis/superutils/SuperUtils.kt | 8 ++--- .../commands/CommandScheduleRestart.kt | 31 +++++++++++++++++++ src/main/resources/plugin.yml | 8 +++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/net/trivernis/superutils/commands/CommandScheduleRestart.kt diff --git a/src/main/kotlin/net/trivernis/superutils/EventListener.kt b/src/main/kotlin/net/trivernis/superutils/EventListener.kt index fcf32c1..c53cf0f 100644 --- a/src/main/kotlin/net/trivernis/superutils/EventListener.kt +++ b/src/main/kotlin/net/trivernis/superutils/EventListener.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 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.") + } + } } } } \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt index eaad8fa..b343f5e 100644 --- a/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt +++ b/src/main/kotlin/net/trivernis/superutils/SuperUtils.kt @@ -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) { diff --git a/src/main/kotlin/net/trivernis/superutils/commands/CommandScheduleRestart.kt b/src/main/kotlin/net/trivernis/superutils/commands/CommandScheduleRestart.kt new file mode 100644 index 0000000..6cfdc36 --- /dev/null +++ b/src/main/kotlin/net/trivernis/superutils/commands/CommandScheduleRestart.kt @@ -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): 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 + } + +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 834d32e..2ca1934 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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