Fix config.yml overwriting worlds.yml, Fix invalid spawn locations

This commit is contained in:
fernferret 2011-10-13 16:37:53 -04:00
parent b2ef10a699
commit d3c1538083
4 changed files with 35 additions and 13 deletions

View File

@ -9,6 +9,9 @@ package com.onarandombox.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.utils.BlockSafety;
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.configuration.ConfigurationSection;
@ -732,9 +735,25 @@ public class MVWorld implements MultiverseWorld {
double x = config.getDouble("spawn.x", w.getSpawnLocation().getX());
double y = config.getDouble("spawn.y", w.getSpawnLocation().getY());
double z = config.getDouble("spawn.z", w.getSpawnLocation().getZ());
this.plugin.log(Level.FINE, "Read spawn from config as: " + x + ", " + y + ", " + z);
float pitch = (float) config.getDouble("spawn.pitch", w.getSpawnLocation().getPitch());
float yaw = (float) config.getDouble("spawn.yaw", w.getSpawnLocation().getYaw());
this.spawnLocation = new Location(w, x, y, z, yaw, pitch);
SafeTTeleporter teleporter = this.plugin.getTeleporter();
BlockSafety bs = new BlockSafety();
if (!bs.playerCanSpawnHereSafely(this.spawnLocation)) {
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.setSpawnLocation(newSpawn);
} else {
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
}
}
}
@Override

View File

@ -615,12 +615,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.log(Level.SEVERE, "Could not save Multiverse config.yml config. Please check your file permissions.");
}
try {
this.multiverseConfig.save(new File(getDataFolder(), "worlds.yml"));
} catch (IOException e) {
retVal = false;
this.log(Level.SEVERE, "Could not save Multiverse worlds.yml config. Please check your file permissions.");
}
this.worldManager.saveWorldsConfig();
return retVal;
}
}

View File

@ -49,11 +49,15 @@ public class SafeTTeleporter {
return null;
}
private Location getSafeLocation(Location l) {
public Location getSafeLocation(Location l) {
return this.getSafeLocation(l, 6, 9);
}
public Location getSafeLocation(Location l, int tolerance, int radius) {
// Check around the player first in a configurable radius:
// TODO: Make this configurable
Location safe = checkAboveAndBelowLocation(l, 6, 9);
Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
if (safe != null) {
safe.setX(safe.getBlockX() + .5);
safe.setZ(safe.getBlockZ() + .5);

View File

@ -133,12 +133,8 @@ public class WorldManager implements MVWorldManager {
unloadWorld(name);
this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml");
this.configWorlds.set("worlds." + name, null);
try {
this.configWorlds.save(new File(this.plugin.getDataFolder(), "config.yml"));
} catch (IOException e) {
this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your settings.");
}
this.saveWorldsConfig();
return true;
} else {
this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml");
@ -433,4 +429,12 @@ public class WorldManager implements MVWorldManager {
this.configWorlds = YamlConfiguration.loadConfiguration(file);
return this.configWorlds;
}
public void saveWorldsConfig() {
try {
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
} catch (IOException e) {
this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your settings.");
}
}
}