Fixed config...

This commit is contained in:
main() 2012-02-04 14:22:55 +01:00
parent 5d1532e811
commit a1075224d3
18 changed files with 319 additions and 223 deletions

View File

@ -196,7 +196,7 @@
<dependency>
<groupId>me.main__.util</groupId>
<artifactId>SerializationConfig</artifactId>
<version>1.0</version>
<version>1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -14,6 +14,7 @@ import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVPlugin;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
@ -67,6 +68,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private static Map<String, String> teleportQueue = new HashMap<String, String>();
private AnchorManager anchorManager = new AnchorManager(this);
// TODO please let's make this non-static
private static MultiverseCoreConfiguration config;
/**
@ -186,8 +188,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
* @deprecated This is deprecated.
*/
@Override
@Deprecated
public FileConfiguration getMVConfiguration() {
return this.multiverseConfig;
}
@ -252,11 +256,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Now set the firstspawnworld (after the worlds are loaded):
// Default as the server.props world.
this.worldManager.setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld", getDefaultWorldName()));
this.worldManager.setFirstSpawnWorld(config.getFirstSpawnWorld());
// We have to set this one here, if it's not present, we don't know the name of the default world.
// and this one won't be in the defaults yml file.
try {
this.multiverseConfig.set("firstspawnworld", this.worldManager.getFirstSpawnWorld().getName());
config.setFirstSpawnWorld(this.worldManager.getFirstSpawnWorld().getName());
} catch (NullPointerException e) {
// A test that had no worlds loaded was being run. This should never happen in production
}
@ -335,9 +339,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
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.multiverseConfig.options().copyDefaults(false);
this.multiverseConfig.options().copyHeader(true);
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
MultiverseCoreConfiguration wantedConfig = null;
@ -348,8 +351,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
} finally {
config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig);
}
// ... and save it
multiverseConfig.set("multiverse-configuration", config);
this.messaging.setCooldown(config.getMessageCooldown());
@ -361,19 +362,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.saveMVConfigs();
}
/**
* Safely return a world name.
* (The tests call this with no worlds loaded)
*
* @return The default world name.
*/
private String getDefaultWorldName() {
if (this.getServer().getWorlds().size() > 0) {
return this.getServer().getWorlds().get(0).getName();
}
return "";
}
/**
* {@inheritDoc}
*/
@ -441,7 +429,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
if (this.playerSessions.containsKey(player.getName())) {
return this.playerSessions.get(player.getName());
} else {
this.playerSessions.put(player.getName(), new MVPlayerSession(player, this.multiverseConfig, this));
this.playerSessions.put(player.getName(), new MVPlayerSession(player, config));
return this.playerSessions.get(player.getName());
}
}
@ -726,6 +714,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/
public boolean saveMVConfig() {
try {
this.multiverseConfig.set("multiverse-configuration", config);
this.multiverseConfig.save(new File(getDataFolder(), "config.yml"));
return true;
} catch (IOException e) {
@ -853,10 +842,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
}
/**
* Gets our {@link MultiverseCoreConfiguration}.
* @return The {@link MultiverseCoreConfiguration} we're using.
* {@inheritDoc}
*/
public static MultiverseCoreConfiguration getStaticConfig() {
@Override
public MultiverseCoreConfig getMVConfig() {
return config;
}
}

View File

@ -2,27 +2,35 @@ package com.onarandombox.MultiverseCore;
import java.util.Map;
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import me.main__.util.SerializationConfig.Property;
import me.main__.util.SerializationConfig.SerializationConfig;
/**
* Our configuration.
*/
public class MultiverseCoreConfiguration extends SerializationConfig {
public class MultiverseCoreConfiguration extends SerializationConfig implements MultiverseCoreConfig {
@Property
private boolean enforceAccess;
private boolean enforceaccess;
@Property
private boolean prefixChat;
@Property
private boolean teleportIntercept;
private boolean teleportintercept;
@Property
private boolean firstSpawnOverride;
private boolean firstspawnoverride;
@Property
private boolean displayPermErrors;
@Property
private int globalDebug;
private int globaldebug;
@Property
private int messageCooldown;
private int messagecooldown;
@Property
private int version;
@Property
private String firstspawnworld;
@Property
private int portalcooldown;
public MultiverseCoreConfiguration() {
super();
@ -38,127 +46,176 @@ public class MultiverseCoreConfiguration extends SerializationConfig {
@Override
public void setDefaults() {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
enforceAccess = false;
enforceaccess = false;
prefixChat = true;
teleportIntercept = true;
firstSpawnOverride = true;
teleportintercept = true;
firstspawnoverride = true;
displayPermErrors = true;
globalDebug = 0;
messageCooldown = 5000;
globaldebug = 0;
messagecooldown = 5000;
portalcooldown = 5000;
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
}
// And here we go:
/**
* Gets enforceAccess.
* @return enforceAccess.
* {@inheritDoc}
*/
@Override
public boolean getEnforceAccess() {
return enforceAccess;
return enforceaccess;
}
/**
* Sets enforceAccess.
* @param enforceAccess The new value.
* {@inheritDoc}
*/
@Override
public void setEnforceAccess(boolean enforceAccess) {
this.enforceAccess = enforceAccess;
this.enforceaccess = enforceAccess;
}
/**
* Gets prefixChat.
* @return prefixChat.
* {@inheritDoc}
*/
@Override
public boolean getPrefixChat() {
return prefixChat;
}
/**
* Sets prefixChat.
* @param prefixChat The new value.
* {@inheritDoc}
*/
@Override
public void setPrefixChat(boolean prefixChat) {
this.prefixChat = prefixChat;
}
/**
* Gets teleportIntercept.
* @return teleportIntercept.
* {@inheritDoc}
*/
@Override
public boolean getTeleportIntercept() {
return teleportIntercept;
return teleportintercept;
}
/**
* Sets teleportIntercept.
* @param teleportIntercept The new value.
* {@inheritDoc}
*/
@Override
public void setTeleportIntercept(boolean teleportIntercept) {
this.teleportIntercept = teleportIntercept;
this.teleportintercept = teleportIntercept;
}
/**
* Gets firstSpawnOverride.
* @return firstSpawnOverride.
* {@inheritDoc}
*/
@Override
public boolean getFirstSpawnOverride() {
return firstSpawnOverride;
return firstspawnoverride;
}
/**
* Sets firstSpawnOverride.
* @param firstSpawnOverride The new value.
* {@inheritDoc}
*/
@Override
public void setFirstSpawnOverride(boolean firstSpawnOverride) {
this.firstSpawnOverride = firstSpawnOverride;
this.firstspawnoverride = firstSpawnOverride;
}
/**
* Gets displayPermErrors.
* @return displayPermErrors.
* {@inheritDoc}
*/
@Override
public boolean getDisplayPermErrors() {
return displayPermErrors;
}
/**
* Sets displayPermErrors.
* @param displayPermErrors The new value.
* {@inheritDoc}
*/
@Override
public void setDisplayPermErrors(boolean displayPermErrors) {
this.displayPermErrors = displayPermErrors;
}
/**
* Gets globalDebug.
* @return globalDebug.
* {@inheritDoc}
*/
@Override
public int getGlobalDebug() {
return globalDebug;
return globaldebug;
}
/**
* Sets globalDebug.
* @param globalDebug The new value.
* {@inheritDoc}
*/
@Override
public void setGlobalDebug(int globalDebug) {
this.globalDebug = globalDebug;
this.globaldebug = globalDebug;
}
/**
* Gets messageCooldown.
* @return messageCooldown.
* {@inheritDoc}
*/
@Override
public int getMessageCooldown() {
return messageCooldown;
return messagecooldown;
}
/**
* Sets messageCooldown.
* @param messageCooldown The new value.
* {@inheritDoc}
*/
@Override
public void setMessageCooldown(int messageCooldown) {
this.messageCooldown = messageCooldown;
this.messagecooldown = messageCooldown;
}
/**
* {@inheritDoc}
*/
@Override
public int getVersion() {
return version;
}
/**
* {@inheritDoc}
*/
@Override
public void setVersion(int version) {
this.version = version;
}
/**
* {@inheritDoc}
*/
@Override
public String getFirstSpawnWorld() {
return firstspawnworld;
}
/**
* {@inheritDoc}
*/
@Override
public void setFirstSpawnWorld(String firstSpawnWorld) {
this.firstspawnworld = firstSpawnWorld;
}
/**
* {@inheritDoc}
*/
@Override
public int getPortalCooldown() {
return portalcooldown;
}
/**
* {@inheritDoc}
*/
@Override
public void setPortalCooldown(int portalCooldown) {
this.portalcooldown = portalCooldown;
}
}

View File

@ -26,7 +26,9 @@ public interface Core {
* Gets the Multiverse config file.
*
* @return The Multiverse config file.
* @deprecated Don't modify the config-file manually!
*/
@Deprecated
FileConfiguration getMVConfiguration();
/**
@ -215,4 +217,9 @@ public interface Core {
*/
void setSafeTTeleporter(SafeTTeleporter safeTTeleporter);
/**
* Gets the {@link MultiverseCoreConfig}.
* @return The configuration.
*/
MultiverseCoreConfig getMVConfig();
}

View File

@ -0,0 +1,136 @@
package com.onarandombox.MultiverseCore.api;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
/**
* The configuration of MultiverseCore.
*/
public interface MultiverseCoreConfig extends ConfigurationSerializable {
/**
* Sets a property using a {@link String}.
* @param property The name of the property.
* @param value The value.
* @return True on success, false if the operation failed.
*/
boolean setProperty(String property, String value);
/**
* Sets portalCooldown.
* @param portalCooldown The new value.
*/
void setPortalCooldown(int portalCooldown);
/**
* Gets portalCooldown.
* @return portalCooldown.
*/
int getPortalCooldown();
/**
* Sets firstSpawnWorld.
* @param firstSpawnWorld The new value.
*/
void setFirstSpawnWorld(String firstSpawnWorld);
/**
* Gets firstSpawnWorld.
* @return firstSpawnWorld.
*/
String getFirstSpawnWorld();
/**
* Sets version.
* @param version The new value.
*/
void setVersion(int version);
/**
* Gets version.
* @return version.
*/
int getVersion();
/**
* Sets messageCooldown.
* @param messageCooldown The new value.
*/
void setMessageCooldown(int messageCooldown);
/**
* Gets messageCooldown.
* @return messageCooldown.
*/
int getMessageCooldown();
/**
* Sets globalDebug.
* @param globalDebug The new value.
*/
void setGlobalDebug(int globalDebug);
/**
* Gets globalDebug.
* @return globalDebug.
*/
int getGlobalDebug();
/**
* Sets displayPermErrors.
* @param displayPermErrors The new value.
*/
void setDisplayPermErrors(boolean displayPermErrors);
/**
* Gets displayPermErrors.
* @return displayPermErrors.
*/
boolean getDisplayPermErrors();
/**
* Sets firstSpawnOverride.
* @param firstSpawnOverride The new value.
*/
void setFirstSpawnOverride(boolean firstSpawnOverride);
/**
* Gets firstSpawnOverride.
* @return firstSpawnOverride.
*/
boolean getFirstSpawnOverride();
/**
* Sets teleportIntercept.
* @param teleportIntercept The new value.
*/
void setTeleportIntercept(boolean teleportIntercept);
/**
* Gets teleportIntercept.
* @return teleportIntercept.
*/
boolean getTeleportIntercept();
/**
* Sets prefixChat.
* @param prefixChat The new value.
*/
void setPrefixChat(boolean prefixChat);
/**
* Gets prefixChat.
* @return prefixChat.
*/
boolean getPrefixChat();
/**
* Sets enforceAccess.
* @param enforceAccess The new value.
*/
void setEnforceAccess(boolean enforceAccess);
/**
* Gets enforceAccess.
* @return enforceAccess.
*/
boolean getEnforceAccess();
}

View File

@ -8,12 +8,12 @@
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.enums.ConfigProperty;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import java.util.List;
import java.util.Map;
/**
* Allows you to set Global MV Variables.
@ -28,7 +28,6 @@ public class ConfigCommand extends MultiverseCommand {
this.addKey("mvconfig");
this.addKey("mv conf");
this.addKey("mvconf");
this.addCommandExample("All values: " + ConfigProperty.getAllValues());
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");
@ -38,55 +37,31 @@ public class ConfigCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
if (args.size() <= 1) {
String[] allProps = ConfigProperty.getAllValues().split(" ");
String currentvals = "";
for (String prop : allProps) {
currentvals += ChatColor.GREEN;
currentvals += prop;
currentvals += ChatColor.WHITE;
currentvals += " = ";
currentvals += ChatColor.GOLD;
currentvals += this.plugin.getMVConfiguration().get(prop, "NOT SET");
currentvals += ChatColor.WHITE;
currentvals += ", ";
StringBuilder builder = new StringBuilder();
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
for (Map.Entry<String, Object> entry : serializedConfig.entrySet()) {
builder.append(ChatColor.GREEN);
builder.append(entry.getKey());
builder.append(ChatColor.WHITE).append(" = ").append(ChatColor.GOLD);
builder.append(entry.getValue().toString());
builder.append(ChatColor.WHITE).append(", ");
}
sender.sendMessage(currentvals.substring(0, currentvals.length() - 2));
String message = builder.toString();
message = message.substring(0, message.length() - 2);
sender.sendMessage(message);
return;
}
if (!this.plugin.getMVConfig().setProperty(args.get(0).toLowerCase(), args.get(1))) {
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
return;
}
// special rule
if (args.get(0).equalsIgnoreCase("firstspawnworld")) {
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), args.get(1));
// Don't forget to set the world!
this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1));
} else if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown")
|| args.get(0).equalsIgnoreCase("debug")) {
try {
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Integer.parseInt(args.get(1)));
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be an integer!");
return;
}
} else {
ConfigProperty property = null;
try {
property = ConfigProperty.valueOf(args.get(0).toLowerCase());
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA
+ args.get(0) + ChatColor.WHITE + " you can't set " + ChatColor.AQUA + args.get(0));
sender.sendMessage(ChatColor.GREEN + "Valid values are:");
sender.sendMessage(ConfigProperty.getAllValues());
return;
}
if (property != null) {
try {
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(1)));
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be true or false!");
return;
}
}
}
if (this.plugin.saveMVConfigs()) {
sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!");
this.plugin.loadConfigs();

View File

@ -36,14 +36,14 @@ public class DebugCommand extends MultiverseCommand {
public void runCommand(CommandSender sender, List<String> args) {
if (args.size() == 1) {
if (args.get(0).equalsIgnoreCase("off")) {
MultiverseCore.getStaticConfig().setGlobalDebug(0);
plugin.getMVConfig().setGlobalDebug(0);
} else {
try {
int debugLevel = Integer.parseInt(args.get(0));
if (debugLevel > 3 || debugLevel < 0) {
throw new NumberFormatException();
}
MultiverseCore.getStaticConfig().setGlobalDebug(debugLevel);
plugin.getMVConfig().setGlobalDebug(debugLevel);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE
+ " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)");
@ -55,10 +55,10 @@ public class DebugCommand extends MultiverseCommand {
}
private void displayDebugMode(CommandSender sender) {
if (MultiverseCore.getStaticConfig().getGlobalDebug() == 0) {
if (plugin.getMVConfig().getGlobalDebug() == 0) {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
} else {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + MultiverseCore.getStaticConfig().getGlobalDebug());
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + plugin.getMVConfig().getGlobalDebug());
this.plugin.log(Level.FINE, "Multiverse Debug ENABLED");
}
}

View File

@ -110,7 +110,7 @@ public class TeleportCommand extends MultiverseCommand {
return;
}
if (MultiverseCore.getStaticConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) {
if (plugin.getMVConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) {
if (teleportee.equals(teleporter)) {
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
} else {

View File

@ -53,16 +53,16 @@ public class VersionCommand extends MultiverseCommand {
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
.append(this.plugin.getMVConfiguration().getDouble("version", -1)).append(")").append('\n');
buffer.append("[Multiverse-Core] messagecooldown: ").append(this.plugin.getMessaging().getCooldown()).append('\n');
.append(this.plugin.getMVConfig().getVersion()).append(")").append('\n');
buffer.append("[Multiverse-Core] messagecooldown: ").append(plugin.getMessaging().getCooldown()).append('\n');
buffer.append("[Multiverse-Core] teleportcooldown: ").append("Not yet IMPLEMENTED").append('\n');
buffer.append("[Multiverse-Core] worldnameprefix: ").append(MultiverseCore.getStaticConfig().getPrefixChat()).append('\n');
buffer.append("[Multiverse-Core] enforceaccess: ").append(MultiverseCore.getStaticConfig().getEnforceAccess()).append('\n');
buffer.append("[Multiverse-Core] displaypermerrors: ").append(MultiverseCore.getStaticConfig().getDisplayPermErrors()).append('\n');
buffer.append("[Multiverse-Core] teleportintercept: ").append(MultiverseCore.getStaticConfig().getTeleportIntercept()).append('\n');
buffer.append("[Multiverse-Core] firstspawnoverride: ").append(MultiverseCore.getStaticConfig().getFirstSpawnOverride()).append('\n');
buffer.append("[Multiverse-Core] firstspawnworld: ").append(this.plugin.getMVConfiguration().getString("firstspawnworld", "NOT SET")).append('\n');
buffer.append("[Multiverse-Core] debug: ").append(MultiverseCore.getStaticConfig().getGlobalDebug()).append('\n');
buffer.append("[Multiverse-Core] worldnameprefix: ").append(plugin.getMVConfig().getPrefixChat()).append('\n');
buffer.append("[Multiverse-Core] enforceaccess: ").append(plugin.getMVConfig().getEnforceAccess()).append('\n');
buffer.append("[Multiverse-Core] displaypermerrors: ").append(plugin.getMVConfig().getDisplayPermErrors()).append('\n');
buffer.append("[Multiverse-Core] teleportintercept: ").append(plugin.getMVConfig().getTeleportIntercept()).append('\n');
buffer.append("[Multiverse-Core] firstspawnoverride: ").append(plugin.getMVConfig().getFirstSpawnOverride()).append('\n');
buffer.append("[Multiverse-Core] firstspawnworld: ").append(plugin.getMVConfig().getFirstSpawnWorld()).append('\n');
buffer.append("[Multiverse-Core] debug: ").append(plugin.getMVConfig().getGlobalDebug()).append('\n');
buffer.append("[Multiverse-Core] Special Code: FRN002").append('\n');
MVVersionEvent versionEvent = new MVVersionEvent(buffer.toString());

View File

@ -1,64 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.enums;
/**
* An enum containing all config-properties that can be set.
*/
public enum ConfigProperty {
/**
* How long to leave in between sending a message to the player. (NOT YET IMPLEMENTED)
*/
messagecooldown,
/**
* How fast are people allowed to use /MVTP (NOT YET IMPLEMENTED).
*/
teleportcooldown,
/**
* Prefix chat-messages with world-names.
*/
worldnameprefix,
/**
* If value is set to false, Multiverse will NOT enforce world access permissions.
*/
enforceaccess,
/**
* Whether users should get detailed information about the permissions they would need.
*/
displaypermerrors,
/**
* Debug-information.
*/
debug,
/**
* The world new users will spawn in.
*/
firstspawnworld,
/**
* Whether Multiverse should intercept teleports.
*/
teleportintercept,
/**
* Whether Multiverse should override the first spawn.
*/
firstspawnoverride;
/**
* Constructs a string containing all values in this enum.
*
* @return That {@link String}.
*/
public static String getAllValues() {
String buffer = "";
for (ConfigProperty c : ConfigProperty.values()) {
// All values will NOT Contain spaces.
buffer += c.toString() + " ";
}
return buffer;
}
}

View File

@ -55,7 +55,7 @@ public class MVPlayerListener implements Listener {
}
// Check whether the Server is set to prefix the chat with the World name.
// If not we do nothing, if so we need to check if the World has an Alias.
if (MultiverseCore.getStaticConfig().getPrefixChat()) {
if (plugin.getMVConfig().getPrefixChat()) {
String world = event.getPlayer().getWorld().getName();
String prefix = "";
// If we're not a MV world, don't do anything
@ -127,7 +127,7 @@ public class MVPlayerListener implements Listener {
Player p = event.getPlayer();
if (!p.hasPlayedBefore()) {
this.plugin.log(Level.FINE, "Player joined first!");
if (MultiverseCore.getStaticConfig().getFirstSpawnOverride()) {
if (plugin.getMVConfig().getFirstSpawnOverride()) {
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): " + worldManager.getFirstSpawnWorld().getSpawnLocation());
this.spawnNewPlayer(p);
}
@ -197,7 +197,7 @@ public class MVPlayerListener implements Listener {
teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName()));
return;
}
if (MultiverseCore.getStaticConfig().getEnforceAccess()) {
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
@ -262,7 +262,7 @@ public class MVPlayerListener implements Listener {
event.getPlayer().getName(), event.getTo().getWorld().getName()));
return;
}
if (MultiverseCore.getStaticConfig().getEnforceAccess()) {
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
if (event.isCancelled()) {
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s",

View File

@ -98,7 +98,7 @@ public class MVPermissions implements PermissionsInterface {
*/
public boolean canEnterWorld(Player p, MultiverseWorld w) {
// If we're not enforcing access, anyone can enter.
if (!MultiverseCore.getStaticConfig().getEnforceAccess()) {
if (!plugin.getMVConfig().getEnforceAccess()) {
return true;
}
return this.hasPermission(p, "multiverse.access." + w.getName(), false);

View File

@ -7,8 +7,8 @@
package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.configuration.Configuration;
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
import org.bukkit.entity.Player;
import java.util.Date;
@ -23,9 +23,9 @@ public class MVPlayerSession {
private long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
private long messageLast = 0L; // Timestamp for the Players last Alert Message.
private Configuration config; // Configuration file to find out Cooldown Timers.
private MultiverseCoreConfiguration config; // Configuration file to find out Cooldown Timers.
public MVPlayerSession(Player player, Configuration config, MultiverseCore multiVerseCore) {
public MVPlayerSession(Player player, MultiverseCoreConfiguration config) {
this.player = player;
this.config = config;
// this.bedSpawn = null;
@ -42,6 +42,6 @@ public class MVPlayerSession {
*/
public boolean getTeleportable() {
long time = (new Date()).getTime();
return ((time - this.teleportLast) > this.config.getInt("portalcooldown", 5000)); // SUPPRESS CHECKSTYLE: MagicNumberCheck
return ((time - this.teleportLast) > this.config.getPortalCooldown());
}
}

View File

@ -100,7 +100,7 @@ public class PermissionTools {
*/
public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) {
Player teleporterPlayer;
if (MultiverseCore.getStaticConfig().getTeleportIntercept()) {
if (plugin.getMVConfig().getTeleportIntercept()) {
if (teleporter instanceof ConsoleCommandSender) {
return true;
}
@ -171,7 +171,7 @@ public class PermissionTools {
this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
Player teleporterPlayer;
if (MultiverseCore.getStaticConfig().getTeleportIntercept()) {
if (plugin.getMVConfig().getTeleportIntercept()) {
// The console can send anyone anywhere
if (teleporter instanceof ConsoleCommandSender) {
return true;

View File

@ -210,7 +210,7 @@ public class WorldManager implements MVWorldManager {
*/
@Override
public void setFirstSpawnWorld(String world) {
if (world == null) {
if ((world == null) && (this.plugin.getServer().getWorlds().size() > 0)) {
this.firstSpawn = this.plugin.getServer().getWorlds().get(0).getName();
} else {
this.firstSpawn = world;

View File

@ -4,11 +4,3 @@
# 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

View File

@ -22,12 +22,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@ -54,6 +56,7 @@ public class TestDebugMode {
public void testEnableDebugMode() {
// Pull a core instance from the server.
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
Core core = (Core) plugin;
// Make sure Core is not null
assertNotNull(plugin);
@ -70,12 +73,12 @@ public class TestDebugMode {
when(mockCommand.getName()).thenReturn("mv");
// Assert debug mode is off
Assert.assertEquals(0, MultiverseCore.getStaticConfig().getGlobalDebug());
Assert.assertEquals(0, core.getMVConfig().getGlobalDebug());
// Send the debug command.
String[] debugArgs = new String[] { "debug", "3" };
plugin.onCommand(mockCommandSender, mockCommand, "", debugArgs);
Assert.assertEquals(3, MultiverseCore.getStaticConfig().getGlobalDebug());
Assert.assertEquals(3, core.getMVConfig().getGlobalDebug());
}
}

View File

@ -34,6 +34,7 @@ import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.verification.VerificationModeFactory;
@ -165,10 +166,10 @@ public class TestWorldProperties {
assertFalse(thunderChangeOnEvent.isCancelled());
// call player chat event
MultiverseCore.getStaticConfig().setPrefixChat(true);
core.getMVConfig().setPrefixChat(true);
core.getPlayerListener().playerChat(playerChatEvent);
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
MultiverseCore.getStaticConfig().setPrefixChat(false);
core.getMVConfig().setPrefixChat(false);
core.getPlayerListener().playerChat(playerChatEvent);
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
@ -263,7 +264,7 @@ public class TestWorldProperties {
assertTrue(thunderChangeOnEvent.isCancelled());
// call player chat event
MultiverseCore.getStaticConfig().setPrefixChat(true);
core.getMVConfig().setPrefixChat(true);
core.getPlayerListener().playerChat(playerChatEvent);
// never because it's hidden!
verify(playerChatEvent, never()).setFormat(
@ -271,7 +272,7 @@ public class TestWorldProperties {
mvWorld.setHidden(false);
core.getPlayerListener().playerChat(playerChatEvent);
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
MultiverseCore.getStaticConfig().setPrefixChat(false);
core.getMVConfig().setPrefixChat(false);
core.getPlayerListener().playerChat(playerChatEvent);
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)