Fix Anchors not being saved proplery, Fix safe spawn disabling, closes #207, Remove server.properties code, that bukkit bug is gone, closes #275

This commit is contained in:
Eric Stokes 2011-11-28 00:08:39 -07:00
parent e110b1f6a5
commit 5d2a1e478c
6 changed files with 61 additions and 36 deletions

View File

@ -46,6 +46,7 @@ public class MVWorld implements MultiverseWorld {
private Map<String, List<String>> masterList;
private Map<String, MVConfigProperty> propertyList;
private String generator;
private Permission permission;
private Permission exempt;
@ -110,6 +111,7 @@ public class MVWorld implements MultiverseWorld {
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
this.propertyAliases = new HashMap<String, String>();
this.propertyAliases.put("curr", "currency");
@ -633,6 +635,7 @@ public class MVWorld implements MultiverseWorld {
}
private Location readSpawnFromConfig(World w) {
Location spawnLocation = w.getSpawnLocation();
Location configLocation = this.getSpawnLocation();
@ -642,11 +645,11 @@ public class MVWorld implements MultiverseWorld {
BlockSafety bs = new BlockSafety();
// Verify that location was safe
if (!bs.playerCanSpawnHereSafely(configLocation)) {
if (!((BooleanConfigProperty) this.getKnownProperty("adjustspawn")).getValue()) {
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());
if (!this.getAdjustSpawn()) {
this.plugin.log(Level.FINE, "Spawn location from world.dat file was unsafe!!");
this.plugin.log(Level.FINE, "NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
this.plugin.log(Level.FINE, "To turn on spawn adjustment for this world simply type:");
this.plugin.log(Level.FINE, "/mvm set adjustspawn true " + this.getAlias());
return configLocation;
}
// If it's not, find a better one.
@ -659,9 +662,20 @@ public class MVWorld implements MultiverseWorld {
this.setSpawnLocation(newSpawn);
configLocation = this.getSpawnLocation();
this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(configLocation));
} else {
// If it's a standard end world, let's check in a better place:
Location newerSpawn = null;
newerSpawn = bs.getTopBlock(new Location(w, 0, 0, 0));
if (newerSpawn != null) {
this.setSpawnLocation(newerSpawn);
configLocation = this.getSpawnLocation();
this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(configLocation));
} else {
this.plugin.log(Level.SEVERE, "New safe spawn NOT found!!!");
}
}
}
return configLocation;
}
@ -725,9 +739,9 @@ public class MVWorld implements MultiverseWorld {
public String getAllPropertyNames() {
ChatColor color = ChatColor.AQUA;
String result = "";
for(String name : this.propertyList.keySet()) {
for (String name : this.propertyList.keySet()) {
result += color + name + " ";
color = (color == ChatColor.AQUA)? ChatColor.GOLD:ChatColor.AQUA;
color = (color == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA;
}
return result;
}

View File

@ -164,7 +164,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.banker = new AllPay(this, tag + " ");
// Output a little snippet to show it's enabled.
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + Protocol + ") Enabled - By " + getAuthors());
this.checkServerProps();
// Load the defaultWorldGenerators
this.worldManager.getDefaultWorldGenerators();
@ -569,28 +568,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.serverFolder = newServerFolder;
}
private void checkServerProps() {
File serverProperties = new File(serverFolder, "server.properties");
try {
FileInputStream fileStream = new FileInputStream(serverProperties);
DataInputStream in = new DataInputStream(fileStream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String propLine;
while ((propLine = br.readLine()) != null) {
// Print the content on the console
if (propLine.matches(".*spawn-monsters.*") && !propLine.matches(".*spawn-monsters\\s*=\\s*true.*")) {
this.log(Level.SEVERE, "Monster spawning has been DISABLED.");
this.log(Level.SEVERE, "In order to let Multiverse fully control your worlds:");
this.log(Level.SEVERE, "Please set 'spawn-monsters=true' in your server.properties file!");
MultiverseCore.MobsDisabledInDefaultWorld = true;
}
}
} catch (IOException e) {
// This should never happen...
this.log(Level.SEVERE, e.getMessage());
}
}
public void setSpout() {
this.spoutInterface = new SpoutInterface();
this.commandHandler.registerCommand(new SpoutCommand(this));

View File

@ -32,6 +32,7 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
this.addCommandExample("/mv anchors ");
this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP);
this.setItemsPerPage(8);
}
private List<String> getFancyAnchorList(Player p) {

View File

@ -9,7 +9,9 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.BlockSafety;
import com.onarandombox.MultiverseCore.utils.LocationManipulation;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
@ -19,7 +21,6 @@ import org.bukkit.permissions.PermissionDefault;
import java.util.List;
public class SetSpawnCommand extends MultiverseCommand {
public SetSpawnCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Set World Spawn");
@ -47,6 +48,14 @@ public class SetSpawnCommand extends MultiverseCommand {
MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
if (foundWorld != null) {
foundWorld.setSpawnLocation(p.getLocation());
BlockSafety bs = new BlockSafety();
if(!bs.playerCanSpawnHereSafely(p.getLocation()) && foundWorld.getAdjustSpawn()) {
sender.sendMessage("It looks like that location would normally be unsafe. But I trust you.");
sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world.");
sender.sendMessage("If you want this turned back on just do:");
sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias());
foundWorld.setAdjustSpawn(false);
}
sender.sendMessage("Spawn was set to: " + LocationManipulation.strCoords(p.getLocation()));
} else {
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());

View File

@ -23,7 +23,9 @@ public class BlockSafety {
// TODO Auto-generated constructor stub
}
/** This function checks whether the block at the given coordinates are above air or not. */
/**
* This function checks whether the block at the given coordinates are above air or not.
*/
public boolean isBlockAboveAir(Location l) {
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
downOne.setY(downOne.getY() - 1);
@ -79,11 +81,34 @@ public class BlockSafety {
return true;
}
public Location getTopBlock(Location l) {
Location check = l.clone();
check.setY(127);
while (check.getY() > 0) {
if (this.playerCanSpawnHereSafely(check)) {
return check;
}
check.setY(check.getY() - 1);
}
return null;
}
public Location getBottomBlock(Location l) {
Location check = l.clone();
check.setY(0);
while (check.getY() <= 126) {
if (this.playerCanSpawnHereSafely(check)) {
return check;
}
check.setY(check.getY() + 1);
}
return null;
}
/**
* If someone has a better way of this... Please either tell us, or submit a pull request!
*
* @param type
*
* @return
*/
private boolean isSolidBlock(Material type) {
@ -174,7 +199,6 @@ public class BlockSafety {
* Checks recursively below location L for 2 blocks of water
*
* @param l
*
* @return
*/
public boolean hasTwoBlocksofWaterBelow(Location l) {

View File

@ -45,7 +45,7 @@ public class LocationManipulation {
return "";
}
StringBuilder l = new StringBuilder();
l.append(location.getWorld() + ":");
l.append(location.getWorld().getName() + ":");
l.append(location.getBlockX() + ",");
l.append(location.getBlockY() + ",");
l.append(location.getBlockZ() + ":");