mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Merge branch 'master' of github.com:Multiverse/Multiverse-Core into util-refactoring
This commit is contained in:
commit
9a28158e5f
@ -1 +1 @@
|
|||||||
Subproject commit 18c55a9070a5e64b2cb0737940290643f324fa7d
|
Subproject commit 7abba1f0040862e9fabdafb3d44c6cf0b914cc7c
|
17
pom.xml
17
pom.xml
@ -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>
|
||||||
@ -16,6 +16,10 @@
|
|||||||
<id>onarandombox</id>
|
<id>onarandombox</id>
|
||||||
<url>http://repo.onarandombox.com/content/groups/public</url>
|
<url>http://repo.onarandombox.com/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>Bukkit Offical</id>
|
||||||
|
<url>http://repo.bukkit.org/content/repositories/public</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
@ -77,7 +81,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 +166,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</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -229,6 +233,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>
|
||||||
|
@ -22,6 +22,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;
|
||||||
@ -67,6 +68,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>();
|
||||||
@ -89,6 +91,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();
|
||||||
@ -106,6 +109,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<?>>();
|
||||||
@ -203,6 +208,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,7 +249,16 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
*/
|
*/
|
||||||
public boolean setActualKeepSpawnInMemory() {
|
public boolean setActualKeepSpawnInMemory() {
|
||||||
// Ensure the memory setting is correct
|
// Ensure the memory setting is correct
|
||||||
this.world.setKeepSpawnInMemory(this.getKnownProperty("memory", Boolean.class).getValue());
|
this.getCBWorld().setKeepSpawnInMemory(this.getKnownProperty("memory", Boolean.class).getValue());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the active difficulty-property to set the "actual" property.
|
||||||
|
* @return True if the property was successfully set.
|
||||||
|
*/
|
||||||
|
public boolean setActualDifficulty() {
|
||||||
|
this.getCBWorld().setDifficulty(this.getKnownProperty("difficulty", Difficulty.class).getValue());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +415,12 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncMobs() {
|
/**
|
||||||
|
* Ensure that the value of the animals and monsters config
|
||||||
|
* properties are set in accordance with the current animals
|
||||||
|
* and monsters in the world, respectively.
|
||||||
|
*/
|
||||||
|
public void syncMobs() {
|
||||||
|
|
||||||
if (this.getAnimalList().isEmpty()) {
|
if (this.getAnimalList().isEmpty()) {
|
||||||
this.world.setSpawnFlags(this.world.getAllowMonsters(), this.getKnownProperty("animals", Boolean.class).getValue());
|
this.world.setSpawnFlags(this.world.getAllowMonsters(), this.getKnownProperty("animals", Boolean.class).getValue());
|
||||||
@ -534,18 +562,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -595,6 +621,14 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPermissibleName() {
|
||||||
|
return this.name.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@ -977,7 +1011,7 @@ public class MVWorld implements MultiverseWorld {
|
|||||||
+ "' is Located at: " + plugin.getLocationManipulation().locationToString(configLocation));
|
+ "' is Located at: " + plugin.getLocationManipulation().locationToString(configLocation));
|
||||||
} else {
|
} else {
|
||||||
// If it's a standard end world, let's check in a better place:
|
// If it's a standard end world, let's check in a better place:
|
||||||
Location newerSpawn = null;
|
Location newerSpawn;
|
||||||
newerSpawn = bs.getTopBlock(new Location(w, 0, 0, 0));
|
newerSpawn = bs.getTopBlock(new Location(w, 0, 0, 0));
|
||||||
if (newerSpawn != null) {
|
if (newerSpawn != null) {
|
||||||
this.setSpawnLocation(newerSpawn);
|
this.setSpawnLocation(newerSpawn);
|
||||||
@ -1118,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.
|
||||||
|
@ -28,21 +28,17 @@ 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.*;
|
import com.onarandombox.MultiverseCore.utils.*;
|
||||||
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;
|
||||||
|
|
||||||
@ -61,7 +57,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.
|
||||||
@ -153,8 +149,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);
|
||||||
@ -168,7 +162,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 MultiverseMessaging messaging;
|
private MultiverseMessaging messaging;
|
||||||
private BlockSafety blockSafety;
|
private BlockSafety blockSafety;
|
||||||
@ -322,28 +316,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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -584,33 +560,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.
|
||||||
*
|
*
|
||||||
@ -720,15 +669,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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -757,6 +697,24 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
return this.playerListener;
|
return this.playerListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link MVEntityListener}.
|
||||||
|
*
|
||||||
|
* @return The {@link MVEntityListener}.
|
||||||
|
*/
|
||||||
|
public MVEntityListener getEntityListener() {
|
||||||
|
return this.entityListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link MVWeatherListener}.
|
||||||
|
*
|
||||||
|
* @return The {@link MVWeatherListener}.
|
||||||
|
*/
|
||||||
|
public MVWeatherListener getWeatherListener() {
|
||||||
|
return this.weatherListener;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the Multiverse-Config.
|
* Saves the Multiverse-Config.
|
||||||
*
|
*
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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.");
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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!");
|
||||||
|
@ -109,6 +109,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: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
||||||
|
@ -106,7 +106,7 @@ public class DifficultyConfigProperty implements MVActiveConfigProperty<Difficul
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getMethod() {
|
public String getMethod() {
|
||||||
return "setDifficulty";
|
return "setActualDifficulty";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
package com.onarandombox.MultiverseCore.event;
|
package com.onarandombox.MultiverseCore.event;
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,6 +24,24 @@ public class MVConfigReloadEvent extends Event {
|
|||||||
this.configsLoaded = configsLoaded;
|
this.configsLoaded = configsLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a config to this event.
|
* Adds a config to this event.
|
||||||
* @param config The config to add.
|
* @param config The config to add.
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is thrown when a portal is touched.
|
* This event is thrown when a portal is touched.
|
||||||
@ -26,6 +27,24 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
|
|||||||
this.l = l;
|
this.l = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Location} of the portal-block that was touched.
|
* Gets the {@link Location} of the portal-block that was touched.
|
||||||
* @return The {@link Location} of the portal-block that was touched.
|
* @return The {@link Location} of the portal-block that was touched.
|
||||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.event;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player is respawning.
|
* Called when a player is respawning.
|
||||||
@ -27,6 +28,24 @@ public class MVRespawnEvent extends Event {
|
|||||||
this.respawnMethod = respawnMethod;
|
this.respawnMethod = respawnMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Player} that's respawning.
|
* Gets the {@link Player} that's respawning.
|
||||||
* @return The {@link Player} that's respawning.
|
* @return The {@link Player} that's respawning.
|
||||||
|
@ -14,6 +14,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that gets called when a player use the /mvtp command.
|
* Event that gets called when a player use the /mvtp command.
|
||||||
@ -33,6 +34,24 @@ public class MVTeleportEvent extends Event implements Cancellable {
|
|||||||
this.useSafeTeleport = safeTeleport;
|
this.useSafeTeleport = safeTeleport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player who will be teleported by this event.
|
* Returns the player who will be teleported by this event.
|
||||||
*
|
*
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.onarandombox.MultiverseCore.event;
|
package com.onarandombox.MultiverseCore.event;
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when somebody requests version information about Multiverse.
|
* Called when somebody requests version information about Multiverse.
|
||||||
@ -14,6 +15,24 @@ public class MVVersionEvent extends Event {
|
|||||||
versionInfoBuilder = new StringBuilder(versionInfo);
|
versionInfoBuilder = new StringBuilder(versionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version-info currently saved in this event.
|
* Gets the version-info currently saved in this event.
|
||||||
* @return The version-info.
|
* @return The version-info.
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
|
||||||
* Multiverse 2 is licensed under the BSD License. *
|
|
||||||
* For more information please check the README.md file included *
|
|
||||||
* with this project. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
package com.onarandombox.MultiverseCore.event;
|
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when somebody requests version information about Multiverse.
|
|
||||||
* @deprecated Use {@link MVVersionEvent} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class MVVersionRequestEvent extends Event {
|
|
||||||
|
|
||||||
private String pasteBinBuffer;
|
|
||||||
|
|
||||||
public MVVersionRequestEvent(String pasteBinBuffer) {
|
|
||||||
super("MVVersion");
|
|
||||||
this.pasteBinBuffer = pasteBinBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the pasteBinBuffer.
|
|
||||||
* @return The pasteBinBuffer.
|
|
||||||
* @deprecated Use {@link MVVersionEvent} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public String getPasteBinBuffer() {
|
|
||||||
return this.pasteBinBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the pasteBinBuffer.
|
|
||||||
* @param buffer The new pasteBinBuffer.
|
|
||||||
* @deprecated Use {@link MVVersionEvent} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void setPasteBinBuffer(String buffer) {
|
|
||||||
this.pasteBinBuffer = buffer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,6 +4,7 @@ import org.bukkit.event.Cancellable;
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a world is about to be deleted by Multiverse.
|
* Called when a world is about to be deleted by Multiverse.
|
||||||
@ -24,6 +25,24 @@ public class MVWorldDeleteEvent extends Event implements Cancellable {
|
|||||||
this.removeFromConfig = removeFromConfig;
|
this.removeFromConfig = removeFromConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of HANDLERS.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is fired *before* the property is actually changed.
|
* This event is fired *before* the property is actually changed.
|
||||||
@ -27,7 +28,6 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
|||||||
private String value;
|
private String value;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, String value) {
|
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, String value) {
|
||||||
super("MVWorldPropertyChange");
|
super("MVWorldPropertyChange");
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@ -36,6 +36,24 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the handler list. This is required by the event system.
|
||||||
|
* @return A list of handlers.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the changed world property's name.
|
* Gets the changed world property's name.
|
||||||
* @return The changed world property's name.
|
* @return The changed world property's name.
|
||||||
|
@ -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.
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
// This code should NEVER execute. I just left the verbose conditions in right now.
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
||||||
|
@ -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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +61,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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class PermissionTools {
|
|||||||
|
|
||||||
// If the toWorld isn't controlled by MV,
|
// If the toWorld isn't controlled by MV,
|
||||||
// We don't care.
|
// We don't care.
|
||||||
if(toWorld == null) {
|
if (toWorld == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
|
@ -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) {
|
||||||
if (generator != null) {
|
builder.append(" & seed: ").append(seed);
|
||||||
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (generator != null) {
|
||||||
|
builder.append(" & generator: ").append(generator);
|
||||||
|
}
|
||||||
|
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++;
|
||||||
|
@ -0,0 +1,344 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* 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.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||||
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.internal.verification.VerificationModeFactory;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||||
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||||
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
|
||||||
|
WeatherChangeEvent.class, ThunderChangeEvent.class, PlayerChatEvent.class,
|
||||||
|
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
|
||||||
|
FoodLevelChangeEvent.class, WorldManager.class })
|
||||||
|
public class TestWorldProperties {
|
||||||
|
|
||||||
|
private TestInstanceCreator creator;
|
||||||
|
private MultiverseCore core;
|
||||||
|
private CommandSender mockCommandSender;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
private WeatherChangeEvent weatherChangeOffEvent;
|
||||||
|
private WeatherChangeEvent weatherChangeOnEvent;
|
||||||
|
private ThunderChangeEvent thunderChangeOffEvent;
|
||||||
|
private ThunderChangeEvent thunderChangeOnEvent;
|
||||||
|
private Player mockPlayer;
|
||||||
|
private PlayerChatEvent playerChatEvent;
|
||||||
|
private Player mockNewPlayer;
|
||||||
|
private PlayerJoinEvent playerNewJoinEvent;
|
||||||
|
private PlayerJoinEvent playerJoinEvent;
|
||||||
|
private PlayerRespawnEvent playerRespawnBed;
|
||||||
|
private PlayerRespawnEvent playerRespawnNormal;
|
||||||
|
private Entity mockEntity;
|
||||||
|
private EntityRegainHealthEvent entityRegainHealthEvent;
|
||||||
|
private FoodLevelChangeEvent entityFoodLevelChangeEvent;
|
||||||
|
private FoodLevelChangeEvent entityFoodLevelRiseEvent;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
creator = new TestInstanceCreator();
|
||||||
|
assertTrue(creator.setUp());
|
||||||
|
core = creator.getCore();
|
||||||
|
mockCommandSender = creator.getCommandSender();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
creator.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
// Initialize a fake command
|
||||||
|
Command mockCommand = mock(Command.class);
|
||||||
|
when(mockCommand.getName()).thenReturn("mv");
|
||||||
|
|
||||||
|
// Import the first world
|
||||||
|
String[] normalArgs = new String[] { "import", "world", "normal" };
|
||||||
|
core.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||||
|
verify(mockCommandSender).sendMessage("Starting import of world 'world'...");
|
||||||
|
verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!");
|
||||||
|
|
||||||
|
// Import a second world
|
||||||
|
String[] netherArgs = new String[] { "import", "world_nether", "nether" };
|
||||||
|
core.onCommand(mockCommandSender, mockCommand, "", netherArgs);
|
||||||
|
verify(mockCommandSender).sendMessage("Starting import of world 'world_nether'...");
|
||||||
|
verify(mockCommandSender, VerificationModeFactory.times(2)).sendMessage(
|
||||||
|
ChatColor.GREEN + "Complete!");
|
||||||
|
|
||||||
|
// ////////////////////////////////////////////////
|
||||||
|
// let's set some world-properties
|
||||||
|
// we can test the API with this, too :D
|
||||||
|
MVWorldManager worldManager = core.getMVWorldManager();
|
||||||
|
assertNotNull(worldManager);
|
||||||
|
|
||||||
|
MultiverseWorld mvWorld = worldManager.getMVWorld("world");
|
||||||
|
MultiverseWorld netherWorld = worldManager.getMVWorld("world_nether");
|
||||||
|
assertNotNull(mvWorld);
|
||||||
|
assertNotNull(netherWorld);
|
||||||
|
assertSame(mvWorld, worldManager.getFirstSpawnWorld());
|
||||||
|
assertSame(mvWorld, worldManager.getSpawnWorld());
|
||||||
|
|
||||||
|
/* ***************************** *
|
||||||
|
* Check defaults
|
||||||
|
* ***************************** */
|
||||||
|
assertFalse(mvWorld.isHidden());
|
||||||
|
assertEquals(mvWorld.getName(), mvWorld.getAlias());
|
||||||
|
assertEquals(ChatColor.WHITE, mvWorld.getColor());
|
||||||
|
assertTrue(mvWorld.isPVPEnabled());
|
||||||
|
assertEquals((Object) 1D, (Object) mvWorld.getScaling()); // we're casting this to objects to use
|
||||||
|
// assertEquals(Object,Object) instead of assertEquals(double,double)
|
||||||
|
assertNull(mvWorld.getRespawnToWorld());
|
||||||
|
assertTrue(mvWorld.isWeatherEnabled());
|
||||||
|
World cbWorld = mvWorld.getCBWorld();
|
||||||
|
when(cbWorld.getDifficulty()).thenReturn(Difficulty.NORMAL);
|
||||||
|
assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
|
||||||
|
assertTrue(mvWorld.canAnimalsSpawn());
|
||||||
|
assertTrue(mvWorld.canMonstersSpawn());
|
||||||
|
assertEquals(-1, mvWorld.getCurrency());
|
||||||
|
assertEquals(0, mvWorld.getPrice(), 0);
|
||||||
|
assertTrue(mvWorld.getHunger());
|
||||||
|
assertTrue(mvWorld.getAutoHeal());
|
||||||
|
assertTrue(mvWorld.getAdjustSpawn());
|
||||||
|
assertEquals(GameMode.SURVIVAL, mvWorld.getGameMode());
|
||||||
|
assertTrue(mvWorld.isKeepingSpawnInMemory());
|
||||||
|
assertTrue(mvWorld.getBedRespawn());
|
||||||
|
assertTrue(mvWorld.getAutoLoad());
|
||||||
|
assertEquals(new Location(mvWorld.getCBWorld(), 0, 64, 0), mvWorld.getSpawnLocation());
|
||||||
|
|
||||||
|
/* ****************************************** *
|
||||||
|
* Call some events and verify behavior
|
||||||
|
* ****************************************** */
|
||||||
|
createEvents(mvWorld);
|
||||||
|
|
||||||
|
// call both weather change events
|
||||||
|
core.getWeatherListener().weatherChange(weatherChangeOffEvent);
|
||||||
|
assertFalse(weatherChangeOffEvent.isCancelled());
|
||||||
|
core.getWeatherListener().weatherChange(weatherChangeOnEvent);
|
||||||
|
assertFalse(weatherChangeOnEvent.isCancelled());
|
||||||
|
|
||||||
|
// call both thunder change events
|
||||||
|
core.getWeatherListener().thunderChange(thunderChangeOffEvent);
|
||||||
|
assertFalse(thunderChangeOffEvent.isCancelled());
|
||||||
|
core.getWeatherListener().thunderChange(thunderChangeOnEvent);
|
||||||
|
assertFalse(thunderChangeOnEvent.isCancelled());
|
||||||
|
|
||||||
|
// call player chat event
|
||||||
|
MultiverseCore.PrefixChat = true;
|
||||||
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
|
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||||
|
MultiverseCore.PrefixChat = false;
|
||||||
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
|
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||||
|
|
||||||
|
// call player join events
|
||||||
|
core.getPlayerListener().playerJoin(playerJoinEvent);
|
||||||
|
verify(mockPlayer, never()).teleport(any(Location.class));
|
||||||
|
core.getPlayerListener().playerJoin(playerNewJoinEvent);
|
||||||
|
verify(mockNewPlayer).teleport(worldManager.getFirstSpawnWorld().getSpawnLocation());
|
||||||
|
|
||||||
|
// call player respawn events
|
||||||
|
core.getPlayerListener().playerRespawn(playerRespawnBed);
|
||||||
|
// bedrespawn is on so nothing should happen
|
||||||
|
verify(playerRespawnBed, never()).setRespawnLocation(any(Location.class));
|
||||||
|
core.getPlayerListener().playerRespawn(playerRespawnNormal);
|
||||||
|
verify(playerRespawnNormal).setRespawnLocation(mvWorld.getSpawnLocation());
|
||||||
|
|
||||||
|
// call entity regain health event
|
||||||
|
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
|
||||||
|
// autoheal is on so nothing should happen
|
||||||
|
verify(entityRegainHealthEvent, never()).setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
|
/* ************************ *
|
||||||
|
* Modify & Verify
|
||||||
|
* ************************ */
|
||||||
|
mvWorld.setHidden(true);
|
||||||
|
assertEquals(true, mvWorld.isHidden());
|
||||||
|
mvWorld.setAlias("alias");
|
||||||
|
assertEquals("alias", mvWorld.getAlias());
|
||||||
|
assertTrue(mvWorld.setColor("BLACK"));
|
||||||
|
ChatColor oldColor = mvWorld.getColor();
|
||||||
|
assertFalse(mvWorld.setColor("INVALID COLOR"));
|
||||||
|
assertEquals(oldColor, mvWorld.getColor());
|
||||||
|
assertEquals(oldColor.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
|
||||||
|
mvWorld.setPVPMode(false);
|
||||||
|
assertEquals(false, mvWorld.isPVPEnabled());
|
||||||
|
assertTrue(mvWorld.setScaling(2D));
|
||||||
|
assertEquals((Object) 2D, (Object) mvWorld.getScaling());
|
||||||
|
assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
|
||||||
|
assertTrue(mvWorld.setRespawnToWorld("world_nether"));
|
||||||
|
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
|
||||||
|
mvWorld.getRespawnToWorld());
|
||||||
|
mvWorld.setEnableWeather(false);
|
||||||
|
assertEquals(false, mvWorld.isWeatherEnabled());
|
||||||
|
assertTrue(mvWorld.setDifficulty("PEACEFUL"));
|
||||||
|
Difficulty oldDifficulty = mvWorld.getDifficulty();
|
||||||
|
assertFalse(mvWorld.setDifficulty("INVALID DIFFICULTY"));
|
||||||
|
assertEquals(oldDifficulty, mvWorld.getDifficulty());
|
||||||
|
mvWorld.setAllowAnimalSpawn(false);
|
||||||
|
assertEquals(false, mvWorld.canAnimalsSpawn());
|
||||||
|
mvWorld.setAllowMonsterSpawn(false);
|
||||||
|
assertEquals(false, mvWorld.canMonstersSpawn());
|
||||||
|
mvWorld.setCurrency(1);
|
||||||
|
assertEquals(1, mvWorld.getCurrency());
|
||||||
|
mvWorld.setPrice(1D);
|
||||||
|
assertEquals((Object) 1D, (Object) mvWorld.getPrice());
|
||||||
|
mvWorld.setHunger(false);
|
||||||
|
assertEquals(false, mvWorld.getHunger());
|
||||||
|
mvWorld.setAutoHeal(false);
|
||||||
|
assertEquals(false, mvWorld.getAutoHeal());
|
||||||
|
mvWorld.setAdjustSpawn(false);
|
||||||
|
assertEquals(false, mvWorld.getAdjustSpawn());
|
||||||
|
assertTrue(mvWorld.setGameMode("CREATIVE"));
|
||||||
|
GameMode oldGamemode = mvWorld.getGameMode();
|
||||||
|
assertFalse(mvWorld.setGameMode("INVALID GAMEMODE"));
|
||||||
|
assertEquals(oldGamemode, mvWorld.getGameMode());
|
||||||
|
mvWorld.setKeepSpawnInMemory(false);
|
||||||
|
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
|
||||||
|
mvWorld.setBedRespawn(false);
|
||||||
|
assertEquals(false, mvWorld.getBedRespawn());
|
||||||
|
mvWorld.setAutoLoad(false);
|
||||||
|
assertEquals(false, mvWorld.getAutoLoad());
|
||||||
|
mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
||||||
|
assertEquals(new Location(mvWorld.getCBWorld(), 1, 1, 1), mvWorld.getSpawnLocation());
|
||||||
|
|
||||||
|
/* ****************************************** *
|
||||||
|
* Call some events and verify behavior
|
||||||
|
* ****************************************** */
|
||||||
|
// We have to recreate the events and the mock-objects
|
||||||
|
createEvents(mvWorld);
|
||||||
|
|
||||||
|
// call both weather change events
|
||||||
|
core.getWeatherListener().weatherChange(weatherChangeOffEvent);
|
||||||
|
assertFalse(weatherChangeOffEvent.isCancelled());
|
||||||
|
core.getWeatherListener().weatherChange(weatherChangeOnEvent);
|
||||||
|
assertTrue(weatherChangeOnEvent.isCancelled());
|
||||||
|
|
||||||
|
// call both thunder change events
|
||||||
|
core.getWeatherListener().thunderChange(thunderChangeOffEvent);
|
||||||
|
assertFalse(thunderChangeOffEvent.isCancelled());
|
||||||
|
core.getWeatherListener().thunderChange(thunderChangeOnEvent);
|
||||||
|
assertTrue(thunderChangeOnEvent.isCancelled());
|
||||||
|
|
||||||
|
// call player chat event
|
||||||
|
MultiverseCore.PrefixChat = true;
|
||||||
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
|
// never because it's hidden!
|
||||||
|
verify(playerChatEvent, never()).setFormat(
|
||||||
|
"[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||||
|
mvWorld.setHidden(false);
|
||||||
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
|
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||||
|
MultiverseCore.PrefixChat = false;
|
||||||
|
core.getPlayerListener().playerChat(playerChatEvent);
|
||||||
|
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||||
|
|
||||||
|
// call player join events
|
||||||
|
core.getPlayerListener().playerJoin(playerJoinEvent);
|
||||||
|
verify(mockPlayer, never()).teleport(any(Location.class));
|
||||||
|
core.getPlayerListener().playerJoin(playerNewJoinEvent);
|
||||||
|
verify(mockNewPlayer).teleport(new Location(mvWorld.getCBWorld(), 1, 1, 1));
|
||||||
|
|
||||||
|
// call player respawn events
|
||||||
|
core.getPlayerListener().playerRespawn(playerRespawnBed);
|
||||||
|
// bedrespawn is off so something should happen (and we've set respawn to nether...)
|
||||||
|
verify(playerRespawnBed).setRespawnLocation(netherWorld.getSpawnLocation());
|
||||||
|
core.getPlayerListener().playerRespawn(playerRespawnNormal);
|
||||||
|
verify(playerRespawnNormal).setRespawnLocation(netherWorld.getSpawnLocation());
|
||||||
|
|
||||||
|
// call entity regain health event
|
||||||
|
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
|
||||||
|
// autoheal is off so something should happen
|
||||||
|
verify(entityRegainHealthEvent).setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createEvents(MultiverseWorld mvWorld) {
|
||||||
|
//// Weather events
|
||||||
|
// weather change
|
||||||
|
weatherChangeOffEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), false);
|
||||||
|
weatherChangeOnEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), true);
|
||||||
|
// thunder change
|
||||||
|
thunderChangeOffEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), false);
|
||||||
|
thunderChangeOnEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), true);
|
||||||
|
//// Player events
|
||||||
|
// player chat
|
||||||
|
mockPlayer = mock(Player.class);
|
||||||
|
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
|
||||||
|
when(mockPlayer.hasPlayedBefore()).thenReturn(true);
|
||||||
|
playerChatEvent = PowerMockito.mock(PlayerChatEvent.class);
|
||||||
|
when(playerChatEvent.getPlayer()).thenReturn(mockPlayer);
|
||||||
|
when(playerChatEvent.getFormat()).thenReturn("format");
|
||||||
|
// player join
|
||||||
|
mockNewPlayer = mock(Player.class);
|
||||||
|
when(mockNewPlayer.hasPlayedBefore()).thenReturn(false);
|
||||||
|
playerJoinEvent = PowerMockito.mock(PlayerJoinEvent.class);
|
||||||
|
when(playerJoinEvent.getPlayer()).thenReturn(mockPlayer);
|
||||||
|
playerNewJoinEvent = PowerMockito.mock(PlayerJoinEvent.class);
|
||||||
|
when(playerNewJoinEvent.getPlayer()).thenReturn(mockNewPlayer);
|
||||||
|
// player respawn
|
||||||
|
playerRespawnBed = PowerMockito.mock(PlayerRespawnEvent.class);
|
||||||
|
when(playerRespawnBed.getPlayer()).thenReturn(mockPlayer);
|
||||||
|
when(playerRespawnBed.isBedSpawn()).thenReturn(true);
|
||||||
|
playerRespawnNormal = PowerMockito.mock(PlayerRespawnEvent.class);
|
||||||
|
when(playerRespawnNormal.getPlayer()).thenReturn(mockPlayer);
|
||||||
|
when(playerRespawnNormal.isBedSpawn()).thenReturn(false);
|
||||||
|
//// Entity events
|
||||||
|
mockEntity = mock(Entity.class);
|
||||||
|
// entity regain health
|
||||||
|
entityRegainHealthEvent = PowerMockito.mock(EntityRegainHealthEvent.class);
|
||||||
|
when(entityRegainHealthEvent.getRegainReason()).thenReturn(RegainReason.REGEN);
|
||||||
|
when(mockEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
|
||||||
|
when(entityRegainHealthEvent.getEntity()).thenReturn(mockEntity);
|
||||||
|
// entity food level change event
|
||||||
|
entityFoodLevelChangeEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
|
||||||
|
// this won't do anything since we're not mocking a player,
|
||||||
|
// but the plugin should be able to handle this!
|
||||||
|
when(entityFoodLevelChangeEvent.getEntity()).thenReturn(mockEntity);
|
||||||
|
entityFoodLevelRiseEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
|
||||||
|
when(mockPlayer.getFoodLevel()).thenReturn(2);
|
||||||
|
when(entityFoodLevelRiseEvent.getEntity()).thenReturn(mockPlayer);
|
||||||
|
when(entityFoodLevelRiseEvent.getFoodLevel()).thenReturn(3);
|
||||||
|
}
|
||||||
|
}
|
@ -168,6 +168,41 @@ public class TestWorldStuff {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
public void testNullWorld() {
|
||||||
|
// Pull a core instance from the server.
|
||||||
|
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||||
|
|
||||||
|
// Make sure Core is not null
|
||||||
|
assertNotNull(plugin);
|
||||||
|
|
||||||
|
// Make sure Core is enabled
|
||||||
|
assertTrue(plugin.isEnabled());
|
||||||
|
|
||||||
|
// Initialize a fake command
|
||||||
|
Command mockCommand = mock(Command.class);
|
||||||
|
when(mockCommand.getName()).thenReturn("mv");
|
||||||
|
|
||||||
|
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||||
|
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||||
|
|
||||||
|
// Create the NULL world
|
||||||
|
// The safe check is now BALLS SLOW. Use the -n to skip checking.
|
||||||
|
String[] normalArgs = new String[]{ "create", "nullworld", "normal", "-n" };
|
||||||
|
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||||
|
|
||||||
|
// We should now have one world!
|
||||||
|
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
verify(mockCommandSender).sendMessage("Starting creation of world 'nullworld'...");
|
||||||
|
verify(mockCommandSender).sendMessage("Complete!");
|
||||||
|
|
||||||
|
WorldCreatorMatcher matcher = new WorldCreatorMatcher(new WorldCreator("nullworld"));
|
||||||
|
verify(mockServer).createWorld(Matchers.argThat(matcher));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// TODO Migrate this to TestWorldProperties
|
||||||
public void testModifyGameMode() {
|
public void testModifyGameMode() {
|
||||||
// Pull a core instance from the server.
|
// Pull a core instance from the server.
|
||||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,60 +31,16 @@ 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.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
|
when(mockWorld.getWorldType()).thenReturn(type);
|
||||||
|
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 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 {
|
||||||
if (!(invocation.getMock() instanceof World))
|
if (!(invocation.getMock() instanceof World))
|
||||||
@ -93,23 +48,92 @@ 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;
|
||||||
|
}
|
||||||
|
Material blockType = Material.AIR;
|
||||||
|
Block mockBlock = mock(Block.class);
|
||||||
|
if (loc.getBlockY() < 64) {
|
||||||
|
blockType = Material.DIRT;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
private static World nullWorld(String world, World.Environment env, WorldType type) {
|
||||||
World w = basics(world, env);
|
World mockWorld = mock(World.class);
|
||||||
|
when(mockWorld.getName()).thenReturn(world);
|
||||||
|
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||||
|
when(mockWorld.getWorldType()).thenReturn(type);
|
||||||
|
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||||
|
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||||
|
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
if (!(invocation.getMock() instanceof World))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
World thiss = (World) invocation.getMock();
|
||||||
|
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||||
|
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Location loc;
|
||||||
|
try {
|
||||||
|
loc = (Location) invocation.getArguments()[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block mockBlock = mock(Block.class);
|
||||||
|
Material blockType = Material.AIR;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static World makeNewMockWorld(String world, World.Environment env, WorldType type) {
|
||||||
|
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 makeNewNullMockWorld(String world, World.Environment env, WorldType type) {
|
||||||
|
World w = nullWorld(world, env, type);
|
||||||
|
registerWorld(w);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
@ -121,7 +145,13 @@ public class MockWorldFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<World> getWorlds() {
|
public static List<World> getWorlds() {
|
||||||
return new ArrayList<World>(createdWorlds.values());
|
// we have to invert the order!
|
||||||
|
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
|
||||||
|
List<World> retList = new ArrayList<World>();
|
||||||
|
for (int i = (myList.size() - 1); i >= 0; i--) {
|
||||||
|
retList.add(myList.get(i));
|
||||||
|
}
|
||||||
|
return retList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearWorlds() {
|
public static void clearWorlds() {
|
||||||
|
@ -26,9 +26,11 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
@ -36,6 +38,9 @@ import org.powermock.api.mockito.PowerMockito;
|
|||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
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.FileUtils;
|
||||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
|
|
||||||
@ -122,12 +127,45 @@ public class TestInstanceCreator {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment());
|
// Add special case for creating null worlds.
|
||||||
|
// Not sure I like doing it this way, but this is a special case
|
||||||
|
if (arg.name().equalsIgnoreCase("nullworld")) {
|
||||||
|
return MockWorldFactory.makeNewNullMockWorld(arg.name(), arg.environment(), arg.type());
|
||||||
|
}
|
||||||
|
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
|
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
|
||||||
|
|
||||||
|
// add mock scheduler
|
||||||
|
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
||||||
|
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
||||||
|
thenAnswer(new Answer<Integer>() {
|
||||||
|
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Runnable arg;
|
||||||
|
try {
|
||||||
|
arg = (Runnable) invocation.getArguments()[1];
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
arg.run();
|
||||||
|
return null;
|
||||||
|
}});
|
||||||
|
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
||||||
|
thenAnswer(new Answer<Integer>() {
|
||||||
|
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Runnable arg;
|
||||||
|
try {
|
||||||
|
arg = (Runnable) invocation.getArguments()[1];
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
arg.run();
|
||||||
|
return null;
|
||||||
|
}});
|
||||||
|
when(mockServer.getScheduler()).thenReturn(mockScheduler);
|
||||||
|
|
||||||
// Set server
|
// Set server
|
||||||
Field serverfield = JavaPlugin.class.getDeclaredField("server");
|
Field serverfield = JavaPlugin.class.getDeclaredField("server");
|
||||||
serverfield.setAccessible(true);
|
serverfield.setAccessible(true);
|
||||||
@ -139,6 +177,24 @@ public class TestInstanceCreator {
|
|||||||
worldmanagerfield.setAccessible(true);
|
worldmanagerfield.setAccessible(true);
|
||||||
worldmanagerfield.set(core, wm);
|
worldmanagerfield.set(core, wm);
|
||||||
|
|
||||||
|
// Set playerListener
|
||||||
|
MVPlayerListener pl = PowerMockito.spy(new MVPlayerListener(core));
|
||||||
|
Field playerlistenerfield = MultiverseCore.class.getDeclaredField("playerListener");
|
||||||
|
playerlistenerfield.setAccessible(true);
|
||||||
|
playerlistenerfield.set(core, pl);
|
||||||
|
|
||||||
|
// Set entityListener
|
||||||
|
MVEntityListener el = PowerMockito.spy(new MVEntityListener(core));
|
||||||
|
Field entitylistenerfield = MultiverseCore.class.getDeclaredField("entityListener");
|
||||||
|
entitylistenerfield.setAccessible(true);
|
||||||
|
entitylistenerfield.set(core, el);
|
||||||
|
|
||||||
|
// Set weatherListener
|
||||||
|
MVWeatherListener wl = PowerMockito.spy(new MVWeatherListener(core));
|
||||||
|
Field weatherlistenerfield = MultiverseCore.class.getDeclaredField("weatherListener");
|
||||||
|
weatherlistenerfield.setAccessible(true);
|
||||||
|
weatherlistenerfield.set(core, wl);
|
||||||
|
|
||||||
// Init our command sender
|
// Init our command sender
|
||||||
final Logger commandSenderLogger = Logger.getLogger("CommandSender");
|
final Logger commandSenderLogger = Logger.getLogger("CommandSender");
|
||||||
commandSenderLogger.setParent(Util.logger);
|
commandSenderLogger.setParent(Util.logger);
|
||||||
|
Loading…
Reference in New Issue
Block a user