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

Conflicts:
	src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java
	src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java
This commit is contained in:
main() 2012-10-16 19:38:04 +02:00
commit 88088548f8
41 changed files with 1749 additions and 434 deletions

71
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversecore</groupId> <groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId> <artifactId>Multiverse-Core</artifactId>
<version>2.4</version> <version>2.5</version>
<name>Multiverse-Core</name> <name>Multiverse-Core</name>
<description>World Management Plugin</description> <description>World Management Plugin</description>
<properties> <properties>
@ -20,6 +20,10 @@
<id>Bukkit Official</id> <id>Bukkit Official</id>
<url>http://repo.bukkit.org/content/repositories/public</url> <url>http://repo.bukkit.org/content/repositories/public</url>
</repository> </repository>
<repository>
<id>mcstats</id>
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
</repository>
</repositories> </repositories>
<pluginRepositories> <pluginRepositories>
@ -101,12 +105,6 @@
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<!-- Maven Source Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
@ -136,6 +134,33 @@
<configLocation>${project.basedir}/config/mv_checks.xml</configLocation> <configLocation>${project.basedir}/config/mv_checks.xml</configLocation>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>javadoc-jar</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@ -152,6 +177,8 @@
<include>me.main__.util:SerializationConfig</include> <include>me.main__.util:SerializationConfig</include>
<include>com.fernferret.allpay:AllPay</include> <include>com.fernferret.allpay:AllPay</include>
<include>com.pneumaticraft.commandhandler:CommandHandler</include> <include>com.pneumaticraft.commandhandler:CommandHandler</include>
<include>com.dumptruckman.minecraft:buscript</include>
<include>org.mcstats:metrics</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
@ -167,6 +194,14 @@
<pattern>com.pneumaticraft.commandhandler</pattern> <pattern>com.pneumaticraft.commandhandler</pattern>
<shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern> <shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>buscript</pattern>
<shadedPattern>buscript.multiverse</shadedPattern>
</relocation>
<relocation>
<pattern>org.mcstats</pattern>
<shadedPattern>org.mcstats.multiverse</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
</execution> </execution>
@ -180,7 +215,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.2.5-R1.0</version> <version>1.3.1-R2.1-SNAPSHOT</version>
<!-- If you want the lates, use this --> <!-- If you want the lates, use this -->
<!-- <version>LATEST</version> --> <!-- <version>LATEST</version> -->
<type>jar</type> <type>jar</type>
@ -198,7 +233,7 @@
<dependency> <dependency>
<groupId>me.main__.util</groupId> <groupId>me.main__.util</groupId>
<artifactId>SerializationConfig</artifactId> <artifactId>SerializationConfig</artifactId>
<version>1.6</version> <version>1.6b</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@ -221,6 +256,24 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- End of CommandHandler Dependency --> <!-- End of CommandHandler Dependency -->
<!-- Start of Buscript Dependency -->
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Buscript Dependency -->
<!-- Start of Metrics Dependency -->
<dependency>
<groupId>org.mcstats</groupId>
<artifactId>metrics</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Metrics Dependency -->
<!-- Start of Test Dependencies --> <!-- Start of Test Dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@ -9,15 +9,15 @@ package com.onarandombox.MultiverseCore;
import com.onarandombox.MultiverseCore.api.BlockSafety; import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.configuration.EntryFee; import com.onarandombox.MultiverseCore.configuration.EntryFee;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation; import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
import com.onarandombox.MultiverseCore.configuration.SpawnSettings; import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator; import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
import com.onarandombox.MultiverseCore.enums.AllowedPortalType; import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor; import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import me.main__.util.SerializationConfig.ChangeDeniedException; import me.main__.util.SerializationConfig.ChangeDeniedException;
import me.main__.util.SerializationConfig.IllegalPropertyValueException; import me.main__.util.SerializationConfig.IllegalPropertyValueException;
import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.NoSuchPropertyException;
@ -26,7 +26,6 @@ import me.main__.util.SerializationConfig.SerializationConfig;
import me.main__.util.SerializationConfig.Serializor; import me.main__.util.SerializationConfig.Serializor;
import me.main__.util.SerializationConfig.ValidateAllWith; import me.main__.util.SerializationConfig.ValidateAllWith;
import me.main__.util.SerializationConfig.VirtualProperty; import me.main__.util.SerializationConfig.VirtualProperty;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -61,6 +60,24 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16; private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16;
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16; private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
private static final Map<String, String> PROPERTY_ALIASES;
static {
PROPERTY_ALIASES = new HashMap<String, String>();
PROPERTY_ALIASES.put("curr", "currency");
PROPERTY_ALIASES.put("scaling", "scale");
PROPERTY_ALIASES.put("aliascolor", "color");
PROPERTY_ALIASES.put("heal", "autoHeal");
PROPERTY_ALIASES.put("storm", "allowWeather");
PROPERTY_ALIASES.put("weather", "allowWeather");
PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory");
PROPERTY_ALIASES.put("memory", "keepSpawnInMemory");
PROPERTY_ALIASES.put("mode", "gameMode");
PROPERTY_ALIASES.put("diff", "difficulty");
PROPERTY_ALIASES.put("spawnlocation", "spawn");
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
}
/* /*
* We have to use setCBWorld(), setPlugin() and initPerms() to prepare this object for use. * We have to use setCBWorld(), setPlugin() and initPerms() to prepare this object for use.
*/ */
@ -70,7 +87,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
private MultiverseCore plugin; // Hold the Plugin Instance. private MultiverseCore plugin; // Hold the Plugin Instance.
private Reference<World> world = new WeakReference<World>(null); // A reference to the World Instance. private volatile Reference<World> world = new WeakReference<World>(null); // A reference to the World Instance.
private String name; // The Worlds Name, EG its folder name. private String name; // The Worlds Name, EG its folder name.
/** /**
@ -336,13 +353,15 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
// -------------------------------------------------------------- // --------------------------------------------------------------
// Begin properties // Begin properties
@Property(description = "Sorry, 'hidden' must either be: true or false.") @Property(description = "Sorry, 'hidden' must either be: true or false.")
private boolean hidden; private volatile boolean hidden;
@Property(description = "Alias must be a valid string.") @Property(description = "Alias must be a valid string.")
private String alias; private volatile String alias;
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.") @Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
private EnglishChatColor color; private volatile EnglishChatColor color;
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
private volatile EnglishChatStyle style;
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) @Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
private VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() { private volatile VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() {
@Override @Override
public void set(Boolean newValue) { public void set(Boolean newValue) {
world.get().setPVP(newValue); world.get().setPVP(newValue);
@ -354,14 +373,14 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
} }
}; };
@Property(validator = ScalePropertyValidator.class, description = "Scale must be a positive double value. ex: 2.3") @Property(validator = ScalePropertyValidator.class, description = "Scale must be a positive double value. ex: 2.3")
private double scale; private volatile double scale;
@Property(validator = RespawnWorldPropertyValidator.class, description = "You must set this to the NAME not alias of a world.") @Property(validator = RespawnWorldPropertyValidator.class, description = "You must set this to the NAME not alias of a world.")
private String respawnWorld; private volatile String respawnWorld;
@Property(validator = AllowWeatherPropertyValidator.class, description = "Sorry, this must either be: true or false.") @Property(validator = AllowWeatherPropertyValidator.class, description = "Sorry, this must either be: true or false.")
private boolean allowWeather; private volatile boolean allowWeather;
@Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true, @Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true,
description = "Difficulty must be set as one of the following: peaceful easy normal hard") description = "Difficulty must be set as one of the following: peaceful easy normal hard")
private VirtualProperty<Difficulty> difficulty = new VirtualProperty<Difficulty>() { private volatile VirtualProperty<Difficulty> difficulty = new VirtualProperty<Difficulty>() {
@Override @Override
public void set(Difficulty newValue) { public void set(Difficulty newValue) {
world.get().setDifficulty(newValue); world.get().setDifficulty(newValue);
@ -373,22 +392,22 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
} }
}; };
@Property(validator = SpawningPropertyValidator.class, description = "Sorry, 'animals' must either be: true or false.") @Property(validator = SpawningPropertyValidator.class, description = "Sorry, 'animals' must either be: true or false.")
private SpawnSettings spawning; private volatile SpawnSettings spawning;
@Property @Property
private EntryFee entryfee; private volatile EntryFee entryfee;
@Property(description = "Sorry, 'hunger' must either be: true or false.") @Property(description = "Sorry, 'hunger' must either be: true or false.")
private boolean hunger; private volatile boolean hunger;
@Property(description = "Sorry, 'autoheal' must either be: true or false.") @Property(description = "Sorry, 'autoheal' must either be: true or false.")
private boolean autoHeal; private volatile boolean autoHeal;
@Property(description = "Sorry, 'adjustspawn' must either be: true or false.") @Property(description = "Sorry, 'adjustspawn' must either be: true or false.")
private boolean adjustSpawn; private volatile boolean adjustSpawn;
@Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.") @Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.")
private AllowedPortalType portalForm; private volatile AllowedPortalType portalForm;
@Property(serializor = GameModePropertySerializor.class, validator = GameModePropertyValidator.class, @Property(serializor = GameModePropertySerializor.class, validator = GameModePropertyValidator.class,
description = "GameMode must be set as one of the following: survival creative") description = "GameMode must be set as one of the following: survival creative")
private GameMode gameMode; private volatile GameMode gameMode;
@Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true) @Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
private VirtualProperty<Boolean> keepSpawnInMemory = new VirtualProperty<Boolean>() { private volatile VirtualProperty<Boolean> keepSpawnInMemory = new VirtualProperty<Boolean>() {
@Override @Override
public void set(Boolean newValue) { public void set(Boolean newValue) {
world.get().setKeepSpawnInMemory(newValue); world.get().setKeepSpawnInMemory(newValue);
@ -400,10 +419,10 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
} }
}; };
@Property @Property
private SpawnLocation spawnLocation; private volatile SpawnLocation spawnLocation;
@Property(validator = SpawnLocationPropertyValidator.class, virtualType = Location.class, @Property(validator = SpawnLocationPropertyValidator.class, virtualType = Location.class,
description = "There is no help available for this variable. Go bug Rigby90 about it.") description = "There is no help available for this variable. Go bug Rigby90 about it.")
private VirtualProperty<Location> spawn = new VirtualProperty<Location>() { private volatile VirtualProperty<Location> spawn = new VirtualProperty<Location>() {
@Override @Override
public void set(Location newValue) { public void set(Location newValue) {
if (getCBWorld() != null) if (getCBWorld() != null)
@ -421,15 +440,14 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
} }
}; };
@Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.") @Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.")
private boolean autoLoad; private volatile boolean autoLoad;
@Property(description = "If a player dies in this world, shoudld they go to their bed?") @Property(description = "If a player dies in this world, shoudld they go to their bed?")
private boolean bedRespawn; private volatile boolean bedRespawn;
@Property @Property
private List<String> worldBlacklist; private volatile List<String> worldBlacklist;
@SuppressWarnings("unused") // it IS used!
@Property(serializor = TimePropertySerializor.class, virtualType = Long.class, @Property(serializor = TimePropertySerializor.class, virtualType = Long.class,
description = "Set the time to whatever you want! (Will NOT freeze time)") description = "Set the time to whatever you want! (Will NOT freeze time)")
private VirtualProperty<Long> time = new VirtualProperty<Long>() { private volatile VirtualProperty<Long> time = new VirtualProperty<Long>() {
@Override @Override
public void set(Long newValue) { public void set(Long newValue) {
world.get().setTime(newValue); world.get().setTime(newValue);
@ -441,11 +459,11 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
} }
}; };
@Property @Property
private Environment environment; private volatile Environment environment;
@Property @Property
private long seed; private volatile long seed;
@Property @Property
private String generator; private volatile String generator;
// End of properties // End of properties
// -------------------------------------------------------------- // --------------------------------------------------------------
@ -621,6 +639,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.hidden = false; this.hidden = false;
this.alias = new String(); this.alias = new String();
this.color = EnglishChatColor.WHITE; this.color = EnglishChatColor.WHITE;
this.style = EnglishChatStyle.NORMAL;
this.scale = getDefaultScale(environment); this.scale = getDefaultScale(environment);
this.respawnWorld = new String(); this.respawnWorld = new String();
this.allowWeather = true; this.allowWeather = true;
@ -644,19 +663,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
* @see SerializationConfig * @see SerializationConfig
*/ */
protected static Map<String, String> getAliases() { protected static Map<String, String> getAliases() {
Map<String, String> aliases = new HashMap<String, String>(); return PROPERTY_ALIASES;
aliases.put("curr", "currency");
aliases.put("scaling", "scale");
aliases.put("aliascolor", "color");
aliases.put("heal", "autoHeal");
aliases.put("storm", "allowWeather");
aliases.put("weather", "allowWeather");
aliases.put("spawnmemory", "keepSpawnInMemory");
aliases.put("memory", "keepSpawnInMemory");
aliases.put("mode", "gameMode");
aliases.put("diff", "difficulty");
aliases.put("spawnlocation", "spawn");
return aliases;
} }
private static double getDefaultScale(Environment environment) { private static double getDefaultScale(Environment environment) {
@ -708,10 +715,17 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
if (alias.length() == 0) { if (alias.length() == 0) {
alias = this.getName(); alias = this.getName();
} }
if ((color == null) || (color.getColor() == null)) { if ((color == null) || (color.getColor() == null)) {
this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE); this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE);
} }
return color.getColor() + alias + ChatColor.WHITE;
StringBuilder nameBuilder = new StringBuilder().append(color.getColor());
if (style.getColor() != null)
nameBuilder.append(style.getColor());
nameBuilder.append(alias).append(ChatColor.WHITE).toString();
return nameBuilder.toString();
} }
/** /**
@ -1365,6 +1379,22 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
this.setPropertyValueUnchecked("portalForm", portalType); this.setPropertyValueUnchecked("portalForm", portalType);
} }
/**
* {@inheritDoc}
*/
@Override
public ChatColor getStyle() {
return style.getColor();
}
/**
* {@inheritDoc}
*/
@Override
public boolean setStyle(String style) {
return this.setPropertyUnchecked("style", style);
}
@Override @Override
public String toString() { public String toString() {
StringBuilder toStringBuilder = new StringBuilder(); StringBuilder toStringBuilder = new StringBuilder();

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore;
import buscript.Buscript;
import com.fernferret.allpay.AllPay; import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.api.BlockSafety; import com.onarandombox.MultiverseCore.api.BlockSafety;
@ -18,7 +19,38 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging; import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter; import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.commands.*; import com.onarandombox.MultiverseCore.commands.AnchorCommand;
import com.onarandombox.MultiverseCore.commands.CheckCommand;
import com.onarandombox.MultiverseCore.commands.CloneCommand;
import com.onarandombox.MultiverseCore.commands.ConfigCommand;
import com.onarandombox.MultiverseCore.commands.ConfirmCommand;
import com.onarandombox.MultiverseCore.commands.CoordCommand;
import com.onarandombox.MultiverseCore.commands.CreateCommand;
import com.onarandombox.MultiverseCore.commands.DebugCommand;
import com.onarandombox.MultiverseCore.commands.DeleteCommand;
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
import com.onarandombox.MultiverseCore.commands.HelpCommand;
import com.onarandombox.MultiverseCore.commands.ImportCommand;
import com.onarandombox.MultiverseCore.commands.InfoCommand;
import com.onarandombox.MultiverseCore.commands.ListCommand;
import com.onarandombox.MultiverseCore.commands.LoadCommand;
import com.onarandombox.MultiverseCore.commands.ModifyAddCommand;
import com.onarandombox.MultiverseCore.commands.ModifyClearCommand;
import com.onarandombox.MultiverseCore.commands.ModifyCommand;
import com.onarandombox.MultiverseCore.commands.ModifyRemoveCommand;
import com.onarandombox.MultiverseCore.commands.ModifySetCommand;
import com.onarandombox.MultiverseCore.commands.PurgeCommand;
import com.onarandombox.MultiverseCore.commands.RegenCommand;
import com.onarandombox.MultiverseCore.commands.ReloadCommand;
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
import com.onarandombox.MultiverseCore.commands.ScriptCommand;
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
import com.onarandombox.MultiverseCore.commands.VersionCommand;
import com.onarandombox.MultiverseCore.commands.WhoCommand;
import com.onarandombox.MultiverseCore.destination.AnchorDestination; import com.onarandombox.MultiverseCore.destination.AnchorDestination;
import com.onarandombox.MultiverseCore.destination.BedDestination; import com.onarandombox.MultiverseCore.destination.BedDestination;
import com.onarandombox.MultiverseCore.destination.CannonDestination; import com.onarandombox.MultiverseCore.destination.CannonDestination;
@ -28,22 +60,32 @@ import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination; import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
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.MVWeatherListener;
import com.onarandombox.MultiverseCore.localization.MessageProvider; import com.onarandombox.MultiverseCore.localization.MessageProvider;
import com.onarandombox.MultiverseCore.localization.MessageProviding; import com.onarandombox.MultiverseCore.localization.MessageProviding;
import com.onarandombox.MultiverseCore.listeners.MVPortalListener; import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
import com.onarandombox.MultiverseCore.utils.*; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import com.onarandombox.MultiverseCore.localization.MultiverseMessage;
import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider; import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider;
import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.DebugLog;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.onarandombox.MultiverseCore.utils.MVPermissions;
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler; import com.pneumaticraft.commandhandler.CommandHandler;
import me.main__.util.SerializationConfig.SerializationConfig; import me.main__.util.SerializationConfig.SerializationConfig;
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;
@ -53,6 +95,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -60,11 +103,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -72,7 +116,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, MessageProviding { public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, MessageProviding {
private static final int PROTOCOL = 14; private static final int PROTOCOL = 17;
// TODO: Investigate if this one is really needed to be static. // TODO: Investigate if this one is really needed to be static.
// Doubt it. -- FernFerret // Doubt it. -- FernFerret
private static Map<String, String> teleportQueue = new HashMap<String, String>(); private static Map<String, String> teleportQueue = new HashMap<String, String>();
@ -80,7 +124,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
private AnchorManager anchorManager = new AnchorManager(this); private AnchorManager anchorManager = new AnchorManager(this);
private MessageProvider messageProvider = new SimpleMessageProvider(this); private MessageProvider messageProvider = new SimpleMessageProvider(this);
// TODO please let's make this non-static // TODO please let's make this non-static
private MultiverseCoreConfiguration config; private volatile MultiverseCoreConfiguration config;
/** /**
* This method is used to find out who is teleporting a player. * This method is used to find out who is teleporting a player.
@ -154,19 +198,21 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
// Configurations // Configurations
private FileConfiguration multiverseConfig = null; private FileConfiguration multiverseConfig = null;
private MVWorldManager worldManager = new WorldManager(this); private final MVWorldManager worldManager = new WorldManager(this);
// Setup the block/player/entity listener. // Setup the block/player/entity listener.
private MVPlayerListener playerListener = new MVPlayerListener(this); private final MVPlayerListener playerListener = new MVPlayerListener(this);
private MVEntityListener entityListener = new MVEntityListener(this); private final MVEntityListener entityListener = new MVEntityListener(this);
private MVPluginListener pluginListener = new MVPluginListener(this); private final MVPluginListener pluginListener = new MVPluginListener(this);
private MVWeatherListener weatherListener = new MVWeatherListener(this); private final MVWeatherListener weatherListener = new MVWeatherListener(this);
private MVPortalListener portalListener = new MVPortalListener(this); private final MVPortalListener portalListener = new MVPortalListener(this);
private MVChatListener chatListener;
// HashMap to contain information relating to the Players. // HashMap to contain information relating to the Players.
private HashMap<String, MVPlayerSession> playerSessions; private HashMap<String, MVPlayerSession> playerSessions;
private GenericBank bank = null; private GenericBank bank = null;
private AllPay banker; private AllPay banker;
private Buscript buscript;
private int pluginCount; private int pluginCount;
private DestinationFactory destFactory; private DestinationFactory destFactory;
//private SpoutInterface spoutInterface = null; //private SpoutInterface spoutInterface = null;
@ -187,6 +233,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
getDataFolder().mkdirs(); getDataFolder().mkdirs();
// Setup our Debug Log // Setup our Debug Log
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log"); debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
debugLog.setStandardLogger(LOGGER);
SerializationConfig.initLogging(debugLog);
// Setup our BlockSafety // Setup our BlockSafety
this.blockSafety = new SimpleBlockSafety(this); this.blockSafety = new SimpleBlockSafety(this);
// Setup our LocationManipulation // Setup our LocationManipulation
@ -265,13 +313,25 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
this.anchorManager.loadAnchors(); this.anchorManager.loadAnchors();
// Now set the firstspawnworld (after the worlds are loaded): // Now set the firstspawnworld (after the worlds are loaded):
this.worldManager.setFirstSpawnWorld(config.getFirstSpawnWorld()); this.worldManager.setFirstSpawnWorld(getMVConfig().getFirstSpawnWorld());
try { try {
config.setFirstSpawnWorld(this.worldManager.getFirstSpawnWorld().getName()); getMVConfig().setFirstSpawnWorld(this.worldManager.getFirstSpawnWorld().getName());
} catch (NullPointerException e) { } catch (NullPointerException e) {
// A test that had no worlds loaded was being run. This should never happen in production // A test that had no worlds loaded was being run. This should never happen in production
} }
this.saveMVConfig(); this.saveMVConfig();
// Register async or sync player chat according to config
try {
Class.forName("org.bukkit.event.player.AsyncPlayerChatEvent");
} catch (ClassNotFoundException e) {
getMVConfig().setUseAsyncChat(false);
}
if (getMVConfig().getUseAsyncChat()) {
this.chatListener = new MVAsyncPlayerChatListener(this, this.playerListener);
} else {
this.chatListener = new MVPlayerChatListener(this, this.playerListener);
}
getServer().getPluginManager().registerEvents(this.chatListener, this);
/* /*
// Check to see if spout was already loaded (most likely): // Check to see if spout was already loaded (most likely):
if (this.getServer().getPluginManager().getPlugin("Spout") != null) { if (this.getServer().getPluginManager().getPlugin("Spout") != null) {
@ -279,6 +339,109 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
this.log(Level.INFO, "Spout integration enabled."); this.log(Level.INFO, "Spout integration enabled.");
} }
*/ */
this.initializeBuscript();
this.setupMetrics();
}
/**
* Initializes the buscript javascript library.
*/
private void initializeBuscript() {
buscript = new Buscript(this);
// Add global variable "multiverse" to javascript environment
buscript.getGlobalScope().put("multiverse", buscript.getGlobalScope(), this);
}
/**
* Plotter for Environment-Values.
*/
private static final class EnvironmentPlotter extends Metrics.Plotter {
private MultiverseCore core;
private final Environment env;
public EnvironmentPlotter(MultiverseCore core, Environment env) {
super(envToString(env));
this.core = core;
this.env = env;
}
private static String envToString(Environment env) {
return new StringBuilder().append(env.name().toUpperCase().charAt(0))
.append(env.name().toLowerCase().substring(1)).toString();
}
@Override
public int getValue() {
int count = 0;
for (MultiverseWorld w : core.getMVWorldManager().getMVWorlds())
if (w.getEnvironment() == env)
count++;
core.log(Level.FINE, String.format("Tracking %d worlds of type %s", count, env));
return count;
}
}
/**
* Plotter for Generator-Values.
*/
private static final class GeneratorPlotter extends Metrics.Plotter {
private MultiverseCore core;
private final String gen;
public GeneratorPlotter(MultiverseCore core, String gen) {
super(gen);
this.core = core;
this.gen = gen;
}
@Override
public int getValue() {
int count = 0;
for (MultiverseWorld w : core.getMVWorldManager().getMVWorlds())
if (gen.equals(w.getGenerator()))
count++;
core.log(Level.FINE, String.format("Tracking %d worlds of type %s", count, gen));
return count;
}
}
private void setupMetrics() {
try {
Metrics m = new Metrics(this);
Metrics.Graph envGraph = m.createGraph("worlds_by_env");
for (Environment env : Environment.values())
envGraph.addPlotter(new EnvironmentPlotter(this, env));
m.addCustomData(new Metrics.Plotter("Loaded worlds") {
@Override
public int getValue() {
return getMVWorldManager().getMVWorlds().size();
}
});
m.addCustomData(new Metrics.Plotter("Total number of worlds") {
@Override
public int getValue() {
return getMVWorldManager().getMVWorlds().size()
+ getMVWorldManager().getUnloadedWorlds().size();
}
});
Set<String> gens = new HashSet<String>();
for (MultiverseWorld w : this.getMVWorldManager().getMVWorlds())
gens.add(w.getGenerator());
gens.remove(null);
gens.remove("null");
Metrics.Graph genGraph = m.createGraph("custom_gens");
for (String gen : gens)
genGraph.addPlotter(new GeneratorPlotter(this, gen));
m.start();
log(Level.FINE, "Metrics have run!");
} catch (IOException e) {
log(Level.WARNING, "There was an issue while enabling metrics: " + e.getMessage());
}
} }
private void initializeDestinationFactory() { private void initializeDestinationFactory() {
@ -317,19 +480,17 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
this.multiverseConfig.options().copyDefaults(false); this.multiverseConfig.options().copyDefaults(false);
this.multiverseConfig.options().copyHeader(true); this.multiverseConfig.options().copyHeader(true);
this.migrateWorldConfig();
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
MultiverseCoreConfiguration wantedConfig = null; MultiverseCoreConfiguration wantedConfig = null;
try { try {
wantedConfig = (MultiverseCoreConfiguration) multiverseConfig.get("multiverse-configuration"); wantedConfig = (MultiverseCoreConfiguration) multiverseConfig.get("multiverse-configuration");
} catch (Exception e) { } catch (Exception ignore) {
// We're just thinking "no risk no fun" and therefore have to catch and forget this exception
} finally { } finally {
config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig); config = ((wantedConfig == null) ? new MultiverseCoreConfiguration() : wantedConfig);
} }
this.migrateWorldConfig();
this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml"));
this.messaging.setCooldown(config.getMessageCooldown()); this.messaging.setCooldown(getMVConfig().getMessageCooldown());
// Remove old values. // Remove old values.
this.multiverseConfig.set("enforcegamemodes", null); this.multiverseConfig.set("enforcegamemodes", null);
@ -348,42 +509,42 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
private void migrate22Values() { private void migrate22Values() {
if (this.multiverseConfig.isSet("worldnameprefix")) { if (this.multiverseConfig.isSet("worldnameprefix")) {
this.log(Level.INFO, "Migrating 'worldnameprefix'..."); this.log(Level.INFO, "Migrating 'worldnameprefix'...");
this.config.setPrefixChat(this.multiverseConfig.getBoolean("worldnameprefix")); this.getMVConfig().setPrefixChat(this.multiverseConfig.getBoolean("worldnameprefix"));
this.multiverseConfig.set("worldnameprefix", null); this.multiverseConfig.set("worldnameprefix", null);
} }
if (this.multiverseConfig.isSet("firstspawnworld")) { if (this.multiverseConfig.isSet("firstspawnworld")) {
this.log(Level.INFO, "Migrating 'firstspawnworld'..."); this.log(Level.INFO, "Migrating 'firstspawnworld'...");
this.config.setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld")); this.getMVConfig().setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld"));
this.multiverseConfig.set("firstspawnworld", null); this.multiverseConfig.set("firstspawnworld", null);
} }
if (this.multiverseConfig.isSet("enforceaccess")) { if (this.multiverseConfig.isSet("enforceaccess")) {
this.log(Level.INFO, "Migrating 'enforceaccess'..."); this.log(Level.INFO, "Migrating 'enforceaccess'...");
this.config.setEnforceAccess(this.multiverseConfig.getBoolean("enforceaccess")); this.getMVConfig().setEnforceAccess(this.multiverseConfig.getBoolean("enforceaccess"));
this.multiverseConfig.set("enforceaccess", null); this.multiverseConfig.set("enforceaccess", null);
} }
if (this.multiverseConfig.isSet("displaypermerrors")) { if (this.multiverseConfig.isSet("displaypermerrors")) {
this.log(Level.INFO, "Migrating 'displaypermerrors'..."); this.log(Level.INFO, "Migrating 'displaypermerrors'...");
this.config.setDisplayPermErrors(this.multiverseConfig.getBoolean("displaypermerrors")); this.getMVConfig().setDisplayPermErrors(this.multiverseConfig.getBoolean("displaypermerrors"));
this.multiverseConfig.set("displaypermerrors", null); this.multiverseConfig.set("displaypermerrors", null);
} }
if (this.multiverseConfig.isSet("teleportintercept")) { if (this.multiverseConfig.isSet("teleportintercept")) {
this.log(Level.INFO, "Migrating 'teleportintercept'..."); this.log(Level.INFO, "Migrating 'teleportintercept'...");
this.config.setTeleportIntercept(this.multiverseConfig.getBoolean("teleportintercept")); this.getMVConfig().setTeleportIntercept(this.multiverseConfig.getBoolean("teleportintercept"));
this.multiverseConfig.set("teleportintercept", null); this.multiverseConfig.set("teleportintercept", null);
} }
if (this.multiverseConfig.isSet("firstspawnoverride")) { if (this.multiverseConfig.isSet("firstspawnoverride")) {
this.log(Level.INFO, "Migrating 'firstspawnoverride'..."); this.log(Level.INFO, "Migrating 'firstspawnoverride'...");
this.config.setFirstSpawnOverride(this.multiverseConfig.getBoolean("firstspawnoverride")); this.getMVConfig().setFirstSpawnOverride(this.multiverseConfig.getBoolean("firstspawnoverride"));
this.multiverseConfig.set("firstspawnoverride", null); this.multiverseConfig.set("firstspawnoverride", null);
} }
if (this.multiverseConfig.isSet("messagecooldown")) { if (this.multiverseConfig.isSet("messagecooldown")) {
this.log(Level.INFO, "Migrating 'messagecooldown'..."); this.log(Level.INFO, "Migrating 'messagecooldown'...");
this.config.setMessageCooldown(this.multiverseConfig.getInt("messagecooldown")); this.getMVConfig().setMessageCooldown(this.multiverseConfig.getInt("messagecooldown"));
this.multiverseConfig.set("messagecooldown", null); this.multiverseConfig.set("messagecooldown", null);
} }
if (this.multiverseConfig.isSet("debug")) { if (this.multiverseConfig.isSet("debug")) {
this.log(Level.INFO, "Migrating 'debug'..."); this.log(Level.INFO, "Migrating 'debug'...");
this.config.setGlobalDebug(this.multiverseConfig.getInt("debug")); this.getMVConfig().setGlobalDebug(this.multiverseConfig.getInt("debug"));
this.multiverseConfig.set("debug", null); this.multiverseConfig.set("debug", null);
} }
if (this.multiverseConfig.isSet("version")) { if (this.multiverseConfig.isSet("version")) {
@ -395,12 +556,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
/** /**
* Migrate the worlds.yml to SerializationConfig. * Migrate the worlds.yml to SerializationConfig.
*/ */
private void migrateWorldConfig() { private void migrateWorldConfig() { // SUPPRESS CHECKSTYLE: MethodLength
FileConfiguration wconf = YamlConfiguration FileConfiguration wconf = YamlConfiguration
.loadConfiguration(new File(getDataFolder(), "worlds.yml")); .loadConfiguration(new File(getDataFolder(), "worlds.yml"));
if (!wconf.isConfigurationSection("worlds")) // empty config if (!wconf.isConfigurationSection("worlds")) { // empty config
this.log(Level.FINE, "No worlds to migrate!");
return; return;
}
Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false); Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);
@ -411,6 +574,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
// fine // fine
newValues.put(entry.getKey(), entry.getValue()); newValues.put(entry.getKey(), entry.getValue());
} else if (entry.getValue() instanceof ConfigurationSection) { } else if (entry.getValue() instanceof ConfigurationSection) {
this.log(Level.FINE, "Migrating: " + entry.getKey());
// we have to migrate this // we have to migrate this
MVWorld world = new MVWorld(Collections.EMPTY_MAP); MVWorld world = new MVWorld(Collections.EMPTY_MAP);
ConfigurationSection section = (ConfigurationSection) entry.getValue(); ConfigurationSection section = (ConfigurationSection) entry.getValue();
@ -617,6 +781,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
this.commandHandler.registerCommand(new ListCommand(this)); this.commandHandler.registerCommand(new ListCommand(this));
this.commandHandler.registerCommand(new InfoCommand(this)); this.commandHandler.registerCommand(new InfoCommand(this));
this.commandHandler.registerCommand(new CreateCommand(this)); this.commandHandler.registerCommand(new CreateCommand(this));
this.commandHandler.registerCommand(new CloneCommand(this));
this.commandHandler.registerCommand(new ImportCommand(this)); this.commandHandler.registerCommand(new ImportCommand(this));
this.commandHandler.registerCommand(new ReloadCommand(this)); this.commandHandler.registerCommand(new ReloadCommand(this));
this.commandHandler.registerCommand(new SetSpawnCommand(this)); this.commandHandler.registerCommand(new SetSpawnCommand(this));
@ -645,6 +810,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
this.commandHandler.registerCommand(new DebugCommand(this)); this.commandHandler.registerCommand(new DebugCommand(this));
this.commandHandler.registerCommand(new GeneratorCommand(this)); this.commandHandler.registerCommand(new GeneratorCommand(this));
this.commandHandler.registerCommand(new CheckCommand(this)); this.commandHandler.registerCommand(new CheckCommand(this));
this.commandHandler.registerCommand(new ScriptCommand(this));
} }
/** /**
@ -667,7 +833,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
if (this.playerSessions.containsKey(player.getName())) { if (this.playerSessions.containsKey(player.getName())) {
return this.playerSessions.get(player.getName()); return this.playerSessions.get(player.getName());
} else { } else {
this.playerSessions.put(player.getName(), new MVPlayerSession(player, config)); this.playerSessions.put(player.getName(), new MVPlayerSession(player, getMVConfig()));
return this.playerSessions.get(player.getName()); return this.playerSessions.get(player.getName());
} }
} }
@ -702,7 +868,17 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
} }
ArrayList<String> allArgs = new ArrayList<String>(Arrays.asList(args)); ArrayList<String> allArgs = new ArrayList<String>(Arrays.asList(args));
allArgs.add(0, command.getName()); allArgs.add(0, command.getName());
return this.commandHandler.locateAndRunCommand(sender, allArgs, config.getDisplayPermErrors()); try {
return this.commandHandler.locateAndRunCommand(sender, allArgs, getMVConfig().getDisplayPermErrors());
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "An internal error occurred when attempting to perform this command.");
if (sender.isOp())
sender.sendMessage(ChatColor.RED + "Details were printed to the server console and logs, please add that to your bug report.");
else
sender.sendMessage(ChatColor.RED + "Try again and contact the server owner or an admin if this problem persists.");
return true;
}
} }
/** /**
@ -721,17 +897,15 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
*/ */
public static void staticLog(Level level, String msg) { public static void staticLog(Level level, String msg) {
if (level == Level.FINE && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 1) { if (level == Level.FINE && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 1) {
staticDebugLog(Level.INFO, msg); staticDebugLog(level, msg);
return;
} else if (level == Level.FINER && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 2) { } else if (level == Level.FINER && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 2) {
staticDebugLog(Level.INFO, msg); staticDebugLog(level, msg);
return;
} else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) { } else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) {
staticDebugLog(Level.INFO, msg); staticDebugLog(level, msg);
return;
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) { } else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
LOGGER.log(level, String.format("%s %s", LOG_TAG, msg)); String message = LOG_TAG + " " + msg;
debugLog.log(level, String.format("%s %s", LOG_TAG, msg)); LOGGER.log(level, message);
debugLog.log(level, message);
} }
} }
@ -743,8 +917,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
* @param msg The message * @param msg The message
*/ */
public static void staticDebugLog(Level level, String msg) { public static void staticDebugLog(Level level, String msg) {
LOGGER.log(level, "[MVCore-Debug] " + msg); debugLog.log(level, msg);
debugLog.log(level, "[MVCore-Debug] " + msg);
} }
/** /**
@ -929,6 +1102,15 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
return this.playerListener; return this.playerListener;
} }
/**
* Gets the {@link MVChatListener}.
*
* @return The {@link MVChatListener}.
*/
public MVChatListener getChatListener() {
return this.chatListener;
}
/** /**
* Gets the {@link MVEntityListener}. * Gets the {@link MVEntityListener}.
* *
@ -954,7 +1136,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
*/ */
public boolean saveMVConfig() { public boolean saveMVConfig() {
try { try {
this.multiverseConfig.set("multiverse-configuration", config); this.multiverseConfig.set("multiverse-configuration", getMVConfig());
this.multiverseConfig.save(new File(getDataFolder(), "config.yml")); this.multiverseConfig.save(new File(getDataFolder(), "config.yml"));
return true; return true;
} catch (IOException e) { } catch (IOException e) {
@ -991,38 +1173,27 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
return this.worldManager.deleteWorld(name); return this.worldManager.deleteWorld(name);
} }
/**
* NOT deprecated for the time as queued commands use this.
* However, this is not in the API and other plugins should therefore not use it.
*
* @param oldName World to copy
* @param newName World to create
* @param generator The Custom generator plugin to use.
* @return True if success, false if fail.
*/
public Boolean cloneWorld(String oldName, String newName, String generator) {
return this.worldManager.cloneWorld(oldName, newName, generator);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* @deprecated This is deprecated!
*/ */
@Override @Override
@Deprecated
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) { public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) {
MultiverseWorld world = this.worldManager.getMVWorld(name); return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed);
if (world == null) {
return false;
}
List<Player> ps = world.getCBWorld().getPlayers();
if (useNewSeed) {
// Set the worldseed.
if (randomSeed) {
Random random = new Random();
Long newseed = random.nextLong();
seed = newseed.toString();
}
((WorldManager) this.worldManager).getConfigWorlds().set("worlds." + name + ".seed", seed);
}
if (this.worldManager.deleteWorld(name, false)) {
this.worldManager.loadWorlds(false);
SafeTTeleporter teleporter = this.getSafeTTeleporter();
Location newSpawn = this.getServer().getWorld(name).getSpawnLocation();
// Send all players that were in the old world, BACK to it!
for (Player p : ps) {
teleporter.safelyTeleport(null, p, newSpawn, true);
}
return true;
}
return false;
} }
/** /**
@ -1118,4 +1289,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag
public static MultiverseCoreConfiguration getStaticConfig() { public static MultiverseCoreConfiguration getStaticConfig() {
return MultiverseCoreConfiguration.getInstance(); return MultiverseCoreConfiguration.getInstance();
} }
@Override
public Buscript getScriptAPI() {
return buscript;
}
} }

View File

@ -1,13 +1,12 @@
package com.onarandombox.MultiverseCore; package com.onarandombox.MultiverseCore;
import java.util.Map;
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig; import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.NoSuchPropertyException;
import me.main__.util.SerializationConfig.Property; import me.main__.util.SerializationConfig.Property;
import me.main__.util.SerializationConfig.SerializationConfig; import me.main__.util.SerializationConfig.SerializationConfig;
import java.util.Map;
/** /**
* Our configuration. * Our configuration.
*/ */
@ -22,6 +21,13 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
MultiverseCoreConfiguration.instance = instance; MultiverseCoreConfiguration.instance = instance;
} }
/**
* @return True if the static instance of config is set.
*/
public static boolean isSet() {
return instance != null;
}
/** /**
* Gets the statically saved instance. * Gets the statically saved instance.
* @return The statically saved instance. * @return The statically saved instance.
@ -33,25 +39,27 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
} }
@Property @Property
private boolean enforceaccess; private volatile boolean enforceaccess;
@Property @Property
private boolean prefixchat; private volatile boolean prefixchat;
@Property @Property
private boolean teleportintercept; private volatile boolean useasyncchat;
@Property @Property
private boolean firstspawnoverride; private volatile boolean teleportintercept;
@Property @Property
private boolean displaypermerrors; private volatile boolean firstspawnoverride;
@Property @Property
private int globaldebug; private volatile boolean displaypermerrors;
@Property @Property
private int messagecooldown; private volatile int globaldebug;
@Property @Property
private double version; private volatile int messagecooldown;
@Property @Property
private String firstspawnworld; private volatile double version;
@Property @Property
private int teleportcooldown; private volatile String firstspawnworld;
@Property
private volatile int teleportcooldown;
public MultiverseCoreConfiguration() { public MultiverseCoreConfiguration() {
super(); super();
@ -67,9 +75,10 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void setDefaults() { protected void setDefaults() {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
enforceaccess = false; enforceaccess = false;
useasyncchat = true;
prefixchat = true; prefixchat = true;
teleportintercept = true; teleportintercept = true;
firstspawnoverride = true; firstspawnoverride = true;
@ -254,4 +263,14 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
public void setTeleportCooldown(int teleportCooldown) { public void setTeleportCooldown(int teleportCooldown) {
this.teleportcooldown = teleportCooldown; this.teleportcooldown = teleportCooldown;
} }
@Override
public void setUseAsyncChat(boolean useAsyncChat) {
this.useasyncchat = useAsyncChat;
}
@Override
public boolean getUseAsyncChat() {
return this.useasyncchat;
}
} }

View File

@ -7,6 +7,7 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
import buscript.Buscript;
import com.fernferret.allpay.AllPay; import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.destination.DestinationFactory; import com.onarandombox.MultiverseCore.destination.DestinationFactory;
@ -128,7 +129,10 @@ public interface Core {
* @param seed The seed of the world. * @param seed The seed of the world.
* *
* @return True if success, false if fail. * @return True if success, false if fail.
*
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String)} instead.
*/ */
@Deprecated
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed); Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
/** /**
@ -222,4 +226,11 @@ public interface Core {
* @return The configuration. * @return The configuration.
*/ */
MultiverseCoreConfig getMVConfig(); MultiverseCoreConfig getMVConfig();
/**
* Gets the buscript object for Multiverse. This is what handles Javascript processing.
*
* @return The Multiverse buscript object.
*/
Buscript getScriptAPI();
} }

