Add migrater for new configs, remove default, it's autogenned now

This commit is contained in:
Eric Stokes 2012-02-03 23:36:17 -07:00
parent 5d1532e811
commit 90b04aa798
5 changed files with 101 additions and 39 deletions

View File

@ -180,7 +180,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.1-R2</version> <version>1.1-R3</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>

View File

@ -252,14 +252,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Now set the firstspawnworld (after the worlds are loaded): // Now set the firstspawnworld (after the worlds are loaded):
// Default as the server.props world. // Default as the server.props world.
this.worldManager.setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld", getDefaultWorldName())); if (this.config.getFirstSpawnWorld() == null) {
// We have to set this one here, if it's not present, we don't know the name of the default world. this.config.setFirstSpawnWorld(getDefaultWorldName());
// and this one won't be in the defaults yml file.
try {
this.multiverseConfig.set("firstspawnworld", this.worldManager.getFirstSpawnWorld().getName());
} catch (NullPointerException e) {
// A test that had no worlds loaded was being run. This should never happen in production
} }
this.worldManager.setFirstSpawnWorld(this.config.getFirstSpawnWorld());
this.saveMVConfig(); this.saveMVConfig();
// Check to see if spout was already loaded (most likely): // Check to see if spout was already loaded (most likely):
if (this.getServer().getPluginManager().getPlugin("Spout") != null) { if (this.getServer().getPluginManager().getPlugin("Spout") != null) {
@ -333,11 +329,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public void loadConfigs() { public void loadConfigs() {
// Now grab the Configuration Files. // Now grab the Configuration Files.
this.multiverseConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml")); this.multiverseConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
Configuration coreDefaults = YamlConfiguration.loadConfiguration(this.getClass().getResourceAsStream("/defaults/config.yml"));
this.multiverseConfig.setDefaults(coreDefaults);
this.multiverseConfig.options().copyDefaults(true);
this.saveMVConfig();
this.multiverseConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml")); this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
MultiverseCoreConfiguration wantedConfig = null; MultiverseCoreConfiguration wantedConfig = null;
@ -358,9 +349,62 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.multiverseConfig.set("bedrespawn", null); this.multiverseConfig.set("bedrespawn", null);
this.multiverseConfig.set("opfallback", null); this.multiverseConfig.set("opfallback", null);
// Old Config Format
this.migrate22Values();
this.saveMVConfigs(); this.saveMVConfigs();
} }
/**
* Thes are the MV config 2.0-2.2 values,
* they should be migrated to the new format.
*/
private void migrate22Values() {
if (this.multiverseConfig.isSet("worldnameprefix")) {
this.log(Level.INFO, "Migrating 'worldnameprefix'...");
this.config.setPrefixChat(this.multiverseConfig.getBoolean("worldnameprefix"));
this.multiverseConfig.set("worldnameprefix", null);
}
if (this.multiverseConfig.isSet("firstspawnworld")) {
this.log(Level.INFO, "Migrating 'firstspawnworld'...");
this.config.setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld"));
this.multiverseConfig.set("firstspawnworld", null);
}
if (this.multiverseConfig.isSet("enforceaccess")) {
this.log(Level.INFO, "Migrating 'enforceaccess'...");
this.config.setEnforceAccess(this.multiverseConfig.getBoolean("enforceaccess"));
this.multiverseConfig.set("enforceaccess", null);
}
if (this.multiverseConfig.isSet("displaypermerrors")) {
this.log(Level.INFO, "Migrating 'displaypermerrors'...");
this.config.setDisplayPermErrors(this.multiverseConfig.getBoolean("displaypermerrors"));
this.multiverseConfig.set("displaypermerrors", null);
}
if (this.multiverseConfig.isSet("teleportintercept")) {
this.log(Level.INFO, "Migrating 'teleportintercept'...");
this.config.setTeleportIntercept(this.multiverseConfig.getBoolean("teleportintercept"));
this.multiverseConfig.set("teleportintercept", null);
}
if (this.multiverseConfig.isSet("firstspawnoverride")) {
this.log(Level.INFO, "Migrating 'firstspawnoverride'...");
this.config.setFirstSpawnOverride(this.multiverseConfig.getBoolean("firstspawnoverride"));
this.multiverseConfig.set("firstspawnoverride", null);
}
if (this.multiverseConfig.isSet("messagecooldown")) {
this.log(Level.INFO, "Migrating 'messagecooldown'...");
this.config.setMessageCooldown(this.multiverseConfig.getInt("messagecooldown"));
this.multiverseConfig.set("messagecooldown", null);
}
if (this.multiverseConfig.isSet("debug")) {
this.log(Level.INFO, "Migrating 'debug'...");
this.config.setGlobalDebug(this.multiverseConfig.getInt("debug"));
this.multiverseConfig.set("debug", null);
}
if (this.multiverseConfig.isSet("version")) {
this.log(Level.INFO, "Migrating 'version'...");
this.multiverseConfig.set("version", null);
}
}
/** /**
* Safely return a world name. * Safely return a world name.
* (The tests call this with no worlds loaded) * (The tests call this with no worlds loaded)

View File

@ -18,11 +18,15 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
@Property @Property
private boolean firstSpawnOverride; private boolean firstSpawnOverride;
@Property @Property
private String firstSpawnWorld;
@Property
private boolean displayPermErrors; private boolean displayPermErrors;
@Property @Property
private int globalDebug; private int globalDebug;
@Property @Property
private int messageCooldown; private int messageCooldown;
@Property
private double version;
public MultiverseCoreConfiguration() { public MultiverseCoreConfiguration() {
super(); super();
@ -45,6 +49,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
displayPermErrors = true; displayPermErrors = true;
globalDebug = 0; globalDebug = 0;
messageCooldown = 5000; messageCooldown = 5000;
this.version = 2.8;
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
} }
@ -55,7 +60,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return enforceAccess. * @return enforceAccess.
*/ */
public boolean getEnforceAccess() { public boolean getEnforceAccess() {
return enforceAccess; return this.enforceAccess;
} }
/** /**
@ -71,7 +76,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return prefixChat. * @return prefixChat.
*/ */
public boolean getPrefixChat() { public boolean getPrefixChat() {
return prefixChat; return this.prefixChat;
} }
/** /**
@ -87,7 +92,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return teleportIntercept. * @return teleportIntercept.
*/ */
public boolean getTeleportIntercept() { public boolean getTeleportIntercept() {
return teleportIntercept; return this.teleportIntercept;
} }
/** /**
@ -103,7 +108,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return firstSpawnOverride. * @return firstSpawnOverride.
*/ */
public boolean getFirstSpawnOverride() { public boolean getFirstSpawnOverride() {
return firstSpawnOverride; return this.firstSpawnOverride;
} }
/** /**
@ -119,7 +124,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return displayPermErrors. * @return displayPermErrors.
*/ */
public boolean getDisplayPermErrors() { public boolean getDisplayPermErrors() {
return displayPermErrors; return this.displayPermErrors;
} }
/** /**
@ -135,7 +140,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return globalDebug. * @return globalDebug.
*/ */
public int getGlobalDebug() { public int getGlobalDebug() {
return globalDebug; return this.globalDebug;
} }
/** /**
@ -151,7 +156,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
* @return messageCooldown. * @return messageCooldown.
*/ */
public int getMessageCooldown() { public int getMessageCooldown() {
return messageCooldown; return this.messageCooldown;
} }
/** /**
@ -161,4 +166,28 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
public void setMessageCooldown(int messageCooldown) { public void setMessageCooldown(int messageCooldown) {
this.messageCooldown = messageCooldown; this.messageCooldown = messageCooldown;
} }
/**
* Gets firstSpawnWorld.
* @return firstSpawnWorld.
*/
public String getFirstSpawnWorld() {
return this.firstSpawnWorld;
}
/**
* Sets firstSpawnWorld.
* @param firstSpawnWorld The new value.
*/
public void setFirstSpawnWorld(String firstSpawnWorld) {
this.firstSpawnWorld = firstSpawnWorld;
}
/**
* Gets the version of this config.
* @return version.
*/
public double getVersion() {
return this.version;
}
} }

