Merge branch 'master' of github.com:Multiverse/Multiverse-Core into new-tests

Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
This commit is contained in:
main() 2012-01-23 19:05:21 +01:00
commit 0980e0a201
23 changed files with 486 additions and 477 deletions

@ -1 +1 @@
Subproject commit 18c55a9070a5e64b2cb0737940290643f324fa7d Subproject commit 7abba1f0040862e9fabdafb3d44c6cf0b914cc7c

13
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversecore</groupId> <groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId> <artifactId>Multiverse-Core</artifactId>
<version>2.2</version> <version>2.3</version>
<name>Multiverse-Core</name> <name>Multiverse-Core</name>
<description>World Management Plugin</description> <description>World Management Plugin</description>
<properties> <properties>
@ -77,7 +77,7 @@
</goals> </goals>
<configuration> <configuration>
<sources> <sources>
<source>${project.basedir}/lib/allpay/src</source> <source>${project.basedir}/lib/allpay/src/main/java</source>
<source>${project.basedir}/lib/commandhandler/src</source> <source>${project.basedir}/lib/commandhandler/src</source>
<source>${project.basedir}/lib/commandhandler/lib/ShellParser/src</source> <source>${project.basedir}/lib/commandhandler/lib/ShellParser/src</source>
</sources> </sources>
@ -162,7 +162,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.0.0-R1-SNAPSHOT</version> <version>1.1-R1-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@ -229,6 +229,13 @@
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>ca.agnate</groupId>
<artifactId>EconXP</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Economy Dependencies --> <!-- End of Economy Dependencies -->
<!-- Start of Test Dependencies --> <!-- Start of Test Dependencies -->
<dependency> <dependency>

View File

