From 9a7c6202ccee8b9596b892abe41a36f0c35db0fb Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Tue, 22 Nov 2011 21:52:18 -0700 Subject: [PATCH] Add bedrespawn as a per-world property. Fixes #192. Fixes #221. --- .../onarandombox/MultiverseCore/MVWorld.java | 16 +++++++++++++-- .../MultiverseCore/MultiverseCore.java | 2 -- .../MultiverseCore/api/MultiverseWorld.java | 20 ++++++++++++++++++- .../commands/ConfigCommand.java | 1 - .../commands/VersionCommand.java | 1 - .../configuration/MVCoreConfigMigrator.java | 1 - .../MultiverseCore/enums/ConfigProperty.java | 2 +- .../listeners/MVPlayerListener.java | 9 +++------ 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index df595b14..a791b7eb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -105,6 +105,7 @@ public class MVWorld implements MultiverseWorld { this.propertyList.put("memory", fac.getNewProperty("keepspawninmemory", true, "keepspawninmemory", "Sorry, 'memory' must either be:" + ChatColor.GREEN + " true " + ChatColor.WHITE + "or" + ChatColor.RED + " false" + ChatColor.WHITE + ".")); this.propertyList.put("spawn", fac.getNewProperty("spawn", this.world.getSpawnLocation(), "There is no help available for this variable. Go bug Rigby90 about it.")); this.propertyList.put("autoload", fac.getNewProperty("autoload", true, "Set this to false ONLY if you don't want this world to load itself on server restart.")); + this.propertyList.put("bedrespawn", fac.getNewProperty("bedrespawn", true, "If a player dies in this world, shoudld they go to their bed?")); ((LocationConfigProperty) this.getKnownProperty("spawn")).setValue(this.readSpawnFromConfig(this.getCBWorld())); // Set aliases @@ -695,8 +696,8 @@ public class MVWorld implements MultiverseWorld { } @Override - public void setAutoLoad(boolean adjust) { - ((BooleanConfigProperty) this.getKnownProperty("autoload")).setValue(adjust); + public void setAutoLoad(boolean autoLoad) { + ((BooleanConfigProperty) this.getKnownProperty("autoload")).setValue(autoLoad); saveConfig(); } @@ -704,4 +705,15 @@ public class MVWorld implements MultiverseWorld { public boolean getAutoLoad() { return ((BooleanConfigProperty) this.getKnownProperty("autoload")).getValue(); } + + @Override + public void setBedRespawn(boolean respawn) { + ((BooleanConfigProperty) this.getKnownProperty("bedrespawn")).setValue(respawn); + saveConfig(); + } + + @Override + public boolean getBedRespawn() { + return ((BooleanConfigProperty) this.getKnownProperty("bedrespawn")).getValue(); + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 8e3ff1db..5a78b874 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -52,7 +52,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { public static boolean EnforceAccess; public static boolean EnforceGameModes; public static boolean PrefixChat; - public static boolean BedRespawn; private File testConfigDirectory; private PluginDescriptionFile testDescriptionFile; @@ -299,7 +298,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { EnforceAccess = this.multiverseConfig.getBoolean("enforceaccess", false); EnforceGameModes = this.multiverseConfig.getBoolean("enforcegamemodes", true); PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true); - BedRespawn = this.multiverseConfig.getBoolean("bedrespawn", true); this.messaging = new MVMessaging(this); this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); this.saveMVConfigs(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index c0f69fc9..2755e1b0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -485,7 +485,7 @@ public interface MultiverseWorld { /** * Sets whether or not Multiverse should auto-load this world. - * + *

* True is default. * * @param autoLoad True if multiverse should autoload this world the spawn, false if not. @@ -499,5 +499,23 @@ public interface MultiverseWorld { */ public boolean getAutoLoad(); + /** + * Sets whether or not a player who dies in this world will respawn in their + * bed or follow the normal respawn pattern. + *

+ * True is default. + * + * @param autoLoad True if players dying in this world respawn at their bed. + */ + public void setBedRespawn(boolean autoLoad); + + /** + * Gets whether or not a player who dies in this world will respawn in their + * bed or follow the normal respawn pattern. + * + * @return True if players dying in this world should respawn at their bed. + */ + public boolean getBedRespawn(); + } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java index e03c0c1b..baccc0ec 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java @@ -32,7 +32,6 @@ public class ConfigCommand extends MultiverseCommand { this.addCommandExample("/mv config show"); this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3"); this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false"); - this.addCommandExample("/mv config " + ChatColor.GREEN + "bedrespawn" + ChatColor.AQUA + " true"); this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP); this.worldManager = this.plugin.getMVWorldManager(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 234dab53..d04f84ee 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -60,7 +60,6 @@ public class VersionCommand extends MultiverseCommand { logAndAddToPasteBinBuffer("worldnameprefix: " + MultiverseCore.PrefixChat); logAndAddToPasteBinBuffer("enforceaccess: " + MultiverseCore.EnforceAccess); logAndAddToPasteBinBuffer("enforcegamemodes: " + MultiverseCore.EnforceGameModes); - logAndAddToPasteBinBuffer("bedrespawn: " + MultiverseCore.BedRespawn); logAndAddToPasteBinBuffer("debug: " + MultiverseCore.GlobalDebug); logAndAddToPasteBinBuffer("Special Code: FRN002"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVCoreConfigMigrator.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVCoreConfigMigrator.java index c8aacc31..740e97d6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/MVCoreConfigMigrator.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/MVCoreConfigMigrator.java @@ -74,7 +74,6 @@ public class MVCoreConfigMigrator extends MVConfigMigrator { newConfig.setProperty("opfallback", true); newConfig.setProperty("disableautoheal", false); newConfig.setProperty("fakepvp", false); - newConfig.setProperty("bedrespawn", true); newConfig.setProperty("version", 2.2); newConfig.save(); return true; diff --git a/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java index 45d7d785..e20f0b2f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java @@ -9,7 +9,7 @@ package com.onarandombox.MultiverseCore.enums; /** Multiverse 2 */ public enum ConfigProperty { - messagecooldown, teleportcooldown, worldnameprefix, bedrespawn, enforcegamemodes, enforceaccess, debug; + messagecooldown, teleportcooldown, worldnameprefix, enforcegamemodes, enforceaccess, debug; public static String getAllValues() { diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index e7f0f920..0da23a1f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -11,7 +11,6 @@ import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; -import com.onarandombox.MultiverseCore.utils.LocationManipulation; import com.onarandombox.MultiverseCore.utils.SafeTTeleporter; import com.onarandombox.MultiverseCore.utils.WorldManager; import org.bukkit.*; @@ -57,19 +56,17 @@ public class MVPlayerListener extends PlayerListener { @Override public void onPlayerRespawn(PlayerRespawnEvent event) { World world = event.getPlayer().getWorld(); - + MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); // If it's not a World MV manages we stop. - if (!this.worldManager.isMVWorld(world.getName())) { + if (mvWorld == null) { return; } - if (MultiverseCore.BedRespawn) { + if (mvWorld.getBedRespawn()) { this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed"); return; } - // Get the MultiverseWorld - MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); // Get the instance of the World the player should respawn at. MultiverseWorld respawnWorld = null; if (this.worldManager.isMVWorld(mvWorld.getRespawnToWorld())) {