View File

@ -60,6 +60,16 @@ public interface MVWorldManager {
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures, boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
String generator, boolean useSpawnAdjust); String generator, boolean useSpawnAdjust);
/**
* Make a copy of a world.
*
* @param oldName Name of world to be copied
* @param newName Name of world to be created
* @param generator The Custom generator plugin to use.
* @return True if the world is copied successfully, false if not.
*/
boolean cloneWorld(String oldName, String newName, String generator);
/** /**
* Remove the world from the Multiverse list, from the * Remove the world from the Multiverse list, from the
* config and deletes the folder. * config and deletes the folder.
@ -245,4 +255,16 @@ public interface MVWorldManager {
* @return The {@link MultiverseWorld} new players should spawn in. * @return The {@link MultiverseWorld} new players should spawn in.
*/ */
MultiverseWorld getFirstSpawnWorld(); MultiverseWorld getFirstSpawnWorld();
/**
* Regenerates a world.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed IF the new seed should be random
* @param seed The seed of the world.
*
* @return True if success, false if fail.
*/
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
} }

View File

@ -133,4 +133,16 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
* @return enforceAccess. * @return enforceAccess.
*/ */
boolean getEnforceAccess(); boolean getEnforceAccess();
/**
* Sets useasyncchat.
* @param useAsyncChat The new value.
*/
void setUseAsyncChat(boolean useAsyncChat);
/**
* Gets useasyncchat.
* @return useasyncchat.
*/
boolean getUseAsyncChat();
} }

