Compare commits

..
6 Commits
Author SHA1 Message Date
main() d65cc8215c Testing... 2012-05-03 17:05:17 +02:00
main() c6feb127de Rewritten for SerializationConfig
Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/MVWorld.java
	src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java
2012-05-03 16:47:11 +02:00
main() 77480915a1 Merge branch 'master' of github.com:Multiverse/Multiverse-Core into allow-flight 2012-04-30 14:31:06 +02:00
main() c233b74c98 Merge branch 'master' into allow-flight
Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java
2012-02-26 16:50:02 +01:00
main() ae95a4c4f9 Merge branch 'master' of github.com:Multiverse/Multiverse-Core into allow-flight 2012-02-04 20:00:21 +01:00
Eric Stokes 49fd9e81d1 Inital allow flight code, if we use it 2012-01-29 16:57:16 -07:00
17 changed files with 272 additions and 473 deletions

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>2.5</version>
<version>2.4</version>
<name>Multiverse-Core</name>
<description>World Management Plugin</description>
<properties>
@@ -198,7 +198,7 @@
<dependency>
<groupId>me.main__.util</groupId>
<artifactId>SerializationConfig</artifactId>
<version>1.6b</version>
<version>1.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
@@ -9,15 +9,15 @@ package com.onarandombox.MultiverseCore;
import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.configuration.EntryFee;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import me.main__.util.SerializationConfig.ChangeDeniedException;
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
import me.main__.util.SerializationConfig.NoSuchPropertyException;
@@ -26,6 +26,7 @@ import me.main__.util.SerializationConfig.SerializationConfig;
import me.main__.util.SerializationConfig.Serializor;
import me.main__.util.SerializationConfig.ValidateAllWith;
import me.main__.util.SerializationConfig.VirtualProperty;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
@@ -60,24 +61,6 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16;
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
private static Map<String, String> propertyAliases;
static {
propertyAliases = new HashMap<String, String>();
propertyAliases.put("curr", "currency");
propertyAliases.put("scaling", "scale");
propertyAliases.put("aliascolor", "color");
propertyAliases.put("heal", "autoHeal");
propertyAliases.put("storm", "allowWeather");
propertyAliases.put("weather", "allowWeather");
propertyAliases.put("spawnmemory", "keepSpawnInMemory");
propertyAliases.put("memory", "keepSpawnInMemory");
propertyAliases.put("mode", "gameMode");
propertyAliases.put("diff", "difficulty");
propertyAliases.put("spawnlocation", "spawn");
propertyAliases.put("animals", "spawning.animals.spawn");
propertyAliases.put("monsters", "spawning.monsters.spawn");
}
/*
* We have to use setCBWorld(), setPlugin() and initPerms() to prepare this object for use.
*/
@@ -292,10 +275,26 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
@Override
public GameMode validateChange(String property, GameMode newValue, GameMode oldValue,
MVWorld object) throws ChangeDeniedException {
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
for (Player p : object.getCBWorld().getPlayers()) {
plugin.log(Level.FINER, String.format("Setting %s's GameMode to %s",
p.getName(), newValue.toString()));
plugin.getPlayerListener().handleGameMode(p, MVWorld.this);
plugin.getPlayerListener().handleGameMode(p, object);
}
return super.validateChange(property, newValue, oldValue, object);
}
}
/**
* Used to apply the allowFlight-property.
*/
private final class AllowFlightPropertyValidator extends WorldPropertyValidator<Boolean> {
@Override
public Boolean validateChange(String property, Boolean newValue, Boolean oldValue,
MVWorld object) throws ChangeDeniedException {
for (Player p : object.getCBWorld().getPlayers()) {
plugin.log(Level.FINER, String.format("Setting %s's allowFlight to %s",
p.getName(), newValue));
plugin.getPlayerListener().handleAllowFlight(p, object);
}
return super.validateChange(property, newValue, oldValue, object);
}
@@ -358,8 +357,6 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
private String alias;
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
private EnglishChatColor color;
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
private EnglishChatStyle style;
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
private VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() {
@Override
@@ -459,6 +456,8 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
return world.get().getTime();
}
};
@Property(validator = AllowFlightPropertyValidator.class)
private boolean allowFlight;
@Property
private Environment environment;
@Property
@@ -640,7 +639,6 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.hidden = false;
this.alias = new String();
this.color = EnglishChatColor.WHITE;
this.style = EnglishChatStyle.NORMAL;
this.scale = getDefaultScale(environment);
this.respawnWorld = new String();
this.allowWeather = true;
@@ -656,6 +654,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.bedRespawn = true;
this.worldBlacklist = new ArrayList<String>();
this.generator = null;
this.allowFlight = true;
}
/**
@@ -664,7 +663,19 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
* @see SerializationConfig
*/
protected static Map<String, String> getAliases() {
return propertyAliases;
Map<String, String> aliases = new HashMap<String, String>();
aliases.put("curr", "currency");
aliases.put("scaling", "scale");
aliases.put("aliascolor", "color");
aliases.put("heal", "autoHeal");
aliases.put("storm", "allowWeather");
aliases.put("weather", "allowWeather");
aliases.put("spawnmemory", "keepSpawnInMemory");
aliases.put("memory", "keepSpawnInMemory");
aliases.put("mode", "gameMode");
aliases.put("diff", "difficulty");
aliases.put("spawnlocation", "spawn");
return aliases;
}
private static double getDefaultScale(Environment environment) {
@@ -716,17 +727,10 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
if (alias.length() == 0) {
alias = this.getName();
}
if ((color == null) || (color.getColor() == null)) {
this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE);
}
StringBuilder nameBuilder = new StringBuilder().append(color.getColor());
if (style.getColor() != null)
nameBuilder.append(style.getColor());
nameBuilder.append(alias).append(ChatColor.WHITE).toString();
return nameBuilder.toString();
return color.getColor() + alias + ChatColor.WHITE;
}
/**
@@ -1384,16 +1388,16 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
* {@inheritDoc}
*/
@Override
public ChatColor getStyle() {
return style.getColor();
public boolean isFlightAllowed() {
return allowFlight;
}
/**
* {@inheritDoc}
*/
@Override
public boolean setStyle(String style) {
return this.setPropertyUnchecked("style", style);
public void setFlightAllowed(boolean flightAllowed) {
this.setPropertyValueUnchecked("allowFlight", flightAllowed);
}
@Override
@@ -18,36 +18,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
import com.onarandombox.MultiverseCore.commands.CheckCommand;
import com.onarandombox.MultiverseCore.commands.ConfigCommand;
import com.onarandombox.MultiverseCore.commands.ConfirmCommand;
import com.onarandombox.MultiverseCore.commands.CoordCommand;
import com.onarandombox.MultiverseCore.commands.CreateCommand;
import com.onarandombox.MultiverseCore.commands.DebugCommand;
import com.onarandombox.MultiverseCore.commands.DeleteCommand;
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
import com.onarandombox.MultiverseCore.commands.HelpCommand;
import com.onarandombox.MultiverseCore.commands.ImportCommand;
import com.onarandombox.MultiverseCore.commands.InfoCommand;
import com.onarandombox.MultiverseCore.commands.ListCommand;
import com.onarandombox.MultiverseCore.commands.LoadCommand;
import com.onarandombox.MultiverseCore.commands.ModifyAddCommand;
import com.onarandombox.MultiverseCore.commands.ModifyClearCommand;
import com.onarandombox.MultiverseCore.commands.ModifyCommand;
import com.onarandombox.MultiverseCore.commands.ModifyRemoveCommand;
import com.onarandombox.MultiverseCore.commands.ModifySetCommand;
import com.onarandombox.MultiverseCore.commands.PurgeCommand;
import com.onarandombox.MultiverseCore.commands.RegenCommand;
import com.onarandombox.MultiverseCore.commands.ReloadCommand;
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
import com.onarandombox.MultiverseCore.commands.VersionCommand;
import com.onarandombox.MultiverseCore.commands.WhoCommand;
import com.onarandombox.MultiverseCore.commands.*;
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
import com.onarandombox.MultiverseCore.destination.BedDestination;
import com.onarandombox.MultiverseCore.destination.CannonDestination;
@@ -60,19 +31,13 @@ import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.DebugLog;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.onarandombox.MultiverseCore.utils.MVPermissions;
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
import com.onarandombox.MultiverseCore.utils.*;
import com.pneumaticraft.commandhandler.CommandHandler;
import me.main__.util.SerializationConfig.SerializationConfig;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
@@ -102,7 +67,7 @@ import java.util.logging.Logger;
* The implementation of the Multiverse-{@link Core}.
*/
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private static final int PROTOCOL = 15;
private static final int PROTOCOL = 14;
// TODO: Investigate if this one is really needed to be static.
// Doubt it. -- FernFerret
private static Map<String, String> teleportQueue = new HashMap<String, String>();
@@ -216,8 +181,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
getDataFolder().mkdirs();
// Setup our Debug Log
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
debugLog.setStandardLogger(LOGGER);
SerializationConfig.initLogging(debugLog);
// Setup our BlockSafety
this.blockSafety = new SimpleBlockSafety(this);
// Setup our LocationManipulation
@@ -341,6 +304,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.multiverseConfig.options().copyDefaults(false);
this.multiverseConfig.options().copyHeader(true);
this.migrateWorldConfig();
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
MultiverseCoreConfiguration wantedConfig = null;
try {
wantedConfig = (MultiverseCoreConfiguration) multiverseConfig.get("multiverse-configuration");
@@ -349,8 +315,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
} finally {
config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig);
}
this.migrateWorldConfig();
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
this.messaging.setCooldown(config.getMessageCooldown());
@@ -422,10 +386,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
FileConfiguration wconf = YamlConfiguration
.loadConfiguration(new File(getDataFolder(), "worlds.yml"));
if (!wconf.isConfigurationSection("worlds")) {// empty config
this.log(Level.FINE, "No worlds to migrate!");
if (!wconf.isConfigurationSection("worlds")) // empty config
return;
}
Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);
@@ -436,7 +398,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// fine
newValues.put(entry.getKey(), entry.getValue());
} else if (entry.getValue() instanceof ConfigurationSection) {
this.log(Level.FINE, "Migrating: " + entry.getKey());
// we have to migrate this
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
ConfigurationSection section = (ConfigurationSection) entry.getValue();
@@ -748,14 +709,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public static void staticLog(Level level, String msg) {
if (level == Level.FINE && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 1) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level == Level.FINER && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 2) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
String message = LOG_TAG + " " + msg;
LOGGER.log(level, message);
debugLog.log(level, message);
LOGGER.log(level, String.format("%s %s", LOG_TAG, msg));
debugLog.log(level, String.format("%s %s", LOG_TAG, msg));
}
}
@@ -767,7 +730,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* @param msg The message
*/
public static void staticDebugLog(Level level, String msg) {
debugLog.log(level, msg);
LOGGER.log(level, "[MVCore-Debug] " + msg);
debugLog.log(level, "[MVCore-Debug] " + msg);
}
/**
@@ -1,12 +1,13 @@
package com.onarandombox.MultiverseCore;
import java.util.Map;
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import me.main__.util.SerializationConfig.NoSuchPropertyException;
import me.main__.util.SerializationConfig.Property;
import me.main__.util.SerializationConfig.SerializationConfig;
import java.util.Map;
/**
* Our configuration.
*/
@@ -21,13 +22,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
MultiverseCoreConfiguration.instance = instance;
}
/**
* @return True if the static instance of config is set.
*/
public static boolean isSet() {
return instance != null;
}
/**
* Gets the statically saved instance.
* @return The statically saved instance.
@@ -1,162 +0,0 @@
package com.onarandombox.MultiverseCore.api;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.DebugLog;
import com.pneumaticraft.commandhandler.CommandHandler;
/**
* Make things easier for MV-Plugins!
*/
public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
private MultiverseCore core;
/**
* Prefix for standard log entrys.
*/
protected String logTag;
private DebugLog debugLog;
/**
* {@inheritDoc}
*
* Note: You can't override this, use {@link #onPluginEnable()} instead!
* @see #onPluginEnable()
*/
@Override
public final void onEnable() {
MultiverseCore theCore = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
if (theCore == null) {
this.getLogger().severe("Core not found! The plugin dev needs to add a dependency!");
this.getLogger().severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
if (theCore.getProtocolVersion() < this.getProtocolVersion()) {
this.getLogger().severe("You need a newer version of Multiverse-Core!");
this.getLogger().severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
this.setCore(theCore);
// Turn on Logging
this.getServer().getLogger().info(String.format("%s - Version %s enabled - By %s",
this.getDescription().getName(), this.getDescription().getVersion(), getAuthors()));
getDataFolder().mkdirs();
File debugLogFile = new File(getDataFolder(), "debug.log");
try {
debugLogFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
debugLog = new DebugLog("Multiverse-Adventure", getDataFolder() + File.separator + "debug.log");
debugLog.setTag(String.format("[%s-Debug]", this.getDescription().getName()));
this.onPluginEnable();
}
/**
* Parse the Authors Array into a readable String with ',' and 'and'.
*
* @return The readable authors-{@link String}
*/
protected String getAuthors() {
String authors = "";
List<String> auths = this.getDescription().getAuthors();
if (auths.size() == 0) {
return "";
}
if (auths.size() == 1) {
return auths.get(0);
}
for (int i = 0; i < auths.size(); i++) {
if (i == this.getDescription().getAuthors().size() - 1) {
authors += " and " + this.getDescription().getAuthors().get(i);
} else {
authors += ", " + this.getDescription().getAuthors().get(i);
}
}
return authors.substring(2);
}
/**
* Called when the plugin is enabled.
* @see #onEnable()
*/
protected abstract void onPluginEnable();
/**
* You can register commands here.
* @param handler The CommandHandler.
*/
protected abstract void registerCommands(CommandHandler handler);
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!this.isEnabled()) {
sender.sendMessage("This plugin is Disabled!");
return true;
}
ArrayList<String> allArgs = new ArrayList<String>(args.length + 1);
allArgs.add(command.getName());
allArgs.addAll(Arrays.asList(args));
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
}
@Override
public void log(Level level, String msg) {
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2)
|| (level == Level.FINEST && debugLevel >= 3)) {
debugLog.log(level, msg);
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
String message = new StringBuilder(getLogTag()).append(msg).toString();
this.getServer().getLogger().log(level, message);
debugLog.log(level, message);
}
}
private String getLogTag() {
if (logTag == null)
logTag = String.format("[%s]", this.getDescription().getName());
return logTag;
}
/**
* Sets the debug log-tag.
* @param tag The new tag.
*/
protected final void setDebugLogTag(String tag) {
this.debugLog.setTag(tag);
}
@Override
public final String dumpVersionInfo(String buffer) {
throw new UnsupportedOperationException("This is gone.");
}
@Override
public final MultiverseCore getCore() {
if (this.core == null)
throw new IllegalStateException("Core is null!");
return this.core;
}
@Override
public final void setCore(MultiverseCore core) {
this.core = core;
}
}
@@ -288,21 +288,6 @@ public interface MultiverseWorld {
*/
boolean setColor(String color);
/**
* Gets the style that this world's name/alias will display as.
*
* @return The style of this world. {@code null} for "normal" style.
*/
ChatColor getStyle();
/**
* Sets the style that this world's name/alias will display as.
*
* @param style A valid style name.
* @return True if the style was set, false if not.
*/
boolean setStyle(String style);
/**
* Tells you if someone entered a valid color.
*
@@ -669,4 +654,25 @@ public interface MultiverseWorld {
* @return All property names, with alternating colors.
*/
String getAllPropertyNames();
/**
* Gets whether or not flight is allowed in this world.
* <p>
* It should be noted that this refers to clientside flying. Creative
* mode will always allow server based flying.
*
* @return True if flight is allowed.
*/
boolean isFlightAllowed();
/**
* Sets whether or not flight is allowed in this world.
* <p>
* It should be noted that this refers to clientside flying. Creative
* mode will always allow server based flying.
*
* @param flightAllowed Wheter or not flight is allowed in this world.
*/
void setFlightAllowed(boolean flightAllowed);
}
@@ -68,7 +68,7 @@ public class WhoCommand extends MultiverseCommand {
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
world.getColoredWorldString(), ChatColor.AQUA));
sender.sendMessage(buildPlayerString(world, p));
sender.sendMessage(buildPlayerString(world));
return;
}
}
@@ -79,7 +79,7 @@ public class WhoCommand extends MultiverseCommand {
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p)));
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world)));
shownOne = true;
}
}
@@ -90,15 +90,14 @@ public class WhoCommand extends MultiverseCommand {
return;
}
private static String buildPlayerString(MultiverseWorld world, Player viewer) {
private static String buildPlayerString(MultiverseWorld world) {
List<Player> players = world.getCBWorld().getPlayers();
if (players.size() == 0) {
return "No players found.";
} else {
StringBuilder playerBuilder = new StringBuilder();
for (Player player : players) {
if ((viewer == null) || viewer.canSee(player))
playerBuilder.append(player.getDisplayName()).append(", ");
playerBuilder.append(player.getDisplayName()).append(", ");
}
String bString = playerBuilder.toString();
return bString.substring(0, bString.length() - 2);
@@ -11,33 +11,49 @@ import org.bukkit.ChatColor;
/**
* A regular {@link ChatColor} represented by an english string.
* @see ChatColor
*/
public enum EnglishChatColor {
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
AQUA(ChatColor.AQUA),
BLACK(ChatColor.BLACK),
BLUE(ChatColor.BLUE),
DARKAQUA(ChatColor.DARK_AQUA),
DARKBLUE(ChatColor.DARK_BLUE),
DARKGRAY(ChatColor.DARK_GRAY),
DARKGREEN(ChatColor.DARK_GREEN),
DARKPURPLE(ChatColor.DARK_PURPLE),
DARKRED(ChatColor.DARK_RED),
GOLD(ChatColor.GOLD),
GRAY(ChatColor.GRAY),
GREEN(ChatColor.GREEN),
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
RED(ChatColor.RED),
YELLOW(ChatColor.YELLOW),
WHITE(ChatColor.WHITE);
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
/*
* I know. this is quite ugly.
*/
/** AQUA. */
AQUA("AQUA", ChatColor.AQUA),
/** BLACK. */
BLACK("BLACK", ChatColor.BLACK),
/** BLUE. */
BLUE("BLUE", ChatColor.BLUE),
/** DARKAQUA. */
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA),
/** DARKBLUE. */
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE),
/** DARKGRAY. */
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY),
/** DARKGREEN. */
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN),
/** DARKPURPLE. */
DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE),
/** DARKRED. */
DARKRED("DARKRED", ChatColor.DARK_RED),
/** GOLD. */
GOLD("GOLD", ChatColor.GOLD),
/** GRAY. */
GRAY("GRAY", ChatColor.GRAY),
/** GREEN. */
GREEN("GREEN", ChatColor.GREEN),
/** LIGHTPURPLE. */
LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE),
/** RED. */
RED("RED", ChatColor.RED),
/** YELLOW. */
YELLOW("YELLOW", ChatColor.YELLOW),
/** WHITE. */
WHITE("WHITE", ChatColor.WHITE);
private ChatColor color;
private String text;
private final ChatColor color;
//private final String text;
EnglishChatColor(ChatColor color) {
EnglishChatColor(String name, ChatColor color) {
this.color = color;
this.text = name;
}
/**
@@ -45,7 +61,7 @@ public enum EnglishChatColor {
* @return The text.
*/
public String getText() {
return this.name();
return this.text;
}
/**
@@ -76,7 +92,7 @@ public enum EnglishChatColor {
public static EnglishChatColor fromString(String text) {
if (text != null) {
for (EnglishChatColor c : EnglishChatColor.values()) {
if (text.equalsIgnoreCase(c.name())) {
if (text.equalsIgnoreCase(c.text)) {
return c;
}
}
@@ -1,49 +0,0 @@
package com.onarandombox.MultiverseCore.enums;
import org.bukkit.ChatColor;
/**
* A regular {@link ChatColor} represented by an english string.
* @see ChatColor
*/
public enum EnglishChatStyle {
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
/** No style. */
NORMAL(null),
MAGIC(ChatColor.MAGIC),
BOLD(ChatColor.BOLD),
STRIKETHROUGH(ChatColor.STRIKETHROUGH),
UNDERLINE(ChatColor.UNDERLINE),
ITALIC(ChatColor.ITALIC);
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
private final ChatColor color;
EnglishChatStyle(ChatColor color) {
this.color = color;
}
/**
* Gets the color.
* @return The color as {@link ChatColor}.
*/
public ChatColor getColor() {
return color;
}
/**
* Constructs an {@link EnglishChatStyle} from a {@link String}.
* @param text The {@link String}.
* @return The {@link EnglishChatStyle}.
*/
public static EnglishChatStyle fromString(String text) {
if (text != null) {
for (EnglishChatStyle c : EnglishChatStyle.values()) {
if (text.equalsIgnoreCase(c.name())) {
return c;
}
}
}
return null;
}
}
@@ -105,7 +105,7 @@ public class MVEntityListener implements Listener {
/**
* Handle people with non-standard animals: ie a patched craftbukkit.
*/
if (type == null || type.getName() == null) {
if (type == null) {
this.plugin.log(Level.FINER, "Found a null typed creature.");
return;
}
@@ -128,8 +128,8 @@ public class MVPlayerListener implements Listener {
if (!p.hasPlayedBefore()) {
this.plugin.log(Level.FINER, "Player joined for the FIRST time!");
if (plugin.getMVConfig().getFirstSpawnOverride()) {
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): "
+ worldManager.getFirstSpawnWorld().getSpawnLocation());
this.plugin.log(Level.FINE, String.format("Moving NEW player to(firstspawnoverride): %s",
worldManager.getFirstSpawnWorld().getSpawnLocation()));
this.sendPlayerToDefaultWorld(p);
}
return;
@@ -170,8 +170,9 @@ public class MVPlayerListener implements Listener {
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void playerTeleport(PlayerTeleportEvent event) {
this.plugin.log(Level.FINER, "Got teleport event for player '"
+ event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
this.plugin.log(Level.FINER, String.format(
"Got teleport event for player '%s' with cause '%s'",
event.getPlayer().getName(), event.getCause()));
if (event.isCancelled()) {
return;
}
@@ -186,15 +187,14 @@ public class MVPlayerListener implements Listener {
teleporter = this.plugin.getServer().getPlayer(teleporterName);
}
}
this.plugin.log(Level.FINER, "Inferred sender '" + teleporter + "' from name '"
+ teleporterName + "', fetched from name '" + teleportee.getName() + "'");
this.plugin.log(Level.FINER, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'",
teleporter, teleporterName, teleportee.getName()));
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
if (fromWorld == null || toWorld == null)
return;
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
// The player is Teleporting to the same world.
this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world.");
this.plugin.log(Level.FINER, String.format("Player '%s' is teleporting to the same world.",
teleportee.getName()));
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
return;
}
@@ -202,31 +202,33 @@ public class MVPlayerListener implements Listener {
// Charge the teleporter
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
+ "' because '" + teleporter.getName()
+ "' don't have the FUNDS required to enter it.");
this.plugin.log(Level.FINE, String.format(
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.",
teleportee.getName(), toWorld.getAlias(), teleporter.getName()));
return;
}
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
+ "' because '" + teleporter.getName()
+ "' don't have: multiverse.access." + event.getTo().getWorld().getName());
this.plugin.log(Level.FINE, String.format(
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
teleportee.getName(), toWorld.getAlias(), teleporter.getName(),
event.getTo().getWorld().getName()));
} else {
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
}
} else {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
this.plugin.log(Level.FINE, String.format(
"Player '%s' was allowed to go to '%s' because enforceaccess is off.",
teleportee.getName(), toWorld.getAlias()));
}
}
private void stateSuccess(String playerName, String worldName) {
this.plugin.log(Level.FINE, "MV-Core is allowing Player '" + playerName
+ "' to go to '" + worldName + "'.");
this.plugin.log(Level.FINE, String.format(
"MV-Core is allowing Player '%s' to go to '%s'.",
playerName, worldName));
}
/**
@@ -277,22 +279,19 @@ public class MVPlayerListener implements Listener {
}
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true));
if (event.isCancelled()) {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
+ "' because they don't have the FUNDS required to enter.");
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have the FUNDS required to enter.",
event.getPlayer().getName(), event.getTo().getWorld().getName()));
return;
}
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
if (event.isCancelled()) {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
+ "' because they don't have: multiverse.access." + event.getTo().getWorld().getName());
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s",
event.getPlayer().getName(), event.getTo().getWorld().getName(), event.getTo().getWorld().getName()));
}
} else {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
+ "' because enforceaccess is off.");
this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
event.getPlayer().getName(), event.getTo().getWorld().getName()));
}
}
@@ -300,6 +299,7 @@ public class MVPlayerListener implements Listener {
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
}
@@ -313,8 +313,8 @@ public class MVPlayerListener implements Listener {
if (mvWorld != null) {
this.handleGameMode(player, mvWorld);
} else {
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
+ "' not managed by Multiverse.");
this.plugin.log(Level.FINER, String.format(
"Not handling gamemode for world '%s' not managed by Multiverse.", world.getName()));
}
}
@@ -325,28 +325,59 @@ public class MVPlayerListener implements Listener {
*/
public void handleGameMode(final Player player, final MultiverseWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
// destination world, otherwise we'd be changing the player mode if they haven't moved anywhere.
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) {
MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: "
+ player.getName() + ", Changing to " + world.getGameMode().toString());
MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld());
MultiverseCore.staticLog(Level.FINEST, "To World: " + world);
player.setGameMode(world.getGameMode());
} else {
MultiverseCore.staticLog(Level.FINE, "The gamemode was NOT changed for player '"
+ player.getName() + "' because he is now in world '"
+ player.getWorld().getName() + "' instead of world '"
+ world.getName() +"'");
MultiverseCore.staticLog(Level.FINE,
String.format("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
player.getName(), player.getWorld().getName(), world.getName()));
}
}
}, 1L);
} else {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
this.plugin.log(Level.FINE, String.format("Player: %s is IMMUNE to gamemode changes!", player.getName()));
}
}
/**
* Handles the allowflight attribute for the specified {@link Player}.
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void handleAllowFlight(final Player player, final MultiverseWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they haven't moved anywhere.
if (!this.pt.playerCanIgnoreAllowFlightRestriction(world, player)) {
this.plugin.log(Level.FINE, "Handeling flight for player: " + player.getName());
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) {
player.setAllowFlight(world.isFlightAllowed());
MultiverseCore.staticLog(Level.FINER,
String.format("%s's allowFlight was set to %b!",
player.getName(), world.isFlightAllowed()));
} else {
MultiverseCore.staticLog(Level.FINE,
String.format("allowFlight was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
player.getName(), player.getWorld().getName(), world.getName()));
}
}
}, 1L);
} else {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to flight changes!");
}
}
}
@@ -7,14 +7,10 @@
package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
@@ -25,10 +21,10 @@ import java.util.logging.Logger;
/**
* The Multiverse debug-logger.
*/
public class DebugLog extends Logger {
public class DebugLog {
private FileHandler fh;
private Logger standardLog = null;
private String prefix = "[MVCore-Debug] ";
private Logger log;
/**
* Creates a new debug logger.
@@ -37,16 +33,16 @@ public class DebugLog extends Logger {
* @param file The file to log to.
*/
public DebugLog(String logger, String file) {
super(logger, null);
this.log = Logger.getLogger(logger);
try {
this.fh = new FileHandler(file, true);
this.setUseParentHandlers(false);
List<Handler> toRemove = Arrays.asList(this.getHandlers());
for (Handler handler : toRemove) {
this.removeHandler(handler);
this.log.setUseParentHandlers(false);
for (Handler handler : this.log.getHandlers()) {
this.log.removeHandler(handler);
}
this.addHandler(this.fh);
this.setLevel(Level.ALL);
this.log.addHandler(this.fh);
this.log.setLevel(Level.ALL);
this.fh.setFormatter(new LogFormatter());
} catch (SecurityException e) {
e.printStackTrace();
@@ -55,39 +51,14 @@ public class DebugLog extends Logger {
}
}
/**
* Sets the log-tag.
* @param tag The new tag.
*/
public void setTag(String tag) {
this.prefix = tag + " ";
}
/**
* Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file.
*
* @param logger Logger to send debug messages to.
*/
public void setStandardLogger(Logger logger) {
this.standardLog = logger;
}
/**
* Log a message at a certain level.
*
* @param level The log-{@link Level}.
* @param msg the message.
*/
@Override
public void log(Level level, String msg) {
if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) {
// only redirect to standardLog if it's lower than INFO so we don't log that twice!
if ((level.intValue() < Level.INFO.intValue()) && (standardLog != null)) {
standardLog.log(level, prefix + msg);
}
super.log(level, prefix + msg);
}
this.log.log(level, msg);
}
/**
@@ -47,6 +47,21 @@ public class MVPermissions implements PermissionsInterface {
return p.hasPermission("mv.bypass.gamemode." + w.getName());
}
/**
* Check if a Player can ignore GameMode restrictions for world they travel to.
*
* @param p The {@link Player} to check.
* @param w The {@link MultiverseWorld} the player wants to teleport to.
* @return True if they should bypass restrictions.
*/
public boolean canIgnoreAllowFlightRestriction(Player p, MultiverseWorld w) {
if (p.hasPermission("mv.bypass.allowflight.*")) {
this.plugin.log(Level.FINER, "Player has mv.bypass.allowflight.* they can fly!");
return true;
}
return p.hasPermission("mv.bypass.allowflight." + w.getName());
}
/**
* Check if a Player can teleport to the Destination world from there current world.
*
@@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore.utils;
import java.util.logging.Level;
import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@@ -15,8 +16,6 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import java.util.logging.Level;
/**
* Utility-class for permissions.
*/
@@ -135,10 +134,6 @@ public class PermissionTools {
// Only check payments if it's a different world:
if (!toWorld.equals(fromWorld)) {
// Don't bother checking economy stuff if it doesn't even cost to enter.
if (toWorld.getPrice() == 0D) {
return true;
}
// If the player does not have to pay, return now.
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
return true;
@@ -251,4 +246,21 @@ public class PermissionTools {
return true;
}
}
/**
* Checks to see if a player should bypass allow-flight restrictions.
*
* @param toWorld world travelling to.
* @param teleportee player travelling.
* @return True if they should bypass restrictions
*/
public boolean playerCanIgnoreAllowFlightRestriction(MultiverseWorld toWorld, Player teleportee) {
if (toWorld != null) {
return this.plugin.getMVPerms().canIgnoreAllowFlightRestriction(teleportee, toWorld);
} else {
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
return true;
}
}
}
@@ -14,7 +14,6 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
@@ -289,15 +288,13 @@ public class WorldManager implements MVWorldManager {
if (worlds.containsKey(worldName))
throw new IllegalArgumentException("That world is already loaded!");
MVWorld mvworld = worldsFromTheConfig.get(worldName);
World cbworld = Bukkit.getWorld(worldName);
if (cbworld == null) {
try {
cbworld = creator.createWorld();
} catch (Exception e) {
e.printStackTrace();
brokenWorld(worldName);
return false;
}
World cbworld;
try {
cbworld = creator.createWorld();
} catch (Exception e) {
e.printStackTrace();
brokenWorld(worldName);
return false;
}
mvworld.init(cbworld, plugin);
this.worldPurger.purgeWorld(mvworld);
@@ -23,6 +23,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
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;
@@ -7,14 +7,18 @@
package com.onarandombox.MultiverseCore.test.utils;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.FileUtils;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.Assert;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@@ -33,15 +37,13 @@ import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.MockGateway;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.FileUtils;
import com.onarandombox.MultiverseCore.utils.WorldManager;
public class TestInstanceCreator {
private MultiverseCore core;
@@ -256,8 +258,6 @@ public class TestInstanceCreator {
return false;
}
core.onDisable();
FileUtils.deleteFolder(serverDirectory);
MockWorldFactory.clearWorlds();