From 1712b175d87020699b4eb433eefba54836eac4ca Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sat, 22 Oct 2011 11:00:32 -0600 Subject: [PATCH] Add autoheal and adjustSpawn as per-world properties --- .../onarandombox/MultiverseCore/MVWorld.java | 36 ++++++++++++++++--- .../MultiverseCore/api/MultiverseWorld.java | 18 ++++++++-- .../commands/ModifySetCommand.java | 2 ++ .../MultiverseCore/enums/SetProperties.java | 3 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 5187d5b3..3ba1b740 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -69,6 +69,8 @@ public class MVWorld implements MultiverseWorld { private boolean allowWeather; private Location spawnLocation; private boolean isHidden = false; + private boolean autoheal = true; + private boolean adjustSpawn = true; public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString) { this.config = config; @@ -322,6 +324,10 @@ public class MVWorld implements MultiverseWorld { this.setHunger(value); } else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) { this.setEnableWeather(value); + } else if (name.equalsIgnoreCase("heal") || name.equalsIgnoreCase("autoheal")) { + this.setAutoHeal(value); + } else if (name.equalsIgnoreCase("adjustspawn")) { + this.setAdjustSpawn(value); } else if (name.equalsIgnoreCase("hidden")) { this.setHidden(value); } else { @@ -757,22 +763,30 @@ public class MVWorld implements MultiverseWorld { float yaw = (float) worldSection.getDouble("spawn.yaw", w.getSpawnLocation().getYaw()); this.setSpawnLocation(new Location(w, x, y, z, yaw, pitch)); + this.plugin.log(Level.FINEST, "Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(this.getSpawnLocation())); SafeTTeleporter teleporter = this.plugin.getTeleporter(); BlockSafety bs = new BlockSafety(); if (!bs.playerCanSpawnHereSafely(this.spawnLocation)) { + if (!this.adjustSpawn) { + this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe!!"); + this.plugin.log(Level.WARNING, "NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to."); + this.plugin.log(Level.WARNING, "To turn on spawn adjustment for this world simply type:"); + this.plugin.log(Level.WARNING, "/mvm set adjustspawn true " + this.getAlias()); + return; + } this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting..."); Location newSpawn = teleporter.getSafeLocation(this.spawnLocation, 128, 128); // I think we could also do this, as I think this is what Notch does. // Not sure how it will work in the nether... //Location newSpawn = this.spawnLocation.getWorld().getHighestBlockAt(this.spawnLocation).getLocation(); if (newSpawn != null) { - this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(newSpawn)); + this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(newSpawn)); this.setSpawnLocation(newSpawn); } else { this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!"); } } - this.plugin.log(Level.FINEST, "Spawn for '" + this.getName() + "' Located at: " + LocationManipulation.locationToString(this.getSpawnLocation())); + } @Override @@ -832,15 +846,27 @@ public class MVWorld implements MultiverseWorld { return true; } - // TODO: Implment this, I'm going to bed tonight. @Override public boolean getAutoHeal() { - return true; + return this.autoheal; } - // TODO: Implment this, I'm going to bed tonight. @Override public void setAutoHeal(boolean heal) { + this.autoheal = heal; + this.worldSection.set("autoheal", this.autoheal); + saveConfig(); + } + @Override + public void setAdjustSpawn(boolean adjust) { + this.adjustSpawn = adjust; + this.worldSection.set("adjustspawn", this.adjustSpawn); + saveConfig(); + } + + @Override + public boolean getAdjustSpawn() { + return this.adjustSpawn; } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 75c1f8b5..5ca71d62 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -426,16 +426,30 @@ public interface MultiverseWorld { public boolean clearList(String property); /** - * Sets whether or not a world will autoheal players if the difficulty is on peaceful. + * Sets whether or not a world will auto-heal players if the difficulty is on peaceful. * * @param heal True if the world will heal. */ public void setAutoHeal(boolean heal); /** - * Gets whether or not a world will autoheal players if the difficulty is on peaceful. + * Gets whether or not a world will auto-heal players if the difficulty is on peaceful. * * @return True if the world should heal (default), false if not. */ public boolean getAutoHeal(); + + /** + * Sets whether or not Multiverse should auto-adjust the spawn for this world. + * + * @param adjust True if multiverse should adjust the spawn, false if not. + */ + public void setAdjustSpawn(boolean adjust); + + /** + * Gets whether or not Multiverse should auto-adjust the spawn for this world. + * + * @return True if Multiverse should adjust the spawn, false if not. + */ + public boolean getAdjustSpawn(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java index 3184ffa5..d95556a3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java @@ -44,6 +44,8 @@ public class ModifySetCommand extends MultiverseCommand { this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hunger " + ChatColor.RED + "false"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hidden " + ChatColor.RED + "true"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "pvp " + ChatColor.RED + "false"); + this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true"); + this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false"); this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn"); this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP); this.worldManager = this.plugin.getMVWorldManager(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/enums/SetProperties.java b/src/main/java/com/onarandombox/MultiverseCore/enums/SetProperties.java index a9968657..9befdd99 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/enums/SetProperties.java +++ b/src/main/java/com/onarandombox/MultiverseCore/enums/SetProperties.java @@ -15,5 +15,6 @@ package com.onarandombox.MultiverseCore.enums; public enum SetProperties { alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, - gamemode, mode, hunger, difficulty, diff, hidden, spawn + gamemode, mode, hunger, difficulty, diff, hidden, spawn, autoheal, + heal, adjustspawn }