View File

@ -0,0 +1,162 @@
package com.onarandombox.MultiverseCore.api;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.DebugLog;
import com.pneumaticraft.commandhandler.CommandHandler;
/**
* Make things easier for MV-Plugins!
*/
public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
private MultiverseCore core;
/**
* Prefix for standard log entrys.
*/
protected String logTag;
private DebugLog debugLog;
/**
* {@inheritDoc}
*
* Note: You can't override this, use {@link #onPluginEnable()} instead!
* @see #onPluginEnable()
*/
@Override
public final void onEnable() {
MultiverseCore theCore = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core");
if (theCore == null) {
this.getLogger().severe("Core not found! The plugin dev needs to add a dependency!");
this.getLogger().severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
if (theCore.getProtocolVersion() < this.getProtocolVersion()) {
this.getLogger().severe("You need a newer version of Multiverse-Core!");
this.getLogger().severe("Disabling!");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
this.setCore(theCore);
// Turn on Logging
this.getServer().getLogger().info(String.format("%s - Version %s enabled - By %s",
this.getDescription().getName(), this.getDescription().getVersion(), getAuthors()));
getDataFolder().mkdirs();
File debugLogFile = new File(getDataFolder(), "debug.log");
try {
debugLogFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
debugLog = new DebugLog("Multiverse-Adventure", getDataFolder() + File.separator + "debug.log");
debugLog.setTag(String.format("[%s-Debug]", this.getDescription().getName()));
this.onPluginEnable();
}
/**
* Parse the Authors Array into a readable String with ',' and 'and'.
*
* @return The readable authors-{@link String}
*/
protected String getAuthors() {
String authors = "";
List<String> auths = this.getDescription().getAuthors();
if (auths.size() == 0) {
return "";
}
if (auths.size() == 1) {
return auths.get(0);
}
for (int i = 0; i < auths.size(); i++) {
if (i == this.getDescription().getAuthors().size() - 1) {
authors += " and " + this.getDescription().getAuthors().get(i);
} else {
authors += ", " + this.getDescription().getAuthors().get(i);
}
}
return authors.substring(2);
}
/**
* Called when the plugin is enabled.
* @see #onEnable()
*/
protected abstract void onPluginEnable();
/**
* You can register commands here.
* @param handler The CommandHandler.
*/
protected abstract void registerCommands(CommandHandler handler);
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!this.isEnabled()) {
sender.sendMessage("This plugin is Disabled!");
return true;
}
ArrayList<String> allArgs = new ArrayList<String>(args.length + 1);
allArgs.add(command.getName());
allArgs.addAll(Arrays.asList(args));
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
}
@Override
public void log(Level level, String msg) {
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2)
|| (level == Level.FINEST && debugLevel >= 3)) {
debugLog.log(level, msg);
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
String message = new StringBuilder(getLogTag()).append(msg).toString();
this.getServer().getLogger().log(level, message);
debugLog.log(level, message);
}
}
private String getLogTag() {
if (logTag == null)
logTag = String.format("[%s]", this.getDescription().getName());
return logTag;
}
/**
* Sets the debug log-tag.
* @param tag The new tag.
*/
protected final void setDebugLogTag(String tag) {
this.debugLog.setTag(tag);
}
@Override
public final String dumpVersionInfo(String buffer) {
throw new UnsupportedOperationException("This is gone.");
}
@Override
public final MultiverseCore getCore() {
if (this.core == null)
throw new IllegalStateException("Core is null!");
return this.core;
}
@Override
public final void setCore(MultiverseCore core) {
this.core = core;
}
}