@ -23,6 +23,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -68,6 +69,7 @@ public class MVWorld implements MultiverseWorld {
private Permission ignoreperm; private Permission ignoreperm;
private static final Map<String, String> TIME_ALIASES; private static final Map<String, String> TIME_ALIASES;
private WorldType type;
static { static {
Map<String, String> staticTimes = new HashMap<String, String>(); Map<String, String> staticTimes = new HashMap<String, String>();
@ -90,6 +92,7 @@ public class MVWorld implements MultiverseWorld {
this.name = world.getName(); this.name = world.getName();
this.seed = seed; this.seed = seed;
this.environment = world.getEnvironment(); this.environment = world.getEnvironment();
this.type = world.getWorldType();
// Initialize our lists // Initialize our lists
this.initLists(); this.initLists();
@ -107,6 +110,8 @@ public class MVWorld implements MultiverseWorld {
} }
worldSection.set("environment", this.environment.toString()); worldSection.set("environment", this.environment.toString());
worldSection.set("type", this.type.toString());
// Start NEW config awesomeness. // Start NEW config awesomeness.
ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection); ConfigPropertyFactory fac = new ConfigPropertyFactory(this.worldSection);
this.propertyList = new HashMap<String, MVConfigProperty<?>>(); this.propertyList = new HashMap<String, MVConfigProperty<?>>();
@ -204,6 +209,15 @@ public class MVWorld implements MultiverseWorld {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name); this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name);
} }
// Sync all active settings.
this.setActualPVP();
this.verifyScaleSetProperly();
this.setActualKeepSpawnInMemory();
this.setActualDifficulty();
this.setActualGameMode();
this.setActualSpawn();
this.syncMobs();
} }
/** /**
@ -549,18 +563,16 @@ public class MVWorld implements MultiverseWorld {
Method method = this.getClass().getMethod(property.getMethod()); Method method = this.getClass().getMethod(property.getMethod());
Object returnVal = method.invoke(this); Object returnVal = method.invoke(this);
if (returnVal instanceof Boolean) { if (returnVal instanceof Boolean) {
if ((Boolean) returnVal) {
this.saveConfig();
}
return (Boolean) returnVal; return (Boolean) returnVal;
} else { } else {
this.saveConfig();
return true; return true;
} }
} catch (NoSuchMethodException e) { } catch (Exception e) {
System.out.println(e); e.printStackTrace();
return false;
} catch (IllegalAccessException e) {
System.out.println(e);
return false;
} catch (InvocationTargetException e) {
System.out.println(e);
return false; return false;
} }
} }
@ -610,6 +622,14 @@ public class MVWorld implements MultiverseWorld {
return this.name; return this.name;
} }
/**
* {@inheritDoc}
*/
@Override
public String getPermissibleName() {
return this.name.toLowerCase();
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1132,6 +1152,14 @@ public class MVWorld implements MultiverseWorld {
return String.format("%d:%02d", hours, minutes); return String.format("%d:%02d", hours, minutes);
} }
/**
* {@inheritDoc}
*/
@Override
public WorldType getWorldType() {
return this.type;
}
/** /**
* Used by the active time-property to set the "actual" property. * Used by the active time-property to set the "actual" property.
* @return True if the property was successfully set. * @return True if the property was successfully set.

View File

@ -25,7 +25,6 @@ import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.MultiverseCore.listeners.MVPortalAdjustListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.AnchorManager; import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.DebugLog; import com.onarandombox.MultiverseCore.utils.DebugLog;
@ -38,15 +37,12 @@ import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler; import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration; import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -65,7 +61,7 @@ import java.util.logging.Logger;
* The implementation of the Multiverse-{@link Core}. * The implementation of the Multiverse-{@link Core}.
*/ */
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private static final int PROTOCOL = 10; private static final int PROTOCOL = 12;
// Global Multiverse config variable, states whether or not // Global Multiverse config variable, states whether or not
// Multiverse should stop other plugins from teleporting players // Multiverse should stop other plugins from teleporting players
// to worlds. // to worlds.
@ -157,7 +153,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup the block/player/entity listener. // Setup the block/player/entity listener.
private MVPlayerListener playerListener = new MVPlayerListener(this); private MVPlayerListener playerListener = new MVPlayerListener(this);
private MVPortalAdjustListener portalAdjustListener = new MVPortalAdjustListener(this);
private MVEntityListener entityListener = new MVEntityListener(this); private MVEntityListener entityListener = new MVEntityListener(this);
private MVPluginListener pluginListener = new MVPluginListener(this); private MVPluginListener pluginListener = new MVPluginListener(this);
private MVWeatherListener weatherListener = new MVWeatherListener(this); private MVWeatherListener weatherListener = new MVWeatherListener(this);
@ -171,7 +166,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private int pluginCount; private int pluginCount;
private DestinationFactory destFactory; private DestinationFactory destFactory;
private SpoutInterface spoutInterface = null; private SpoutInterface spoutInterface = null;
private static final double ALLPAY_VERSION = 3; private static final double ALLPAY_VERSION = 5;
private static final double CH_VERSION = 4; private static final double CH_VERSION = 4;
private MVMessaging messaging; private MVMessaging messaging;
@ -319,28 +314,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/ */
private void registerEvents() { private void registerEvents() {
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this.playerListener, Priority.Highest, this); // Cancel Teleports if needed. pm.registerEvents(this.playerListener, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Priority.Normal, this); // To create the Player Session pm.registerEvents(this.entityListener, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); // To remove Player Sessions pm.registerEvents(this.pluginListener, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight. pm.registerEvents(this.weatherListener, this);
pm.registerEvent(Event.Type.PLAYER_LOGIN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight.
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.High, this);
// We want this high to have it go last, so it can cancel if needbe.
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.portalAdjustListener, Priority.Lowest, this); // To handle portal correction
pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
pm.registerEvent(Event.Type.FOOD_LEVEL_CHANGE, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.WEATHER_CHANGE, this.weatherListener, Priority.Normal, this);
pm.registerEvent(Event.Type.THUNDER_CHANGE, this.weatherListener, Priority.Normal, this);
} }
/** /**
@ -581,33 +558,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return MultiverseCore.LOG_TAG; return MultiverseCore.LOG_TAG;
} }
// TODO This code should get moved somewhere more appropriate, but for now, it's here.
// TODO oh, and it should be static.
/**
* Converts a {@link String} into an {@link Environment}.
*
* @param env The environment as {@link String}
* @return The environment as {@link Environment}
*/
public Environment getEnvFromString(String env) {
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
env = "NETHER";
if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS"))
env = "THE_END";
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
env = "NORMAL";
try {
// If the value wasn't found, maybe it's new, try checking the enum directly.
return Environment.valueOf(env);
} catch (IllegalArgumentException e) {
return null;
}
}
/** /**
* Shows a message that the given world is not a MultiverseWorld. * Shows a message that the given world is not a MultiverseWorld.
* *
@ -717,15 +667,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public void setSpout() { public void setSpout() {
this.spoutInterface = new SpoutInterface(); this.spoutInterface = new SpoutInterface();
this.commandHandler.registerCommand(new SpoutCommand(this)); this.commandHandler.registerCommand(new SpoutCommand(this));
if (FirstSpawnOverride) {
this.log(Level.WARNING, "Disabling MV's 'firstspawnoverride', since spout doesn't handle new players well yet.");
this.log(Level.WARNING, "This means *new players* may not spawn where you've set your \"mvspawn\" AND");
this.log(Level.WARNING, "the config value 'firstspawnworld' will have NO effect!!!");
this.log(Level.WARNING, "Talk to the Spout devs to get this fixed!");
this.log(Level.WARNING, " --FernFerret");
FirstSpawnOverride = false;
this.multiverseConfig.set("firstspawnoverride", false);
}
} }
/** /**

View File

@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.utils.PurgeWorlds; import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
@ -32,10 +33,11 @@ public interface MVWorldManager {
* @param seedString The seed in the form of a string. * @param seedString The seed in the form of a string.
* If the seed is a Long, * If the seed is a Long,
* it will be interpreted as such. * it will be interpreted as such.
* @param type The Type of the world to be made.
* @param generator The Custom generator plugin to use. * @param generator The Custom generator plugin to use.
* @return True if the world is added, false if not. * @return True if the world is added, false if not.
*/ */
boolean addWorld(String name, Environment env, String seedString, String generator); boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator);
/** /**
* Add a new World to the Multiverse Setup. * Add a new World to the Multiverse Setup.
@ -45,11 +47,12 @@ public interface MVWorldManager {
* @param seedString The seed in the form of a string. * @param seedString The seed in the form of a string.
* If the seed is a Long, * If the seed is a Long,
* it will be interpreted as such. * it will be interpreted as such.
* @param type The Type of the world to be made.
* @param generator The Custom generator plugin to use. * @param generator The Custom generator plugin to use.
* @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat. * @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat.
* @return True if the world is added, false if not. * @return True if the world is added, false if not.
*/ */
boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust); boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust);
/** /**
* Remove the world from the Multiverse list, from the * Remove the world from the Multiverse list, from the

View File

@ -15,6 +15,7 @@ import org.bukkit.Difficulty;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -22,8 +23,6 @@ import java.util.List;
/** /**
* The API for a Multiverse Handled World. * The API for a Multiverse Handled World.
* <p>
* Currently INCOMPLETE
*/ */
public interface MultiverseWorld { public interface MultiverseWorld {
@ -146,6 +145,18 @@ public interface MultiverseWorld {
*/ */
String getName(); String getName();
/**
* Gets the lowercased name of the world. This method is required, since the permissables
* lowercase all permissions when recalculating.
* <p>
* Note: This also means if a user has worlds named: world and WORLD, that they can both
* exist, and both be teleported to independently, but their permissions **cannot** be
* uniqueified at this time. See bug report #.
*
* @return The lowercased name of the world.
*/
String getPermissibleName();
/** /**
* Gets the alias of this world. * Gets the alias of this world.
* <p> * <p>
@ -536,7 +547,7 @@ public interface MultiverseWorld {
/** /**
* Sets the current time in a world. * Sets the current time in a world.
* * <p>
* This method will take the following formats: * This method will take the following formats:
* 11:37am * 11:37am
* 4:30p * 4:30p
@ -552,4 +563,14 @@ public interface MultiverseWorld {
* @return The time as a short string: 12:34pm * @return The time as a short string: 12:34pm
*/ */
String getTime(); String getTime();
/**
* Gets the type of this world. As of 1.1-R1 this will be:
* FLAT or NORMAL
* <p>
* This is *not* the generator.
*
* @return The Type of this world.
*/
WorldType getWorldType();
} }

View File

@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.pneumaticraft.commandhandler.CommandHandler; import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -28,8 +29,8 @@ public class CreateCommand extends MultiverseCommand {
public CreateCommand(MultiverseCore plugin) { public CreateCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.setName("Create World"); this.setName("Create World");
this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] [-n]"); this.setCommandUsage("/mv create" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n]");
this.setArgRange(2, 7); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.setArgRange(2, 9); // SUPPRESS CHECKSTYLE: MagicNumberCheck
this.addKey("mvcreate"); this.addKey("mvcreate");
this.addKey("mvc"); this.addKey("mvc");
this.addKey("mv create"); this.addKey("mv create");
@ -37,6 +38,7 @@ public class CreateCommand extends MultiverseCommand {
this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal"); this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal");
this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether"); this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether");
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end"); this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end");
this.addCommandExample("/mv create " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat");
this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel"); this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel");
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon"); this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
this.worldManager = this.plugin.getMVWorldManager(); this.worldManager = this.plugin.getMVWorldManager();
@ -49,6 +51,7 @@ public class CreateCommand extends MultiverseCommand {
String env = args.get(1); String env = args.get(1);
String seed = CommandHandler.getFlag("-s", args); String seed = CommandHandler.getFlag("-s", args);
String generator = CommandHandler.getFlag("-g", args); String generator = CommandHandler.getFlag("-g", args);
String typeString = CommandHandler.getFlag("-t", args);
boolean useSpawnAdjust = true; boolean useSpawnAdjust = true;
for (String s : args) { for (String s : args) {
if (s.equalsIgnoreCase("-n")) { if (s.equalsIgnoreCase("-n")) {
@ -61,16 +64,27 @@ public class CreateCommand extends MultiverseCommand {
return; return;
} }
Environment environment = this.plugin.getEnvFromString(env); Environment environment = EnvironmentCommand.getEnvFromString(env);
if (environment == null) { if (environment == null) {
sender.sendMessage(ChatColor.RED + "That is not a valid environment."); sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
EnvironmentCommand.showEnvironments(sender); EnvironmentCommand.showEnvironments(sender);
return; return;
} }
// If they didn't specify a type, default to NORMAL
if (typeString == null) {
typeString = "NORMAL";
}
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
if (type == null) {
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
EnvironmentCommand.showWorldTypes(sender);
return;
}
Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'..."); Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");
if (this.worldManager.addWorld(worldName, environment, seed, generator, useSpawnAdjust)) { if (this.worldManager.addWorld(worldName, environment, seed, type, generator, useSpawnAdjust)) {
Command.broadcastCommandMessage(sender, "Complete!"); Command.broadcastCommandMessage(sender, "Complete!");
} else { } else {
Command.broadcastCommandMessage(sender, "FAILED."); Command.broadcastCommandMessage(sender, "FAILED.");

View File

@ -9,6 +9,8 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -26,10 +28,11 @@ public class EnvironmentCommand extends MultiverseCommand {
this.setArgRange(0, 0); this.setArgRange(0, 0);
this.addKey("mvenv"); this.addKey("mvenv");
this.addKey("mv env"); this.addKey("mv env");
this.addKey("mv type");
this.addKey("mv environment"); this.addKey("mv environment");
this.addKey("mv environments"); this.addKey("mv environments");
this.addCommandExample("/mv env"); this.addCommandExample("/mv env");
this.setPermission("multiverse.core.list.environments", "Lists valid known environments.", PermissionDefault.OP); this.setPermission("multiverse.core.list.environments", "Lists valid known environments/world types.", PermissionDefault.OP);
} }
/** /**
@ -43,9 +46,67 @@ public class EnvironmentCommand extends MultiverseCommand {
sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.RED + "NETHER");
sender.sendMessage(ChatColor.AQUA + "END"); sender.sendMessage(ChatColor.AQUA + "END");
} }
/**
* Shows all valid known world types to a {@link CommandSender}.
*
* @param sender The {@link CommandSender}.
*/
public static void showWorldTypes(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
sender.sendMessage(String.format("%sNORMAL %sor %sFLAT",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA));
}
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
EnvironmentCommand.showEnvironments(sender); EnvironmentCommand.showEnvironments(sender);
EnvironmentCommand.showWorldTypes(sender);
}
/**
* Converts a {@link String} into a {@link WorldType}.
*
* @param type The WorldType as a {@link String}
* @return The WorldType as a {@link WorldType}
*/
public static WorldType getWorldTypeFromString(String type) {
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
if (type.equalsIgnoreCase("normal"))
type = "NORMAL";
if (type.equalsIgnoreCase("flat"))
type = "FLAT";
try {
// Now that we've converted a potentially unfriendly value
// to a friendly one, get it from the ENUM!
return WorldType.valueOf(type);
} catch (IllegalArgumentException e) {
return null;
}
}
/**
* Converts a {@link String} into an {@link org.bukkit.World.Environment}.
*
* @param env The environment as {@link String}
* @return The environment as {@link org.bukkit.World.Environment}
*/
public static World.Environment getEnvFromString(String env) {
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
env = "NETHER";
if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS"))
env = "THE_END";
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
env = "NORMAL";
try {
// Now that we've converted a potentially unfriendly value
// to a friendly one, get it from the ENUM!
return World.Environment.valueOf(env);
} catch (IllegalArgumentException e) {
return null;
}
} }
} }

View File

@ -5,8 +5,6 @@
* with this project. * * with this project. *
******************************************************************************/ ******************************************************************************/
// TODO maybe remove this comment...?
// This file is no longer licensed under that silly CC license. I have blanked it out and will start implementaiton of my own in a few days. For now there is no help.
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;

View File

@ -13,6 +13,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.pneumaticraft.commandhandler.CommandHandler; import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -32,12 +33,13 @@ public class ImportCommand extends MultiverseCommand {
public ImportCommand(MultiverseCore plugin) { public ImportCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.setName("Import World"); this.setName("Import World");
this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]"); this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n] -t [TYPE]");
this.setArgRange(1, 3); this.setArgRange(2, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
this.addKey("mvimport"); this.addKey("mvimport");
this.addKey("mvim"); this.addKey("mvim");
this.addKey("mv import"); this.addKey("mv import");
this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal"); this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal");
this.addCommandExample("/mv import " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat");
this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether"); this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether");
this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator"); this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator");
this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP); this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP);
@ -126,6 +128,7 @@ public class ImportCommand extends MultiverseCommand {
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
String generator = CommandHandler.getFlag("-g", args); String generator = CommandHandler.getFlag("-g", args);
String typeString = CommandHandler.getFlag("-t", args);
boolean useSpawnAdjust = true; boolean useSpawnAdjust = true;
for (String s : args) { for (String s : args) {
if (s.equalsIgnoreCase("-n")) { if (s.equalsIgnoreCase("-n")) {
@ -134,16 +137,27 @@ public class ImportCommand extends MultiverseCommand {
} }
String env = args.get(1); String env = args.get(1);
Environment environment = this.plugin.getEnvFromString(env); Environment environment = EnvironmentCommand.getEnvFromString(env);
if (environment == null) { if (environment == null) {
sender.sendMessage(ChatColor.RED + "That is not a valid environment."); sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
EnvironmentCommand.showEnvironments(sender); EnvironmentCommand.showEnvironments(sender);
return; return;
} }
// If they didn't specify a type, default to NORMAL
if (typeString == null) {
typeString = "NORMAL";
}
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
if (type == null) {
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
EnvironmentCommand.showWorldTypes(sender);
return;
}
if (worldFile.exists() && env != null) { if (worldFile.exists() && env != null) {
Command.broadcastCommandMessage(sender, "Starting import of world '" + worldName + "'..."); Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
if (this.worldManager.addWorld(worldName, environment, null, generator, useSpawnAdjust)) if (this.worldManager.addWorld(worldName, environment, null, type, generator, useSpawnAdjust))
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!"); Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
else else
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!"); Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");

View File

@ -110,6 +110,7 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyMessage("World Name: ", world.getName(), colors)); message.add(new FancyMessage("World Name: ", world.getName(), colors));
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors)); message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors));
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors)); //message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
Location spawn = world.getSpawnLocation(); Location spawn = world.getSpawnLocation();
message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors)); message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors));