View File

@ -99,6 +99,7 @@ public class MVPermissions implements PermissionsInterface {
public boolean canEnterWorld(Player p, MultiverseWorld w) { public boolean canEnterWorld(Player p, MultiverseWorld w) {
// If we're not enforcing access, anyone can enter. // If we're not enforcing access, anyone can enter.
if (!MultiverseCore.getStaticConfig().getEnforceAccess()) { if (!MultiverseCore.getStaticConfig().getEnforceAccess()) {
this.plugin.log(Level.FINEST, "EnforceAccess is OFF. Player was allowed in " + w.getAlias());
return true; return true;
} }
return this.hasPermission(p, "multiverse.access." + w.getName(), false); return this.hasPermission(p, "multiverse.access." + w.getName(), false);
@ -169,9 +170,9 @@ public class MVPermissions implements PermissionsInterface {
// plugin reloads, when MV asks the API if a player has a perm, it reports that they do NOT. // plugin reloads, when MV asks the API if a player has a perm, it reports that they do NOT.
// For the moment, we're going to check all of this node's parents to see if the user has those. It stops // For the moment, we're going to check all of this node's parents to see if the user has those. It stops
// when if finds a true or there are no more parents. --FF // when if finds a true or there are no more parents. --FF
if (!hasPermission) { // if (!hasPermission) {
hasPermission = this.hasAnyParentPermission(sender, node); // hasPermission = this.hasAnyParentPermission(sender, node);
} // }
return hasPermission; return hasPermission;
} }
@ -179,10 +180,12 @@ public class MVPermissions implements PermissionsInterface {
// TODO: Better player checks, most likely not needed, but safer. // TODO: Better player checks, most likely not needed, but safer.
private boolean checkActualPermission(CommandSender sender, String node) { private boolean checkActualPermission(CommandSender sender, String node) {
Player player = (Player) sender; Player player = (Player) sender;
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]");
boolean hasPermission = sender.hasPermission(node); boolean hasPermission = sender.hasPermission(node);
if (hasPermission) { if (hasPermission) {
this.plugin.log(Level.FINER, "Player [" + player.getName() + "] HAS PERMISSION [" + node + "]!"); this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
} else {
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
} }
return hasPermission; return hasPermission;
} }

View File

@ -1,14 +0,0 @@
# This is the MV2 Config. If you mess it up, copy the values out
# delete it, and it will be regenerated. Then use the ingame interface
# to add your values back via the "/mv conf" command.
# When in-game, simply type: "/mv conf ?" for help.
# A config with explanations can be found here:
# https://github.com/Multiverse/Multiverse-Core/wiki/config.yml
worldnameprefix: true
enforceaccess: true
displaypermerrors: true
teleportintercept: true
firstspawnoverride: true
messagecooldown: 5000
version: 2.7