View File

@ -288,6 +288,21 @@ public interface MultiverseWorld {
*/ */
boolean setColor(String color); boolean setColor(String color);
/**
* Gets the style that this world's name/alias will display as.
*
* @return The style of this world. {@code null} for "normal" style.
*/
ChatColor getStyle();
/**
* Sets the style that this world's name/alias will display as.
*
* @param style A valid style name.
* @return True if the style was set, false if not.
*/
boolean setStyle(String style);
/** /**
* Tells you if someone entered a valid color. * Tells you if someone entered a valid color.
* *

View File

@ -3,14 +3,14 @@ package com.onarandombox.MultiverseCore.api;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
/** /**
* Used to remove animals from worlds that don't belong there. * Used to remove animals from worlds that don't belong there.
*/ */
public interface WorldPurger { public interface WorldPurger {
/** /**
* Synchronizes the given world with it's settings. * Synchronizes the given worlds with their settings.
* *
* @param worlds A list of {@link MultiverseWorld} * @param worlds A list of {@link MultiverseWorld}
*/ */
@ -46,4 +46,23 @@ public interface WorldPurger {
void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals, void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals,
boolean negateMonsters, CommandSender sender); boolean negateMonsters, CommandSender sender);
/**
* Determines whether the specified creature should be killed.
*
* @param e The creature.
* @param thingsToKill A {@link List} of animals/monsters to be killed.
* @param negateAnimals Whether the monsters in the list should be negated.
* @param negateMonsters Whether the animals in the list should be negated.
* @return {@code true} if the creature should be killed, otherwise {@code false}.
*/
boolean shouldWeKillThisCreature(Entity e, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters);
/**
* Determines whether the specified creature should be killed and automatically reads the params from a world object.
*
* @param w The world.
* @param e The creature.
* @return {@code true} if the creature should be killed, otherwise {@code false}.
*/
boolean shouldWeKillThisCreature(MultiverseWorld w, Entity e);
} }

View File

@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,7 +35,11 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing"); this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing");
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d"); this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
this.addCommandExample("/mv anchors "); this.addCommandExample("/mv anchors ");
this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP); this.setPermission("multiverse.core.anchor.list", "Allows a player to list all anchors.", PermissionDefault.OP);
this.addAdditonalPermission(new Permission("multiverse.core.anchor.create",
"Allows a player to create anchors.", PermissionDefault.OP));
this.addAdditonalPermission(new Permission("multiverse.core.anchor.delete",
"Allows a player to delete anchors.", PermissionDefault.OP));
this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
} }
@ -49,6 +54,11 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
} }
private void showList(CommandSender sender, List<String> args) { private void showList(CommandSender sender, List<String> args) {
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.list", true)) {
sender.sendMessage(ChatColor.RED + "You don't have the permission to list anchors!");
return;
}
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]===="); sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====");
Player p = null; Player p = null;
if (sender instanceof Player) { if (sender instanceof Player) {
@ -105,11 +115,15 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
return; return;
} }
if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) { if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) {
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true)) {
sender.sendMessage(ChatColor.RED + "You don't have the permission to delete anchors!");
} else {
if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) { if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) {
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!"); sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!");
} else { } else {
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!"); sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!");
} }
}
return; return;
} }
@ -118,13 +132,16 @@ public class AnchorCommand extends PaginatedCoreCommand<String> {
return; return;
} }
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true)) {
sender.sendMessage(ChatColor.RED + "You don't have the permission to create anchors!");
} else {
Player player = (Player) sender; Player player = (Player) sender;
if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) { if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) {
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!"); sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!");
} else { } else {
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!"); sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!");
} }
}
} }
@Override @Override

View File

@ -0,0 +1,60 @@
/******************************************************************************
* 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.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList;
import java.util.List;
/**
* Creates a clone of a world.
*/
public class CloneCommand extends MultiverseCommand {
private MVWorldManager worldManager;
public CloneCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Clone World");
this.setCommandUsage("/mv clone" + ChatColor.GREEN + " {TARGET} {NAME}" + ChatColor.GOLD + " -g [GENERATOR[:ID]]");
this.setArgRange(2, 4); // SUPPRESS CHECKSTYLE: MagicNumberCheck
this.addKey("mvclone");
this.addKey("mvcl");
this.addKey("mv cl");
this.addKey("mv clone");
this.addCommandExample("/mv clone " + ChatColor.GOLD + "world" + ChatColor.GREEN + " world_backup");
this.addCommandExample("/mv clone " + ChatColor.GOLD + "skyblock_pristine" + ChatColor.GREEN + " skyblock");
this.addCommandExample("To clone a world that uses a generator:");
this.addCommandExample("/mv clone " + ChatColor.GOLD + "CleanRoom"
+ ChatColor.GREEN + " CleanRoomCopy" + ChatColor.DARK_AQUA + " -g CleanRoomGenerator");
this.setPermission("multiverse.core.clone", "Clones a world.", PermissionDefault.OP);
this.worldManager = this.plugin.getMVWorldManager();
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
Class<?>[] paramTypes = {String.class, String.class, String.class};
List<Object> objectArgs = new ArrayList<Object>();
objectArgs.add(args.get(0));
objectArgs.add(args.get(1));
objectArgs.add(CommandHandler.getFlag("-g", args));
if (!this.worldManager.isMVWorld(args.get(0))) {
// If no world was found, we can't clone.
sender.sendMessage("Sorry, Multiverse doesn't know about world " + args.get(0) + ", so we can't clone it!");
sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed.");
return;
}
this.plugin.getCommandHandler().queueCommand(sender, "mvclone", "cloneWorld", objectArgs,
paramTypes, ChatColor.GREEN + "World Cloned!", ChatColor.RED + "World could NOT be cloned!");
}
}

View File

@ -48,8 +48,8 @@ public class DebugCommand extends MultiverseCommand {
sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE
+ " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)");
} }
} }
plugin.saveMVConfigs();
} }
this.displayDebugMode(sender); this.displayDebugMode(sender);
} }

View File

@ -53,8 +53,8 @@ public class EnvironmentCommand extends MultiverseCommand {
*/ */
public static void showWorldTypes(CommandSender sender) { public static void showWorldTypes(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:"); sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT %sor %sVERSION_1_1", sender.sendMessage(String.format("%sNORMAL%s, %sFLAT, %sLARGEBIOMES %sor %sVERSION_1_1",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.GOLD)); ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD));
} }
@Override @Override
@ -75,6 +75,9 @@ public class EnvironmentCommand extends MultiverseCommand {
type = "NORMAL"; type = "NORMAL";
if (type.equalsIgnoreCase("flat")) if (type.equalsIgnoreCase("flat"))
type = "FLAT"; type = "FLAT";
if (type.equalsIgnoreCase("largebiomes")) {
type = "LARGE_BIOMES";
}
try { try {
// Now that we've converted a potentially unfriendly value // Now that we've converted a potentially unfriendly value
// to a friendly one, get it from the ENUM! // to a friendly one, get it from the ENUM!

View File

@ -85,6 +85,9 @@ public class ModifyAddCommand extends MultiverseCommand {
if (world.addToVariable(property, value)) { if (world.addToVariable(property, value)) {
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property); + value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
if (!plugin.saveWorldConfig()) {
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
}
} else { } else {
sender.sendMessage(value + " could not be added to " + property); sender.sendMessage(value + " could not be added to " + property);
} }

View File

@ -80,6 +80,9 @@ public class ModifyClearCommand extends MultiverseCommand {
sender.sendMessage(property + " was cleared. It contains 0 values now."); sender.sendMessage(property + " was cleared. It contains 0 values now.");
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was " sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
+ ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now."); + ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now.");
if (!plugin.saveWorldConfig()) {
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
}
} else { } else {
sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property
+ ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared."); + ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared.");

View File

@ -85,6 +85,9 @@ public class ModifyRemoveCommand extends MultiverseCommand {
if (world.removeFromVariable(property, value)) { if (world.removeFromVariable(property, value)) {
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property); + " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
if (!plugin.saveWorldConfig()) {
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
}
} else { } else {
sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY
+ value + ChatColor.WHITE + " from " + ChatColor.GOLD + property); + value + ChatColor.WHITE + " from " + ChatColor.GOLD + property);

View File

@ -111,6 +111,9 @@ public class ModifySetCommand extends MultiverseCommand {
if (world.setPropertyValue(property, value)) { if (world.setPropertyValue(property, value)) {
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
if (!plugin.saveWorldConfig()) {
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
}
} else { } else {
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property)); sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
} }

View File

@ -0,0 +1,54 @@
/******************************************************************************
* 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.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.io.File;
import java.util.List;
/**
* States who is in what world.
*/
public class ScriptCommand extends MultiverseCommand {
public ScriptCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Runs a script.");
this.setCommandUsage("/mv script" + ChatColor.GOLD + " {script} [target]");
this.setArgRange(1, 2);
this.addKey("mv script");
this.addKey("mvscript");
this.addCommandExample(String.format("/mv script %sscript.txt", ChatColor.GOLD));
this.addCommandExample(String.format("/mv script %stest.txt %ssomeplayer", ChatColor.GOLD, ChatColor.GREEN));
this.setPermission("multiverse.core.script", "Runs a script.", PermissionDefault.OP);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
if (!file.exists()) {
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
return;
}
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
String target = null;
if (args.size() == 2) {
target = args.get(1);
}
plugin.getScriptAPI().executeScript(file, target, player);
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
}
}