View File

@ -18,9 +18,10 @@ import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid; import org.bukkit.entity.Squid;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
@ -29,9 +30,9 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
* Multiverse's {@link EntityListener}. * Multiverse's Entity {@link Listener}.
*/ */
public class MVEntityListener extends EntityListener { public class MVEntityListener implements Listener {
private MultiverseCore plugin; private MultiverseCore plugin;
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -41,8 +42,12 @@ public class MVEntityListener extends EntityListener {
this.worldManager = plugin.getMVWorldManager(); this.worldManager = plugin.getMVWorldManager();
} }
@Override /**
public void onFoodLevelChange(FoodLevelChangeEvent event) { * This method is called when an entity's food level goes higher or lower.
* @param event The Event that was fired.
*/
@EventHandler
public void foodLevelChange(FoodLevelChangeEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -58,9 +63,12 @@ public class MVEntityListener extends EntityListener {
} }
} }
/**
@Override * This method is called when an entity's health goes up or down.
public void onEntityRegainHealth(EntityRegainHealthEvent event) { * @param event The Event that was fired.
*/
@EventHandler
public void entityRegainHealth(EntityRegainHealthEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -75,8 +83,8 @@ public class MVEntityListener extends EntityListener {
* Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit. * Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit.
* @param event The event. * @param event The event.
*/ */
@Override @EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) { public void creatureSpawn(CreatureSpawnEvent event) {
// Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour. // Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour.
if (event.getSpawnReason() == SpawnReason.CUSTOM) { if (event.getSpawnReason() == SpawnReason.CUSTOM) {
@ -124,7 +132,7 @@ public class MVEntityListener extends EntityListener {
} else if (creatureList.isEmpty()) { } else if (creatureList.isEmpty()) {
// 2. There are no exceptions and animals are NOT allowed. Kill it. // 2. There are no exceptions and animals are NOT allowed. Kill it.
return true; return true;
} else if (creatureList.contains(creature) && allowCreatureSpawning) { } else if (creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) {
// 3. There ARE exceptions and animals ARE allowed. Kill it. // 3. There ARE exceptions and animals ARE allowed. Kill it.
return true; return true;
} else if (!creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) { } else if (!creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) {
@ -136,9 +144,10 @@ public class MVEntityListener extends EntityListener {
} else if (!creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) { } else if (!creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) {
// 6. Animals are NOT allowed to spawn, and this creature is not in the save list... KILL IT // 6. Animals are NOT allowed to spawn, and this creature is not in the save list... KILL IT
return true; return true;
} } else {
// This code should NEVER execute. I just left the verbose conditions in right now. // This code should NEVER execute. I just left the verbose conditions in right now.
return false; throw new UnsupportedOperationException();
}
} }
} }

View File

@ -12,14 +12,18 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.PermissionTools; import com.onarandombox.MultiverseCore.utils.PermissionTools;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
@ -28,9 +32,9 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
* Multiverse's {@link PlayerListener}. * Multiverse's {@link Listener} for players.
*/ */
public class MVPlayerListener extends PlayerListener { public class MVPlayerListener implements Listener {
private MultiverseCore plugin; private MultiverseCore plugin;
private MVWorldManager worldManager; private MVWorldManager worldManager;
private PermissionTools pt; private PermissionTools pt;
@ -41,9 +45,12 @@ public class MVPlayerListener extends PlayerListener {
worldManager = plugin.getMVWorldManager(); worldManager = plugin.getMVWorldManager();
pt = new PermissionTools(plugin); pt = new PermissionTools(plugin);
} }
/**
@Override * This method is called when a player wants to chat.
public void onPlayerChat(PlayerChatEvent event) { * @param event The Event that was fired.
*/
@EventHandler
public void playerChat(PlayerChatEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -66,8 +73,12 @@ public class MVPlayerListener extends PlayerListener {
} }
} }
@Override /**
public void onPlayerRespawn(PlayerRespawnEvent event) { * This method is called when a player respawns.
* @param event The Event that was fired.
*/
@EventHandler(priority = EventPriority.LOW)
public void playerRespawn(PlayerRespawnEvent event) {
World world = event.getPlayer().getWorld(); World world = event.getPlayer().getWorld();
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
// If it's not a World MV manages we stop. // If it's not a World MV manages we stop.
@ -108,8 +119,12 @@ public class MVPlayerListener extends PlayerListener {
return w.getSpawnLocation(); return w.getSpawnLocation();
} }
@Override /**
public void onPlayerJoin(PlayerJoinEvent event) { * This method is called when a player joins the server.
* @param event The Event that was fired.
*/
@EventHandler
public void playerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();
if (!p.hasPlayedBefore()) { if (!p.hasPlayedBefore()) {
this.plugin.log(Level.FINE, "Player joined first!"); this.plugin.log(Level.FINE, "Player joined first!");
@ -125,19 +140,31 @@ public class MVPlayerListener extends PlayerListener {
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
} }
@Override /**
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { * This method is called when a player changes worlds.
* @param event The Event that was fired.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void playerChangedWorld(PlayerChangedWorldEvent event) {
// Permissions now determine whether or not to handle a gamemode. // Permissions now determine whether or not to handle a gamemode.
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
} }
@Override /**
public void onPlayerQuit(PlayerQuitEvent event) { * This method is called when a player quits the game.
* @param event The Event that was fired.
*/
@EventHandler
public void playerQuit(PlayerQuitEvent event) {
this.plugin.removePlayerSession(event.getPlayer()); this.plugin.removePlayerSession(event.getPlayer());
} }
@Override /**
public void onPlayerTeleport(PlayerTeleportEvent event) { * This method is called when a player teleports anywhere.
* @param event The Event that was fired.
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void playerTeleport(PlayerTeleportEvent event) {
this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'"); this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
if (event.isCancelled()) { if (event.isCancelled()) {
@ -183,8 +210,39 @@ public class MVPlayerListener extends PlayerListener {
} }
} }
@Override /**
public void onPlayerPortal(PlayerPortalEvent event) { * This method is called to adjust the portal location to the actual portal location (and not
* right outside of it.
* @param event The Event that was fired.
*/
@EventHandler(priority = EventPriority.LOWEST)
public void playerPortalCheck(PlayerPortalEvent event) {
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
if (event.isCancelled() || event.getFrom() == null) {
return;
}
// REMEMBER! getTo MAY be NULL HERE!!!
// If the player was actually outside of the portal, adjust the from location
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
// TODO: we want to do here.
if (newloc != null) {
event.setFrom(newloc);
}
}
// Wait for the adjust, then return!
if (event.getTo() == null) {
return;
}
}
/**
* This method is called when a player actually portals via a vanilla style portal.
* @param event The Event that was fired.
*/
@EventHandler(priority = EventPriority.HIGH)
public void playerPortal(PlayerPortalEvent event) {
if (event.isCancelled() || (event.getFrom() == null)) { if (event.isCancelled() || (event.getFrom() == null)) {
return; return;
} }

View File

@ -9,17 +9,19 @@ package com.onarandombox.MultiverseCore.listeners;
import com.fernferret.allpay.AllPay; import com.fernferret.allpay.AllPay;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
* Multiverse's {@link ServerListener}. * Multiverse's Plugin {@link Listener}.
*/ */
public class MVPluginListener extends ServerListener { public class MVPluginListener implements Listener {
private MultiverseCore plugin; private MultiverseCore plugin;
@ -31,8 +33,8 @@ public class MVPluginListener extends ServerListener {
* Keep an eye out for Plugins which we can utilize. * Keep an eye out for Plugins which we can utilize.
* @param event The event. * @param event The event.
*/ */
@Override @EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) { public void pluginEnable(PluginEnableEvent event) {
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support // Let AllPay handle all econ plugin loadings, only go for econ plugins we support
if (Arrays.asList(AllPay.validEconPlugins).contains(event.getPlugin().getDescription().getName())) { if (Arrays.asList(AllPay.validEconPlugins).contains(event.getPlugin().getDescription().getName())) {
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin()); this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
@ -48,8 +50,8 @@ public class MVPluginListener extends ServerListener {
* We'll check if any of the plugins we rely on decide to Disable themselves. * We'll check if any of the plugins we rely on decide to Disable themselves.
* @param event The event. * @param event The event.
*/ */
@Override @EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) { public void pluginDisable(PluginDisableEvent event) {
// TODO: Disable econ when it disables. // TODO: Disable econ when it disables.
} }

View File

@ -1,55 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
* 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.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.SafeTTeleporter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerPortalEvent;
import java.util.logging.Level;
/**
* Multiverse's second {@link PlayerListener}.
* <p>
* Used to double-monitor {@link Type#PLAYER_PORTAL}.
*/
public class MVPortalAdjustListener extends PlayerListener {
private MultiverseCore plugin;
public MVPortalAdjustListener(MultiverseCore core) {
this.plugin = core;
}
@Override
public void onPlayerPortal(PlayerPortalEvent event) {
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
if (event.isCancelled() || event.getFrom() == null) {
return;
}
// REMEMBER! getTo MAY be NULL HERE!!!
// If the player was actually outside of the portal, adjust the from location
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
Location newloc = SafeTTeleporter.findPortalBlockNextTo(event.getFrom());
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
// TODO: we want to do here.
if (newloc != null) {
event.setFrom(newloc);
}
}
// Wait for the adjust, then return!
if (event.getTo() == null) {
return;
}
}
}

View File

@ -9,22 +9,30 @@ package com.onarandombox.MultiverseCore.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.WeatherListener;
/** /**
* Multiverse's {@link WeatherListener}. * Multiverse's Weather {@link Listener}.
*/ */
public class MVWeatherListener extends WeatherListener { public class MVWeatherListener implements Listener {
private MultiverseCore plugin; private MultiverseCore plugin;
public MVWeatherListener(MultiverseCore plugin) { public MVWeatherListener(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@Override /**
public void onWeatherChange(WeatherChangeEvent event) { * This method is called when the weather changes.
* @param event The Event that was fired.
*/
@EventHandler
public void weatherChange(WeatherChangeEvent event) {
if (event.isCancelled()) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) { if (world != null) {
// If it's going to start raining and we have weather disabled // If it's going to start raining and we have weather disabled
@ -32,8 +40,15 @@ public class MVWeatherListener extends WeatherListener {
} }
} }
@Override /**
public void onThunderChange(ThunderChangeEvent event) { * This method is called when a big storm is going to start.
* @param event The Event that was fired.
*/
@EventHandler
public void thunderChange(ThunderChangeEvent event) {
if (event.isCancelled()) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName()); MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) { if (world != null) {
// If it's going to start raining and we have weather disabled // If it's going to start raining and we have weather disabled

View File

@ -7,9 +7,6 @@
package com.onarandombox.MultiverseCore.listeners; package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent; import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
@ -17,80 +14,66 @@ import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent; import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent; import com.onarandombox.MultiverseCore.event.MVWorldPropertyChangeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/** /**
* Subclasses of this listener can be used to conveniently listen to MultiverseCore-events. * Subclasses of this listener can be used to conveniently listen to MultiverseCore-events.
*/ */
public abstract class MultiverseCoreListener extends CustomEventListener { public abstract class MultiverseCoreListener implements Listener {
/**
* {@inheritDoc}
*/
@Override
public final void onCustomEvent(Event event) {
if (event.getEventName().equals("MVConfigReload") && event instanceof MVConfigReloadEvent) {
onMVConfigReload((MVConfigReloadEvent) event);
} else if (event.getEventName().equals("MVPlayerTouchedPortalEvent") && event instanceof MVPlayerTouchedPortalEvent) {
onPlayerTouchedPortal((MVPlayerTouchedPortalEvent) event);
} else if (event.getEventName().equals("MVRespawn") && event instanceof MVRespawnEvent) {
onPlayerRespawn((MVRespawnEvent) event);
} else if (event.getEventName().equals("SafeTTeleporter") && event instanceof MVTeleportEvent) {
onPlayerTeleport((MVTeleportEvent) event);
} else if (event.getEventName().equals("MVVersionEvent") && event instanceof MVVersionEvent) {
onVersionRequest((MVVersionEvent) event);
} else if (event.getEventName().equals("MVWorldDeleteEvent") && event instanceof MVWorldDeleteEvent) {
onWorldDelete((MVWorldDeleteEvent) event);
} else if (event.getEventName().equals("MVWorldPropertyChange") && event instanceof MVWorldPropertyChangeEvent) {
onWorldPropertyChange((MVWorldPropertyChangeEvent) event);
}
}
/** /**
* Called when a {@link MVWorldPropertyChangeEvent} is fired. * Called when a {@link MVWorldPropertyChangeEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onWorldPropertyChange(MVWorldPropertyChangeEvent event) { @EventHandler
public void worldPropertyChange(MVWorldPropertyChangeEvent event) {
} }
/** /**
* Called when a {@link MVWorldDeleteEvent} is fired. * Called when a {@link MVWorldDeleteEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onWorldDelete(MVWorldDeleteEvent event) { @EventHandler
public void worldDelete(MVWorldDeleteEvent event) {
} }
/** /**
* Called when a {@link MVVersionEvent} is fired. * Called when a {@link MVVersionEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onVersionRequest(MVVersionEvent event) { @EventHandler
public void versionRequest(MVVersionEvent event) {
} }
/** /**
* Called when a {@link MVTeleportEvent} is fired. * Called when a {@link MVTeleportEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onPlayerTeleport(MVTeleportEvent event) { @EventHandler
public void playerTeleport(MVTeleportEvent event) {
} }
/** /**
* Called when a {@link MVRespawnEvent} is fired. * Called when a {@link MVRespawnEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onPlayerRespawn(MVRespawnEvent event) { @EventHandler
public void playerRespawn(MVRespawnEvent event) {
} }
/** /**
* Called when a {@link MVPlayerTouchedPortalEvent} is fired. * Called when a {@link MVPlayerTouchedPortalEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onPlayerTouchedPortal(MVPlayerTouchedPortalEvent event) { @EventHandler
public void playerTouchedPortal(MVPlayerTouchedPortalEvent event) {
} }
/** /**
* Called when a {@link MVConfigReloadEvent} is fired. * Called when a {@link MVConfigReloadEvent} is fired.
* @param event The event. * @param event The event.
*/ */
public void onMVConfigReload(MVConfigReloadEvent event) { @EventHandler
public void configReload(MVConfigReloadEvent event) {
} }
} }

View File

@ -17,6 +17,7 @@ import org.bukkit.util.Vector;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
/** /**
@ -57,7 +58,10 @@ public class LocationManipulation {
if (location == null) { if (location == null) {
return ""; return "";
} }
return String.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), // We set the locale to ENGLISH here so we always save with the format:
// world:1.2,5.4,3.6:1.8:21.3
// Otherwise we blow up when parsing!
return String.format(Locale.ENGLISH, "%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} }

View File

@ -148,7 +148,7 @@ public class PermissionTools {
if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) { if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) {
return false; return false;
} else if (pay) { } else if (pay) {
bank.pay(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); bank.give(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
} }
} }
return true; return true;

View File

@ -11,10 +11,12 @@ import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent; import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -80,16 +82,16 @@ public class WorldManager implements MVWorldManager {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean addWorld(String name, Environment env, String seedString, String generator) { public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator) {
return this.addWorld(name, env, seedString, generator, true); return this.addWorld(name, env, seedString, type, generator, true);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean addWorld(String name, Environment env, String seedString, String generator, boolean useSpawnAdjust) { public boolean addWorld(String name, Environment env, String seedString, WorldType type, String generator, boolean useSpawnAdjust) {
plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + generator); plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + type.toString() + ", " + generator);
Long seed = null; Long seed = null;
WorldCreator c = new WorldCreator(name); WorldCreator c = new WorldCreator(name);
if (seedString != null && seedString.length() > 0) { if (seedString != null && seedString.length() > 0) {
@ -101,27 +103,26 @@ public class WorldManager implements MVWorldManager {
c.seed(seed); c.seed(seed);
} }
// TODO: Use the fancy kind with the commandSender // TODO: Use the fancy kind with the commandSender
if (generator != null && generator.length() != 0) { if (generator != null && generator.length() != 0) {
c.generator(generator); c.generator(generator);
} }
c.environment(env); c.environment(env);
c.type(type);
World world = null; World world;
StringBuilder builder = new StringBuilder();
builder.append("Loading World & Settings - '").append(name).append("'");
builder.append(" - Env: ").append(env);
builder.append(" - Type: ").append(type);
if (seed != null) { if (seed != null) {
builder.append(" & seed: ").append(seed);
}
if (generator != null) { if (generator != null) {
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator); builder.append(" & generator: ").append(generator);
} else {
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed);
}
} else {
if (generator != null) {
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator);
} else {
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
}
} }
this.plugin.log(Level.INFO, builder.toString());
try { try {
world = c.createWorld(); world = c.createWorld();
} catch (Exception e) { } catch (Exception e) {
@ -275,10 +276,12 @@ public class WorldManager implements MVWorldManager {
if ((worldKeys != null) && (worldKeys.contains(name))) { if ((worldKeys != null) && (worldKeys.contains(name))) {
// Grab the initial values from the config file. // Grab the initial values from the config file.
String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String. String environment = this.configWorlds.getString("worlds." + name + ".environment", "NORMAL"); // Grab the Environment as a String.
String type = this.configWorlds.getString("worlds." + name + ".type", "NORMAL");
String seedString = this.configWorlds.getString("worlds." + name + ".seed", ""); String seedString = this.configWorlds.getString("worlds." + name + ".seed", "");
String generatorString = this.configWorlds.getString("worlds." + name + ".generator"); String generatorString = this.configWorlds.getString("worlds." + name + ".generator");
addWorld(name, this.plugin.getEnvFromString(environment), seedString, generatorString); addWorld(name, EnvironmentCommand.getEnvFromString(environment), seedString,
EnvironmentCommand.getWorldTypeFromString(type), generatorString);
if (this.unloadedWorlds.contains(name)) { if (this.unloadedWorlds.contains(name)) {
this.unloadedWorlds.remove(name); this.unloadedWorlds.remove(name);
} }
@ -464,9 +467,9 @@ public class WorldManager implements MVWorldManager {
String name = w.getName(); String name = w.getName();
if (!worldStrings.contains(name)) { if (!worldStrings.contains(name)) {
if (this.defaultGens.containsKey(name)) { if (this.defaultGens.containsKey(name)) {
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", this.defaultGens.get(name)); this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), this.defaultGens.get(name));
} else { } else {
this.addWorld(name, w.getEnvironment(), w.getSeed() + "", null); this.addWorld(name, w.getEnvironment(), w.getSeed() + "", w.getWorldType(), null);
} }
} }
@ -537,7 +540,8 @@ public class WorldManager implements MVWorldManager {
continue; continue;
} }
// Grab the initial values from the config file. // Grab the initial values from the config file.
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String. String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL");
String type = this.configWorlds.getString("worlds." + worldKey + ".type", "NORMAL");
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null); String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", null);
if (seedString == null) { if (seedString == null) {
seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + ""; seedString = this.configWorlds.getLong("worlds." + worldKey + ".seed") + "";
@ -548,7 +552,9 @@ public class WorldManager implements MVWorldManager {
this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :("); this.plugin.log(Level.WARNING, "Found SKYLANDS world. Not importing automatically, as it won't work atm :(");
continue; continue;
} }
addWorld(worldKey, this.plugin.getEnvFromString(environment), seedString, generatorString); // TODO: UNCOMMENT BEFORE RELEASE
addWorld(worldKey, EnvironmentCommand.getEnvFromString(environment), seedString,
EnvironmentCommand.getWorldTypeFromString(type), generatorString);
// Increment the world count // Increment the world count
count++; count++;

View File

@ -12,6 +12,9 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.*; import org.bukkit.block.*;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
/** /**
* Multiverse 2 * Multiverse 2
@ -27,35 +30,31 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the metadata for this block * {@inheritDoc}
*
* @return block specific metadata
*/ */
@Override @Override
public byte getData() { public byte getData() {
return 0; return 0;
} }
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face)} */ /**
* {@inheritDoc}
*/
@Override @Override
public Block getFace(BlockFace face) { public Block getFace(BlockFace face) {
return null; return null;
} }
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face, int distance)} */ /**
* {@inheritDoc}
*/
@Override @Override
public Block getFace(BlockFace face, int distance) { public Block getFace(BlockFace face, int distance) {
return null; return null;
} }
/** /**
* Gets the block at the given offsets * {@inheritDoc}
*
* @param modX X-coordinate offset
* @param modY Y-coordinate offset
* @param modZ Z-coordinate offset
*
* @return Block at the given offsets
*/ */
@Override @Override
public Block getRelative(int modX, int modY, int modZ) { public Block getRelative(int modX, int modY, int modZ) {
@ -63,15 +62,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the block at the given face<br /> * {@inheritDoc}
* <br />
* This method is equal to getRelative(face, 1)
*
* @param face Face of this block to return
*
* @return Block at the given face
*
* @see #getRelative(org.bukkit.block.BlockFace, int)
*/ */
@Override @Override
public Block getRelative(BlockFace face) { public Block getRelative(BlockFace face) {
@ -79,20 +70,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the block at the given distance of the given face<br /> * {@inheritDoc}
* <br />
* For example, the following method places water at 100,102,100; two blocks
* above 100,100,100.
* <pre>
* Block block = world.getBlockAt(100,100,100);
* Block shower = block.getFace(BlockFace.UP, 2);
* shower.setType(Material.WATER);
* </pre>
*
* @param face Face of this block to return
* @param distance Distance to get the block at
*
* @return Block at the given face
*/ */
@Override @Override
public Block getRelative(BlockFace face, int distance) { public Block getRelative(BlockFace face, int distance) {
@ -100,9 +78,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the type of this block * {@inheritDoc}
*
* @return block type
*/ */
@Override @Override
public Material getType() { public Material getType() {
@ -110,29 +86,33 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the type-id of this block * {@inheritDoc}
*
* @return block type-id
*/ */
@Override @Override
public int getTypeId() { public int getTypeId() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
/** /**
* Gets the light level between 0-15 * {@inheritDoc}
*
* @return light level
*/ */
@Override @Override
public byte getLightLevel() { public byte getLightLevel() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
}
@Override
public byte getLightFromSky() {
return 0;
}
@Override
public byte getLightFromBlocks() {
return 0;
} }
/** /**
* Gets the world which contains this Block * {@inheritDoc}
*
* @return World containing this block
*/ */
@Override @Override
public World getWorld() { public World getWorld() {
@ -140,9 +120,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the x-coordinate of this block * {@inheritDoc}
*
* @return x-coordinate
*/ */
@Override @Override
public int getX() { public int getX() {
@ -150,9 +128,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the y-coordinate of this block * {@inheritDoc}
*
* @return y-coordinate
*/ */
@Override @Override
public int getY() { public int getY() {
@ -160,9 +136,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the z-coordinate of this block * {@inheritDoc}
*
* @return z-coordinate
*/ */
@Override @Override
public int getZ() { public int getZ() {
@ -170,9 +144,7 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the Location of the block * {@inheritDoc}
*
* @return Location of block
*/ */
@Override @Override
public Location getLocation() { public Location getLocation() {
@ -180,34 +152,26 @@ public class MockBlock implements Block{
} }
/** /**
* Gets the chunk which contains this block * {@inheritDoc}
*
* @return Containing Chunk
*/ */
@Override @Override
public Chunk getChunk() { public Chunk getChunk() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
} }
/** /**
* Sets the metadata for this block * {@inheritDoc}
*
* @param data New block specific metadata
*/ */
@Override @Override
public void setData(byte data) { public void setData(byte data) {
//To change body of implemented methods use File | Settings | File Templates.
} }
@Override @Override
public void setData(byte data, boolean applyPhyiscs) { public void setData(byte data, boolean applyPhyiscs) {
//To change body of implemented methods use File | Settings | File Templates.
} }
/** /**
* Sets the type of this block * {@inheritDoc}
*
* @param type Material to change this block to
*/ */
@Override @Override
public void setType(Material type) { public void setType(Material type) {
@ -215,145 +179,97 @@ public class MockBlock implements Block{
} }
/** /**
* Sets the type-id of this block * {@inheritDoc}
*
* @param type Type-Id to change this block to
*
* @return whether the block was changed
*/ */
@Override @Override
public boolean setTypeId(int type) { public boolean setTypeId(int type) {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
@Override @Override
public boolean setTypeId(int type, boolean applyPhysics) { public boolean setTypeId(int type, boolean applyPhysics) {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
@Override @Override
public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) { public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Gets the face relation of this block compared to the given block<br /> * {@inheritDoc}
* <br />
* For example:
* <pre>
* Block current = world.getBlockAt(100, 100, 100);
* Block target = world.getBlockAt(100, 101, 100);
*
* current.getFace(target) == BlockFace.Up;
* </pre>
* <br />
* If the given block is not connected to this block, null may be returned
*
* @param block Block to compare against this block
*
* @return BlockFace of this block which has the requested block, or null
*/ */
@Override @Override
public BlockFace getFace(Block block) { public BlockFace getFace(Block block) {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
} }
/** /**
* Captures the current state of this block. You may then cast that state * {@inheritDoc}
* into any accepted type, such as Furnace or Sign.
* <p>
* The returned object will never be updated, and you are not guaranteed that
* (for example) a sign is still a sign after you capture its state.
*
* @return BlockState with the current state of this block.
*/ */
@Override @Override
public BlockState getState() { public BlockState getState() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
} }
/** /**
* Returns the biome that this block resides in * {@inheritDoc}
*
* @return Biome type containing this block
*/ */
@Override @Override
public Biome getBiome() { public Biome getBiome() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
} }
/** /**
* Returns true if the block is being powered by Redstone. * {@inheritDoc}
*
* @return True if the block is powered.
*/ */
@Override @Override
public boolean isBlockPowered() { public boolean isBlockPowered() {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Returns true if the block is being indirectly powered by Redstone. * {@inheritDoc}
*
* @return True if the block is indirectly powered.
*/ */
@Override @Override
public boolean isBlockIndirectlyPowered() { public boolean isBlockIndirectlyPowered() {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Returns true if the block face is being powered by Redstone. * {@inheritDoc}
*
* @param face The block face
*
* @return True if the block face is powered.
*/ */
@Override @Override
public boolean isBlockFacePowered(BlockFace face) { public boolean isBlockFacePowered(BlockFace face) {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Returns true if the block face is being indirectly powered by Redstone. * {@inheritDoc}
*
* @param face The block face
*
* @return True if the block face is indirectly powered.
*/ */
@Override @Override
public boolean isBlockFaceIndirectlyPowered(BlockFace face) { public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Returns the redstone power being provided to this block face * {@inheritDoc}
*
* @param face the face of the block to query or BlockFace.SELF for the block itself
*
* @return The power level.
*/ */
@Override @Override
public int getBlockPower(BlockFace face) { public int getBlockPower(BlockFace face) {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
/** /**
* Returns the redstone power being provided to this block * {@inheritDoc}
*
* @return The power level.
*/ */
@Override @Override
public int getBlockPower() { public int getBlockPower() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
/** /**
* Checks if this block is empty. * {@inheritDoc}
* <p>
* A block is considered empty when {@link #getType()} returns {@link org.bukkit.Material#AIR}.
*
* @return true if this block is empty
*/ */
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
@ -361,46 +277,54 @@ public class MockBlock implements Block{
} }
/** /**
* Checks if this block is liquid. * {@inheritDoc}
* <p>
* A block is considered liquid when {@link #getType()} returns {@link org.bukkit.Material#WATER}, {@link
* org.bukkit.Material#STATIONARY_WATER}, {@link org.bukkit.Material#LAVA} or {@link
* org.bukkit.Material#STATIONARY_LAVA}.
*
* @return true if this block is liquid
*/ */
@Override @Override
public boolean isLiquid() { public boolean isLiquid() {
return false; //To change body of implemented methods use File | Settings | File Templates. return false;
} }
/** /**
* Gets the temperature of the biome of this block * {@inheritDoc}
*
* @return Temperature of this block
*/ */
@Override @Override
public double getTemperature() { public double getTemperature() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
/** /**
* Gets the humidity of the biome of this block * {@inheritDoc}
*
* @return Humidity of this block
*/ */
@Override @Override
public double getHumidity() { public double getHumidity() {
return 0; //To change body of implemented methods use File | Settings | File Templates. return 0;
} }
/** /**
* Returns the reaction of the block when moved by a piston * {@inheritDoc}
*
* @return reaction
*/ */
@Override @Override
public PistonMoveReaction getPistonMoveReaction() { public PistonMoveReaction getPistonMoveReaction() {
return null; //To change body of implemented methods use File | Settings | File Templates. return null;
}
@Override
public boolean breakNaturally() {
return false;
}
@Override
public boolean breakNaturally(ItemStack itemStack) {
return false;
}
@Override
public Collection<ItemStack> getDrops() {
return null;
}
@Override
public Collection<ItemStack> getDrops(ItemStack itemStack) {
return null;
} }
} }

View File

@ -7,8 +7,7 @@
package com.onarandombox.MultiverseCore.test.utils; package com.onarandombox.MultiverseCore.test.utils;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,9 +18,9 @@ import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.mockito.ArgumentMatcher;
import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -32,59 +31,15 @@ public class MockWorldFactory {
private MockWorldFactory() { private MockWorldFactory() {
} }
private static class LocationMatcher extends ArgumentMatcher<Location> {
private Location l;
public LocationMatcher(Location location) {
this.l = location;
}
public boolean matches(Object creator) {
return creator.equals(l);
}
}
private static class LocationMatcherAbove extends LocationMatcher {
public LocationMatcherAbove(Location location) {
super(location);
}
public boolean matches(Object creator) {
Util.log("Checking above...");
if (super.l == null || creator == null) {
return false;
}
boolean equal = ((Location) creator).getBlockY() >= super.l.getBlockY();
Util.log("Checking equals/\\..." + equal);
return equal;
}
}
private static class LocationMatcherBelow extends LocationMatcher {
public LocationMatcherBelow(Location location) {
super(location);
}
public boolean matches(Object creator) {
if (super.l == null || creator == null) {
return false;
}
boolean equal = ((Location) creator).getBlockY() < super.l.getBlockY();
Util.log("Checking equals\\/..." + equal);
return equal;
}
}
private static void registerWorld(World world) { private static void registerWorld(World world) {
createdWorlds.put(world.getName(), world); createdWorlds.put(world.getName(), world);
} }
private static World basics(String world, World.Environment env) { private static World basics(String world, World.Environment env, WorldType type) {
World mockWorld = mock(World.class); World mockWorld = mock(World.class);
when(mockWorld.getName()).thenReturn(world); when(mockWorld.getName()).thenReturn(world);
when(mockWorld.getEnvironment()).thenReturn(env); when(mockWorld.getEnvironment()).thenReturn(env);
when(mockWorld.getWorldType()).thenReturn(type);
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0)); when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() { when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
public File answer(InvocationOnMock invocation) throws Throwable { public File answer(InvocationOnMock invocation) throws Throwable {
@ -93,23 +48,43 @@ public class MockWorldFactory {
World thiss = (World) invocation.getMock(); World thiss = (World) invocation.getMock();
return new File(TestInstanceCreator.serverDirectory, thiss.getName()); return new File(TestInstanceCreator.serverDirectory, thiss.getName());
}}); }
LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(mockWorld, 0, 0, 0)); });
LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(mockWorld, 0, 0, 0)); when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.AIR)); public Block answer(InvocationOnMock invocation) throws Throwable {
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldBelow))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.STONE)); Location loc;
try {
loc = (Location) invocation.getArguments()[0];
} catch (Exception e) {
return null;
}
Block mockBlock = mock(Block.class);
Material blockType = Material.AIR; // TODO we might use other materials, too
when(mockBlock.getType()).thenReturn(blockType);
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
when(mockBlock.getX()).thenReturn(loc.getBlockX());
when(mockBlock.getY()).thenReturn(loc.getBlockY());
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
when(mockBlock.getLocation()).thenReturn(loc);
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
return mockBlock;
}
});
return mockWorld; return mockWorld;
} }
public static World makeNewMockWorld(String world, World.Environment env) { public static World makeNewMockWorld(String world, World.Environment env, WorldType type) {
World w = basics(world, env); World w = basics(world, env, type);
registerWorld(w); registerWorld(w);
return w; return w;
} }
public static World makeNewMockWorld(String world, World.Environment env, long seed, public static World makeNewMockWorld(String world, World.Environment env, WorldType type, long seed,
ChunkGenerator generator) { ChunkGenerator generator) {
World mockWorld = basics(world, env); World mockWorld = basics(world, env, type);
when(mockWorld.getGenerator()).thenReturn(generator); when(mockWorld.getGenerator()).thenReturn(generator);
when(mockWorld.getSeed()).thenReturn(seed); when(mockWorld.getSeed()).thenReturn(seed);
registerWorld(mockWorld); registerWorld(mockWorld);

View File

@ -127,7 +127,7 @@ public class TestInstanceCreator {
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment()); return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type());
} }
}); });