Compare commits

..
Author SHA1 Message Date
main() 10fe24a018 Replaced respawnworld and bedspawn with respawnDestination
Not tested at all
Experimental
Handle with care
I'm tired
2012-10-22 21:25:46 +02:00
57 changed files with 1059 additions and 2147 deletions

No files matched your search

+3 -17
View File
@@ -185,7 +185,6 @@
<include>com.dumptruckman.minecraft:buscript</include>
<include>org.mcstats:metrics</include>
<include>com.dumptruckman.minecraft:Logging</include>
<include>com.dumptruckman.minecraft:Permissions-Bukkit</include>
<include>com.fernferret.allpay:AllPay</include>
</includes>
</artifactSet>
@@ -214,10 +213,6 @@
<pattern>com.dumptruckman.minecraft.util.Logging</pattern>
<shadedPattern>com.onarandombox.MultiverseCore.utils.CoreLogging</shadedPattern>
</relocation>
<relocation>
<pattern>com.dumptruckman.minecraft.pluginbase</pattern>
<shadedPattern>com.onarandombox.MultiverseCore.pluginbase</shadedPattern>
</relocation>
<relocation>
<pattern>com.dumptruckman.minecraft.util.DebugLog</pattern>
<shadedPattern>com.onarandombox.MultiverseCore.utils.DebugFileLogger</shadedPattern>
@@ -235,7 +230,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.5-R0.2</version>
<version>1.3.2-R2.1-SNAPSHOT</version>
<!-- If you want the lates, use this -->
<!-- <version>LATEST</version> -->
<type>jar</type>
@@ -253,7 +248,7 @@
<dependency>
<groupId>me.main__.util</groupId>
<artifactId>SerializationConfig</artifactId>
<version>1.7</version>
<version>1.6b</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
@@ -305,20 +300,11 @@
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>Logging</artifactId>
<version>1.0.9</version>
<version>1.0.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Logging Dependency -->
<!-- Start of Permissions lib Dependency -->
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>Permissions-Bukkit</artifactId>
<version>1.5-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- End of Permissions lib Dependency -->
<!-- Start of Test Dependencies -->
<dependency>
<groupId>junit</groupId>
File diff suppressed because it is too large. Load diff
@@ -8,11 +8,9 @@
package com.onarandombox.MultiverseCore;
import buscript.Buscript;
import com.dumptruckman.minecraft.pluginbase.permission.BukkitPermFactory;
import com.dumptruckman.minecraft.util.Logging;
import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank;
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
@@ -32,8 +30,6 @@ 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.GameruleCommand;
import com.onarandombox.MultiverseCore.commands.GamerulesCommand;
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
import com.onarandombox.MultiverseCore.commands.HelpCommand;
import com.onarandombox.MultiverseCore.commands.ImportCommand;
@@ -51,7 +47,6 @@ 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.SilentCommand;
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
@@ -65,10 +60,10 @@ import com.onarandombox.MultiverseCore.destination.ExactDestination;
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
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.MVMapListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
@@ -81,14 +76,12 @@ 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.VaultHandler;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
import me.main__.util.SerializationConfig.NoSuchPropertyException;
import me.main__.util.SerializationConfig.SerializationConfig;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
@@ -98,7 +91,12 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
@@ -118,7 +116,7 @@ import java.util.logging.Level;
/**
* The implementation of the Multiverse-{@link Core}.
*/
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listener {
private static final int PROTOCOL = 18;
// TODO: Investigate if this one is really needed to be static.
// Doubt it. -- FernFerret
@@ -149,7 +147,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* @param teleportee The name of the player that was teleported.
*/
public static void addPlayerToTeleportQueue(String teleporter, String teleportee) {
Logging.finest("Adding mapping '%s' => '%s' to teleport queue", teleporter, teleportee);
Logging.finest( "Adding mapping '%s' => '%s' to teleport queue", teleporter, teleportee);
teleportQueue.put(teleportee, teleporter);
}
@@ -208,7 +206,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// HashMap to contain information relating to the Players.
private HashMap<String, MVPlayerSession> playerSessions;
private VaultHandler vaultHandler;
private Economy vaultEco = null;
private GenericBank bank = null;
private AllPay banker;
private Buscript buscript;
@@ -224,13 +222,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
@Override
public void onLoad() {
// Register permission handler
BukkitPermFactory.registerPermissionName(getClass(), "multiverse");
BukkitPermFactory.registerPermissionName(Core.class, "multiverse");
// Register our config
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
// Register our world
SerializationConfig.registerAll(WorldProperties.class);
SerializationConfig.registerAll(MVWorld.class);
// Create our DataFolder
getDataFolder().mkdirs();
// Setup our Debug Log
@@ -256,7 +251,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
* @deprecated Now using Vault.
*/
@Override
@Deprecated
@@ -264,9 +258,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return this.bank;
}
/**
* {@inheritDoc}
*/
@Override
public VaultHandler getVaultHandler() {
return vaultHandler;
public Economy getVaultEconomy() {
return vaultEco;
}
/**
@@ -276,7 +273,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public void onEnable() {
this.messaging = new MVMessaging();
this.banker = new AllPay(this, LOG_TAG + " ");
this.vaultHandler = new VaultHandler(this);
// Output a little snippet to show it's enabled.
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + PROTOCOL + ") Enabled - By " + getAuthors());
// Load the defaultWorldGenerators
this.worldManager.getDefaultWorldGenerators();
@@ -305,10 +303,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup & Load our Configuration files.
loadConfigs();
if (this.multiverseConfig != null) {
Logging.setDebugLevel(getMVConfig().getGlobalDebug());
Logging.setShowingConfig(!getMVConfig().getSilentStart());
this.worldManager.loadDefaultWorlds();
this.worldManager.loadWorlds(true);
Logging.setDebugLevel(getMVConfig().getGlobalDebug());
} else {
this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse.");
}
@@ -344,9 +341,43 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.initializeBuscript();
this.setupMetrics();
// Listen out for vault.
getServer().getPluginManager().registerEvents(this, this);
this.setupVaultEconomy();
}
// Output a little snippet to show it's enabled.
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors());
private boolean setupVaultEconomy() {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
final RegisteredServiceProvider<Economy> economyProvider
= getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
Logging.fine("Vault economy enabled.");
vaultEco = economyProvider.getProvider();
} else {
Logging.finer("Vault economy not detected.");
vaultEco = null;
}
} else {
Logging.finer("Vault was not found.");
vaultEco = null;
}
return (vaultEco != null);
}
@EventHandler
private void vaultEnabled(PluginEnableEvent event) {
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
setupVaultEconomy();
}
}
@EventHandler
private void vaultDisabled(PluginDisableEvent event) {
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
Logging.fine("Vault economy disabled");
setupVaultEconomy();
}
}
/**
@@ -470,7 +501,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
pm.registerEvents(this.pluginListener, this);
pm.registerEvents(this.weatherListener, this);
pm.registerEvents(this.portalListener, this);
pm.registerEvents(new MVMapListener(this), this);
}
/**
@@ -513,47 +544,47 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/
private void migrate22Values() {
if (this.multiverseConfig.isSet("worldnameprefix")) {
Logging.config("Migrating 'worldnameprefix'...");
this.log(Level.INFO, "Migrating 'worldnameprefix'...");
this.getMVConfig().setPrefixChat(this.multiverseConfig.getBoolean("worldnameprefix"));
this.multiverseConfig.set("worldnameprefix", null);
}
if (this.multiverseConfig.isSet("firstspawnworld")) {
Logging.config("Migrating 'firstspawnworld'...");
this.log(Level.INFO, "Migrating 'firstspawnworld'...");
this.getMVConfig().setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld"));
this.multiverseConfig.set("firstspawnworld", null);
}
if (this.multiverseConfig.isSet("enforceaccess")) {
Logging.config("Migrating 'enforceaccess'...");
this.log(Level.INFO, "Migrating 'enforceaccess'...");
this.getMVConfig().setEnforceAccess(this.multiverseConfig.getBoolean("enforceaccess"));
this.multiverseConfig.set("enforceaccess", null);
}
if (this.multiverseConfig.isSet("displaypermerrors")) {
Logging.config("Migrating 'displaypermerrors'...");
this.log(Level.INFO, "Migrating 'displaypermerrors'...");
this.getMVConfig().setDisplayPermErrors(this.multiverseConfig.getBoolean("displaypermerrors"));
this.multiverseConfig.set("displaypermerrors", null);
}
if (this.multiverseConfig.isSet("teleportintercept")) {
Logging.config("Migrating 'teleportintercept'...");
this.log(Level.INFO, "Migrating 'teleportintercept'...");
this.getMVConfig().setTeleportIntercept(this.multiverseConfig.getBoolean("teleportintercept"));
this.multiverseConfig.set("teleportintercept", null);
}
if (this.multiverseConfig.isSet("firstspawnoverride")) {
Logging.config("Migrating 'firstspawnoverride'...");
this.log(Level.INFO, "Migrating 'firstspawnoverride'...");
this.getMVConfig().setFirstSpawnOverride(this.multiverseConfig.getBoolean("firstspawnoverride"));
this.multiverseConfig.set("firstspawnoverride", null);
}
if (this.multiverseConfig.isSet("messagecooldown")) {
Logging.config("Migrating 'messagecooldown'...");
this.log(Level.INFO, "Migrating 'messagecooldown'...");
this.getMVConfig().setMessageCooldown(this.multiverseConfig.getInt("messagecooldown"));
this.multiverseConfig.set("messagecooldown", null);
}
if (this.multiverseConfig.isSet("debug")) {
Logging.config("Migrating 'debug'...");
this.log(Level.INFO, "Migrating 'debug'...");
this.getMVConfig().setGlobalDebug(this.multiverseConfig.getInt("debug"));
this.multiverseConfig.set("debug", null);
}
if (this.multiverseConfig.isSet("version")) {
Logging.config("Migrating 'version'...");
this.log(Level.INFO, "Migrating 'version'...");
this.multiverseConfig.set("version", null);
}
}
@@ -575,13 +606,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
boolean wasChanged = false;
Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
for (Map.Entry<String, Object> entry : values.entrySet()) {
if (entry.getValue() instanceof WorldProperties) {
if (entry.getValue() instanceof MVWorld) {
// fine
newValues.put(entry.getKey(), entry.getValue());
} else if (entry.getValue() instanceof ConfigurationSection) {
this.log(Level.FINE, "Migrating: " + entry.getKey());
// we have to migrate this
WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
ConfigurationSection section = (ConfigurationSection) entry.getValue();
// migrate animals and monsters
@@ -651,9 +682,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// migrate gamemode
if (section.isString("gamemode")) {
final GameMode gameMode = GameMode.valueOf(section.getString("gamemode").toUpperCase());
if (gameMode != null) {
world.setGameMode(gameMode);
try {
world.setPropertyValue("gamemode", section.getString("gamemode"));
} catch (PropertyDoesNotExistException e) {
throw new RuntimeException("Who forgot to update the migrator?", e);
}
}
@@ -675,8 +707,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// migrate portalform
if (section.isString("portalform")) {
try {
world.setProperty("portalform", section.getString("portalform"), true);
} catch (NoSuchPropertyException e) {
world.setPropertyValue("portalform", section.getString("portalform"));
} catch (PropertyDoesNotExistException e) {
throw new RuntimeException("Who forgot to update the migrator?", e);
}
}
@@ -684,8 +716,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// migrate environment
if (section.isString("environment")) {
try {
world.setProperty("environment", section.getString("environment"), true);
} catch (NoSuchPropertyException e) {
world.setPropertyValue("environment", section.getString("environment"));
} catch (PropertyDoesNotExistException e) {
throw new RuntimeException("Who forgot to update the migrator?", e);
}
}
@@ -723,7 +755,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// migrate spawn
if (section.isConfigurationSection("spawn")) {
ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
Location spawnLoc = new NullLocation();
Location spawnLoc = world.getSpawnLocation();
if (spawnSect.isDouble("yaw"))
spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
if (spawnSect.isDouble("pitch"))
@@ -738,19 +770,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
world.setSpawnLocation(spawnLoc);
}
// migrate difficulty
if (section.isString("difficulty")) {
final Difficulty difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
if (difficulty != null) {
world.setDifficulty(difficulty);
}
}
// migrate keepspawninmemory
if (section.isBoolean("keepspawninmemory")) {
world.setKeepSpawnInMemory(section.getBoolean("keepspawninmemory"));
}
newValues.put(entry.getKey(), world);
wasChanged = true;
} else {
@@ -825,12 +844,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Misc Commands
this.commandHandler.registerCommand(new EnvironmentCommand(this));
this.commandHandler.registerCommand(new DebugCommand(this));
this.commandHandler.registerCommand(new SilentCommand(this));
this.commandHandler.registerCommand(new GeneratorCommand(this));
this.commandHandler.registerCommand(new CheckCommand(this));
this.commandHandler.registerCommand(new ScriptCommand(this));
this.commandHandler.registerCommand(new GameruleCommand(this));
this.commandHandler.registerCommand(new GamerulesCommand(this));
}
/**
@@ -841,6 +857,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.saveMVConfigs();
this.banker = null;
this.bank = null;
log(Level.INFO, "- Disabled");
Logging.shutdown();
}
@@ -1028,7 +1045,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
* @deprecated Now using Vault.
*/
@Override
@Deprecated
@@ -1038,7 +1054,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
/**
* {@inheritDoc}
* @deprecated Now using Vault.
*/
@Override
@Deprecated
@@ -54,8 +54,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
@Property
private volatile int globaldebug;
@Property
private volatile boolean silentstart;
@Property
private volatile int messagecooldown;
@Property
private volatile double version;
@@ -63,10 +61,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
private volatile String firstspawnworld;
@Property
private volatile int teleportcooldown;
@Property
private volatile boolean defaultportalsearch;
@Property
private volatile int portalsearchradius;
public MultiverseCoreConfiguration() {
super();
@@ -94,9 +88,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
messagecooldown = 5000;
teleportcooldown = 1000;
this.version = 2.9;
silentstart = false;
defaultportalsearch = false;
portalsearchradius = 16;
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
}
@@ -284,35 +275,4 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
public boolean getUseAsyncChat() {
return this.useasyncchat;
}
@Override
public void setSilentStart(boolean silentStart) {
Logging.setShowingConfig(!silentStart);
this.silentstart = silentStart;
}
@Override
public boolean getSilentStart() {
return silentstart;
}
@Override
public void setUseDefaultPortalSearch(boolean useDefaultPortalSearch) {
defaultportalsearch = useDefaultPortalSearch;
}
@Override
public boolean isUsingDefaultPortalSearch() {
return defaultportalsearch;
}
@Override
public void setPortalSearchRadius(int searchRadius) {
this.portalsearchradius = searchRadius;
}
@Override
public int getPortalSearchRadius() {
return portalsearchradius;
}
}
@@ -1,633 +0,0 @@
package com.onarandombox.MultiverseCore;
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
import com.onarandombox.MultiverseCore.configuration.EntryFee;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
import me.main__.util.SerializationConfig.Property;
import me.main__.util.SerializationConfig.SerializationConfig;
import me.main__.util.SerializationConfig.Serializor;
import me.main__.util.SerializationConfig.Validator;
import me.main__.util.SerializationConfig.VirtualProperty;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.configuration.serialization.SerializableAs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SerializableAs("MVWorld")
public class WorldProperties extends SerializationConfig {
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("limit", "playerLimit");
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate");
PROPERTY_ALIASES.put("flight", "allowFlight");
PROPERTY_ALIASES.put("fly", "allowFlight");
PROPERTY_ALIASES.put("allowfly", "allowFlight");
}
public WorldProperties(Map<String, Object> values) {
super(values);
}
public WorldProperties() {
super();
}
public WorldProperties(final boolean fixSpawn, final Environment environment) {
super();
if (!fixSpawn) {
this.adjustSpawn = false;
}
setScaling(getDefaultScale(environment));
}
void setMVWorld(MVWorld world) {
registerObjectUsing(world);
registerGlobalValidator(new WorldPropertyValidator());
}
/**
* Serializor for the color-property.
*/
private static final class EnumPropertySerializor<T extends Enum<T>> implements Serializor<T, String> {
@Override
public String serialize(T from) {
return from.toString();
}
@Override
public T deserialize(String serialized, Class<T> wanted) throws IllegalPropertyValueException {
try {
return Enum.valueOf(wanted, serialized.toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalPropertyValueException(e);
}
}
}
/**
* Serializor for the difficulty-property.
*/
private static final class DifficultyPropertySerializor implements Serializor<Difficulty, String> {
@Override
public String serialize(Difficulty from) {
return from.toString();
}
@Override
public Difficulty deserialize(String serialized, Class<Difficulty> wanted) throws IllegalPropertyValueException {
try {
return Difficulty.getByValue(Integer.parseInt(serialized));
} catch (Exception e) {
}
try {
return Difficulty.valueOf(serialized.toUpperCase());
} catch (Exception e) {
}
throw new IllegalPropertyValueException();
}
}
/**
* Serializor for the gameMode-property.
*/
private static final class GameModePropertySerializor implements Serializor<GameMode, String> {
@Override
public String serialize(GameMode from) {
return from.toString();
}
@Override
public GameMode deserialize(String serialized, Class<GameMode> wanted) throws IllegalPropertyValueException {
try {
return GameMode.getByValue(Integer.parseInt(serialized));
} catch (NumberFormatException nfe) {
}
try {
return GameMode.valueOf(serialized.toUpperCase());
} catch (Exception e) {
}
throw new IllegalPropertyValueException();
}
}
/**
* Serializor for the time-property.
*/
private static final class TimePropertySerializor implements Serializor<Long, String> {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?";
private static final Map<String, String> TIME_ALIASES;
static {
Map<String, String> staticTimes = new HashMap<String, String>();
staticTimes.put("morning", "8:00");
staticTimes.put("day", "12:00");
staticTimes.put("noon", "12:00");
staticTimes.put("midnight", "0:00");
staticTimes.put("night", "20:00");
// now set TIME_ALIASES to a "frozen" map
TIME_ALIASES = Collections.unmodifiableMap(staticTimes);
}
@Override
public String serialize(Long from) {
// I'm tired, so they get time in 24 hour for now.
// Someone else can add 12 hr format if they want :P
int hours = (int) ((from / 1000 + 8) % 24);
int minutes = (int) (60 * (from % 1000) / 1000);
return String.format("%d:%02d", hours, minutes);
}
@Override
public Long deserialize(String serialized, Class<Long> wanted) throws IllegalPropertyValueException {
if (TIME_ALIASES.containsKey(serialized.toLowerCase())) {
serialized = TIME_ALIASES.get(serialized.toLowerCase());
}
// Regex that extracts a time in the following formats:
// 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file.
Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(serialized);
matcher.find();
int hour = 0;
double minute = 0;
int count = matcher.groupCount();
if (count >= 2) {
hour = Integer.parseInt(matcher.group(1));
minute = Integer.parseInt(matcher.group(2));
}
// If there were 4 matches (all, hour, min, am/pm)
if (count == 4) {
// We want 24 hour time for calcs, but if they
// added a p[m], turn it into a 24 hr one.
if (matcher.group(3).equals("p")) {
hour += 12;
}
}
// Translate 24th hour to 0th hour.
if (hour == 24) {
hour = 0;
}
// Clamp the hour
if (hour > 23 || hour < 0) {
throw new IllegalPropertyValueException("Illegal hour!");
}
// Clamp the minute
if (minute > 59 || minute < 0) {
throw new IllegalPropertyValueException("Illegal minute!");
}
// 60 seconds in a minute, time needs to be in hrs * 1000, per
// the bukkit docs.
double totaltime = (hour + (minute / 60.0)) * 1000;
// Somehow there's an 8 hour offset...
totaltime -= 8000;
if (totaltime < 0) {
totaltime = 24000 + totaltime;
}
return (long) totaltime;
}
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
}
// --------------------------------------------------------------
// Begin properties
@Property(description = "Sorry, 'hidden' must either be: true or false.")
private volatile boolean hidden;
@Property(description = "Alias must be a valid string.")
private volatile String alias;
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
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)
volatile VirtualProperty<Boolean> pvp;
@Property(description = "Scale must be a positive double value. ex: 2.3")
private volatile double scale;
@Property(description = "You must set this to the NAME not alias of a world.")
private volatile String respawnWorld;
@Property(description = "Sorry, this must either be: true or false.")
private volatile boolean allowWeather;
@Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true,
description = "Difficulty must be set as one of the following: peaceful easy normal hard")
volatile VirtualProperty<Difficulty> difficulty;
@Property(description = "Sorry, 'animals' must either be: true or false.")
private volatile SpawnSettings spawning;
@Property
private volatile EntryFee entryfee;
@Property(description = "Sorry, 'hunger' must either be: true or false.")
private volatile boolean hunger;
@Property(description = "Sorry, 'autoheal' must either be: true or false.")
private volatile boolean autoHeal;
@Property(description = "Sorry, 'adjustspawn' must either be: true or false.")
private volatile boolean adjustSpawn;
@Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.")
private volatile AllowedPortalType portalForm;
@Property(serializor = GameModePropertySerializor.class, description = "GameMode must be set as one of the following: survival creative")
private volatile GameMode gameMode;
@Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
volatile VirtualProperty<Boolean> keepSpawnInMemory;
@Property
volatile SpawnLocation spawnLocation;
@Property(virtualType = Location.class,
description = "There is no help available for this variable. Go bug Rigby90 about it.")
volatile VirtualProperty<Location> spawn;
@Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.")
private volatile boolean autoLoad;
@Property(description = "If a player dies in this world, shoudld they go to their bed?")
private volatile boolean bedRespawn;
@Property
private volatile List<String> worldBlacklist;
@Property(serializor = TimePropertySerializor.class, virtualType = Long.class,
description = "Set the time to whatever you want! (Will NOT freeze time)")
volatile VirtualProperty<Long> time;
@Property
volatile Environment environment;
@Property
volatile long seed;
@Property
private volatile String generator;
@Property
private volatile int playerLimit;
@Property
private volatile boolean allowFlight;
// End of properties
// --------------------------------------------------------------
void setValidator(String fieldName, Validator validator) {
registerValidator(fieldName, validator); //To change body of overridden methods use File | Settings | File Templates.
}
/**
* {@inheritDoc}
*/
@Override
public void copyValues(SerializationConfig other) {
super.copyValues(other);
}
/**
* This prepares the MVWorld for unloading.
*/
public void cacheVirtualProperties() {
try {
this.buildVPropChanges();
} catch (IllegalStateException e) {
// do nothing
}
}
/**
* {@inheritDoc}
*/
@Override
protected void setDefaults() {
this.hidden = false;
this.alias = new String();
this.color = EnglishChatColor.WHITE;
this.style = EnglishChatStyle.NORMAL;
this.scale = 1D;
this.respawnWorld = new String();
this.allowWeather = true;
this.spawning = new SpawnSettings();
this.entryfee = new EntryFee();
this.hunger = true;
this.autoHeal = true;
this.adjustSpawn = true;
this.portalForm = AllowedPortalType.ALL;
this.gameMode = GameMode.SURVIVAL;
this.spawnLocation = new NullLocation();
this.autoLoad = true;
this.bedRespawn = true;
this.worldBlacklist = new ArrayList<String>();
this.generator = null;
this.playerLimit = -1;
this.allowFlight = true;
}
private static double getDefaultScale(Environment environment) {
if (environment == Environment.NETHER) {
return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
} else if (environment == Environment.THE_END) {
return 16.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
}
return 1.0;
}
/**
* getAliases().
* @return The alias-map.
* @see SerializationConfig
*/
protected static Map<String, String> getAliases() {
return PROPERTY_ALIASES;
}
void flushChanges() {
this.flushPendingVPropChanges();
}
String getAlias() {
return this.alias;
}
public void setAlias(String alias) {
this.setPropertyValueUnchecked("alias", alias);
}
public Environment getEnvironment() {
return this.environment;
}
public void setEnvironment(Environment environment) {
this.setPropertyValueUnchecked("environment", environment);
}
public long getSeed() {
return this.seed;
}
public void setSeed(long seed) {
this.setPropertyValueUnchecked("seed", seed);
}
public String getGenerator() {
return this.generator;
}
public void setGenerator(String generator) {
this.setPropertyValueUnchecked("generator", generator);
}
public int getPlayerLimit() {
return this.playerLimit;
}
public void setPlayerLimit(int limit) {
this.setPropertyValueUnchecked("playerLimit", limit);
}
public boolean canAnimalsSpawn() {
return this.spawning.getAnimalSettings().doSpawn();
}
public void setAllowAnimalSpawn(boolean animals) {
this.setPropertyValueUnchecked("spawning.animals.spawn", animals);
}
public List<String> getAnimalList() {
// These don't fire events at the moment. Should they?
return this.spawning.getAnimalSettings().getExceptions();
}
public boolean canMonstersSpawn() {
return this.spawning.getMonsterSettings().doSpawn();
}
public void setAllowMonsterSpawn(boolean monsters) {
this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters);
}
public int getAnimalSpawnRate() {
return this.spawning.getAnimalSettings().getSpawnRate();
}
public int getMonsterSpawnRate() {
return this.spawning.getMonsterSettings().getSpawnRate();
}
public List<String> getMonsterList() {
// These don't fire events at the moment. Should they?
return this.spawning.getMonsterSettings().getExceptions();
}
public boolean isPVPEnabled() {
return this.pvp.get();
}
public void setPVPMode(boolean pvp) {
this.setPropertyValueUnchecked("pvp", pvp);
}
public boolean isHidden() {
return this.hidden;
}
public void setHidden(boolean hidden) {
this.setPropertyValueUnchecked("hidden", hidden);
}
public List<String> getWorldBlacklist() {
return this.worldBlacklist;
}
public double getScaling() {
return this.scale;
}
public boolean setScaling(double scaling) {
return this.setPropertyValueUnchecked("scale", scaling);
}
public boolean setColor(String aliasColor) {
return this.setPropertyUnchecked("color", aliasColor);
}
public boolean setColor(EnglishChatColor color) {
return this.setPropertyValueUnchecked("color", color);
}
public EnglishChatColor getColor() {
return this.color;
}
public String getRespawnToWorld() {
return this.respawnWorld;
}
public boolean setRespawnToWorld(String respawnToWorld) {
return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld);
}
public int getCurrency() {
return this.entryfee.getCurrency();
}
public void setCurrency(int currency) {
this.setPropertyValueUnchecked("entryfee.currency", currency);
}
public double getPrice() {
return this.entryfee.getAmount();
}
public void setPrice(double price) {
this.setPropertyValueUnchecked("entryfee.amount", price);
}
public boolean setGameMode(String mode) {
return this.setPropertyUnchecked("gameMode", mode);
}
public boolean setGameMode(GameMode mode) {
return this.setPropertyValueUnchecked("gameMode", mode);
}
public GameMode getGameMode() {
return this.gameMode;
}
public void setEnableWeather(boolean weather) {
this.setPropertyValueUnchecked("allowWeather", weather);
}
public boolean isWeatherEnabled() {
return this.allowWeather;
}
public boolean isKeepingSpawnInMemory() {
return this.keepSpawnInMemory.get();
}
public void setKeepSpawnInMemory(boolean value) {
this.setPropertyValueUnchecked("keepSpawnInMemory", value);
}
public boolean getHunger() {
return this.hunger;
}
public void setHunger(boolean hunger) {
this.setPropertyValueUnchecked("hunger", hunger);
}
public Location getSpawnLocation() {
return this.spawn.get();
}
public void setSpawnLocation(Location l) {
this.setPropertyValueUnchecked("spawn", l);
}
public Difficulty getDifficulty() {
return this.difficulty.get();
}
@Deprecated
public boolean setDifficulty(String difficulty) {
return this.setPropertyUnchecked("difficulty", difficulty);
}
public boolean setDifficulty(Difficulty difficulty) {
return this.setPropertyValueUnchecked("difficulty", difficulty);
}
public boolean getAutoHeal() {
return this.autoHeal;
}
public void setAutoHeal(boolean heal) {
this.setPropertyValueUnchecked("autoHeal", heal);
}
public void setAdjustSpawn(boolean adjust) {
this.setPropertyValueUnchecked("adjustSpawn", adjust);
}
public boolean getAdjustSpawn() {
return this.adjustSpawn;
}
public void setAutoLoad(boolean load) {
this.setPropertyValueUnchecked("autoLoad", load);
}
public boolean getAutoLoad() {
return this.autoLoad;
}
public void setBedRespawn(boolean respawn) {
this.setPropertyValueUnchecked("bedRespawn", respawn);
}
public boolean getBedRespawn() {
return this.bedRespawn;
}
public String getAllPropertyNames() {
ChatColor myColor = ChatColor.AQUA;
StringBuilder result = new StringBuilder();
Map<String, Object> serialized = this.serialize();
for (String key : serialized.keySet()) {
result.append(myColor).append(key).append(' ');
myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA;
}
return result.toString();
}
public String getTime() {
return this.getPropertyUnchecked("time");
}
public boolean setTime(String timeAsString) {
return this.setPropertyUnchecked("time", timeAsString);
}
public AllowedPortalType getAllowedPortals() {
return portalForm;
}
public void allowPortalMaking(AllowedPortalType portalType) {
this.setPropertyValueUnchecked("portalForm", portalType);
}
public EnglishChatStyle getStyle() {
return style;
}
public boolean setStyle(String style) {
return this.setPropertyUnchecked("style", style);
}
public boolean getAllowFlight() {
return this.allowFlight;
}
public void setAllowFlight(final boolean allowFlight) {
this.setPropertyValueUnchecked("allowFlight", allowFlight);
}
}
@@ -17,8 +17,9 @@ 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.VaultHandler;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@@ -42,18 +43,17 @@ public interface Core {
* Gets the Banking system that Multiverse-Core has hooked into.
*
* @return A {@link GenericBank} that can be used for payments.
* @deprecated Now using vault, see {@link VaultHandler#getEconomy}
* @deprecated Now using vault, see {@link #getVaultEconomy}
*/
@Deprecated
GenericBank getBank();
/**
* Returns the Vault handler used by Multiverse. The returned object will have all methods necessary for
* interfacing with Vault.
* Returns the Vault economy system if Vault is present and has an economy system enabled.
*
* @return the Vault handler for Multiverse.
* @return The vault economy system or null if not configured.
*/
VaultHandler getVaultHandler();
Economy getVaultEconomy();
/**
* Reloads the Multiverse Configuration files:
@@ -155,7 +155,7 @@ public interface Core {
* Sets the {@link GenericBank}-Bank AllPay is using.
*
* @param bank The new {@link GenericBank}
* @deprecated Now using vault, see {@link VaultHandler#getEconomy}
* @deprecated Now using vault, see {@link #getVaultEconomy}
*/
@Deprecated
void setBank(GenericBank bank);
@@ -164,7 +164,7 @@ public interface Core {
* Gets this plugin's {@link AllPay}-Banker.
*
* @return An {@link AllPay}-Banker
* @deprecated Now using vault, see {@link VaultHandler#getEconomy}
* @deprecated Now using vault, see {@link #getVaultEconomy}
*/
@Deprecated
AllPay getBanker();
@@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.api;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -131,14 +130,6 @@ public interface MVDestination {
*/
String getRequiredPermission();
/**
* Checks whether the given permissible has the permission to go to this destination.
*
* @param permissible Whoever we need to check permissions for.
* @return True if they are allowed to go to this destination based on permissions.
*/
boolean hasRequiredPermission(Permissible permissible);
/**
* Should the Multiverse SafeTeleporter be used?
* <p>
@@ -30,14 +30,14 @@ public interface MVPlugin extends LoggablePlugin {
/**
* Gets the reference to MultiverseCore.
*
* @return A valid {@link com.onarandombox.MultiverseCore}.
* @return A valid {@link MultiverseCore}.
*/
MultiverseCore getCore();
/**
* Sets the reference to MultiverseCore.
*
* @param core A valid {@link com.onarandombox.MultiverseCore}.
* @param core A valid {@link MultiverseCore}.
*/
void setCore(MultiverseCore core);
@@ -0,0 +1,18 @@
package com.onarandombox.MultiverseCore.api;
import org.bukkit.Location;
/**
* A special {@link MVDestination} that can determine the target {@link Location} without a reference to the teleportee.
*/
public interface MVStaticDestination extends MVDestination {
/**
* Returns {@link MVDestination}'s target {@link Location}.
* <p>
* Although that shouldn't be necessary, it is recommended to implement
* {@link #getLocation(org.bukkit.entity.Entity)} with a simple call to this method.
* @return The target location.
* @see #getLocation(org.bukkit.entity.Entity)
*/
Location getLocation();
}
@@ -90,17 +90,6 @@ public interface MVWorldManager {
*/
boolean deleteWorld(String name, boolean removeConfig);
/**
*
* @param name The name of the world to remove
* @param removeFromConfig If true(default), we'll remove the entries from the
* config. If false, they'll stay and the world may come back.
* @param deleteWorldFolder If true the world folder will be completely deleted. If false
* only the contents of the world folder will be deleted
* @return True if success, false if failure.
*/
boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder);
/**
* Unload a world from Multiverse.
*
@@ -145,46 +145,4 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
* @return useasyncchat.
*/
boolean getUseAsyncChat();
/**
* Sets whether to suppress startup messages.
*
* @param silentStart true to suppress messages.
*/
void setSilentStart(boolean silentStart);
/**
* Whether we are suppressing startup messages.
*
* @return true if we are suppressing startup messages.
*/
boolean getSilentStart();
/**
* Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input.
*
* @param useDefaultPortalSearch True to let Bukkit determine portal search radius on its own.
*/
void setUseDefaultPortalSearch(boolean useDefaultPortalSearch);
/**
* Gets whether or not Bukkit will be determining portal search radius on its own or if Multiverse should help.
*
* @return True means Bukkit will use its own default values.
*/
boolean isUsingDefaultPortalSearch();
/**
* Sets the radius at which vanilla style portals will be searched for to connect to worlds together.
*
* @param searchRadius The portal search radius.
*/
void setPortalSearchRadius(int searchRadius);
/**
* Gets the radius at which vanilla style portals will be searched for to connect to worlds together.
*
* @return The portal search radius.
*/
int getPortalSearchRadius();
}
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
@@ -245,18 +246,14 @@ public interface MultiverseWorld {
* Gets the permission required to enter this world.
*
* @return The permission required to be exempt from charges to/from this world.
* @deprecated Now using {@link com.onarandombox.MultiverseCore.utils.Permissions#ACCESS}.
*/
@Deprecated
Permission getAccessPermission();
/**
* Gets the permission required to be exempt when entering.
*
* @return The permission required to be exempt when entering.
* @deprecated Now using {@link com.onarandombox.MultiverseCore.utils.Permissions#COST_EXEMPT}.
*/
@Deprecated
Permission getExemptPermission();
// end of permission stuff
@@ -533,7 +530,9 @@ public interface MultiverseWorld {
* Gets the world players will respawn in if they die in this one.
*
* @return A world that exists on the server.
* @deprecated This is now deprecated. Use {@link #getRespawnDestination()} instead.
*/
@Deprecated
World getRespawnToWorld();
/**
@@ -542,7 +541,9 @@ public interface MultiverseWorld {
*
* @param respawnWorld The name of a world that exists on the server.
* @return True if respawnWorld existed, false if not.
* @deprecated This is now deprecated. Use {@link #setRespawnDestination(MVDestination)} instead.
*/
@Deprecated
boolean setRespawnToWorld(String respawnWorld);
/**
@@ -611,7 +612,9 @@ public interface MultiverseWorld {
* bed or follow the normal respawn pattern.
*
* @return True if players dying in this world should respawn at their bed.
* @deprecated This is now deprecated. Use {@link #getRespawnDestination()} instead.
*/
@Deprecated
boolean getBedRespawn();
/**
@@ -621,25 +624,11 @@ public interface MultiverseWorld {
* True is default.
*
* @param autoLoad True if players dying in this world respawn at their bed.
* @deprecated This is now deprecated. Use {@link #setRespawnDestination(MVDestination)} instead.
*/
@Deprecated
void setBedRespawn(boolean autoLoad);
/**
* Sets the player limit for this world after which players without an override
* permission node will not be allowed in. A value of -1 or less signifies no limit
*
* @param limit The new limit
*/
void setPlayerLimit(int limit);
/**
* Gets the player limit for this world after which players without an override
* permission node will not be allowed in. A value of -1 or less signifies no limit
*
* @return The player limit
*/
int getPlayerLimit();
/**
* Same as {@link #getTime()}, but returns a string.
* @return The time as a short string: 12:34pm
@@ -673,6 +662,19 @@ public interface MultiverseWorld {
*/
AllowedPortalType getAllowedPortals();
/**
* Gets the {@link MVDestination} where players are sent if they die and respawn in this world.
* @return The respawn destination.
*/
MVDestination getRespawnDestination();
/**
* Sets the {@link MVDestination} where players are sent if they die and respawn in this world.
* @param dest The new respawn destination.
* @return True if the destination was set, false if not.
*/
boolean setRespawnDestination(MVDestination dest);
// properties that are not "getter+setter" style
/**
* Gets a list of all the worlds that players CANNOT travel to from this world,
@@ -688,18 +690,4 @@ public interface MultiverseWorld {
* @return All property names, with alternating colors.
*/
String getAllPropertyNames();
/**
* Whether or not players are allowed to fly in this world.
*
* @return True if players allowed to fly in this world.
*/
boolean getAllowFlight();
/**
* Sets whether or not players are allowed to fly in this world.
*
* @param allowFlight True to allow flight in this world.
*/
void setAllowFlight(final boolean allowFlight);
}
@@ -68,8 +68,7 @@ public class CreateCommand extends MultiverseCommand {
}
if (this.worldManager.isMVWorld(worldName)) {
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD +ChatColor.UNDERLINE + "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
return;
}
@@ -23,7 +23,7 @@ public class DebugCommand extends MultiverseCommand {
public DebugCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Turn Debug on/off?");
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]");
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off]");
this.setArgRange(0, 1);
this.addKey("mv debug");
this.addKey("mv d");
@@ -55,11 +55,10 @@ public class DebugCommand extends MultiverseCommand {
}
private void displayDebugMode(CommandSender sender) {
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
if (debugLevel == 0) {
if (plugin.getMVConfig().getGlobalDebug() == 0) {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
} else {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel);
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + plugin.getMVConfig().getGlobalDebug());
this.plugin.log(Level.FINE, "Multiverse Debug ENABLED");
}
}
@@ -1,75 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.util.List;
/**
* Allows management of Anchor Destinations.
*/
public class GameruleCommand extends MultiverseCommand {
public GameruleCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Set a Minecraft Game Rule for a World.");
this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]");
this.setArgRange(2, 3);
this.addKey("mv gamerule");
this.addKey("mv rule");
this.addKey("mvgamerule");
this.addKey("mvrule");
this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false");
this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether");
this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
// We NEED a world from the command line
final Player p;
if (sender instanceof Player) {
p = (Player) sender;
} else {
p = null;
}
if (args.size() == 2 && p == null) {
sender.sendMessage("From the command line, WORLD is required.");
sender.sendMessage(this.getCommandDesc());
sender.sendMessage(this.getCommandUsage());
sender.sendMessage("Nothing changed.");
return;
}
final String gameRule = args.get(0);
final String value = args.get(1);
final World world;
if (args.size() == 2) {
world = p.getWorld();
} else {
world = Bukkit.getWorld(args.get(2));
}
if (world.setGameRuleValue(gameRule, value)) {
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
} else {
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
+ ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value);
}
}
}
@@ -1,76 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.util.List;
/**
* Allows management of Anchor Destinations.
*/
public class GamerulesCommand extends MultiverseCommand {
public GamerulesCommand(MultiverseCore plugin) {
super(plugin);
this.setName("List the Minecraft Game Rules for a World.");
this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]");
this.setArgRange(0, 1);
this.addKey("mv gamerules");
this.addKey("mv rules");
this.addKey("mvgamerules");
this.addKey("mvrules");
this.addCommandExample("/mv gamerules");
this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether");
this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
// We NEED a world from the command line
final Player p;
if (sender instanceof Player) {
p = (Player) sender;
} else {
p = null;
}
if (args.size() == 0 && p == null) {
sender.sendMessage("From the command line, WORLD is required.");
sender.sendMessage(this.getCommandDesc());
sender.sendMessage(this.getCommandUsage());
sender.sendMessage("Nothing changed.");
return;
}
final World world;
if (args.size() == 0) {
world = p.getWorld();
} else {
world = Bukkit.getWorld(args.get(0));
}
final StringBuilder gameRules = new StringBuilder();
for (final String gameRule : world.getGameRules()) {
if (gameRules.length() != 0) {
gameRules.append(ChatColor.WHITE).append(", ");
}
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(gameRule));
}
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
sender.sendMessage(gameRules.toString());
}
}
@@ -7,7 +7,6 @@
package com.onarandombox.MultiverseCore.commands;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -16,6 +15,7 @@ import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* Returns a list of loaded generator plugins.
@@ -37,7 +37,7 @@ public class GeneratorCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
Logging.info("PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
this.plugin.log(Level.INFO, "PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
Plugin[] plugins = this.plugin.getServer().getPluginManager().getPlugins();
List<String> generators = new ArrayList<String>();
for (Plugin p : plugins) {
@@ -122,12 +122,11 @@ public class InfoCommand extends MultiverseCommand {
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
Location spawn = world.getSpawnLocation();
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors));
message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
if (world.getPrice() > 0) {
final String formattedAmount;
if (world.getCurrency() <= 0 && plugin.getVaultHandler().getEconomy() != null) {
formattedAmount = plugin.getVaultHandler().getEconomy().format(world.getPrice());
if (world.getCurrency() <= 0 && plugin.getVaultEconomy() != null) {
formattedAmount = plugin.getVaultEconomy().format(world.getPrice());
} else {
formattedAmount = this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency());
}
@@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.Permissions;
import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
@@ -66,7 +65,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
}
}
for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) {
if (p == null || Permissions.ACCESS.hasPermission(p, name)) {
if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) {
worldList.add(ChatColor.GRAY + name + " - UNLOADED");
}
}
@@ -64,9 +64,6 @@ public class SetSpawnCommand extends MultiverseCommand {
foundWorld.setAdjustSpawn(false);
}
sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(p.getLocation()));
if (!plugin.saveWorldConfig()) {
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
}
} else {
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
@@ -1,52 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import java.util.List;
/**
* Enables debug-information.
*/
public class SilentCommand extends MultiverseCommand {
public SilentCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Turn silent mode on/off?");
this.setCommandUsage("/mv silent" + ChatColor.GOLD + " [true|false|on|off]");
this.setArgRange(0, 1);
this.addKey("mv silent");
this.addKey("mvsilent");
this.addCommandExample("/mv silent " + ChatColor.GOLD + "true");
this.setPermission("multiverse.core.silent", "Reduces the amount of startup messages.", PermissionDefault.OP);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
if (args.size() == 1) {
if (args.get(0).equalsIgnoreCase("on")) {
args.set(0, "true");
}
plugin.getMVConfig().setSilentStart(Boolean.valueOf(args.get(0)));
plugin.saveMVConfigs();
}
this.displaySilentMode(sender);
}
private void displaySilentMode(CommandSender sender) {
if (plugin.getMVConfig().getSilentStart()) {
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.GREEN + "ON");
} else {
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.RED + "OFF");
}
}
}
@@ -7,7 +7,6 @@
package com.onarandombox.MultiverseCore.commands;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.utils.webpaste.BitlyURLShortener;
@@ -22,6 +21,7 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.util.List;
import java.util.logging.Level;
/**
* Dumps version info to the console.
@@ -53,10 +53,10 @@ public class VersionCommand extends MultiverseCommand {
buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds()).append('\n');
buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
final boolean usingVault = plugin.getVaultHandler().getEconomy() != null;
final boolean usingVault = this.plugin.getVaultEconomy() != null;
buffer.append("[Multiverse-Core] Using Vault: ").append(usingVault).append('\n');
if (usingVault) {
buffer.append("[Multiverse-Core] Economy being used: ").append(plugin.getVaultHandler().getEconomy().getName()).append('\n');
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getVaultEconomy().getName()).append('\n');
} else {
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
}
@@ -81,7 +81,7 @@ public class VersionCommand extends MultiverseCommand {
final String data = versionEvent.getVersionInfo();
String[] lines = data.split("\n");
for (String line : lines) {
Logging.info(line);
this.plugin.log(Level.INFO, line);
}
this.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(this.plugin, new Runnable() {
@@ -98,7 +98,7 @@ public class VersionCommand extends MultiverseCommand {
}
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
Logging.info("Version info dumped here: %s", pasteUrl);
plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
}
}
});
@@ -0,0 +1,35 @@
package com.onarandombox.MultiverseCore.configuration;
import org.bukkit.Bukkit;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.api.MVDestination;
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
import me.main__.util.SerializationConfig.Serializor;
public class DestinationSerializor implements Serializor<MVDestination, String> {
private static Core getCore() {
Core c = (Core) Bukkit.getPluginManager().getPlugin("Multiverse-Core");
if (c == null)
throw new IllegalStateException("We need our MVCore-plugin!");
return c;
}
/**
* {@inheritDoc}
*/
@Override
public MVDestination deserialize(String arg0, Class<MVDestination> arg1)
throws IllegalPropertyValueException {
return getCore().getDestFactory().getDestination(arg0);
}
/**
* {@inheritDoc}
*/
@Override
public String serialize(MVDestination arg0) {
return arg0.toString();
}
}
@@ -82,6 +82,24 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
return serialized;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Location other = (Location) obj;
return /* (this.getWorld() == other.getWorld() || (this.getWorld() != null && this.getWorld().equals(other.getWorld())))
&& */ (Double.doubleToLongBits(this.getX()) == Double.doubleToLongBits(other.getX()))
&& (Double.doubleToLongBits(this.getY()) == Double.doubleToLongBits(other.getY()))
&& (Double.doubleToLongBits(this.getZ()) == Double.doubleToLongBits(other.getZ()))
&& (Float.floatToIntBits(this.getPitch()) == Float.floatToIntBits(other.getPitch()))
&& (Float.floatToIntBits(this.getYaw()) == Float.floatToIntBits(other.getYaw()));
}
/**
* Let Bukkit be able to deserialize this.
* @param args The map.
@@ -59,14 +59,15 @@ public class SubSpawnSettings extends SerializationConfig {
public List<String> getExceptions() {
return exceptions;
}
/**
* @param rate The new spawn rate
*
* @param The new spawn rate
*/
public void setSpawnRate(int rate) {
this.spawnrate = rate;
}
/**
* @return The spawn rate
*/
@@ -9,10 +9,10 @@ package com.onarandombox.MultiverseCore.destination;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.utils.Permissions;
import com.onarandombox.MultiverseCore.api.MVStaticDestination;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -22,7 +22,7 @@ import java.util.List;
/**
* An anchor-{@link MVDestination}.
*/
public class AnchorDestination implements MVDestination {
public class AnchorDestination implements MVStaticDestination {
private boolean isValid;
private Location location;
private MultiverseCore plugin;
@@ -66,10 +66,18 @@ public class AnchorDestination implements MVDestination {
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
public Location getLocation() {
return this.location;
}
/**
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
return this.getLocation();
}
/**
* {@inheritDoc}
*/
@@ -136,15 +144,7 @@ public class AnchorDestination implements MVDestination {
*/
@Override
public String getRequiredPermission() {
return Permissions.ACCESS.getName(this.location.getWorld().getName());
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasRequiredPermission(Permissible permissible) {
return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName());
return "multiverse.access." + this.location.getWorld().getName();
}
/**
@@ -9,12 +9,10 @@ package com.onarandombox.MultiverseCore.destination;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.utils.Permissions;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -22,6 +20,7 @@ import org.bukkit.util.Vector;
* A bed-{@link MVDestination}.
*/
public class BedDestination implements MVDestination {
public static final String STRING = "b:playerbed";
private boolean isValid;
private Location knownBedLoc;
@@ -106,22 +105,11 @@ public class BedDestination implements MVDestination {
@Override
public String getRequiredPermission() {
if (knownBedLoc != null) {
return Permissions.ACCESS.getName(knownBedLoc.getWorld().getName());
return "multiverse.access." + knownBedLoc.getWorld().getName();
}
return "";
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasRequiredPermission(Permissible permissible) {
if (knownBedLoc != null) {
Permissions.ACCESS.hasPermission(permissible, knownBedLoc.getWorld().getName());
}
return true;
}
/**
* {@inheritDoc}
*/
@@ -133,6 +121,6 @@ public class BedDestination implements MVDestination {
@Override
public String toString() {
return "b:playerbed";
return STRING;
}
}
@@ -9,10 +9,10 @@ package com.onarandombox.MultiverseCore.destination;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.utils.Permissions;
import com.onarandombox.MultiverseCore.api.MVStaticDestination;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -22,7 +22,7 @@ import java.util.List;
/**
* A cannon-{@link MVDestination}.
*/
public class CannonDestination implements MVDestination {
public class CannonDestination implements MVStaticDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid;
private Location location;
@@ -98,10 +98,18 @@ public class CannonDestination implements MVDestination {
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
public Location getLocation() {
return this.location;
}
/**
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
return this.getLocation();
}
/**
* {@inheritDoc}
*/
@@ -207,15 +215,7 @@ public class CannonDestination implements MVDestination {
*/
@Override
public String getRequiredPermission() {
return Permissions.ACCESS.getName(this.location.getWorld().getName());
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasRequiredPermission(Permissible permissible) {
return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName());
return "multiverse.access." + this.location.getWorld().getName();
}
/**
@@ -9,10 +9,10 @@ package com.onarandombox.MultiverseCore.destination;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.utils.Permissions;
import com.onarandombox.MultiverseCore.api.MVStaticDestination;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -22,7 +22,7 @@ import java.util.List;
/**
* An exact {@link MVDestination}.
*/
public class ExactDestination implements MVDestination {
public class ExactDestination implements MVStaticDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid;
private Location location;
@@ -89,10 +89,18 @@ public class ExactDestination implements MVDestination {
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
public Location getLocation() {
return this.location;
}
/**
* {@inheritDoc}
*/
@Override
public Location getLocation(Entity e) {
return this.getLocation();
}
/**
* {@inheritDoc}
*/
@@ -210,15 +218,7 @@ public class ExactDestination implements MVDestination {
*/
@Override
public String getRequiredPermission() {
return Permissions.ACCESS.getName(this.location.getWorld().getName());
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasRequiredPermission(Permissible permissible) {
return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName());
return "multiverse.access." + this.location.getWorld().getName();
}
/**
@@ -11,10 +11,8 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.Permissions;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@@ -27,6 +25,11 @@ public class WorldDestination implements MVDestination {
private float yaw = -1;
private String direction = "";
public WorldDestination() {} // for DestinationFactory
public WorldDestination(MultiverseWorld world) {
this.world = world;
}
/**
* {@inheritDoc}
*/
@@ -151,15 +154,9 @@ public class WorldDestination implements MVDestination {
*/
@Override
public String getRequiredPermission() {
return Permissions.ACCESS.getName(this.world.getName());
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasRequiredPermission(Permissible permissible) {
return Permissions.ACCESS.hasPermission(permissible, this.world.getName());
// TODO: Potenitally replace spaces wiht tabs for friendlier yaml.
// this.world.getName().replace(" ","_");
return "multiverse.access." + this.world.getName();
}
/**
@@ -178,4 +175,10 @@ public class WorldDestination implements MVDestination {
return true;
}
/**
* @return The world.
*/
public MultiverseWorld getWorld() {
return world;
}
}
@@ -1,39 +0,0 @@
package com.onarandombox.MultiverseCore.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.MapInitializeEvent;
import org.bukkit.map.MapView;
/**
* A listener for bukkit map events.
*/
public class MVMapListener implements Listener {
private final MultiverseCore plugin;
public MVMapListener(final MultiverseCore plugin) {
this.plugin = plugin;
}
@EventHandler
public void mapInitialize(final MapInitializeEvent event) {
for (final Player player : Bukkit.getOnlinePlayers()) {
if ((player.getItemInHand().getType() == Material.MAP
|| player.getItemInHand().getType() == Material.EMPTY_MAP)
&& player.getItemInHand().getDurability() == event.getMap().getId()) {
final Location playerLoc = player.getLocation();
final MapView map = event.getMap();
map.setCenterX(playerLoc.getBlockX());
map.setCenterZ(playerLoc.getBlockZ());
map.setWorld(playerLoc.getWorld());
return;
}
}
}
}
@@ -9,12 +9,12 @@ package com.onarandombox.MultiverseCore.listeners;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
import com.onarandombox.MultiverseCore.utils.Permissions;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -66,31 +66,16 @@ public class MVPlayerListener implements Listener {
World world = event.getPlayer().getWorld();
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
// If it's not a World MV manages we stop.
if (mvWorld == null) {
if (mvWorld == null)
return;
}
MVDestination redest = mvWorld.getRespawnDestination();
if (!(redest instanceof InvalidDestination))
event.setRespawnLocation(redest.getLocation(event.getPlayer()));
else
event.setRespawnLocation(world.getSpawnLocation());
if (mvWorld.getBedRespawn() && event.isBedSpawn()) {
this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed");
return;
}
// Get the instance of the World the player should respawn at.
MultiverseWorld respawnWorld = null;
if (this.worldManager.isMVWorld(mvWorld.getRespawnToWorld())) {
respawnWorld = this.worldManager.getMVWorld(mvWorld.getRespawnToWorld());
}
// If it's null then it either means the World doesn't exist or the value is blank, so we don't handle it.
// NOW: We'll always handle it to get more accurate spawns
if (respawnWorld != null) {
world = respawnWorld.getCBWorld();
}
// World has been set to the appropriate world
Location respawnLocation = getMostAccurateRespawnLocation(world);
MVRespawnEvent respawnEvent = new MVRespawnEvent(respawnLocation, event.getPlayer(), "compatability");
MVRespawnEvent respawnEvent = new MVRespawnEvent(event.getRespawnLocation(), event.getPlayer(), "compatability");
this.plugin.getServer().getPluginManager().callEvent(respawnEvent);
event.setRespawnLocation(respawnEvent.getPlayersRespawnLocation());
}
@@ -121,13 +106,13 @@ public class MVPlayerListener implements Listener {
} else {
this.plugin.log(Level.FINER, "Player joined AGAIN!");
if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access!
&& !Permissions.ACCESS.hasPermission(p, p.getWorld().getName())) {
&& !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
this.sendPlayerToDefaultWorld(p);
}
}
// Handle the Players GameMode setting for the new world.
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
playerWorld.put(p.getName(), p.getWorld().getName());
}
@@ -138,7 +123,7 @@ public class MVPlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void playerChangedWorld(PlayerChangedWorldEvent event) {
// Permissions now determine whether or not to handle a gamemode.
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
}
@@ -195,38 +180,20 @@ public class MVPlayerListener implements Listener {
+ "' don't have the FUNDS required to enter it.");
return;
}
// Check if player is allowed to enter the world if we're enforcing permissions
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
if (event.isCancelled() && teleporter != null) {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
+ "' because '" + teleporter.getName() + "' don't have: "
+ Permissions.ACCESS.getName(event.getTo().getWorld().getName()));
return;
+ "' because '" + teleporter.getName()
+ "' don't have: multiverse.access." + event.getTo().getWorld().getName());
} else {
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
}
} else {
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
}
// Does a limit actually exist?
if (toWorld.getPlayerLimit() > -1) {
// Are there equal or more people on the world than the limit?
if (toWorld.getCBWorld().getPlayers().size() >= toWorld.getPlayerLimit()) {
// Ouch the world is full, lets see if the player can bypass that limitation
if (!pt.playerCanBypassPlayerLimit(toWorld, teleporter, teleportee)) {
Logging.fine("Player '%s' was DENIED ACCESS to '%s' because the world is full and '%s' doesn't have: %s.%s",
teleportee.getName(), toWorld.getAlias(), teleporter.getName(),
Permissions.BYPASS_PLAYERLIMIT.getName(), event.getTo().getWorld().getName());
return;
}
}
}
// By this point anything cancelling the event has returned on the method, meaning the teleport is a success \o/
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
}
private void stateSuccess(String playerName, String worldName) {
@@ -290,20 +257,15 @@ public class MVPlayerListener implements Listener {
if (plugin.getMVConfig().getEnforceAccess()) {
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
if (event.isCancelled()) {
//
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
+ "' because they don't have: "
+ Permissions.ACCESS.getName(event.getTo().getWorld().getName()));
+ "' because they don't have: multiverse.access." + event.getTo().getWorld().getName());
}
} else {
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
+ "' because enforceaccess is off.");
}
if (!plugin.getMVConfig().isUsingDefaultPortalSearch()) {
event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius());
}
}
private void sendPlayerToDefaultWorld(final Player player) {
@@ -318,13 +280,13 @@ public class MVPlayerListener implements Listener {
}
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.
private void handleGameModeAndFlight(Player player, World world) {
private void handleGameMode(Player player, World world) {
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
if (mvWorld != null) {
this.handleGameModeAndFlight(player, mvWorld);
this.handleGameMode(player, mvWorld);
} else {
this.plugin.log(Level.FINER, "Not handling gamemode and flight for world '" + world.getName()
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
+ "' not managed by Multiverse.");
}
}
@@ -334,7 +296,7 @@ public class MVPlayerListener implements Listener {
* @param player The {@link Player}.
* @param world The world the player is in.
*/
public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) {
public void handleGameMode(final Player player, final MultiverseWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
@@ -349,26 +311,12 @@ public class MVPlayerListener implements Listener {
Logging.finest("To World: %s", world);
player.setGameMode(world.getGameMode());
} else {
Logging.fine("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
player.getName(), player.getWorld().getName(), world.getName());
Logging.fine("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'", player.getName(), player.getWorld().getName(), world.getName());
}
}
}, 1L);
} else {
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
}
// TODO need a override permission for this
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
if (!this.pt.playerCanIgnoreAllowFlightRestriction(world, player)) {
player.setAllowFlight(false);
if (player.isFlying()) {
player.setFlying(false);
}
}
} else if (world.getAllowFlight()) {
if (player.getGameMode() == GameMode.CREATIVE) {
player.setAllowFlight(true);
}
}
}
}
@@ -34,7 +34,7 @@ public class MVPluginListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
public void pluginEnable(PluginEnableEvent event) {
if (plugin.getVaultHandler().getEconomy() != null) {
if (plugin.getVaultEconomy() != null) {
// Don't hook 2 economy plugins.
return;
}
@@ -50,7 +50,7 @@ public class AnchorManager {
//world:x,y,z:pitch:yaw
Location anchorLocation = plugin.getLocationManipulation().stringToLocation(anchorsSection.getString(key, ""));
if (anchorLocation != null) {
Logging.config("Loading anchor: '%s'...", key);
Logging.info("Loading anchor: '%s'...", key);
this.anchors.put(key, anchorLocation);
} else {
Logging.warning("The location for anchor '%s' is INVALID.", key);
@@ -140,7 +140,7 @@ public class AnchorManager {
if (ancLoc == null) {
continue;
}
if (Permissions.ACCESS.hasPermission(p, ancLoc.getWorld().getName())) {
if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
myAnchors.add(anchor);
}
}
@@ -73,28 +73,28 @@ public class BlockSafety {
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|| this.isSolidBlock(upOne.getBlock().getType())) {
Logging.finest("Error Here (Actual)? (%s)[%s]", actual.getBlock().getType(),
Logging.finer("Error Here (Actual)? (%s)[%s]", actual.getBlock().getType(),
this.isSolidBlock(actual.getBlock().getType()));
Logging.finest("Error Here (upOne)? (%s)[%s]", upOne.getBlock().getType(),
Logging.finer("Error Here (upOne)? (%s)[%s]", upOne.getBlock().getType(),
this.isSolidBlock(upOne.getBlock().getType()));
return false;
}
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
Logging.finest("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(),
Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(),
this.isSolidBlock(downOne.getBlock().getType()));
return false;
}
if (downOne.getBlock().getType() == Material.FIRE) {
Logging.finest("There's fire below! (%s)[%s]", actual.getBlock().getType(),
Logging.finer("There's fire below! (%s)[%s]", actual.getBlock().getType(),
this.isSolidBlock(actual.getBlock().getType()));
return false;
}
if (isBlockAboveAir(actual)) {
Logging.finest("Is block above air [%s]", isBlockAboveAir(actual));
Logging.finest("Has 2 blocks of water below [%s]", this.hasTwoBlocksofWaterBelow(actual));
Logging.finer("Is block above air [%s]", isBlockAboveAir(actual));
Logging.finer("Has 2 blocks of water below [%s]", this.hasTwoBlocksofWaterBelow(actual));
return this.hasTwoBlocksofWaterBelow(actual);
}
return true;
@@ -24,9 +24,7 @@ import java.util.logging.Logger;
/**
* The Multiverse debug-logger.
* @deprecated Deprecated in favor of new Logging lib. See {@link com.dumptruckman.minecraft.util.Logging}.
*/
@Deprecated
public class DebugLog extends Logger {
private FileHandler fh;
private Logger standardLog = null;
@@ -45,27 +45,6 @@ public class FileUtils {
}
}
/**
* Used to delete the contents of a folder, without deleting the folder itself.
*
* @param file The folder whose contents to delete.
* @return true if the contents were successfully deleted
*/
public static boolean deleteFolderContents(File file) {
if (file.exists()) {
boolean ret = true;
// If the file exists, and it has more than one file in it.
if (file.isDirectory()) {
for (File f : file.listFiles()) {
ret = ret && deleteFolder(f);
}
}
return ret;
} else {
return false;
}
}
private static final int COPY_BLOCK_SIZE = 1024;
/**
@@ -36,6 +36,17 @@ public class MVPermissions implements PermissionsInterface {
}
/**
* Check if a Player can ignore GameMode restrictions for world they travel to.
*
* @param p The {@link Player} to check.
* @param w The {@link MultiverseWorld} the player wants to teleport to.
* @return True if they should bypass restrictions.
*/
public boolean canIgnoreGameModeRestriction(Player p, MultiverseWorld w) {
return p.hasPermission("mv.bypass.gamemode." + w.getName());
}
/**
* Check if a Player can teleport to the Destination world from there current world.
*
@@ -92,7 +103,7 @@ public class MVPermissions implements PermissionsInterface {
this.plugin.log(Level.FINEST, "EnforceAccess is OFF. Player was allowed in " + w.getAlias());
return true;
}
return Permissions.ACCESS.hasPermission(p, w.getName());
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
}
private boolean canEnterLocation(Player p, Location l) {
@@ -103,7 +114,7 @@ public class MVPermissions implements PermissionsInterface {
if (!this.plugin.getMVWorldManager().isMVWorld(worldName)) {
return false;
}
return Permissions.ACCESS.hasPermission(p, worldName);
return this.hasPermission(p, "multiverse.access." + worldName, false);
}
/**
@@ -130,7 +141,7 @@ public class MVPermissions implements PermissionsInterface {
if (!canEnterLocation(p, d.getLocation(p))) {
return false;
}
return d.hasRequiredPermission(p);
return this.hasPermission(p, d.getRequiredPermission(), false);
}
/**
@@ -166,14 +177,14 @@ public class MVPermissions implements PermissionsInterface {
ChatColor.DARK_AQUA, ChatColor.WHITE));
cango = false;
}
if (!Permissions.ACCESS.hasPermission(p, worldName)) {
if (!this.hasPermission(p, "multiverse.access." + worldName, false)) {
asker.sendMessage(String.format("The player (%s%s%s) does not have the required world entry permission (%s%s%s) to go to the destination (%s%s%s).",
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
ChatColor.GREEN, Permissions.ACCESS.getName(worldName), ChatColor.WHITE,
ChatColor.GREEN, "multiverse.access." + worldName, ChatColor.WHITE,
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
cango = false;
}
if (d.hasRequiredPermission(p)) {
if (!this.hasPermission(p, d.getRequiredPermission(), false)) {
asker.sendMessage(String.format("The player (%s%s%s) does not have the required entry permission (%s%s%s) to go to the destination (%s%s%s).",
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
ChatColor.GREEN, d.getRequiredPermission(), ChatColor.WHITE,
@@ -140,14 +140,14 @@ public class PermissionTools {
return true;
}
// If the player does not have to pay, return now.
if (Permissions.COST_EXEMPT.hasPermission(teleporter, toWorld.getName())) {
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
return true;
}
final boolean usingVault;
final String formattedAmount;
if (toWorld.getCurrency() <= 0 && plugin.getVaultHandler().getEconomy() != null) {
if (toWorld.getCurrency() <= 0 && plugin.getVaultEconomy() != null) {
usingVault = true;
formattedAmount = plugin.getVaultHandler().getEconomy().format(toWorld.getPrice());
formattedAmount = plugin.getVaultEconomy().format(toWorld.getPrice());
} else {
usingVault = false;
formattedAmount = this.plugin.getBank().getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
@@ -157,13 +157,13 @@ public class PermissionTools {
errString = "You need " + formattedAmount + " to enter " + toWorld.getColoredWorldString();
}
if (usingVault) {
if (!plugin.getVaultHandler().getEconomy().has(teleporterPlayer.getName(), toWorld.getPrice())) {
if (!plugin.getVaultEconomy().has(teleporterPlayer.getName(), toWorld.getPrice())) {
return false;
} else if (pay) {
if (toWorld.getPrice() < 0D) {
plugin.getVaultHandler().getEconomy().depositPlayer(teleporterPlayer.getName(), toWorld.getPrice() * -1D);
plugin.getVaultEconomy().depositPlayer(teleporterPlayer.getName(), toWorld.getPrice() * -1D);
} else {
plugin.getVaultHandler().getEconomy().withdrawPlayer(teleporterPlayer.getName(), toWorld.getPrice());
plugin.getVaultEconomy().withdrawPlayer(teleporterPlayer.getName(), toWorld.getPrice());
}
}
} else {
@@ -258,31 +258,6 @@ public class PermissionTools {
return true;
}
/**
* Checks to see if a player can bypass the player limit.
*
* @param toWorld The world travelling to.
* @param teleporter The player that initiated the teleport.
* @param teleportee The player travelling.
* @return True if they can bypass the player limit.
*/
public boolean playerCanBypassPlayerLimit(MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
if (teleporter == null) {
teleporter = teleportee;
}
if (!(teleporter instanceof Player)) {
return true;
}
if (Permissions.BYPASS_PLAYERLIMIT.hasPermission(teleportee, toWorld.getName())) {
return true;
} else {
teleporter.sendMessage("The world " + toWorld.getColoredWorldString() + " is full");
return false;
}
}
/**
* Checks to see if a player should bypass game mode restrictions.
*
@@ -292,24 +267,7 @@ public class PermissionTools {
*/
public boolean playerCanIgnoreGameModeRestriction(MultiverseWorld toWorld, Player teleportee) {
if (toWorld != null) {
return Permissions.BYPASS_GAMEMODE.hasPermission(teleportee, toWorld.getName());
} else {
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
return true;
}
}
/**
* Checks to see if a player should bypass allow flight restrictions.
*
* @param toWorld world travelling to.
* @param teleportee player travelling.
* @return True if they should bypass restrictions
*/
public boolean playerCanIgnoreAllowFlightRestriction(MultiverseWorld toWorld, Player teleportee) {
if (toWorld != null) {
return Permissions.BYPASS_ALLOWFLY.hasPermission(teleportee, toWorld.getName());
return this.plugin.getMVPerms().canIgnoreGameModeRestriction(teleportee, toWorld);
} else {
// TODO: Determine if this value is false because a world didn't exist
// or if it was because a world wasn't imported.
@@ -1,182 +0,0 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.pluginbase.permission.BukkitPerm;
import com.dumptruckman.minecraft.pluginbase.permission.BukkitPermFactory;
import com.dumptruckman.minecraft.pluginbase.permission.PermDefault;
import com.onarandombox.MultiverseCore.api.Core;
public class Permissions {
// ============ Multiverse Bypass Permissions ============
private static final BukkitPerm MV = BukkitPermFactory.newBukkitPerm(Core.class, "mv.*")
.def(PermDefault.FALSE).build();
private static final BukkitPerm BYPASS_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "mv.bypass.*")
.def(PermDefault.FALSE).parent(MV).build();
private static final BukkitPerm BYPASS_GAMEMODE_ALL = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.gamemode.*").desc("Allows a player to ignore gamemode changes for all worlds.")
.def(PermDefault.FALSE).parent(BYPASS_ALL).build();
private static final BukkitPerm BYPASS_PLAYERLIMIT_ALL = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.playerlimit.*").desc("Allows a player to ignore the player limit for all worlds.")
.def(PermDefault.FALSE).parent(BYPASS_ALL).build();
private static final BukkitPerm BYPASS_ALLOWFLY_ALL = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.allowfly.*").desc("Allows a player to ignore the flight restrictions for all worlds.")
.def(PermDefault.FALSE).parent(BYPASS_ALL).build();
/** Used for bypassing the gamemode of specific worlds. */
public static final BukkitPerm BYPASS_GAMEMODE = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.gamemode").desc("Allows a player to ignore gamemode changes for a specific world.")
.specificOnly().def(PermDefault.FALSE).parent(BYPASS_GAMEMODE_ALL).build();
/** Used for bypassing the player limit of specific worlds. */
public static final BukkitPerm BYPASS_PLAYERLIMIT = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.playerlimit").desc("Allows a player to ignore the player limit for a specific world.")
.specificOnly().def(PermDefault.FALSE).parent(BYPASS_PLAYERLIMIT_ALL).build();
/** Used for bypassing the allow fly setting of specific worlds. */
public static final BukkitPerm BYPASS_ALLOWFLY = BukkitPermFactory.newBukkitPerm(Core.class,
"mv.bypass.allowfly").desc("Allows a player to ignore the flight restrictions for a specific world.")
.specificOnly().def(PermDefault.FALSE).parent(BYPASS_ALLOWFLY_ALL).build();
// ============ Multiverse World Permissions ============
private static final BukkitPerm ACCESS_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "access.*")
.desc("Allows a player to access all worlds.")
.usePluginName().addToAll().build();
private static final BukkitPerm COST_EXEMPT_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "exempt.*")
.desc("Allows a player to bypass the costs for worlds and MV portals.")
.usePluginName().addToAll().build();
public static final BukkitPerm ACCESS = BukkitPermFactory.newBukkitPerm(Core.class, "access")
.desc("Allows a player to access a specific world.")
.usePluginName().specificOnly().parent(ACCESS_ALL).build();
public static final BukkitPerm COST_EXEMPT = BukkitPermFactory.newBukkitPerm(Core.class, "exempt")
.desc("Allows a player to bypass the costs for a specific world and MV portals in that world.")
.usePluginName().specificOnly().parent(COST_EXEMPT_ALL).build();
// ============ Multiverse Teleport Permissions ============
private static final BukkitPerm TELEPORT_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.*")
.desc("Allows the player to use all forms of teleportation.")
.usePluginName().addToAll().build();
private static final BukkitPerm TELEPORT_SELF_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.*")
.desc("Allows the player to use all forms of self teleportation.")
.usePluginName().parent(TELEPORT_ALL).build();
private static final BukkitPerm TELEPORT_OTHER_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.*")
.desc("Allows the player to use all forms of teleportation on other players.")
.usePluginName().parent(TELEPORT_ALL).build();
private static final BukkitPerm TELEPORT_SELF_WORLD = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.w")
.desc("Allows the player to teleport self to any world.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_WORLD = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.w")
.desc("Allows the player to teleport self to a specific world.")
.usePluginName().specificOnly().parent(TELEPORT_SELF_WORLD).build();
private static final BukkitPerm TELEPORT_SELF_ANCHOR = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.a")
.desc("Allows the player to teleport self to any anchor.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_ANCHOR = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.a")
.desc("Allows the player to teleport self to a specific anchor.")
.usePluginName().specificOnly().parent(TELEPORT_SELF_ANCHOR).build();
public static final BukkitPerm TP_SELF_EXACT = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.e")
.desc("Allows the player to teleport self to an exact location.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
private static final BukkitPerm TELEPORT_SELF_PLAYER = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.pl")
.desc("Allows the player to teleport self to any player.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_PLAYER = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.pl")
.desc("Allows the player to teleport self to a specific player.")
.usePluginName().specificOnly().parent(TELEPORT_SELF_PLAYER).build();
public static final BukkitPerm TP_SELF_CANNON = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.ca")
.desc("Allows the player to teleport self to cannon.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_BED = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.b")
.desc("Allows the player to teleport self to their bed.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
private static final BukkitPerm TELEPORT_SELF_PORTAL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.p")
.desc("Allows the player to teleport self to any MV portal.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_PORTAL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.p")
.desc("Allows the player to teleport self to a specific MV portal.")
.usePluginName().specificOnly().parent(TELEPORT_SELF_PORTAL).build();
private static final BukkitPerm TELEPORT_SELF_OPENWARP = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.ow")
.desc("Allows the player to teleport self to any OpenWarp destination.")
.usePluginName().parent(TELEPORT_SELF_ALL).build();
public static final BukkitPerm TP_SELF_OPENWARP = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.self.ow")
.desc("Allows the player to teleport self to a specific OpenWarp destination.")
.usePluginName().specificOnly().parent(TELEPORT_SELF_OPENWARP).build();
private static final BukkitPerm TELEPORT_OTHER_WORLD = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.w")
.desc("Allows the player to teleport other to any world.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_WORLD = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.w")
.desc("Allows the player to teleport other to a specific world.")
.usePluginName().specificOnly().parent(TELEPORT_OTHER_WORLD).build();
private static final BukkitPerm TELEPORT_OTHER_ANCHOR = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.a")
.desc("Allows the player to teleport other to any anchor.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_ANCHOR = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.a")
.desc("Allows the player to teleport other to a specific anchor.")
.usePluginName().specificOnly().parent(TELEPORT_OTHER_ANCHOR).build();
public static final BukkitPerm TP_OTHER_EXACT = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.e")
.desc("Allows the player to teleport other to an exact location.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
private static final BukkitPerm TELEPORT_OTHER_PLAYER = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.pl")
.desc("Allows the player to teleport other to any player.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_PLAYER = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.pl")
.desc("Allows the player to teleport other to a specific player.")
.usePluginName().specificOnly().parent(TELEPORT_OTHER_PLAYER).build();
public static final BukkitPerm TP_OTHER_CANNON = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.ca")
.desc("Allows the player to teleport other to cannon.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_BED = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.b")
.desc("Allows the player to teleport other to their bed.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
private static final BukkitPerm TELEPORT_OTHER_PORTAL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.p")
.desc("Allows the player to teleport other to any MV portal.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_PORTAL = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.p")
.desc("Allows the player to teleport other to a specific MV portal.")
.usePluginName().specificOnly().parent(TELEPORT_OTHER_PORTAL).build();
private static final BukkitPerm TELEPORT_OTHER_OPENWARP = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.ow")
.desc("Allows the player to teleport other to any OpenWarp destination.")
.usePluginName().parent(TELEPORT_OTHER_ALL).build();
public static final BukkitPerm TP_OTHER_OPENWARP = BukkitPermFactory.newBukkitPerm(Core.class, "teleport.other.ow")
.desc("Allows the player to teleport other to a specific OpenWarp destination.")
.usePluginName().specificOnly().parent(TELEPORT_OTHER_OPENWARP).build();
}
@@ -18,7 +18,7 @@ import org.bukkit.entity.Minecart;
import org.bukkit.entity.Vehicle;
import org.bukkit.material.Bed;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -27,18 +27,10 @@ import java.util.Set;
*/
public class SimpleBlockSafety implements BlockSafety {
private final Core plugin;
private static final Set<BlockFace> AROUND_BLOCK = EnumSet.noneOf(BlockFace.class);
static {
AROUND_BLOCK.add(BlockFace.NORTH);
AROUND_BLOCK.add(BlockFace.NORTH_EAST);
AROUND_BLOCK.add(BlockFace.EAST);
AROUND_BLOCK.add(BlockFace.SOUTH_EAST);
AROUND_BLOCK.add(BlockFace.SOUTH);
AROUND_BLOCK.add(BlockFace.SOUTH_WEST);
AROUND_BLOCK.add(BlockFace.WEST);
AROUND_BLOCK.add(BlockFace.NORTH_WEST);
}
private final static Set<BlockFace> AROUND_BLOCK = new HashSet<BlockFace>(){{ add(BlockFace.NORTH); add(BlockFace.NORTH_EAST);
add(BlockFace.EAST); add(BlockFace.SOUTH_EAST);
add(BlockFace.SOUTH); add(BlockFace.SOUTH_WEST);
add(BlockFace.WEST); add(BlockFace.NORTH_WEST); }};
public SimpleBlockSafety(Core plugin) {
this.plugin = plugin;
@@ -135,7 +127,7 @@ public class SimpleBlockSafety implements BlockSafety {
*/
private Location getSafeSpawnAroundABlock(Location l) {
Iterator<BlockFace> checkblock = AROUND_BLOCK.iterator();
while (checkblock.hasNext()) {
while(checkblock.hasNext()) {
final BlockFace face = checkblock.next();
if (this.playerCanSpawnHereSafely(l.getBlock().getRelative(face).getLocation())) {
// Don't forget to center the player.
@@ -7,10 +7,10 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
@@ -18,15 +18,13 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Golem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
/**
* Utility class that removes animals from worlds that don't belong there.
@@ -88,41 +86,18 @@ public class SimpleWorldPurger implements WorldPurger {
if (world == null) {
return;
}
int projectilesKilled = 0;
int entitiesKilled = 0;
boolean specifiedAll = thingsToKill.contains("ALL");
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
List<Entity> worldEntities = world.getEntities();
List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size());
List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size());
for (final Entity e : worldEntities) {
if (e instanceof Projectile) {
final Projectile p = (Projectile) e;
if (p.getShooter() != null) {
projectiles.add((Projectile) e);
}
} else if (e instanceof LivingEntity) {
livingEntities.add((LivingEntity) e);
}
}
for (final LivingEntity e : livingEntities) {
for (Entity e : world.getEntities()) {
if (killDecision(e, thingsToKill, negateAnimals, negateMonsters, specifiedAnimals, specifiedMonsters)) {
final Iterator<Projectile> it = projectiles.iterator();
while (it.hasNext()) {
final Projectile p = it.next();
if (p.getShooter().equals(e)) {
p.remove();
it.remove();
projectilesKilled++;
}
}
e.remove();
entitiesKilled++;
}
}
if (sender != null) {
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "' along with " + projectilesKilled + " projectiles that belonged to them.");
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'");
}
}
@@ -133,7 +108,7 @@ public class SimpleWorldPurger implements WorldPurger {
if (e instanceof Golem || e instanceof Squid || e instanceof Animals) {
// it's an animal
if (specifiedAnimals && !negateAnimals) {
Logging.finest("Removing an entity because I was told to remove all animals in world %s: %s", e.getWorld().getName(), e);
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
return true;
}
if (specifiedAnimals)
@@ -142,7 +117,7 @@ public class SimpleWorldPurger implements WorldPurger {
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
// it's a monster
if (specifiedMonsters && !negateMonsters) {
Logging.finest("Removing an entity because I was told to remove all monsters in world %s: %s", e.getWorld().getName(), e);
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
return true;
}
if (specifiedMonsters)
@@ -154,14 +129,14 @@ public class SimpleWorldPurger implements WorldPurger {
if (type != null && type.equals(e.getType())) {
specified = true;
if (!negate) {
Logging.finest("Removing an entity because it WAS specified and we are NOT negating in world %s: %s", e.getWorld().getName(), e);
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
return true;
}
break;
}
}
if (!specified && negate) {
Logging.finest("Removing an entity because it was NOT specified and we ARE negating in world %s: %s", e.getWorld().getName(), e);
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
return true;
}
@@ -7,8 +7,6 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -89,7 +87,7 @@ public class UpdateChecker {
int compare = v1.compareTo(v2);
if (compare > 0) {
Logging.info("[%s] - Update Available (%s)", this.name, version);
log.info("[" + this.name + "]" + " - Update Available (" + version + ")");
}
rd.close();
@@ -1,72 +0,0 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
/**
* A class we use to interface with Vault when it is present.
*/
public class VaultHandler implements Listener {
private Economy economy;
public VaultHandler(final Plugin plugin) {
Bukkit.getPluginManager().registerEvents(new VaultListener(), plugin);
setupVaultEconomy();
}
private boolean setupVaultEconomy() {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
final RegisteredServiceProvider<Economy> economyProvider =
Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
Logging.fine("Vault economy enabled.");
economy = economyProvider.getProvider();
} else {
Logging.finer("Vault economy not detected.");
economy = null;
}
} else {
Logging.finer("Vault was not found.");
economy = null;
}
return (economy != null);
}
/**
* Listens for Vault plugin events.
*/
private class VaultListener implements Listener {
@EventHandler
private void vaultEnabled(PluginEnableEvent event) {
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
setupVaultEconomy();
}
}
@EventHandler
private void vaultDisabled(PluginDisableEvent event) {
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
Logging.fine("Vault economy disabled");
setupVaultEconomy();
}
}
}
/**
* Returns the Vault economy system if Vault is present and has an economy system enabled.
*
* @return The vault economy system or null if not configured.
*/
public Economy getEconomy() {
return economy;
}
}
@@ -7,10 +7,8 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.WorldProperties;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
@@ -27,6 +25,8 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.Plugin;
import java.io.File;
@@ -51,14 +51,14 @@ public class WorldManager implements MVWorldManager {
private final MultiverseCore plugin;
private final WorldPurger worldPurger;
private final Map<String, MultiverseWorld> worlds;
private Map<String, WorldProperties> worldsFromTheConfig;
private Map<String, MVWorld> worldsFromTheConfig;
private FileConfiguration configWorlds = null;
private Map<String, String> defaultGens;
private String firstSpawn;
public WorldManager(MultiverseCore core) {
this.plugin = core;
this.worldsFromTheConfig = new HashMap<String, WorldProperties>();
this.worldsFromTheConfig = new HashMap<String, MVWorld>();
this.worlds = new ConcurrentHashMap<String, MultiverseWorld>();
this.worldPurger = new SimpleWorldPurger(plugin);
}
@@ -114,7 +114,9 @@ public class WorldManager implements MVWorldManager {
removePlayersFromWorld(oldName);
Logging.config("Copying data for world '%s'", 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
@@ -134,23 +136,23 @@ public class WorldManager implements MVWorldManager {
e.printStackTrace();
return false;
}
Logging.fine("Kind of copied stuff");
this.plugin.log(Level.INFO, "Kind of copied stuff");
WorldCreator worldCreator = new WorldCreator(newName);
Logging.fine("Started to copy settings");
this.plugin.log(Level.INFO, "Started to copy settings");
worldCreator.copy(this.getMVWorld(oldName).getCBWorld());
Logging.fine("Copied lots of settings");
this.plugin.log(Level.INFO, "Copied lots of settings");
boolean useSpawnAdjust = this.getMVWorld(oldName).getAdjustSpawn();
Logging.fine("Copied more settings");
this.plugin.log(Level.INFO, "Copied more settings");
Environment environment = worldCreator.environment();
Logging.fine("Copied most settings");
this.plugin.log(Level.INFO, "Copied most settings");
if (newWorldFile.exists()) {
Logging.fine("Succeeded at copying stuff");
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
Logging.fine("Succeeded at importing stuff");
this.plugin.log(Level.INFO, "Succeeded at importing stuff");
MVWorld newWorld = (MVWorld) this.getMVWorld(newName);
MVWorld oldWorld = (MVWorld) this.getMVWorld(oldName);
newWorld.copyValues(oldWorld);
@@ -206,10 +208,8 @@ public class WorldManager implements MVWorldManager {
}
// Important: doLoad() needs the MVWorld-object in worldsFromTheConfig
if (!worldsFromTheConfig.containsKey(name)) {
WorldProperties props = new WorldProperties(useSpawnAdjust, env);
worldsFromTheConfig.put(name, props);
}
if (!worldsFromTheConfig.containsKey(name))
worldsFromTheConfig.put(name, new MVWorld(useSpawnAdjust));
StringBuilder builder = new StringBuilder();
builder.append("Loading World & Settings - '").append(name).append("'");
@@ -221,7 +221,7 @@ public class WorldManager implements MVWorldManager {
if (generator != null) {
builder.append(" & generator: ").append(generator);
}
Logging.info(builder.toString());
this.plugin.log(Level.INFO, builder.toString());
if (!doLoad(c, true)) {
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
@@ -262,12 +262,12 @@ public class WorldManager implements MVWorldManager {
}
if (this.worldsFromTheConfig.containsKey(name)) {
this.worldsFromTheConfig.remove(name);
Logging.info("World '%s' was removed from config.yml", name);
this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml");
this.saveWorldsConfig();
return true;
} else {
Logging.info("World '%s' was already removed from config.yml", name);
this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml");
}
return false;
}
@@ -309,22 +309,24 @@ public class WorldManager implements MVWorldManager {
@Override
public boolean unloadWorld(String name) {
if (this.worlds.containsKey(name)) {
this.worldsFromTheConfig.get(name).cacheVirtualProperties();
if (this.unloadWorldFromBukkit(name, true)) {
this.worlds.remove(name);
Logging.info("World '%s' was unloaded from memory.", name);
this.plugin.log(Level.INFO, "World '" + name + "' was unloaded from memory.");
this.worldsFromTheConfig.get(name).tearDown();
return true;
} else {
Logging.warning("World '%s' could not be unloaded. Is it a default world?", name);
this.plugin.log(Level.WARNING, "World '" + name + "' could not be unloaded. Is it a default world?");
}
} else if (this.plugin.getServer().getWorld(name) != null) {
Logging.warning("Hmm Multiverse does not know about this world but it's loaded in memory.");
Logging.warning("To let Multiverse know about it, use:");
Logging.warning("/mv import %s %s", name, this.plugin.getServer().getWorld(name).getEnvironment().toString());
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, 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 {
Logging.info("Multiverse does not know about '%s' and it's not loaded by Bukkit.", name);
this.plugin.log(Level.INFO, "Multiverse does not know about " + name + " and it's not loaded by Bukkit.");
}
return false;
}
@@ -354,20 +356,17 @@ public class WorldManager implements MVWorldManager {
}
private boolean doLoad(String name) {
return doLoad(name, false, null);
return doLoad(name, false);
}
private boolean doLoad(String name, boolean ignoreExists, WorldType type) {
private boolean doLoad(String name, boolean ignoreExists) {
if (!worldsFromTheConfig.containsKey(name))
throw new IllegalArgumentException("That world doesn't exist!");
WorldProperties world = worldsFromTheConfig.get(name);
MVWorld world = worldsFromTheConfig.get(name);
WorldCreator creator = WorldCreator.name(name);
creator.environment(world.getEnvironment()).seed(world.getSeed());
if (type != null) {
creator.type(type);
}
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
creator.generator(world.getGenerator());
@@ -387,7 +386,7 @@ public class WorldManager implements MVWorldManager {
return false;
}
WorldProperties mvworld = worldsFromTheConfig.get(worldName);
MVWorld mvworld = worldsFromTheConfig.get(worldName);
World cbworld;
try {
cbworld = creator.createWorld();
@@ -396,9 +395,9 @@ public class WorldManager implements MVWorldManager {
brokenWorld(worldName);
return false;
}
MVWorld world = new MVWorld(plugin, cbworld, mvworld);
this.worldPurger.purgeWorld(world);
this.worlds.put(worldName, world);
mvworld.init(cbworld, plugin);
this.worldPurger.purgeWorld(mvworld);
this.worlds.put(worldName, mvworld);
return true;
}
@@ -406,7 +405,7 @@ public class WorldManager implements MVWorldManager {
* {@inheritDoc}
*/
@Override
public boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder) {
public boolean deleteWorld(String name, boolean removeFromConfig) {
World world = this.plugin.getServer().getWorld(name);
if (world == null) {
// We can only delete loaded worlds
@@ -434,33 +433,25 @@ public class WorldManager implements MVWorldManager {
try {
File worldFile = world.getWorldFolder();
plugin.log(Level.FINER, "deleteWorld(): worldFile: " + worldFile.getAbsolutePath());
if (deleteWorldFolder ? FileUtils.deleteFolder(worldFile) : FileUtils.deleteFolderContents(worldFile)) {
Logging.info("World '%s' was DELETED.", name);
return true;
boolean deletedWorld = FileUtils.deleteFolder(worldFile);
if (deletedWorld) {
this.plugin.log(Level.INFO, "World " + name + " was DELETED.");
} else {
Logging.severe("World '%s' was NOT deleted.", name);
Logging.severe("Are you sure the folder %s exists?", name);
Logging.severe("Please check your file permissions on '%s'", name);
return false;
this.plugin.log(Level.SEVERE, "World " + name + " was NOT deleted.");
this.plugin.log(Level.SEVERE, "Are you sure the folder " + name + " exists?");
this.plugin.log(Level.SEVERE, "Please check your file permissions on " + name);
}
return deletedWorld;
} catch (Throwable e) {
Logging.severe("Hrm, something didn't go as planned. Here's an exception for ya.");
Logging.severe("You can go politely explain your situation in #multiverse on esper.net");
Logging.severe("But from here, it looks like your folder is oddly named.");
Logging.severe("This world has been removed from Multiverse-Core so your best bet is to go delete the folder by hand. Sorry.");
Logging.severe(e.getMessage());
this.plugin.log(Level.SEVERE, "Hrm, something didn't go as planned. Here's an exception for ya.");
this.plugin.log(Level.SEVERE, "You can go politely explain your situation in #multiverse on esper.net");
this.plugin.log(Level.SEVERE, "But from here, it looks like your folder is oddly named.");
this.plugin.log(Level.SEVERE, "This world has been removed from Multiverse-Core so your best bet is to go delete the folder by hand. Sorry.");
this.plugin.log(Level.SEVERE, e.getMessage());
return false;
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteWorld(String name, boolean removeFromConfig) {
return this.deleteWorld(name, removeFromConfig, true);
}
/**
* {@inheritDoc}
*/
@@ -612,13 +603,33 @@ public class WorldManager implements MVWorldManager {
// Basic Counter to count how many Worlds we are loading.
int count = 0;
this.ensureConfigIsPrepared();
this.ensureSecondNamespaceIsPrepared();
// Force the worlds to be loaded, ie don't just load new worlds.
if (forceLoad) {
// Remove all world permissions.
Permission allAccess = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
for (MultiverseWorld w : this.worlds.values()) {
// Remove this world from the master list
if (allAccess != null) {
allAccess.getChildren().remove(w.getAccessPermission().getName());
}
if (allExempt != null) {
allExempt.getChildren().remove(w.getAccessPermission().getName());
}
this.plugin.getServer().getPluginManager().removePermission(w.getAccessPermission().getName());
this.plugin.getServer().getPluginManager().removePermission(w.getExemptPermission().getName());
// Special namespace for gamemodes
this.plugin.getServer().getPluginManager().removePermission("mv.bypass.gamemode." + w.getName());
}
// Recalc the all permission
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allExempt);
this.worlds.clear();
}
for (Map.Entry<String, WorldProperties> entry : worldsFromTheConfig.entrySet()) {
for (Map.Entry<String, MVWorld> entry : worldsFromTheConfig.entrySet()) {
if (worlds.containsKey(entry.getKey())) {
continue;
}
@@ -630,10 +641,18 @@ public class WorldManager implements MVWorldManager {
}
// Simple Output to the Console to show how many Worlds were loaded.
Logging.config("%s - World(s) loaded.", count);
this.plugin.log(Level.INFO, count + " - World(s) loaded.");
this.saveWorldsConfig();
}
private void ensureSecondNamespaceIsPrepared() {
Permission special = this.plugin.getServer().getPluginManager().getPermission("mv.bypass.gamemode.*");
if (special == null) {
special = new Permission("mv.bypass.gamemode.*", PermissionDefault.FALSE);
this.plugin.getServer().getPluginManager().addPermission(special);
}
}
/**
* {@inheritDoc}
* @deprecated This is deprecated!
@@ -670,23 +689,31 @@ public class WorldManager implements MVWorldManager {
// load world-objects
Stack<String> worldKeys = new Stack<String>();
worldKeys.addAll(this.configWorlds.getConfigurationSection("worlds").getKeys(false));
Map<String, WorldProperties> newWorldsFromTheConfig = new HashMap<String, WorldProperties>();
Map<String, MVWorld> newWorldsFromTheConfig = new HashMap<String, MVWorld>();
while (!worldKeys.isEmpty()) {
String key = worldKeys.pop();
String path = "worlds" + SEPARATOR + key;
Object obj = this.configWorlds.get(path);
if ((obj != null) && (obj instanceof WorldProperties)) {
if ((obj != null) && (obj instanceof MVWorld)) {
String worldName = key.replaceAll(String.valueOf(SEPARATOR), ".");
WorldProperties props = (WorldProperties) obj;
MVWorld mvWorld = null;
if (this.worldsFromTheConfig.containsKey(worldName)) {
// Object-Recycling :D
// TODO Why is is checking worldsFromTheConfig and then getting from worlds? So confused... (DTM)
MVWorld mvWorld = (MVWorld) this.worlds.get(worldName);
mvWorld = (MVWorld) this.worlds.get(worldName);
if (mvWorld != null) {
mvWorld.copyValues((WorldProperties) obj);
mvWorld.copyValues((MVWorld) obj);
}
}
newWorldsFromTheConfig.put(worldName, props);
if (mvWorld == null) {
// we have to use a new one
World cbworld = this.plugin.getServer().getWorld(worldName);
mvWorld = (MVWorld) obj;
if (cbworld != null) {
mvWorld.init(cbworld, this.plugin);
}
}
newWorldsFromTheConfig.put(worldName, mvWorld);
} else if (this.configWorlds.isConfigurationSection(path)) {
ConfigurationSection section = this.configWorlds.getConfigurationSection(path);
Set<String> subkeys = section.getKeys(false);
@@ -708,7 +735,7 @@ public class WorldManager implements MVWorldManager {
try {
this.configWorlds.options().pathSeparator(SEPARATOR);
this.configWorlds.set("worlds", null);
for (Map.Entry<String, WorldProperties> entry : worldsFromTheConfig.entrySet()) {
for (Map.Entry<String, ? extends MultiverseWorld> entry : worldsFromTheConfig.entrySet()) {
this.configWorlds.set("worlds" + SEPARATOR + entry.getKey(), entry.getValue());
}
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
@@ -763,10 +790,9 @@ public class WorldManager implements MVWorldManager {
world.setSeed(theSeed);
}
WorldType type = world.getWorldType();
if (this.deleteWorld(name, false, false)) {
this.doLoad(name, true, type);
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!
-21
View File
@@ -211,24 +211,3 @@ commands:
usage: |
/<command> <world> <environment>
/<command> creative grieftastic -- Creates a world called 'grieftastic' exactly identical to the world 'creative'.
mvsilent:
description: Reduces startup messages
usage: |
/<command> [true|false]
mvgamerule:
description: Sets a gamerule.
usage: |
/<command> {RULE} {VALUE} [WORLD]
mvrule:
description: Sets a gamerule.
usage: |
/<command> {RULE} {VALUE} [WORLD]
mvgamerules:
description: Lists the gamerules.
usage: |
/<command> [WORLD]
mvrules:
description: Lists the gamerules.
usage: |
/<command> [WORLD]
@@ -5,11 +5,17 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore;
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import junit.framework.Assert;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -22,12 +28,9 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.File;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
@@ -1,9 +1,13 @@
package com.onarandombox.MultiverseCore;
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 com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -20,13 +24,11 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
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 })
@@ -1,7 +1,8 @@
package com.onarandombox.MultiverseCore;
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import org.bukkit.Server;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
@@ -14,9 +15,9 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@@ -5,20 +5,21 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore;
package com.onarandombox.MultiverseCore.test;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
@@ -72,7 +73,6 @@ public class TestWorldProperties {
private Player mockNewPlayer;
private PlayerJoinEvent playerNewJoinEvent;
private PlayerJoinEvent playerJoinEvent;
private PlayerRespawnEvent playerRespawnBed;
private PlayerRespawnEvent playerRespawnNormal;
private HumanEntity mockHumanEntity;
private EntityRegainHealthEvent entityRegainHealthEvent;
@@ -101,8 +101,8 @@ public class TestWorldProperties {
// Import the first world
String[] normalArgs = new String[] { "import", "world", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", normalArgs);
verify(mockCommandSender).sendMessage("Starting import of world 'world'...");
verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!");
//verify(mockCommandSender).sendMessage("Starting import of world 'world'...");
//verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!");
// Import a second world
String[] netherArgs = new String[] { "import", "world_nether", "nether" };
@@ -132,7 +132,6 @@ public class TestWorldProperties {
assertEquals(ChatColor.WHITE, mvWorld.getColor());
assertTrue(mvWorld.isPVPEnabled());
assertEquals(1D, mvWorld.getScaling(), 0);
assertNull(mvWorld.getRespawnToWorld());
assertTrue(mvWorld.isWeatherEnabled());
assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
assertTrue(mvWorld.canAnimalsSpawn());
@@ -144,7 +143,6 @@ public class TestWorldProperties {
assertTrue(mvWorld.getAdjustSpawn());
assertEquals(GameMode.SURVIVAL, mvWorld.getGameMode());
assertTrue(mvWorld.isKeepingSpawnInMemory());
assertTrue(mvWorld.getBedRespawn());
assertTrue(mvWorld.getAutoLoad());
assertEquals(new SpawnLocation(0, 64, 0), mvWorld.getSpawnLocation());
@@ -179,12 +177,9 @@ public class TestWorldProperties {
core.getPlayerListener().playerJoin(playerNewJoinEvent);
verify(mockNewPlayer).teleport(worldManager.getFirstSpawnWorld().getSpawnLocation());
// call player respawn events
core.getPlayerListener().playerRespawn(playerRespawnBed);
// bedrespawn is on so nothing should happen
verify(playerRespawnBed, never()).setRespawnLocation(any(Location.class));
core.getPlayerListener().playerRespawn(playerRespawnNormal);
verify(playerRespawnNormal).setRespawnLocation(mvWorld.getSpawnLocation());
// call player respawn event
//core.getPlayerListener().playerRespawn(playerRespawnNormal);
//verify(playerRespawnNormal).setRespawnLocation(mvWorld.getSpawnLocation());
// call entity regain health event
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
@@ -207,10 +202,6 @@ public class TestWorldProperties {
assertEquals(false, mvWorld.isPVPEnabled());
assertTrue(mvWorld.setScaling(2D));
assertEquals(2D, mvWorld.getScaling(), 0);
assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
assertTrue(mvWorld.setRespawnToWorld("world_nether"));
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
mvWorld.getRespawnToWorld());
mvWorld.setEnableWeather(false);
assertEquals(false, mvWorld.isWeatherEnabled());
assertTrue(mvWorld.setDifficulty(Difficulty.PEACEFUL));
@@ -233,8 +224,6 @@ public class TestWorldProperties {
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
mvWorld.setKeepSpawnInMemory(false);
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
mvWorld.setBedRespawn(false);
assertEquals(false, mvWorld.getBedRespawn());
mvWorld.setAutoLoad(false);
assertEquals(false, mvWorld.getAutoLoad());
mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
@@ -279,12 +268,9 @@ public class TestWorldProperties {
core.getPlayerListener().playerJoin(playerNewJoinEvent);
verify(mockNewPlayer).teleport(new SpawnLocation(1, 1, 1));
// call player respawn events
core.getPlayerListener().playerRespawn(playerRespawnBed);
// bedrespawn is off so something should happen (and we've set respawn to nether...)
verify(playerRespawnBed).setRespawnLocation(netherWorld.getSpawnLocation());
core.getPlayerListener().playerRespawn(playerRespawnNormal);
verify(playerRespawnNormal).setRespawnLocation(netherWorld.getSpawnLocation());
// call player respawn event
//core.getPlayerListener().playerRespawn(playerRespawnNormal);
//verify(playerRespawnNormal).setRespawnLocation(netherWorld.getSpawnLocation());
// call entity regain health event
core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
@@ -298,7 +284,7 @@ public class TestWorldProperties {
assertTrue(core.saveMVConfigs());
// change a value here
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
WorldProperties worldObj = (WorldProperties) config.get("worlds.world");
MVWorld worldObj = (MVWorld) config.get("worlds.world");
assertTrue(worldObj.setColor("GREEN"));
config.set("worlds.world", worldObj);
config.save(new File(core.getDataFolder(), "worlds.yml"));
@@ -312,8 +298,6 @@ public class TestWorldProperties {
assertEquals(ChatColor.GREEN.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
assertEquals(false, mvWorld.isPVPEnabled());
assertEquals(2D, mvWorld.getScaling(), 0);
assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
mvWorld.getRespawnToWorld());
assertEquals(false, mvWorld.isWeatherEnabled());
assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
assertEquals(false, mvWorld.canAnimalsSpawn());
@@ -325,24 +309,22 @@ public class TestWorldProperties {
assertEquals(false, mvWorld.getAdjustSpawn());
assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
assertEquals(false, mvWorld.isKeepingSpawnInMemory());
assertEquals(false, mvWorld.getBedRespawn());
assertEquals(false, mvWorld.getAutoLoad());
assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());
}
public void createEvents(MultiverseWorld mvWorld) {
final World world = mvWorld.getCBWorld();
//// Weather events
// weather change
weatherChangeOffEvent = new WeatherChangeEvent(world, false);
weatherChangeOnEvent = new WeatherChangeEvent(world, true);
weatherChangeOffEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), false);
weatherChangeOnEvent = new WeatherChangeEvent(mvWorld.getCBWorld(), true);
// thunder change
thunderChangeOffEvent = new ThunderChangeEvent(world, false);
thunderChangeOnEvent = new ThunderChangeEvent(world, true);
thunderChangeOffEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), false);
thunderChangeOnEvent = new ThunderChangeEvent(mvWorld.getCBWorld(), true);
//// Player events
// player chat
mockPlayer = mock(Player.class);
when(mockPlayer.getWorld()).thenReturn(world);
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
when(mockPlayer.hasPlayedBefore()).thenReturn(true);
when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true);
when(mockPlayer.getName()).thenReturn("MultiverseMan");
@@ -357,9 +339,6 @@ public class TestWorldProperties {
playerNewJoinEvent = PowerMockito.mock(PlayerJoinEvent.class);
when(playerNewJoinEvent.getPlayer()).thenReturn(mockNewPlayer);
// player respawn
playerRespawnBed = PowerMockito.mock(PlayerRespawnEvent.class);
when(playerRespawnBed.getPlayer()).thenReturn(mockPlayer);
when(playerRespawnBed.isBedSpawn()).thenReturn(true);
playerRespawnNormal = PowerMockito.mock(PlayerRespawnEvent.class);
when(playerRespawnNormal.getPlayer()).thenReturn(mockPlayer);
when(playerRespawnNormal.isBedSpawn()).thenReturn(false);
@@ -368,7 +347,7 @@ public class TestWorldProperties {
// entity regain health
entityRegainHealthEvent = PowerMockito.mock(EntityRegainHealthEvent.class);
when(entityRegainHealthEvent.getRegainReason()).thenReturn(RegainReason.REGEN);
when(mockHumanEntity.getLocation()).thenReturn(new Location(world, 0, 0, 0));
when(mockHumanEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
when(entityRegainHealthEvent.getEntity()).thenReturn(mockHumanEntity);
// entity food level change event
entityFoodLevelChangeEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
@@ -1,8 +1,10 @@
package com.onarandombox.MultiverseCore;
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -16,10 +18,10 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Arrays;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
@@ -111,13 +113,10 @@ public class TestWorldPurger {
}
private void createAnimals() {
World world = mvWorld.getCBWorld();
sheep = mock(Sheep.class);
when(sheep.getType()).thenReturn(EntityType.SHEEP);
when(sheep.getWorld()).thenReturn(world);
zombie = mock(Zombie.class);
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
when(zombie.getWorld()).thenReturn(world);
when(cbworld.getEntities()).thenReturn(Arrays.asList((Entity) sheep, (Entity) zombie));
}
}
@@ -5,18 +5,15 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore;
package com.onarandombox.MultiverseCore.test;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldCreatorMatcher;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.test.utils.WorldCreatorMatcher;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.WorldCreator;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
package com.onarandombox.MultiverseCore.test.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -5,7 +5,16 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
package com.onarandombox.MultiverseCore.test.utils;
import static org.mockito.Mockito.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.bukkit.Difficulty;
import org.bukkit.Location;
@@ -17,20 +26,9 @@ import org.bukkit.generator.ChunkGenerator;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import static org.mockito.Mockito.*;
public class MockWorldFactory {
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
private static final Map<UUID, World> worldUIDS = new HashMap<UUID, World>();
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
@@ -41,7 +39,6 @@ public class MockWorldFactory {
private static void registerWorld(World world) {
createdWorlds.put(world.getName(), world);
worldUIDS.put(world.getUID(), world);
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
}
@@ -135,7 +132,6 @@ public class MockWorldFactory {
return mockBlock;
}
});
when(mockWorld.getUID()).thenReturn(UUID.randomUUID());
return mockWorld;
}
@@ -207,10 +203,6 @@ public class MockWorldFactory {
return createdWorlds.get(name);
}
public static World getWorld(UUID worldUID) {
return worldUIDS.get(worldUID);
}
public static List<World> getWorlds() {
// we have to invert the order!
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
@@ -225,6 +217,5 @@ public class MockWorldFactory {
for (String name : createdWorlds.keySet())
new File(TestInstanceCreator.worldsDirectory, name).delete();
createdWorlds.clear();
worldUIDS.clear();
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
package com.onarandombox.MultiverseCore.test.utils;
import buscript.Buscript;
import com.onarandombox.MultiverseCore.MultiverseCore;
@@ -13,6 +13,8 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.utils.FileUtils;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import junit.framework.Assert;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -36,7 +38,6 @@ import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -121,19 +122,6 @@ public class TestInstanceCreator {
}
});
when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer<World>() {
@Override
public World answer(InvocationOnMock invocation) throws Throwable {
UUID arg;
try {
arg = (UUID) invocation.getArguments()[0];
} catch (Exception e) {
return null;
}
return MockWorldFactory.getWorld(arg);
}
});
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
@Override
public List<World> answer(InvocationOnMock invocation) throws Throwable {
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
package com.onarandombox.MultiverseCore.test.utils;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
package com.onarandombox.MultiverseCore.test.utils;
import org.bukkit.WorldCreator;
import org.mockito.ArgumentMatcher;