View File

@ -68,7 +68,7 @@ public class WhoCommand extends MultiverseCommand {
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA, sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
world.getColoredWorldString(), ChatColor.AQUA)); world.getColoredWorldString(), ChatColor.AQUA));
sender.sendMessage(buildPlayerString(world)); sender.sendMessage(buildPlayerString(world, p));
return; return;
} }
} }
@ -79,7 +79,7 @@ public class WhoCommand extends MultiverseCommand {
for (MultiverseWorld world : this.worldManager.getMVWorlds()) { for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world))); sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p)));
shownOne = true; shownOne = true;
} }
} }
@ -90,17 +90,14 @@ public class WhoCommand extends MultiverseCommand {
return; return;
} }
private static String buildPlayerString(MultiverseWorld world) { private static String buildPlayerString(MultiverseWorld world, Player viewer) {
List<Player> players = world.getCBWorld().getPlayers(); List<Player> players = world.getCBWorld().getPlayers();
if (players.size() == 0) {
return "No players found.";
} else {
StringBuilder playerBuilder = new StringBuilder(); StringBuilder playerBuilder = new StringBuilder();
for (Player player : players) { for (Player player : players) {
if ((viewer == null) || viewer.canSee(player))
playerBuilder.append(player.getDisplayName()).append(", "); playerBuilder.append(player.getDisplayName()).append(", ");
} }
String bString = playerBuilder.toString(); String bString = playerBuilder.toString();
return bString.substring(0, bString.length() - 2); return (bString.length() == 0) ? "No players found." : bString.substring(0, bString.length() - 2);
}
} }
} }

View File

@ -11,49 +11,33 @@ import org.bukkit.ChatColor;
/** /**
* A regular {@link ChatColor} represented by an english string. * A regular {@link ChatColor} represented by an english string.
* @see ChatColor
*/ */
public enum EnglishChatColor { public enum EnglishChatColor {
/* // BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
* I know. this is quite ugly. AQUA(ChatColor.AQUA),
*/ BLACK(ChatColor.BLACK),
/** AQUA. */ BLUE(ChatColor.BLUE),
AQUA("AQUA", ChatColor.AQUA), DARKAQUA(ChatColor.DARK_AQUA),
/** BLACK. */ DARKBLUE(ChatColor.DARK_BLUE),
BLACK("BLACK", ChatColor.BLACK), DARKGRAY(ChatColor.DARK_GRAY),
/** BLUE. */ DARKGREEN(ChatColor.DARK_GREEN),
BLUE("BLUE", ChatColor.BLUE), DARKPURPLE(ChatColor.DARK_PURPLE),
/** DARKAQUA. */ DARKRED(ChatColor.DARK_RED),
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA), GOLD(ChatColor.GOLD),
/** DARKBLUE. */ GRAY(ChatColor.GRAY),
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE), GREEN(ChatColor.GREEN),
/** DARKGRAY. */ LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY), RED(ChatColor.RED),
/** DARKGREEN. */ YELLOW(ChatColor.YELLOW),
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN), WHITE(ChatColor.WHITE);
/** DARKPURPLE. */ // END CHECKSTYLE-SUPPRESSION: JavadocVariable
DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE),
/** DARKRED. */
DARKRED("DARKRED", ChatColor.DARK_RED),
/** GOLD. */
GOLD("GOLD", ChatColor.GOLD),
/** GRAY. */
GRAY("GRAY", ChatColor.GRAY),
/** GREEN. */
GREEN("GREEN", ChatColor.GREEN),
/** LIGHTPURPLE. */
LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE),
/** RED. */
RED("RED", ChatColor.RED),
/** YELLOW. */
YELLOW("YELLOW", ChatColor.YELLOW),
/** WHITE. */
WHITE("WHITE", ChatColor.WHITE);
private ChatColor color;
private String text;
EnglishChatColor(String name, ChatColor color) { private final ChatColor color;
//private final String text;
EnglishChatColor(ChatColor color) {
this.color = color; this.color = color;
this.text = name;
} }
/** /**
@ -61,7 +45,7 @@ public enum EnglishChatColor {
* @return The text. * @return The text.
*/ */
public String getText() { public String getText() {
return this.text; return this.name();
} }
/** /**
@ -92,7 +76,7 @@ public enum EnglishChatColor {
public static EnglishChatColor fromString(String text) { public static EnglishChatColor fromString(String text) {
if (text != null) { if (text != null) {
for (EnglishChatColor c : EnglishChatColor.values()) { for (EnglishChatColor c : EnglishChatColor.values()) {
if (text.equalsIgnoreCase(c.text)) { if (text.equalsIgnoreCase(c.name())) {
return c; return c;
} }
} }

View File

@ -0,0 +1,49 @@
package com.onarandombox.MultiverseCore.enums;
import org.bukkit.ChatColor;
/**
* A regular {@link ChatColor} represented by an english string.
* @see ChatColor
*/
public enum EnglishChatStyle {
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
/** No style. */
NORMAL(null),
MAGIC(ChatColor.MAGIC),
BOLD(ChatColor.BOLD),
STRIKETHROUGH(ChatColor.STRIKETHROUGH),
UNDERLINE(ChatColor.UNDERLINE),
ITALIC(ChatColor.ITALIC);
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
private final ChatColor color;
EnglishChatStyle(ChatColor color) {
this.color = color;
}
/**
* Gets the color.
* @return The color as {@link ChatColor}.
*/
public ChatColor getColor() {
return color;
}
/**
* Constructs an {@link EnglishChatStyle} from a {@link String}.
* @param text The {@link String}.
* @return The {@link EnglishChatStyle}.
*/
public static EnglishChatStyle fromString(String text) {
if (text != null) {
for (EnglishChatStyle c : EnglishChatStyle.values()) {
if (text.equalsIgnoreCase(c.name())) {
return c;
}
}
}
return null;
}
}

View File

@ -0,0 +1,35 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* A wrapper for the {@link AsyncPlayerChatEvent}.
*/
public class AsyncChatEvent implements ChatEvent {
private final AsyncPlayerChatEvent event;
public AsyncChatEvent(AsyncPlayerChatEvent event) {
this.event = event;
}
@Override
public boolean isCancelled() {
return event.isCancelled();
}
@Override
public String getFormat() {
return event.getFormat();
}
@Override
public void setFormat(String s) {
event.setFormat(s);
}
@Override
public Player getPlayer() {
return event.getPlayer();
}
}

View File

@ -0,0 +1,29 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
/**
* A wrapper for the two chat-events in Bukkit.
*/
public interface ChatEvent {
/**
* @return Whether this event is cancelled.
*/
boolean isCancelled();
/**
* @return The format.
*/
String getFormat();
/**
* Sets the format.
* @param s The new format.
*/
void setFormat(String s);
/**
* @return The player.
*/
Player getPlayer();
}

View File

@ -0,0 +1,34 @@
/******************************************************************************
* 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.listeners;
import java.util.logging.Level;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
public class MVAsyncPlayerChatListener extends MVChatListener {
public MVAsyncPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
super(plugin, playerListener);
plugin.log(Level.FINE, "Created AsyncPlayerChatEvent listener.");
}
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@EventHandler
public void playerChat(AsyncPlayerChatEvent event) {
this.playerChat(new AsyncChatEvent(event));
}
}

View File

@ -0,0 +1,52 @@
package com.onarandombox.MultiverseCore.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.event.Listener;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
public abstract class MVChatListener implements Listener {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final MVPlayerListener playerListener;
public MVChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
this.plugin = plugin;
this.worldManager = plugin.getMVWorldManager();
this.playerListener = playerListener;
}
/**
* This handles a {@link ChatEvent}.
* @param event The {@link ChatEvent}.
*/
public void playerChat(ChatEvent event) {
if (event.isCancelled()) {
return;
}
// Check whether the Server is set to prefix the chat with the World name.
// If not we do nothing, if so we need to check if the World has an Alias.
if (plugin.getMVConfig().getPrefixChat()) {
String world = playerListener.getPlayerWorld().get(event.getPlayer().getName());
if (world == null) {
world = event.getPlayer().getWorld().getName();
playerListener.getPlayerWorld().put(event.getPlayer().getName(), world);
}
String prefix = "";
// If we're not a MV world, don't do anything
if (!this.worldManager.isMVWorld(world)) {
return;
}
MultiverseWorld mvworld = this.worldManager.getMVWorld(world);
if (mvworld.isHidden()) {
return;
}
prefix = mvworld.getColoredWorldString();
String format = event.getFormat();
event.setFormat("[" + prefix + "]" + format);
}
}
}

View File

@ -11,13 +11,8 @@ 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 org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
@ -26,14 +21,12 @@ 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;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
* Multiverse's Entity {@link Listener}. * Multiverse's Entity {@link Listener}.
*/ */
public class MVEntityListener implements Listener { public class MVEntityListener implements Listener {
private MultiverseCore plugin; private MultiverseCore plugin;
private MVWorldManager worldManager; private MVWorldManager worldManager;
@ -87,7 +80,8 @@ public class MVEntityListener implements Listener {
public void creatureSpawn(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.
// TODO: Allow the egg thing to be a config param. Doubt this will be per world; seems silly. // TODO: Allow the egg thing to be a config param. Doubt this will be per world; seems silly.
if (event.getSpawnReason() == SpawnReason.CUSTOM || event.getSpawnReason() == SpawnReason.SPAWNER_EGG) { if (event.getSpawnReason() == SpawnReason.CUSTOM || event.getSpawnReason() == SpawnReason.SPAWNER_EGG
|| event.getSpawnReason() == SpawnReason.BREEDING) {
return; return;
} }
@ -100,53 +94,16 @@ public class MVEntityListener implements Listener {
return; return;
EntityType type = event.getEntityType(); EntityType type = event.getEntityType();
MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
/** /**
* Handle people with non-standard animals: ie a patched craftbukkit. * Handle people with non-standard animals: ie a patched craftbukkit.
*/ */
if (type == null) { if (type == null || type.getName() == null) {
this.plugin.log(Level.FINER, "Found a null typed creature."); this.plugin.log(Level.FINER, "Found a null typed creature.");
return; return;
} }
/** MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
* Animal Handling event.setCancelled(this.plugin.getMVWorldManager().getTheWorldPurger().shouldWeKillThisCreature(mvworld, event.getEntity()));
*/
if (!event.isCancelled() && (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid)) {
event.setCancelled(shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), type.getName().toUpperCase()));
}
/**
* Monster Handling
*/
if (!event.isCancelled() && (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime)) {
event.setCancelled(shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), type.getName().toUpperCase()));
}
}
private static boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
if (creatureList.isEmpty() && allowCreatureSpawning) {
// 1. There are no exceptions and animals are allowed. Save it.
return false;
} else if (creatureList.isEmpty()) {
// 2. There are no exceptions and animals are NOT allowed. Kill it.
return true;
} else if (creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) {
// 3. There ARE exceptions and animals ARE allowed. Kill it.
return true;
} else if (!creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) {
// 4. There ARE exceptions and animals ARE NOT allowed. SAVE it.
return false;
} else if (creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) {
// 5. No animals are allowed to be spawned, BUT this one can stay...
return false;
} 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
return true;
} else {
// This code should NEVER execute. I just left the verbose conditions in right now.
throw new UnsupportedOperationException();
}
} }
} }

View File

@ -0,0 +1,35 @@
/******************************************************************************
* 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.listeners;
import java.util.logging.Level;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChatEvent;
import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
@SuppressWarnings("deprecation") // this exists only for downwards compatibility
public class MVPlayerChatListener extends MVChatListener {
public MVPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
super(plugin, playerListener);
plugin.log(Level.FINE, "Registered PlayerChatEvent listener.");
}
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@EventHandler
public void playerChat(PlayerChatEvent event) {
this.playerChat(new NormalChatEvent(event));
}
}

View File

@ -21,55 +21,37 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; 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.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
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;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
* Multiverse's {@link Listener} for players. * Multiverse's {@link Listener} for players.
*/ */
public class MVPlayerListener implements Listener { public class MVPlayerListener implements Listener {
private MultiverseCore plugin; private final MultiverseCore plugin;
private MVWorldManager worldManager; private final MVWorldManager worldManager;
private PermissionTools pt; private final PermissionTools pt;
private final Map<String, String> playerWorld = new ConcurrentHashMap<String, String>();
public MVPlayerListener(MultiverseCore plugin) { public MVPlayerListener(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
worldManager = plugin.getMVWorldManager(); worldManager = plugin.getMVWorldManager();
pt = new PermissionTools(plugin); pt = new PermissionTools(plugin);
} }
/** /**
* This method is called when a player wants to chat. * @return the playerWorld-map
* @param event The Event that was fired.
*/ */
@EventHandler public Map<String, String> getPlayerWorld() {
public void playerChat(PlayerChatEvent event) { return playerWorld;
if (event.isCancelled()) {
return;
}
// Check whether the Server is set to prefix the chat with the World name.
// If not we do nothing, if so we need to check if the World has an Alias.
if (plugin.getMVConfig().getPrefixChat()) {
String world = event.getPlayer().getWorld().getName();
String prefix = "";
// If we're not a MV world, don't do anything
if (!this.worldManager.isMVWorld(world)) {
return;
}
MultiverseWorld mvworld = this.worldManager.getMVWorld(world);
if (mvworld.isHidden()) {
return;
}
prefix = mvworld.getColoredWorldString();
String format = event.getFormat();
event.setFormat("[" + prefix + "]" + format);
}
} }
/** /**
@ -128,8 +110,8 @@ public class MVPlayerListener implements Listener {
if (!p.hasPlayedBefore()) { if (!p.hasPlayedBefore()) {
this.plugin.log(Level.FINER, "Player joined for the FIRST time!"); this.plugin.log(Level.FINER, "Player joined for the FIRST time!");
if (plugin.getMVConfig().getFirstSpawnOverride()) { if (plugin.getMVConfig().getFirstSpawnOverride()) {
this.plugin.log(Level.FINE, String.format("Moving NEW player to(firstspawnoverride): %s", this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): "
worldManager.getFirstSpawnWorld().getSpawnLocation())); + worldManager.getFirstSpawnWorld().getSpawnLocation());
this.sendPlayerToDefaultWorld(p); this.sendPlayerToDefaultWorld(p);
} }
return; return;
@ -143,6 +125,7 @@ public class MVPlayerListener implements Listener {
} }
// Handle the Players GameMode setting for the new world. // Handle the Players GameMode setting for the new world.
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
playerWorld.put(p.getName(), p.getWorld().getName());
} }
/** /**
@ -153,6 +136,7 @@ public class MVPlayerListener implements Listener {
public void playerChangedWorld(PlayerChangedWorldEvent event) { 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());
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
} }
/** /**
@ -170,9 +154,8 @@ public class MVPlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void playerTeleport(PlayerTeleportEvent event) { public void playerTeleport(PlayerTeleportEvent event) {
this.plugin.log(Level.FINER, String.format( this.plugin.log(Level.FINER, "Got teleport event for player '"
"Got teleport event for player '%s' with cause '%s'", + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
event.getPlayer().getName(), event.getCause()));
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
@ -187,14 +170,15 @@ public class MVPlayerListener implements Listener {
teleporter = this.plugin.getServer().getPlayer(teleporterName); teleporter = this.plugin.getServer().getPlayer(teleporterName);
} }
} }
this.plugin.log(Level.FINER, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'", this.plugin.log(Level.FINER, "Inferred sender '" + teleporter + "' from name '"
teleporter, teleporterName, teleportee.getName())); + teleporterName + "', fetched from name '" + teleportee.getName() + "'");
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
if (fromWorld == null || toWorld == null)
return;
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
// The player is Teleporting to the same world. // The player is Teleporting to the same world.
this.plugin.log(Level.FINER, String.format("Player '%s' is teleporting to the same world.", this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world.");
teleportee.getName()));
this.stateSuccess(teleportee.getName(), toWorld.getAlias()); this.stateSuccess(teleportee.getName(), toWorld.getAlias());
return; return;
} }
@ -202,33 +186,31 @@ public class MVPlayerListener implements Listener {
// Charge the teleporter // Charge the teleporter
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true)); event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
if (event.isCancelled() && teleporter != null) { if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, String.format( this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.", + "' was DENIED ACCESS to '" + toWorld.getAlias()
teleportee.getName(), toWorld.getAlias(), teleporter.getName())); + "' because '" + teleporter.getName()
+ "' don't have the FUNDS required to enter it.");
return; return;
} }
if (plugin.getMVConfig().getEnforceAccess()) { if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee)); event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
if (event.isCancelled() && teleporter != null) { if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, String.format( this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s", + "' was DENIED ACCESS to '" + toWorld.getAlias()
teleportee.getName(), toWorld.getAlias(), teleporter.getName(), + "' because '" + teleporter.getName()
event.getTo().getWorld().getName())); + "' don't have: multiverse.access." + event.getTo().getWorld().getName());
} else { } else {
this.stateSuccess(teleportee.getName(), toWorld.getAlias()); this.stateSuccess(teleportee.getName(), toWorld.getAlias());
} }
} else { } else {
this.plugin.log(Level.FINE, String.format( this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
"Player '%s' was allowed to go to '%s' because enforceaccess is off.", + "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
teleportee.getName(), toWorld.getAlias()));
} }
} }
private void stateSuccess(String playerName, String worldName) { private void stateSuccess(String playerName, String worldName) {
this.plugin.log(Level.FINE, String.format( this.plugin.log(Level.FINE, "MV-Core is allowing Player '" + playerName
"MV-Core is allowing Player '%s' to go to '%s'.", + "' to go to '" + worldName + "'.");
playerName, worldName));
} }
/** /**
@ -279,19 +261,22 @@ public class MVPlayerListener implements Listener {
} }
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true)); event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true));
if (event.isCancelled()) { if (event.isCancelled()) {
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have the FUNDS required to enter.", this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
event.getPlayer().getName(), event.getTo().getWorld().getName())); + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
+ "' because they don't have the FUNDS required to enter.");
return; return;
} }
if (plugin.getMVConfig().getEnforceAccess()) { if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
if (event.isCancelled()) { if (event.isCancelled()) {
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because they don't have: multiverse.access.%s", this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
event.getPlayer().getName(), event.getTo().getWorld().getName(), event.getTo().getWorld().getName())); + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
+ "' because they don't have: multiverse.access." + event.getTo().getWorld().getName());
} }
} else { } else {
this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.", this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
event.getPlayer().getName(), event.getTo().getWorld().getName())); + "' was allowed to go to '" + event.getTo().getWorld().getName()
+ "' because enforceaccess is off.");
} }
} }
@ -299,6 +284,7 @@ public class MVPlayerListener implements Listener {
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this... // Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() { new Runnable() {
@Override
public void run() { public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation()); player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
} }
@ -312,8 +298,8 @@ public class MVPlayerListener implements Listener {
if (mvWorld != null) { if (mvWorld != null) {
this.handleGameMode(player, mvWorld); this.handleGameMode(player, mvWorld);
} else { } else {
this.plugin.log(Level.FINER, String.format( this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
"Not handling gamemode for world '%s' not managed by Multiverse.", world.getName())); + "' not managed by Multiverse.");
} }
} }
@ -328,24 +314,25 @@ public class MVPlayerListener implements Listener {
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) { if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() { new Runnable() {
@Override
public void run() { public void run() {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled. // Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) { if (player.getWorld() == world.getCBWorld()) {
MultiverseCore.staticLog(Level.FINE, String.format( MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: "
"Handling gamemode for player: %s, Changing to %s", + player.getName() + ", Changing to " + world.getGameMode().toString());
player.getName(), world.getGameMode().toString()));
MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld()); MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld());
MultiverseCore.staticLog(Level.FINEST, "To World: " + world); MultiverseCore.staticLog(Level.FINEST, "To World: " + world);
player.setGameMode(world.getGameMode()); player.setGameMode(world.getGameMode());
} else { } else {
MultiverseCore.staticLog(Level.FINE, MultiverseCore.staticLog(Level.FINE, "The gamemode was NOT changed for player '"
String.format("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'", + player.getName() + "' because he is now in world '"
player.getName(), player.getWorld().getName(), world.getName())); + player.getWorld().getName() + "' instead of world '"
+ world.getName() +"'");
} }
} }
}, 1L); }, 1L);
} else { } else {
this.plugin.log(Level.FINE, String.format("Player: %s is IMMUNE to gamemode changes!", player.getName())); this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
} }
} }
} }

View File

@ -0,0 +1,37 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
/**
* A wrapper for the {@link PlayerChatEvent}.
* @deprecated This is deprecated like the {@link PlayerChatEvent}.
*/
@Deprecated
public class NormalChatEvent implements ChatEvent {
private final PlayerChatEvent event;
public NormalChatEvent(PlayerChatEvent event) {
this.event = event;
}
@Override
public boolean isCancelled() {
return event.isCancelled();
}
@Override
public String getFormat() {
return event.getFormat();
}
@Override
public void setFormat(String s) {
event.setFormat(s);
}
@Override
public Player getPlayer() {
return event.getPlayer();
}
}

View File

@ -7,10 +7,14 @@
package com.onarandombox.MultiverseCore.utils; package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Handler; import java.util.logging.Handler;
@ -21,10 +25,10 @@ import java.util.logging.Logger;
/** /**
* The Multiverse debug-logger. * The Multiverse debug-logger.
*/ */
public class DebugLog { public class DebugLog extends Logger {
private FileHandler fh; private FileHandler fh;
private Logger log; private Logger standardLog = null;
private String prefix = "[MVCore-Debug] ";
/** /**
* Creates a new debug logger. * Creates a new debug logger.
@ -33,16 +37,16 @@ public class DebugLog {
* @param file The file to log to. * @param file The file to log to.
*/ */
public DebugLog(String logger, String file) { public DebugLog(String logger, String file) {
this.log = Logger.getLogger(logger); super(logger, null);
try { try {
this.fh = new FileHandler(file, true); this.fh = new FileHandler(file, true);
this.log.setUseParentHandlers(false); this.setUseParentHandlers(false);
for (Handler handler : this.log.getHandlers()) { List<Handler> toRemove = Arrays.asList(this.getHandlers());
this.log.removeHandler(handler); for (Handler handler : toRemove) {
this.removeHandler(handler);
} }
this.log.addHandler(this.fh); this.addHandler(this.fh);
this.log.setLevel(Level.ALL); this.setLevel(Level.ALL);
this.fh.setFormatter(new LogFormatter()); this.fh.setFormatter(new LogFormatter());
} catch (SecurityException e) { } catch (SecurityException e) {
e.printStackTrace(); e.printStackTrace();
@ -51,14 +55,39 @@ public class DebugLog {
} }
} }
/**
* Sets the log-tag.
* @param tag The new tag.
*/
public void setTag(String tag) {
this.prefix = tag + " ";
}
/**
* Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file.
*
* @param logger Logger to send debug messages to.
*/
public void setStandardLogger(Logger logger) {
this.standardLog = logger;
}
/** /**
* Log a message at a certain level. * Log a message at a certain level.
* *
* @param level The log-{@link Level}. * @param level The log-{@link Level}.
* @param msg the message. * @param msg the message.
*/ */
public void log(Level level, String msg) { @Override
this.log.log(level, msg); public void log(final Level level, final String msg) {
if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) {
// only redirect to standardLog if it's lower than INFO so we don't log that twice!
if ((level.intValue() < Level.INFO.intValue()) && (standardLog != null)) {
standardLog.log(Level.INFO, prefix + msg);
}
super.log(level, prefix + msg);
}
} }
/** /**

View File

@ -8,6 +8,13 @@
package com.onarandombox.MultiverseCore.utils; package com.onarandombox.MultiverseCore.utils;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;
/** /**
* File-utilities. * File-utilities.
@ -37,4 +44,58 @@ public class FileUtils {
return false; return false;
} }
} }
private static final int COPY_BLOCK_SIZE = 1024;
/**
* Helper method to copy the world-folder.
* @param source Source-File
* @param target Target-File
* @param log A logger that logs the operation
*
* @return if it had success
*/
public static boolean copyFolder(File source, File target, Logger log) {
InputStream in = null;
OutputStream out = null;
try {
if (source.isDirectory()) {
if (!target.exists())
target.mkdir();
String[] children = source.list();
// for (int i=0; i<children.length; i++) {
for (String child : children) {
copyFolder(new File(source, child), new File(target, child), log);
}
} else {
in = new FileInputStream(source);
out = new FileOutputStream(target);
byte[] buf = new byte[COPY_BLOCK_SIZE];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
}
return true;
} catch (FileNotFoundException e) {
log.warning("Exception while copying file: " + e.getMessage());
} catch (IOException e) {
log.warning("Exception while copying file: " + e.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignore) { }
}
if (out != null) {
try {
out.close();
} catch (IOException ignore) { }
}
}
return false;
}
} }

View File

@ -7,7 +7,6 @@
package com.onarandombox.MultiverseCore.utils; package com.onarandombox.MultiverseCore.utils;
import java.util.logging.Level;
import com.fernferret.allpay.GenericBank; import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@ -16,6 +15,8 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import java.util.logging.Level;
/** /**
* Utility-class for permissions. * Utility-class for permissions.
*/ */
@ -134,6 +135,10 @@ public class PermissionTools {
// Only check payments if it's a different world: // Only check payments if it's a different world:
if (!toWorld.equals(fromWorld)) { if (!toWorld.equals(fromWorld)) {
// Don't bother checking economy stuff if it doesn't even cost to enter.
if (toWorld.getPrice() == 0D) {
return true;
}
// If the player does not have to pay, return now. // If the player does not have to pay, return now.
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) { if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
return true; return true;

View File

@ -62,6 +62,16 @@ public class SimpleWorldPurger implements WorldPurger {
purgeWorld(world, allMobs, !world.canAnimalsSpawn(), !world.canMonstersSpawn()); purgeWorld(world, allMobs, !world.canAnimalsSpawn(), !world.canMonstersSpawn());
} }
/**
* {@inheritDoc}
*/
@Override
public boolean shouldWeKillThisCreature(MultiverseWorld world, Entity e) {
ArrayList<String> allMobs = new ArrayList<String>(world.getAnimalList());
allMobs.addAll(world.getMonsterList());
return this.shouldWeKillThisCreature(e, allMobs, !world.canAnimalsSpawn(), !world.canMonstersSpawn());
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -80,15 +90,25 @@ public class SimpleWorldPurger implements WorldPurger {
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll; boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll; boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
for (Entity e : world.getEntities()) { for (Entity e : world.getEntities()) {
if (killDecision(e, thingsToKill, negateAnimals, negateMonsters, specifiedAnimals, specifiedMonsters)) {
e.remove();
entitiesKilled++;
}
}
if (sender != null) {
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'");
}
}
private boolean killDecision(Entity e, List<String> thingsToKill, boolean negateAnimals,
boolean negateMonsters, boolean specifiedAnimals, boolean specifiedMonsters) {
boolean negate = false; boolean negate = false;
boolean specified = false; boolean specified = false;
if (e instanceof Squid || e instanceof Animals) { if (e instanceof Squid || e instanceof Animals) {
// it's an animal // it's an animal
if (specifiedAnimals && !negateAnimals) { if (specifiedAnimals && !negateAnimals) {
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e); this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
e.remove(); return true;
entitiesKilled++;
continue;
} }
if (specifiedAnimals) if (specifiedAnimals)
specified = true; specified = true;
@ -97,9 +117,7 @@ public class SimpleWorldPurger implements WorldPurger {
// it's a monster // it's a monster
if (specifiedMonsters && !negateMonsters) { if (specifiedMonsters && !negateMonsters) {
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e); this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
e.remove(); return true;
entitiesKilled++;
continue;
} }
if (specifiedMonsters) if (specifiedMonsters)
specified = true; specified = true;
@ -111,23 +129,28 @@ public class SimpleWorldPurger implements WorldPurger {
specified = true; specified = true;
if (!negate) { if (!negate) {
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e); this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
e.remove(); return true;
entitiesKilled++;
continue;
} }
break; break;
} }
} }
if (!specified && negate) { if (!specified && negate) {
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e); this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
e.remove(); return true;
entitiesKilled++;
continue;
} }
return false;
} }
if (sender != null) {
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'"); /**
} * {@inheritDoc}
*/
@Override
public boolean shouldWeKillThisCreature(Entity e, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {
boolean specifiedAll = thingsToKill.contains("ALL");
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
return this.killDecision(e, thingsToKill, negateAnimals, negateMonsters, specifiedAnimals, specifiedMonsters);
} }
/** /**

View File

@ -14,6 +14,8 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter; import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.WorldPurger; import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent; import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
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.WorldCreator; import org.bukkit.WorldCreator;
@ -35,18 +37,21 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Public facing API to add/remove Multiverse worlds. * Public facing API to add/remove Multiverse worlds.
*/ */
public class WorldManager implements MVWorldManager { public class WorldManager implements MVWorldManager {
private MultiverseCore plugin; private final MultiverseCore plugin;
private WorldPurger worldPurger; private final WorldPurger worldPurger;
private final Map<String, MultiverseWorld> worlds;
private Map<String, MVWorld> worldsFromTheConfig; private Map<String, MVWorld> worldsFromTheConfig;
private Map<String, MultiverseWorld> worlds;
private FileConfiguration configWorlds = null; private FileConfiguration configWorlds = null;
private Map<String, String> defaultGens; private Map<String, String> defaultGens;
private String firstSpawn; private String firstSpawn;
@ -54,7 +59,7 @@ public class WorldManager implements MVWorldManager {
public WorldManager(MultiverseCore core) { public WorldManager(MultiverseCore core) {
this.plugin = core; this.plugin = core;
this.worldsFromTheConfig = new HashMap<String, MVWorld>(); this.worldsFromTheConfig = new HashMap<String, MVWorld>();
this.worlds = new HashMap<String, MultiverseWorld>(); this.worlds = new ConcurrentHashMap<String, MultiverseWorld>();
this.worldPurger = new SimpleWorldPurger(plugin); this.worldPurger = new SimpleWorldPurger(plugin);
} }
@ -83,6 +88,87 @@ public class WorldManager implements MVWorldManager {
} }
} }
/**
* {@inheritDoc}
*/
@Override
public boolean cloneWorld(String oldName, String newName, String generator) {
// Make sure we don't already know about the new world.
if (this.isMVWorld(newName)) {
return false;
}
// Make sure the old world is actually a world!
if (this.getUnloadedWorlds().contains(oldName) || !this.isMVWorld(oldName)) {
return false;
}
final File oldWorldFile = new File(this.plugin.getServer().getWorldContainer(), oldName);
final File newWorldFile = new File(this.plugin.getServer().getWorldContainer(), newName);
// Make sure the new world doesn't exist outside of multiverse.
if (newWorldFile.exists()) {
return false;
}
unloadWorld(oldName);
removePlayersFromWorld(oldName);
StringBuilder builder = new StringBuilder();
builder.append("Copying data for world '").append(oldName).append("'...");
this.plugin.log(Level.INFO, builder.toString());
try {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
FileUtils.copyFolder(oldWorldFile, newWorldFile, Logger.getLogger("Minecraft"));
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
// do nothing
}
File uidFile = new File(newWorldFile, "uid.dat");
uidFile.delete();
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
this.plugin.log(Level.INFO, "Kind of copied stuff");
WorldCreator worldCreator = new WorldCreator(newName);
this.plugin.log(Level.INFO, "Started to copy settings");
worldCreator.copy(this.getMVWorld(oldName).getCBWorld());
this.plugin.log(Level.INFO, "Copied lots of settings");
boolean useSpawnAdjust = this.getMVWorld(oldName).getAdjustSpawn();
this.plugin.log(Level.INFO, "Copied more settings");
Environment environment = worldCreator.environment();
this.plugin.log(Level.INFO, "Copied most settings");
if (newWorldFile.exists()) {
this.plugin.log(Level.INFO, "Succeeded at copying stuff");
if (this.addWorld(newName, environment, null, null, null, generator, useSpawnAdjust)) {
// getMVWorld() doesn't actually return an MVWorld
this.plugin.log(Level.INFO, "Succeeded at importing stuff");
MVWorld newWorld = (MVWorld) this.getMVWorld(newName);
MVWorld oldWorld = (MVWorld) this.getMVWorld(oldName);
newWorld.copyValues(oldWorld);
try {
// don't keep the alias the same -- that would be useless
newWorld.setPropertyValue("alias", newName);
} catch (PropertyDoesNotExistException e) {
// this should never happen
throw new RuntimeException(e);
}
return true;
}
}
return false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -137,7 +223,7 @@ public class WorldManager implements MVWorldManager {
} }
this.plugin.log(Level.INFO, builder.toString()); this.plugin.log(Level.INFO, builder.toString());
if (!doLoad(c)) { if (!doLoad(c, true)) {
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'"); this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
return false; return false;
} }
@ -237,6 +323,8 @@ public class WorldManager implements MVWorldManager {
this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's loaded in memory."); this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's loaded in memory.");
this.plugin.log(Level.WARNING, "To let Multiverse know about it, use:"); this.plugin.log(Level.WARNING, "To let Multiverse know about it, use:");
this.plugin.log(Level.WARNING, String.format("/mv import %s %s", name, this.plugin.getServer().getWorld(name).getEnvironment().toString())); this.plugin.log(Level.WARNING, String.format("/mv import %s %s", name, this.plugin.getServer().getWorld(name).getEnvironment().toString()));
} else if (this.worldsFromTheConfig.containsKey(name)) {
return true; // it's already unloaded
} else { } else {
this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit."); this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit.");
} }
@ -268,6 +356,10 @@ public class WorldManager implements MVWorldManager {
} }
private boolean doLoad(String name) { private boolean doLoad(String name) {
return doLoad(name, false);
}
private boolean doLoad(String name, boolean ignoreExists) {
if (!worldsFromTheConfig.containsKey(name)) if (!worldsFromTheConfig.containsKey(name))
throw new IllegalArgumentException("That world doesn't exist!"); throw new IllegalArgumentException("That world doesn't exist!");
@ -278,15 +370,22 @@ public class WorldManager implements MVWorldManager {
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null"))) if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
creator.generator(world.getGenerator()); creator.generator(world.getGenerator());
return doLoad(creator); return doLoad(creator, ignoreExists);
} }
private boolean doLoad(WorldCreator creator) { private boolean doLoad(WorldCreator creator, boolean ignoreExists) {
String worldName = creator.name(); String worldName = creator.name();
if (!worldsFromTheConfig.containsKey(worldName)) if (!worldsFromTheConfig.containsKey(worldName))
throw new IllegalArgumentException("That world doesn't exist!"); throw new IllegalArgumentException("That world doesn't exist!");
if (worlds.containsKey(worldName)) if (worlds.containsKey(worldName))
throw new IllegalArgumentException("That world is already loaded!"); throw new IllegalArgumentException("That world is already loaded!");
if (!ignoreExists && !new File(this.plugin.getServer().getWorldContainer(), worldName).exists()) {
this.plugin.log(Level.WARNING, "WorldManager: Can't load this world because the folder was deleted/moved: " + worldName);
this.plugin.log(Level.WARNING, "Use '/mv remove' to remove it from the config!");
return false;
}
MVWorld mvworld = worldsFromTheConfig.get(worldName); MVWorld mvworld = worldsFromTheConfig.get(worldName);
World cbworld; World cbworld;
try { try {
@ -403,8 +502,12 @@ public class WorldManager implements MVWorldManager {
*/ */
@Override @Override
public MultiverseWorld getMVWorld(String name) { public MultiverseWorld getMVWorld(String name) {
if (this.worlds.containsKey(name)) { if (name == null) {
return this.worlds.get(name); return null;
}
MultiverseWorld world = this.worlds.get(name);
if (world != null) {
return world;
} }
return this.getMVWorldByAlias(name); return this.getMVWorldByAlias(name);
} }
@ -439,7 +542,7 @@ public class WorldManager implements MVWorldManager {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isMVWorld(String name) { public boolean isMVWorld(final String name) {
return (this.worlds.containsKey(name) || isMVWorldAlias(name)); return (this.worlds.containsKey(name) || isMVWorldAlias(name));
} }
@ -457,7 +560,7 @@ public class WorldManager implements MVWorldManager {
* @param alias The alias of the world to check. * @param alias The alias of the world to check.
* @return True if the world exists, false if not. * @return True if the world exists, false if not.
*/ */
private boolean isMVWorldAlias(String alias) { private boolean isMVWorldAlias(final String alias) {
for (MultiverseWorld w : this.worlds.values()) { for (MultiverseWorld w : this.worlds.values()) {
if (w.getAlias().equalsIgnoreCase(alias)) { if (w.getAlias().equalsIgnoreCase(alias)) {
return true; return true;
@ -527,8 +630,9 @@ public class WorldManager implements MVWorldManager {
} }
for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) { for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) {
if (worlds.containsKey(entry.getKey())) if (worlds.containsKey(entry.getKey())) {
continue; continue;
}
if (!entry.getValue().getAutoLoad()) if (!entry.getValue().getAutoLoad())
continue; continue;
@ -592,19 +696,24 @@ public class WorldManager implements MVWorldManager {
Object obj = this.configWorlds.get(path); Object obj = this.configWorlds.get(path);
if ((obj != null) && (obj instanceof MVWorld)) { if ((obj != null) && (obj instanceof MVWorld)) {
String worldName = key.replaceAll(String.valueOf(SEPARATOR), "."); String worldName = key.replaceAll(String.valueOf(SEPARATOR), ".");
MVWorld mvWorld = null;
if (this.worldsFromTheConfig.containsKey(worldName)) { if (this.worldsFromTheConfig.containsKey(worldName)) {
// Object-Recycling :D // Object-Recycling :D
MVWorld oldMVWorld = (MVWorld) this.worlds.get(worldName); // TODO Why is is checking worldsFromTheConfig and then getting from worlds? So confused... (DTM)
oldMVWorld.copyValues((MVWorld) obj); mvWorld = (MVWorld) this.worlds.get(worldName);
newWorldsFromTheConfig.put(worldName, oldMVWorld); if (mvWorld != null) {
} else { mvWorld.copyValues((MVWorld) obj);
}
}
if (mvWorld == null) {
// we have to use a new one // we have to use a new one
World cbworld = this.plugin.getServer().getWorld(worldName); World cbworld = this.plugin.getServer().getWorld(worldName);
MVWorld mvworld = (MVWorld) obj; mvWorld = (MVWorld) obj;
if (cbworld != null) if (cbworld != null) {
mvworld.init(cbworld, this.plugin); mvWorld.init(cbworld, this.plugin);
newWorldsFromTheConfig.put(worldName, mvworld);
} }
}
newWorldsFromTheConfig.put(worldName, mvWorld);
} else if (this.configWorlds.isConfigurationSection(path)) { } else if (this.configWorlds.isConfigurationSection(path)) {
ConfigurationSection section = this.configWorlds.getConfigurationSection(path); ConfigurationSection section = this.configWorlds.getConfigurationSection(path);
Set<String> subkeys = section.getKeys(false); Set<String> subkeys = section.getKeys(false);
@ -655,6 +764,46 @@ public class WorldManager implements MVWorldManager {
return allNames; return allNames;
} }
/**
* {@inheritDoc}
*/
@Override
public boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed) {
MultiverseWorld world = this.getMVWorld(name);
if (world == null)
return false;
List<Player> ps = world.getCBWorld().getPlayers();
if (useNewSeed) {
long theSeed;
if (randomSeed) {
theSeed = new Random().nextLong();
} else {
try {
theSeed = Long.parseLong(seed);
} catch (NumberFormatException e) {
theSeed = seed.hashCode();
}
}
world.setSeed(theSeed);
}
if (this.deleteWorld(name, false)) {
this.doLoad(name, true);
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
Location newSpawn = world.getSpawnLocation();
// Send all players that were in the old world, BACK to it!
for (Player p : ps) {
teleporter.safelyTeleport(null, p, newSpawn, true);
}
return true;
}
return false;
}
/** /**
* Gets the {@link FileConfiguration} that this {@link WorldManager} is using. * Gets the {@link FileConfiguration} that this {@link WorldManager} is using.
* @return The {@link FileConfiguration} that this {@link WorldManager} is using. * @return The {@link FileConfiguration} that this {@link WorldManager} is using.

View File

@ -202,3 +202,12 @@ commands:
description: Regenerates a world Multiverse already knows about. description: Regenerates a world Multiverse already knows about.
usage: | usage: |
/<command> {WORLD} /<command> {WORLD}
mvscript:
description: Runs a script from the Multiverse scripts directory.
usage: |
/<command> {script} [target]
mvclone:
description: World clone command
usage: |
/<command> <world> <environment>
/<command> creative grieftastic -- Creates a world called 'grieftastic' exactly identical to the world 'creative'.

View File

@ -23,7 +23,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;

View File

@ -0,0 +1,158 @@
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
public class TestEntitySpawnRules {
TestInstanceCreator creator;
MultiverseCore core;
MVEntityListener listener;
MultiverseWorld mvWorld;
World cbworld;
Sheep sheep;
Zombie zombie;
CreatureSpawnEvent sheepEvent;
CreatureSpawnEvent zombieEvent;
@Before
public void setUp() throws Exception {
creator = new TestInstanceCreator();
assertTrue(creator.setUp());
core = creator.getCore();
listener = core.getEntityListener();
mvWorld = mock(MultiverseWorld.class);
cbworld = mock(World.class);
when(mvWorld.getCBWorld()).thenReturn(cbworld);
MVWorldManager worldman = mock(MVWorldManager.class);
when(worldman.isMVWorld(anyString())).thenReturn(true);
when(worldman.getMVWorld(anyString())).thenReturn(mvWorld);
Field worldmanfield = MVEntityListener.class.getDeclaredField("worldManager");
worldmanfield.setAccessible(true);
worldmanfield.set(listener, worldman);
core.getMVConfig().setGlobalDebug(3);
}
@After
public void tearDown() throws Exception {
creator.tearDown();
}
private static CreatureSpawnEvent mockSpawnEvent(LivingEntity e, SpawnReason reason) {
CreatureSpawnEvent event = mock(CreatureSpawnEvent.class);
when(event.getEntity()).thenReturn(e);
EntityType type = e.getType();
when(event.getEntityType()).thenReturn(type);
when(event.getSpawnReason()).thenReturn(reason);
return event;
}
private void spawnAll(SpawnReason reason) {
sheepEvent = mockSpawnEvent(sheep, reason);
zombieEvent = mockSpawnEvent(zombie, reason);
listener.creatureSpawn(sheepEvent);
listener.creatureSpawn(zombieEvent);
}
private void spawnAllNatural() {
spawnAll(SpawnReason.NATURAL);
}
private void adjustSettings(boolean animalSpawn, boolean monsterSpawn,
List<String> animalExceptions, List<String> monsterExceptions) {
when(this.mvWorld.canAnimalsSpawn()).thenReturn(animalSpawn);
when(this.mvWorld.canMonstersSpawn()).thenReturn(monsterSpawn);
when(this.mvWorld.getAnimalList()).thenReturn(animalExceptions);
when(this.mvWorld.getMonsterList()).thenReturn(monsterExceptions);
}
@Test
public void test() {
// test 1: no spawning at all allowed
adjustSettings(false, false, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
createAnimals();
spawnAllNatural();
verify(sheepEvent).setCancelled(true);
verify(zombieEvent).setCancelled(true);
// test 2: only monsters
adjustSettings(false, true, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
createAnimals();
spawnAllNatural();
verify(sheepEvent).setCancelled(true);
verify(zombieEvent).setCancelled(false);
// test 3: all spawning allowed
adjustSettings(true, true, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
createAnimals();
spawnAllNatural();
verify(sheepEvent).setCancelled(false);
verify(zombieEvent).setCancelled(false);
// test 4: no spawning with zombie exception
adjustSettings(false, false, Collections.EMPTY_LIST, Arrays.asList("ZOMBIE"));
createAnimals();
spawnAllNatural();
verify(sheepEvent).setCancelled(true);
verify(zombieEvent).setCancelled(false);
// test 5: all spawning with sheep exception
adjustSettings(true, true, Arrays.asList("SHEEP"), Collections.EMPTY_LIST);
createAnimals();
spawnAllNatural();
verify(sheepEvent).setCancelled(true);
verify(zombieEvent).setCancelled(false);
// test 6: eggs
adjustSettings(false, false, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
createAnimals();
spawnAll(SpawnReason.SPAWNER_EGG);
verify(sheepEvent, never()).setCancelled(anyBoolean());
verify(zombieEvent, never()).setCancelled(anyBoolean());
}
private void createAnimals() {
sheep = mock(Sheep.class);
when(sheep.getType()).thenReturn(EntityType.SHEEP);
when(sheep.getWorld()).thenReturn(this.cbworld);
zombie = mock(Zombie.class);
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
when(zombie.getWorld()).thenReturn(this.cbworld);
when(cbworld.getEntities()).thenReturn(Arrays.asList((Entity) sheep, (Entity) zombie));
}
}

View File

@ -7,12 +7,14 @@
package com.onarandombox.MultiverseCore.test; package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*; import com.onarandombox.MultiverseCore.MVWorld;
import static org.mockito.Matchers.any; import com.onarandombox.MultiverseCore.MultiverseCore;
import static org.mockito.Matchers.anyString; import com.onarandombox.MultiverseCore.api.MVWorldManager;
import static org.mockito.Mockito.*; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
import java.io.File; import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
@ -27,7 +29,7 @@ import org.bukkit.entity.Player;
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;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.weather.ThunderChangeEvent;
@ -44,17 +46,16 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import com.onarandombox.MultiverseCore.MVWorld; import java.io.File;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager; import static org.junit.Assert.*;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import static org.mockito.Matchers.any;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation; import static org.mockito.Matchers.anyString;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; import static org.mockito.Mockito.*;
import com.onarandombox.MultiverseCore.utils.WorldManager;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, @PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
WeatherChangeEvent.class, ThunderChangeEvent.class, PlayerChatEvent.class, WeatherChangeEvent.class, ThunderChangeEvent.class, AsyncPlayerChatEvent.class,
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class, PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class }) FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class })
public class TestWorldProperties { public class TestWorldProperties {
@ -68,7 +69,7 @@ public class TestWorldProperties {
private ThunderChangeEvent thunderChangeOffEvent; private ThunderChangeEvent thunderChangeOffEvent;
private ThunderChangeEvent thunderChangeOnEvent; private ThunderChangeEvent thunderChangeOnEvent;
private Player mockPlayer; private Player mockPlayer;
private PlayerChatEvent playerChatEvent; private AsyncPlayerChatEvent playerChatEvent;
private Player mockNewPlayer; private Player mockNewPlayer;
private PlayerJoinEvent playerNewJoinEvent; private PlayerJoinEvent playerNewJoinEvent;
private PlayerJoinEvent playerJoinEvent; private PlayerJoinEvent playerJoinEvent;
@ -167,10 +168,10 @@ public class TestWorldProperties {
// call player chat event // call player chat event
core.getMVConfig().setPrefixChat(true); core.getMVConfig().setPrefixChat(true);
core.getPlayerListener().playerChat(playerChatEvent); ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format"); verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
core.getMVConfig().setPrefixChat(false); core.getMVConfig().setPrefixChat(false);
core.getPlayerListener().playerChat(playerChatEvent); ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!) verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
// call player join events // call player join events
@ -261,15 +262,15 @@ public class TestWorldProperties {
// call player chat event // call player chat event
core.getMVConfig().setPrefixChat(true); core.getMVConfig().setPrefixChat(true);
core.getPlayerListener().playerChat(playerChatEvent); ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
// never because it's hidden! // never because it's hidden!
verify(playerChatEvent, never()).setFormat( verify(playerChatEvent, never()).setFormat(
"[" + mvWorld.getColoredWorldString() + "]" + "format"); "[" + mvWorld.getColoredWorldString() + "]" + "format");
mvWorld.setHidden(false); mvWorld.setHidden(false);
core.getPlayerListener().playerChat(playerChatEvent); ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format"); verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
core.getMVConfig().setPrefixChat(false); core.getMVConfig().setPrefixChat(false);
core.getPlayerListener().playerChat(playerChatEvent); ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!) verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
mvWorld.setHidden(true); // reset hidden-state mvWorld.setHidden(true); // reset hidden-state
@ -344,7 +345,8 @@ public class TestWorldProperties {
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld()); when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
when(mockPlayer.hasPlayedBefore()).thenReturn(true); when(mockPlayer.hasPlayedBefore()).thenReturn(true);
when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true); when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true);
playerChatEvent = PowerMockito.mock(PlayerChatEvent.class); when(mockPlayer.getName()).thenReturn("MultiverseMan");
playerChatEvent = PowerMockito.mock(AsyncPlayerChatEvent.class);
when(playerChatEvent.getPlayer()).thenReturn(mockPlayer); when(playerChatEvent.getPlayer()).thenReturn(mockPlayer);
when(playerChatEvent.getFormat()).thenReturn("format"); when(playerChatEvent.getFormat()).thenReturn("format");
// player join // player join

View File

@ -39,6 +39,7 @@ public class MockWorldFactory {
private static void registerWorld(World world) { private static void registerWorld(World world) {
createdWorlds.put(world.getName(), world); createdWorlds.put(world.getName(), world);
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
} }
private static World basics(String world, World.Environment env, WorldType type) { private static World basics(String world, World.Environment env, WorldType type) {
@ -213,6 +214,8 @@ public class MockWorldFactory {
} }
public static void clearWorlds() { public static void clearWorlds() {
for (String name : createdWorlds.keySet())
new File(TestInstanceCreator.worldsDirectory, name).delete();
createdWorlds.clear(); createdWorlds.clear();
} }
} }

View File

@ -7,18 +7,15 @@
package com.onarandombox.MultiverseCore.test.utils; package com.onarandombox.MultiverseCore.test.utils;
import static org.mockito.Matchers.anyString; import buscript.Buscript;
import static org.mockito.Mockito.*; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import java.io.File; import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import java.lang.reflect.Field; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import java.util.ArrayList; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import java.util.List; import com.onarandombox.MultiverseCore.utils.FileUtils;
import java.util.logging.Level; import com.onarandombox.MultiverseCore.utils.WorldManager;
import java.util.logging.Logger;
import junit.framework.Assert; import junit.framework.Assert;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
@ -37,15 +34,17 @@ import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.MockGateway; import org.powermock.core.MockGateway;
import com.onarandombox.MultiverseCore.MultiverseCore; import java.io.File;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import java.lang.reflect.Field;
import com.onarandombox.MultiverseCore.localization.MessageProvider; import com.onarandombox.MultiverseCore.localization.MessageProvider;
import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider; import com.onarandombox.MultiverseCore.localization.SimpleMessageProvider;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import java.util.ArrayList;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import java.util.List;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; import java.util.logging.Level;
import com.onarandombox.MultiverseCore.utils.FileUtils; import java.util.logging.Logger;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
public class TestInstanceCreator { public class TestInstanceCreator {
private MultiverseCore core; private MultiverseCore core;
@ -64,6 +63,12 @@ public class TestInstanceCreator {
MockGateway.MOCK_STANDARD_METHODS = false; MockGateway.MOCK_STANDARD_METHODS = false;
core = PowerMockito.spy(new MultiverseCore()); core = PowerMockito.spy(new MultiverseCore());
PowerMockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null; // don't run metrics in tests
}
}).when(core, "setupMetrics");
// Let's let all MV files go to bin/test // Let's let all MV files go to bin/test
doReturn(pluginDirectory).when(core).getDataFolder(); doReturn(pluginDirectory).when(core).getDataFolder();
@ -85,6 +90,8 @@ public class TestInstanceCreator {
when(mockPluginManager.getPlugins()).thenReturn(plugins); when(mockPluginManager.getPlugins()).thenReturn(plugins);
when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core); when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
when(mockPluginManager.getPermission(anyString())).thenReturn(null); when(mockPluginManager.getPermission(anyString())).thenReturn(null);
// Tell Buscript Vault is not available.
when(mockPluginManager.getPermission("Vault")).thenReturn(null);
// Make some fake folders to fool the fake MV into thinking these worlds exist // Make some fake folders to fool the fake MV into thinking these worlds exist
File worldNormalFile = new File(core.getServerFolder(), "world"); File worldNormalFile = new File(core.getServerFolder(), "world");
@ -183,6 +190,13 @@ public class TestInstanceCreator {
serverfield.setAccessible(true); serverfield.setAccessible(true);
serverfield.set(core, mockServer); serverfield.set(core, mockServer);
// Set buscript
Buscript buscript = PowerMockito.spy(new Buscript(core));
Field buscriptfield = MultiverseCore.class.getDeclaredField("buscript");
buscriptfield.setAccessible(true);
buscriptfield.set(core, buscript);
when(buscript.getPlugin()).thenReturn(core);
// Set worldManager // Set worldManager
WorldManager wm = PowerMockito.spy(new WorldManager(core)); WorldManager wm = PowerMockito.spy(new WorldManager(core));
Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager"); Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager");
@ -265,6 +279,8 @@ public class TestInstanceCreator {
return false; return false;
} }
core.onDisable();
FileUtils.deleteFolder(serverDirectory); FileUtils.deleteFolder(serverDirectory);
MockWorldFactory.clearWorlds(); MockWorldFactory.clearWorlds();