Move World Functions to a new WorldManager.

This commit is contained in:
Eric Stokes 2011-08-24 17:25:30 -06:00
parent 3876c0f47f
commit 69360a49ec
38 changed files with 542 additions and 411 deletions

View File

@ -12,11 +12,13 @@ import org.bukkit.permissions.PermissionDefault;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.onarandombox.utils.MVDestination;
import com.onarandombox.utils.WorldManager;
import com.pneumaticraft.commandhandler.PermissionsInterface;
public class MVPermissions implements PermissionsInterface {
private MultiverseCore plugin;
private WorldManager worldMgr;
private PermissionHandler permissions = null;
/**
@ -26,6 +28,7 @@ public class MVPermissions implements PermissionsInterface {
*/
public MVPermissions(MultiverseCore plugin) {
this.plugin = plugin;
this.worldMgr = plugin.getWorldManager();
// We have to see if permissions was loaded before MV was
if (this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) {
this.setPermissions(((Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
@ -56,10 +59,10 @@ public class MVPermissions implements PermissionsInterface {
}
public boolean canTravelFromLocation(Player teleporter, Location location) {
if (!this.plugin.isMVWorld(location.getWorld().getName())) {
if (!this.worldMgr.isMVWorld(location.getWorld().getName())) {
return false;
}
return canTravelFromWorld(teleporter, this.plugin.getMVWorld(location.getWorld().getName()));
return canTravelFromWorld(teleporter, this.worldMgr.getMVWorld(location.getWorld().getName()));
}
/**
@ -78,7 +81,7 @@ public class MVPermissions implements PermissionsInterface {
return false;
}
String worldName = l.getWorld().getName();
if (!this.plugin.isMVWorld(worldName)) {
if (!this.plugin.getWorldManager().isMVWorld(worldName)) {
return false;
}
return this.hasPermission(p, "multiverse.access." + worldName, false);
@ -89,7 +92,7 @@ public class MVPermissions implements PermissionsInterface {
return false;
}
String worldName = d.getLocation(p).getWorld().getName();
if (!this.plugin.isMVWorld(worldName)) {
if (!this.worldMgr.isMVWorld(worldName)) {
return false;
}
if (!canEnterLocation(p, d.getLocation(p))) {

View File

@ -330,7 +330,7 @@ public class MVWorld {
} else {
this.world.setSpawnFlags(true, this.world.getAllowAnimals());
}
this.plugin.getWorldPurger().purgeWorld(null, this);
this.plugin.getWorldManager().getWorldPurger().purgeWorld(null, this);
}
private boolean addToList(String list, Integer value) {

View File

@ -10,26 +10,20 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import org.getspout.spoutapi.SpoutManager;
import com.fernferret.allpay.AllPay;
import com.fernferret.allpay.GenericBank;
@ -74,6 +68,7 @@ import com.onarandombox.utils.PlayerDestination;
import com.onarandombox.utils.PurgeWorlds;
import com.onarandombox.utils.UpdateChecker;
import com.onarandombox.utils.WorldDestination;
import com.onarandombox.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
@ -93,6 +88,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
// Configurations
private Configuration configMV = null;
@Deprecated
private Configuration configWorlds = null;
// Setup the block/player/entity listener.
@ -107,10 +103,12 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
public static int GlobalDebug = 0;
// HashMap to contain all the Worlds which this Plugin will manage.
@Deprecated
private HashMap<String, MVWorld> worlds = new HashMap<String, MVWorld>();
// HashMap to contain information relating to the Players.
private HashMap<String, MVPlayerSession> playerSessions;
@Deprecated
private PurgeWorlds worldPurger;
private GenericBank bank = null;
private AllPay banker = new AllPay(this, tag + " ");
@ -118,6 +116,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
protected int pluginCount;
private DestinationFactory destFactory;
private SpoutInterface spoutInterface = null;
private WorldManager worldManager;
@Override
public void onLoad() {
@ -156,6 +155,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
this.registerCommands();
this.playerSessions = new HashMap<String, MVPlayerSession>();
this.worldManager = new WorldManager(this);
// Start the Update Checker
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
@ -166,8 +166,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
// Setup & Load our Configuration files.
loadConfigs();
if (this.configMV != null) {
this.loadWorlds(true);
this.worldManager.loadWorlds(true);
} else {
this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse.");
}
@ -272,290 +271,43 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
}
/**
* Load the Worlds & Settings from the configuration file.
* Deprecated, please use WorldManager.loadWorlds(Boolean forceLoad) now.
*/
@Deprecated
public void loadWorlds(boolean forceLoad) {
// Basic Counter to count how many Worlds we are loading.
int count = 0;
// Grab all the Worlds from the Config.
List<String> worldKeys = this.configWorlds.getKeys("worlds");
// Force the worlds to be loaded, ie don't just load new worlds.
if (forceLoad) {
// Remove all world permissions.
Permission allAccess = this.getServer().getPluginManager().getPermission("multiverse.access.*");
Permission allExempt = this.getServer().getPluginManager().getPermission("multiverse.exempt.*");
for (MVWorld w : this.worlds.values()) {
// Remove this world from the master list
if (allAccess != null) {
allAccess.getChildren().remove(w.getPermission().getName());
}
if (allExempt != null) {
allExempt.getChildren().remove(w.getPermission().getName());
}
this.getServer().getPluginManager().removePermission(w.getPermission().getName());
this.getServer().getPluginManager().removePermission(w.getExempt().getName());
}
// Recalc the all permission
this.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);
this.getServer().getPluginManager().recalculatePermissionDefaults(allExempt);
this.worlds.clear();
}
// Check that the list is not null.
if (worldKeys != null) {
for (String worldKey : worldKeys) {
// Check if the World is already loaded within the Plugin.
if (this.worlds.containsKey(worldKey)) {
continue;
}
// Grab the initial values from the config file.
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", "");
String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator");
addWorld(worldKey, getEnvFromString(environment), seedString, generatorstring);
// Increment the world count
count++;
}
}
// Ensure that the worlds created by the default server were loaded into MV, useful for first time runs
// count += loadDefaultWorlds();
// TODO: This was taken out because some people don't want nether! Instead show a message to people who have MVImport
// and tell them to do MVImports for their worlds!
// Simple Output to the Console to show how many Worlds were loaded.
log(Level.INFO, count + " - World(s) loaded.");
this.worldManager.loadWorlds(true);
}
/**
* Add a new World to the Multiverse Setup.
* <p/>
* Isn't there a prettier way to do this??!!?!?!
*
* @param name World Name
* @param env Environment Type
* Deprecated, please use WorldManager.addWorld(String name, Environment env, String seedString, String generator) now.
*/
@Deprecated
public boolean addWorld(String name, Environment env, String seedString, String generator) {
staticLog(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + generator);
Long seed = null;
if (seedString != null && seedString.length() > 0) {
try {
seed = Long.parseLong(seedString);
} catch (NumberFormatException numberformatexception) {
seed = (long) seedString.hashCode();
}
}
String generatorID = null;
String generatorName = null;
if (generator != null) {
String[] split = generator.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
generatorName = split[0];
generatorID = id;
}
ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name);
if (customGenerator == null && generator != null && (generator.length() > 0)) {
if (!pluginExists(generatorName)) {
log(Level.WARNING, "Could not find plugin: " + generatorName);
} else {
log(Level.WARNING, "Found plugin: " + generatorName + ", but did not find generatorID: " + generatorID);
}
return false;
}
World world = null;
if (seed != null) {
if (customGenerator != null) {
world = getServer().createWorld(name, env, seed, customGenerator);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator);
} else {
world = getServer().createWorld(name, env, seed);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed);
}
} else {
if (customGenerator != null) {
world = getServer().createWorld(name, env, customGenerator);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator);
} else {
world = getServer().createWorld(name, env);
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
}
}
if (world == null) {
log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
return false;
}
MVWorld mvworld = new MVWorld(world, this.configWorlds, this, seed, generator);
this.worldPurger.purgeWorld(null, mvworld);
this.worlds.put(name, mvworld);
return true;
}
private boolean pluginExists(String generator) {
Plugin plugin = getServer().getPluginManager().getPlugin(generator);
return plugin != null;
}
private ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
if (generator == null) {
return null;
}
Plugin plugin = getServer().getPluginManager().getPlugin(generator);
if (plugin == null) {
return null;
} else {
return plugin.getDefaultWorldGenerator(worldName, generatorID);
}
return this.worldManager.addWorld(name, env, seedString, generator);
}
/**
* Remove the world from the Multiverse list
*
* @param name The name of the world to remove
* @return True if success, false if failure.
* Deprecated, please use WorldManager.removeWorldFromList(String name) now.
*/
@Deprecated
public boolean removeWorldFromList(String name) {
if (this.worlds.containsKey(name)) {
this.worlds.remove(name);
this.log(Level.INFO, "World " + name + " was unloaded from memory.");
this.unloadWorld(name, true);
return true;
} else if (this.getServer().getWorld(name) != null) {
this.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's still loaded in memory.");
this.log(Level.WARNING, "To be on the safe side, you should import it then try unloading again...");
} else {
this.log(Level.INFO, "The world " + name + " was already unloaded/did not exist.");
}
return false;
return this.worldManager.removeWorldFromList(name);
}
/**
* Remove the world from the Multiverse list and from the config
*
* @param name The name of the world to remove
* @return True if success, false if failure.
* Deprecated, please use WorldManager.removeWorldFromConfig(String name) now.
*/
@Deprecated
public boolean removeWorldFromConfig(String name) {
if (this.configWorlds.getProperty("worlds." + name) != null) {
removeWorldFromList(name);
this.log(Level.INFO, "World " + name + " was removed from config.yml");
this.configWorlds.removeProperty("worlds." + name);
this.configWorlds.save();
return true;
} else {
this.log(Level.INFO, "World " + name + " was already removed from config.yml");
}
return false;
return this.worldManager.removeWorldFromConfig(name);
}
/**
* Remove the world from the Multiverse list, from the config and deletes the folder
*
* @param name The name of the world to remove
* @return True if success, false if failure.
* Deprecated please use WorldManager.deleteWorld(String name) now.
*/
@Deprecated
public Boolean deleteWorld(String name) {
if (this.getServer().getWorld(name) != null) {
if (!unloadWorld(name, false)) {
// If the world was loaded, and we couldn't unload it, return false. DON"T DELTEE
return false;
}
}
removeWorldFromConfig(name);
try {
File serverFolder = new File(this.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
File worldFile = new File(serverFolder.getAbsolutePath() + File.separator + name);
if (name.equalsIgnoreCase("plugins")) {
this.log(Level.SEVERE, "Really? Are you high? This would delete your plugins folder. Luckily the MV2 devs are crazy smart or you're server would be ended...");
return false;
} else if (name.toLowerCase().contains("plugins")) {
this.log(Level.SEVERE, "I'm sorry, did you mean to type: 'rm plugins" + File.separator + "Essential*'? I could do that for you if you'd like...");
return false;
} else if (name.contains("..")) {
this.log(Level.SEVERE, "Uh yea... No way i'm going to delete a parent directory for you. You can go do 'rm -rf *.*' on your own time...");
return false;
} else if (name.equals(".")) {
this.log(Level.SEVERE, "Why on earth would you want to use Multiverse-Core to delete your Bukkit Server! How many beers have you had tonight... Give the keys to a friend.");
return false;
} else if (!worldFile.isDirectory()) {
this.log(Level.SEVERE, "C'mon man... Really?!?! Multiverse-Core is a great way to get players from A to B, but not to manage your files. To delete this file type:");
this.log(Level.SEVERE, "stop");
this.log(Level.SEVERE, "rm " + worldFile.getAbsolutePath());
return false;
}
boolean deletedWorld = deleteFolder(worldFile);
if (deletedWorld)
{
this.log(Level.INFO, "World " + name + " was DELETED.");
} else {
this.log(Level.SEVERE, "World " + name + " was NOT deleted.");
this.log(Level.SEVERE, "Are you sure the folder " + name + " exists?");
this.log(Level.SEVERE, "Please check your file permissions on " + name);
}
return deletedWorld;
} catch (Exception e) {
this.log(Level.SEVERE, "Hrm, something didn't go as planned. Here's an exception for ya.");
this.log(Level.SEVERE, "You can go politely explain your situation in #multiverse on esper.net");
this.log(Level.SEVERE, "But from here, it looks like your folder is oddly named.");
this.log(Level.SEVERE, "This world has been removed from Multiverse-Core so your best bet is to go delete the folder by hand. Sorry.");
System.out.print(e);
return false;
}
}
private boolean unloadWorld(String name, boolean safely) {
this.removePlayersFromWorld(name);
return getServer().unloadWorld(name, safely);
}
private void removePlayersFromWorld(String name) {
World w = this.getServer().getWorld(name);
if (w != null) {
World safeWorld = this.getServer().getWorlds().get(0);
List<Player> ps = w.getPlayers();
for (Player p : ps) {
p.teleport(safeWorld.getSpawnLocation());
}
}
}
/**
* Delete a folder Courtesy of: lithium3141
*
* @param file The folder to delete
* @return true if success
*/
private boolean deleteFolder(File file) {
if (file.exists()) {
// If the file exists, and it has more than one file in it.
if (file.isDirectory()) {
for (File f : file.listFiles()) {
if (!this.deleteFolder(f)) {
return false;
}
}
}
file.delete();
return !file.exists();
} else {
return false;
}
return this.worldManager.deleteWorld(name);
}
/**
@ -600,6 +352,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
return this.ph;
}
@Deprecated
public PurgeWorlds getWorldPurger() {
return this.worldPurger;
}
@ -683,7 +436,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
}
public String getTag() {
return this.tag;
return MultiverseCore.tag;
}
/**
@ -711,45 +464,19 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
}
// TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF
@Deprecated
public Collection<MVWorld> getMVWorlds() {
return this.worlds.values();
}
@Deprecated
public MVWorld getMVWorld(String name) {
if (this.worlds.containsKey(name)) {
return this.worlds.get(name);
}
return this.getMVWorldByAlias(name);
}
private MVWorld getMVWorldByAlias(String alias) {
for (MVWorld w : this.worlds.values()) {
if (w.getAlias().equalsIgnoreCase(alias)) {
return w;
}
}
return null;
return this.worldManager.getMVWorld(name);
}
@Deprecated
public boolean isMVWorld(String name) {
return (this.worlds.containsKey(name) || isMVWorldAlias(name));
}
/**
* This method ONLY checks the alias of each world.
*
* @param name
* @return
*/
private boolean isMVWorldAlias(String name) {
for (MVWorld w : this.worlds.values()) {
if (w.getAlias().equalsIgnoreCase(name)) {
return true;
}
}
return false;
return this.worldManager.isMVWorld(name);
}
public void showNotMVWorldMessage(CommandSender sender, String worldName) {
@ -840,4 +567,8 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
return this.spoutInterface;
}
public WorldManager getWorldManager() {
return this.worldManager;
}
}

View File

@ -13,8 +13,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.LocationManipulation;
import com.onarandombox.utils.WorldManager;
public class CoordCommand extends MultiverseCommand {
private WorldManager worldManager;
public CoordCommand(MultiverseCore plugin) {
super(plugin);
@ -25,6 +27,7 @@ public class CoordCommand extends MultiverseCommand {
this.addKey("mvcoord");
this.addKey("mvco");
this.setPermission("multiverse.core.coord", "Returns detailed information on the Players where abouts.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -34,12 +37,12 @@ public class CoordCommand extends MultiverseCommand {
Player p = (Player) sender;
World world = p.getWorld();
if (!this.plugin.isMVWorld(world.getName())) {
if (!this.worldManager.isMVWorld(world.getName())) {
this.plugin.showNotMVWorldMessage(sender, world.getName());
return;
}
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
MVWorld mvworld = this.worldManager.getMVWorld(world.getName());
p.sendMessage(ChatColor.AQUA + "--- Location Information ---");
p.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + world.getName());

View File

@ -9,9 +9,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
public class CreateCommand extends MultiverseCommand {
private WorldManager worldManager;
public CreateCommand(MultiverseCore plugin) {
super(plugin);
@ -27,6 +29,7 @@ public class CreateCommand extends MultiverseCommand {
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " skylands");
this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel");
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -40,7 +43,7 @@ public class CreateCommand extends MultiverseCommand {
String seed = CommandHandler.getFlag("-s", args);
String generator = CommandHandler.getFlag("-g", args);
if (new File(worldName).exists() || this.plugin.isMVWorld(worldName)) {
if (new File(worldName).exists() || this.worldManager.isMVWorld(worldName)) {
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
return;
@ -53,7 +56,7 @@ public class CreateCommand extends MultiverseCommand {
return;
}
sender.sendMessage(ChatColor.AQUA + "Starting world creation...");
if (this.plugin.addWorld(worldName, environment, seed, generator)) {
if (this.worldManager.addWorld(worldName, environment, seed, generator)) {
sender.sendMessage(ChatColor.GREEN + "Complete!");
} else {
sender.sendMessage(ChatColor.RED + "FAILED.");

View File

@ -30,7 +30,7 @@ public class DebugCommand extends MultiverseCommand {
} else {
try {
int debugLevel = Integer.parseInt(args.get(0));
if(debugLevel > 3 || debugLevel < 0) {
if (debugLevel > 3 || debugLevel < 0) {
throw new NumberFormatException();
}
MultiverseCore.GlobalDebug = debugLevel;

View File

@ -8,7 +8,6 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class EnvironmentCommand extends MultiverseCommand {
public EnvironmentCommand(MultiverseCore plugin) {
@ -23,7 +22,6 @@ public class EnvironmentCommand extends MultiverseCommand {
this.setPermission("multiverse.core.list.environments", "Lists valid known environments.", PermissionDefault.OP);
}
public static void showEnvironments(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:");
sender.sendMessage(ChatColor.GREEN + "NORMAL");

View File

@ -31,15 +31,15 @@ public class GeneratorCommand extends MultiverseCommand {
Plugin[] plugins = this.plugin.getServer().getPluginManager().getPlugins();
List<String> generators = new ArrayList<String>();
for (Plugin p : plugins) {
if(p.isEnabled() && p.getDefaultWorldGenerator("world", "") != null) {
if (p.isEnabled() && p.getDefaultWorldGenerator("world", "") != null) {
generators.add(p.getDescription().getName());
}
}
sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---");
String loadedGens = "";
boolean altColor = false;
for(String s : generators) {
if(altColor) {
for (String s : generators) {
if (altColor) {
altColor = false;
loadedGens += ChatColor.YELLOW + s + "";
} else {
@ -47,7 +47,7 @@ public class GeneratorCommand extends MultiverseCommand {
loadedGens += ChatColor.WHITE + s + "";
}
}
if(loadedGens.length() == 0) {
if (loadedGens.length() == 0) {
loadedGens = ChatColor.RED + "No Generator Plugins found.";
}
sender.sendMessage(loadedGens);

View File

@ -97,7 +97,7 @@ public class HelpCommand extends MultiverseCommand {
filtered.add(c);
} else if (c.getCommandDesc().matches("(?i).*" + filter + ".*")) {
filtered.add(c);
}else if (c.getCommandUsage().matches("(?i).*" + filter + ".*")) {
} else if (c.getCommandUsage().matches("(?i).*" + filter + ".*")) {
filtered.add(c);
}
}

View File

@ -9,8 +9,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
public class ImportCommand extends MultiverseCommand {
private WorldManager worldManager;
public ImportCommand(MultiverseCore plugin) {
super(plugin);
@ -21,12 +23,13 @@ public class ImportCommand extends MultiverseCommand {
this.addKey("mvim");
this.addKey("mv import");
this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
String worldName = args.get(0);
if (this.plugin.isMVWorld(worldName) && new File(worldName).exists()) {
if (this.worldManager.isMVWorld(worldName) && new File(worldName).exists()) {
sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!");
return;
}
@ -46,7 +49,7 @@ public class ImportCommand extends MultiverseCommand {
if (new File(worldName).exists() && env != null) {
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
this.plugin.addWorld(worldName, environment, null, generator);
this.worldManager.addWorld(worldName, environment, null, generator);
sender.sendMessage(ChatColor.GREEN + "Complete!");
return;
} else if (env == null) {

View File

@ -16,8 +16,10 @@ import com.onarandombox.utils.FancyHeader;
import com.onarandombox.utils.FancyMessage;
import com.onarandombox.utils.FancyText;
import com.onarandombox.utils.LocationManipulation;
import com.onarandombox.utils.WorldManager;
public class InfoCommand extends MultiverseCommand {
private WorldManager worldManager;
public InfoCommand(MultiverseCore plugin) {
super(plugin);
@ -28,6 +30,7 @@ public class InfoCommand extends MultiverseCommand {
this.addKey("mvi");
this.addKey("mv info");
this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -46,7 +49,7 @@ public class InfoCommand extends MultiverseCommand {
}
}
else if (args.size() == 1) {
if (this.plugin.getMVWorld(args.get(0)) != null) {
if (this.worldManager.getMVWorld(args.get(0)) != null) {
// then we have a world!
worldName = args.get(0);
} else {
@ -73,12 +76,12 @@ public class InfoCommand extends MultiverseCommand {
}
}
if (this.plugin.isMVWorld(worldName)) {
if (this.worldManager.isMVWorld(worldName)) {
Player p = null;
if(sender instanceof Player) {
if (sender instanceof Player) {
p = (Player) sender;
}
showPage(pageNum, sender, this.buildEntireCommand(this.plugin.getMVWorld(worldName), p));
showPage(pageNum, sender, this.buildEntireCommand(this.worldManager.getMVWorld(worldName), p));
} else if (this.plugin.getServer().getWorld(worldName) != null) {
sender.sendMessage("That world exists, but multiverse does not know about it!");
sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}");
@ -105,7 +108,7 @@ public class InfoCommand extends MultiverseCommand {
}
if (world.getRespawnToWorld() != null) {
MVWorld respawn = this.plugin.getMVWorld(world.getRespawnToWorld());
MVWorld respawn = this.worldManager.getMVWorld(world.getRespawnToWorld());
if (respawn != null) {
message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors));
} else {
@ -165,10 +168,10 @@ public class InfoCommand extends MultiverseCommand {
}
private String toCommaSeperated(List<String> list) {
if(list == null || list.size() == 0) {
if (list == null || list.size() == 0) {
return "";
}
if(list.size() == 1) {
if (list.size() == 1) {
return list.get(0);
}
String result = list.get(0);

View File

@ -32,7 +32,7 @@ public class ListCommand extends MultiverseCommand {
}
String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n";
for (MVWorld world : this.plugin.getMVWorlds()) {
for (MVWorld world : this.plugin.getWorldManager().getMVWorlds()) {
if (p != null && (!this.plugin.getPermissions().canEnterWorld(p, world))) {
continue;

View File

@ -9,11 +9,13 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
// This will contain all the properties that support the ADD/REMOVE
// Anything not in here will only support the SET action
public class ModifyAddCommand extends MultiverseCommand {
private WorldManager worldManager;
public ModifyAddCommand(MultiverseCore plugin) {
super(plugin);
@ -25,6 +27,7 @@ public class ModifyAddCommand extends MultiverseCommand {
this.addKey("mv modify add");
this.addKey("mvmodify add");
this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -48,9 +51,9 @@ public class ModifyAddCommand extends MultiverseCommand {
String property = args.get(1);
if (args.size() == 2) {
world = this.plugin.getMVWorld(p.getWorld().getName());
world = this.worldManager.getMVWorld(p.getWorld().getName());
} else {
world = this.plugin.getMVWorld(args.get(2));
world = this.worldManager.getMVWorld(args.get(2));
}
if (world == null) {

View File

@ -9,8 +9,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
public class ModifyClearCommand extends MultiverseCommand {
private WorldManager worldManager;
public ModifyClearCommand(MultiverseCore plugin) {
super(plugin);
@ -22,6 +24,7 @@ public class ModifyClearCommand extends MultiverseCommand {
this.addKey("mv modify clear");
this.addKey("mvmodify clear");
this.setPermission("multiverse.core.modify.clear", "Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -43,9 +46,9 @@ public class ModifyClearCommand extends MultiverseCommand {
String property = args.get(0);
if (args.size() == 1) {
world = this.plugin.getMVWorld(p.getWorld().getName());
world = this.worldManager.getMVWorld(p.getWorld().getName());
} else {
world = this.plugin.getMVWorld(args.get(1));
world = this.worldManager.getMVWorld(args.get(1));
}
if (world == null) {

View File

@ -9,8 +9,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
public class ModifyRemoveCommand extends MultiverseCommand {
private WorldManager worldManager;
public ModifyRemoveCommand(MultiverseCore plugin) {
super(plugin);
@ -26,6 +28,7 @@ public class ModifyRemoveCommand extends MultiverseCommand {
this.addKey("mv modify delete");
this.addKey("mvmodify delete");
this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -49,9 +52,9 @@ public class ModifyRemoveCommand extends MultiverseCommand {
String property = args.get(1);
if (args.size() == 2) {
world = this.plugin.getMVWorld(p.getWorld().getName());
world = this.worldManager.getMVWorld(p.getWorld().getName());
} else {
world = this.plugin.getMVWorld(args.get(2));
world = this.worldManager.getMVWorld(args.get(2));
}
if (world == null) {

View File

@ -9,8 +9,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
public class ModifySetCommand extends MultiverseCommand {
private WorldManager worldManager;
public ModifySetCommand(MultiverseCore plugin) {
super(plugin);
@ -22,6 +24,7 @@ public class ModifySetCommand extends MultiverseCommand {
this.addKey("mv modify set");
this.addKey("mvmodify set");
this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -45,9 +48,9 @@ public class ModifySetCommand extends MultiverseCommand {
String property = args.get(0);
if (args.size() == 2) {
world = this.plugin.getMVWorld(p.getWorld().getName());
world = this.worldManager.getMVWorld(p.getWorld().getName());
} else {
world = this.plugin.getMVWorld(args.get(2));
world = this.worldManager.getMVWorld(args.get(2));
}
if (world == null) {

View File

@ -10,6 +10,7 @@ import com.pneumaticraft.commandhandler.Command;
public abstract class MultiverseCommand extends Command {
protected MultiverseCore plugin;
public MultiverseCommand(MultiverseCore plugin) {
super(plugin);
this.plugin = plugin;

View File

@ -12,8 +12,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.PurgeWorlds;
import com.onarandombox.utils.WorldManager;
public class PurgeCommand extends MultiverseCommand {
private WorldManager worldManager;
public PurgeCommand(MultiverseCore plugin) {
super(plugin);
@ -23,6 +25,7 @@ public class PurgeCommand extends MultiverseCommand {
this.addKey("mvpurge");
this.addKey("mv purge");
this.setPermission("multiverse.core.purge", "Removed the specified type of mob from the specified world.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -46,8 +49,8 @@ public class PurgeCommand extends MultiverseCommand {
deathName = args.get(1);
}
if (!worldName.equalsIgnoreCase("all") && !this.plugin.isMVWorld(worldName)) {
((MultiverseCore)this.plugin).showNotMVWorldMessage(sender, worldName);
if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) {
((MultiverseCore) this.plugin).showNotMVWorldMessage(sender, worldName);
sender.sendMessage("It cannot be purged.");
return;
}
@ -55,12 +58,12 @@ public class PurgeCommand extends MultiverseCommand {
List<MVWorld> worldsToRemoveEntitiesFrom = new ArrayList<MVWorld>();
// Handle all case any user who names a world "all" should know better...
if (worldName.equalsIgnoreCase("all")) {
worldsToRemoveEntitiesFrom.addAll(this.plugin.getMVWorlds());
worldsToRemoveEntitiesFrom.addAll(this.worldManager.getMVWorlds());
} else {
worldsToRemoveEntitiesFrom.add(this.plugin.getMVWorld(worldName));
worldsToRemoveEntitiesFrom.add(this.worldManager.getMVWorld(worldName));
}
PurgeWorlds purger = this.plugin.getWorldPurger();
PurgeWorlds purger = this.worldManager.getWorldPurger();
ArrayList<String> thingsToKill = new ArrayList<String>();
if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) {
thingsToKill.add(deathName.toUpperCase());

View File

@ -26,7 +26,7 @@ public class ReloadCommand extends MultiverseCommand {
public void runCommand(CommandSender sender, List<String> args) {
sender.sendMessage(ChatColor.GOLD + "Reloading all Multiverse Plugin configs...");
this.plugin.loadConfigs();
this.plugin.loadWorlds(true);
this.plugin.getWorldManager().loadWorlds(true);
// Create the event
List<String> configsLoaded = new ArrayList<String>();
@ -34,7 +34,7 @@ public class ReloadCommand extends MultiverseCommand {
configsLoaded.add("Multiverse-Core - worlds.yml");
MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded);
this.plugin.getServer().getPluginManager().callEvent(configReload);
for(String s : configReload.getAllConfigsLoaded()) {
for (String s : configReload.getAllConfigsLoaded()) {
sender.sendMessage(s);
}

View File

@ -22,7 +22,7 @@ public class RemoveCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
if (this.plugin.removeWorldFromConfig(args.get(0))) {
if (this.plugin.getWorldManager().removeWorldFromConfig(args.get(0))) {
sender.sendMessage("World removed from config!");
} else {
sender.sendMessage("Error trying to remove world from config!");

View File

@ -33,8 +33,8 @@ public class SetSpawnCommand extends MultiverseCommand {
Player p = (Player) sender;
Location l = p.getLocation();
World w = p.getWorld();
MVWorld foundWorld = this.plugin.getMVWorld(w.getName());
if(foundWorld != null) {
MVWorld foundWorld = this.plugin.getWorldManager().getMVWorld(w.getName());
if (foundWorld != null) {
foundWorld.setSpawn(p.getLocation());
sender.sendMessage("Spawn was set to: " + LocationManipulation.strCoords(p.getLocation()));
} else {
@ -42,7 +42,6 @@ public class SetSpawnCommand extends MultiverseCommand {
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully.");
}
} else {
sender.sendMessage("You cannot use this command from the console.");
}

View File

@ -29,13 +29,13 @@ public class SleepCommand extends MultiverseCommand {
if (p == null) {
return;
}
// MVPlayerSession session = this.plugin.getPlayerSession(p);
// if (session.getBedRespawnLocation() != null) {
// p.teleport(session.getBedRespawnLocation());
// } else {
// sender.sendMessage("Hmm this is awkward...");
// sender.sendMessage("Something is wrong with your bed.");
// sender.sendMessage("It has either been destroyed or obstructed.");
// }
// MVPlayerSession session = this.plugin.getPlayerSession(p);
// if (session.getBedRespawnLocation() != null) {
// p.teleport(session.getBedRespawnLocation());
// } else {
// sender.sendMessage("Hmm this is awkward...");
// sender.sendMessage("Something is wrong with your bed.");
// sender.sendMessage("It has either been destroyed or obstructed.");
// }
}
}

View File

@ -67,8 +67,8 @@ public class SpawnCommand extends MultiverseCommand {
}
private void spawnAccurately(Player player) {
MVWorld world = this.plugin.getMVWorld(player.getWorld().getName());
if(world != null) {
MVWorld world = this.plugin.getWorldManager().getMVWorld(player.getWorld().getName());
if (world != null) {
player.teleport(world.getSpawnLocation());
} else {
player.teleport(player.getWorld().getSpawnLocation());

View File

@ -40,7 +40,7 @@ public class SpoutCommand extends MultiverseCommand {
sender.sendMessage(ChatColor.RED + p.getName() + "You need to be using the Spoutcraft client to run this command!");
return;
}
PopupScreen pop = new GenericPopup();
PopupScreen pop = new GenericPopup();
GenericButton button = new GenericButton("Fish");
button.setX(50);
button.setY(50);

View File

@ -90,7 +90,7 @@ public class TeleportCommand extends MultiverseCommand {
MVDestination d = df.getDestination(destinationName);
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter);
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
if(teleportEvent.isCancelled()) {
if (teleportEvent.isCancelled()) {
return;
}

View File

@ -22,7 +22,7 @@ public class UnloadCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
if (this.plugin.removeWorldFromList(args.get(0))) {
if (this.plugin.getWorldManager().removeWorldFromList(args.get(0))) {
sender.sendMessage("World Unloaded!");
} else {
sender.sendMessage("Error trying to unload world!");

View File

@ -41,7 +41,7 @@ public class VersionCommand extends MultiverseCommand {
logAndAddToPasteBinBuffer("Multiverse-Core Version: " + this.plugin.getDescription().getVersion());
logAndAddToPasteBinBuffer("Bukkit Version: " + this.plugin.getServer().getVersion());
logAndAddToPasteBinBuffer("Loaded Worlds: " + this.plugin.getMVWorlds().size());
logAndAddToPasteBinBuffer("Loaded Worlds: " + this.plugin.getWorldManager().getMVWorlds().size());
logAndAddToPasteBinBuffer("Multiverse Plugins Loaded: " + this.plugin.getPluginCount());
logAndAddToPasteBinBuffer("Economy being used: " + this.plugin.getBank().getEconUsed());
logAndAddToPasteBinBuffer("Permissions Plugin: " + this.plugin.getPermissions().getType());

View File

@ -10,9 +10,12 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
public class WhoCommand extends MultiverseCommand {
private WorldManager worldManager;
public WhoCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Who?");
@ -22,6 +25,7 @@ public class WhoCommand extends MultiverseCommand {
this.addKey("mvw");
this.addKey("mvwho");
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
this.worldManager = this.plugin.getWorldManager();
}
@Override
@ -40,15 +44,15 @@ public class WhoCommand extends MultiverseCommand {
if (args.size() > 0) {
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
showAll = true;
worlds = new ArrayList<MVWorld>(this.plugin.getMVWorlds());
} else if (this.plugin.isMVWorld(args.get(0))) {
worlds.add(this.plugin.getMVWorld(args.get(0)));
worlds = new ArrayList<MVWorld>(this.worldManager.getMVWorlds());
} else if (this.worldManager.isMVWorld(args.get(0))) {
worlds.add(this.worldManager.getMVWorld(args.get(0)));
} else {
sender.sendMessage(ChatColor.RED + "World does not exist");
return;
}
} else {
worlds = new ArrayList<MVWorld>(this.plugin.getMVWorlds());
worlds = new ArrayList<MVWorld>(this.worldManager.getMVWorlds());
}
if (worlds.size() == 0) {
@ -60,7 +64,7 @@ public class WhoCommand extends MultiverseCommand {
}
for (MVWorld world : worlds) {
if (!(this.plugin.isMVWorld(world.getName()))) {
if (!(this.worldManager.isMVWorld(world.getName()))) {
continue;
}

View File

@ -21,15 +21,18 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.WorldManager;
//import org.bukkit.event.entity.ExplosionPrimedEvent;
public class MVEntityListener extends EntityListener {
MultiverseCore plugin;
private MultiverseCore plugin;
private WorldManager worldManager;
public MVEntityListener(MultiverseCore plugin) {
this.plugin = plugin;
this.worldManager = plugin.getWorldManager();
}
/**
@ -56,11 +59,11 @@ public class MVEntityListener extends EntityListener {
Player player = (Player) defender;
World w = player.getWorld();
if (!this.plugin.isMVWorld(w.getName())) {
if (!this.worldManager.isMVWorld(w.getName())) {
// if the world is not handled, we don't care
return;
}
MVWorld world = this.plugin.getMVWorld(w.getName());
MVWorld world = this.worldManager.getMVWorld(w.getName());
if (attacker != null && attacker instanceof Player) {
Player pattacker = (Player) attacker;
@ -102,12 +105,12 @@ public class MVEntityListener extends EntityListener {
return;
// Check if it's a world which we are meant to be managing.
if (!(this.plugin.isMVWorld(world.getName())))
if (!(this.worldManager.isMVWorld(world.getName())))
return;
CreatureType creature = event.getCreatureType();
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
MVWorld mvworld = this.worldManager.getMVWorld(world.getName());
/**
* Animal Handling

View File

@ -15,13 +15,16 @@ import com.onarandombox.MultiverseCore.MVTeleport;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.utils.WorldManager;
public class MVPlayerListener extends PlayerListener {
MultiverseCore plugin;
MVTeleport mvteleporter;
WorldManager worldManager;
public MVPlayerListener(MultiverseCore plugin) {
this.plugin = plugin;
worldManager = plugin.getWorldManager();
}
// Taken out until we do persistance.
@ -44,10 +47,10 @@ public class MVPlayerListener extends PlayerListener {
String world = event.getPlayer().getWorld().getName();
String prefix = "";
// If we're not a MV world, don't do anything
if (!this.plugin.isMVWorld(world)) {
if (!this.worldManager.isMVWorld(world)) {
return;
}
MVWorld mvworld = this.plugin.getMVWorld(world);
MVWorld mvworld = this.worldManager.getMVWorld(world);
prefix = mvworld.getColoredWorldString();
String format = event.getFormat();
event.setFormat("[" + prefix + "]" + format);
@ -61,16 +64,16 @@ public class MVPlayerListener extends PlayerListener {
World world = event.getPlayer().getWorld();
// If it's not a World MV manages we stop.
if (!this.plugin.isMVWorld(world.getName())) {
if (!this.worldManager.isMVWorld(world.getName())) {
return;
}
// Get the MVWorld
MVWorld mvWorld = this.plugin.getMVWorld(world.getName());
MVWorld mvWorld = this.worldManager.getMVWorld(world.getName());
// Get the instance of the World the player should respawn at.
MVWorld respawnWorld = null;
if (this.plugin.isMVWorld(mvWorld.getRespawnToWorld())) {
respawnWorld = this.plugin.getMVWorld(mvWorld.getRespawnToWorld());
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.
@ -87,7 +90,7 @@ public class MVPlayerListener extends PlayerListener {
}
private Location getMostAccurateRespawnLocation(World w) {
MVWorld mvw = this.plugin.getMVWorld(w.getName());
MVWorld mvw = this.worldManager.getMVWorld(w.getName());
if (mvw != null) {
return mvw.getSpawnLocation();
}
@ -96,7 +99,7 @@ public class MVPlayerListener extends PlayerListener {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
if (this.plugin.getMVWorlds().size() == 0 && this.plugin.getPermissions().hasPermission(event.getPlayer(), "multiverse.core.import", true)) {
if (this.worldManager.getMVWorlds().size() == 0 && this.plugin.getPermissions().hasPermission(event.getPlayer(), "multiverse.core.import", true)) {
event.getPlayer().sendMessage("You don't have any worlds imported into Multiverse!");
event.getPlayer().sendMessage("You can import your current worlds with " + ChatColor.AQUA + "/mvimport");
event.getPlayer().sendMessage("or you can create new ones with " + ChatColor.GOLD + "/mvcreate");
@ -111,8 +114,8 @@ public class MVPlayerListener extends PlayerListener {
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
MVWorld fromWorld = this.plugin.getMVWorld(event.getTo().getWorld().getName());
MVWorld toWorld = this.plugin.getMVWorld(event.getTo().getWorld().getName());
MVWorld fromWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
if (toWorld != null) {
if (!this.plugin.getPermissions().canEnterWorld(event.getPlayer(), toWorld)) {
event.getPlayer().sendMessage("You don't have access to go here...");

View File

@ -6,7 +6,6 @@ import java.util.logging.Level;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.getspout.spoutapi.SpoutManager;
import com.fernferret.allpay.AllPay;
import com.nijikokun.bukkit.Permissions.Permissions;

View File

@ -17,7 +17,7 @@ public class MVWeatherListener extends WeatherListener {
@Override
public void onWeatherChange(WeatherChangeEvent event) {
MVWorld world = this.plugin.getMVWorld(event.getWorld().getName());
MVWorld world = this.plugin.getWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) {
// If it's going to start raining and we have weather disabled
event.setCancelled((event.toWeatherState() && !world.getWeatherEnabled()));
@ -27,7 +27,7 @@ public class MVWeatherListener extends WeatherListener {
@Override
public void onThunderChange(ThunderChangeEvent event) {
MVWorld world = this.plugin.getMVWorld(event.getWorld().getName());
MVWorld world = this.plugin.getWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) {
// If it's going to start raining and we have weather disabled
event.setCancelled((event.toThunderState() && !world.getWeatherEnabled()));

View File

@ -50,7 +50,7 @@ public class CannonDestination implements MVDestination {
}
// If it's not a MV world
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).getWorldManager().isMVWorld(parsed.get(1))) {
return false;
}
// Verify X,Y,Z are numbers
@ -96,12 +96,12 @@ public class CannonDestination implements MVDestination {
return;
}
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).getWorldManager().isMVWorld(parsed.get(1))) {
this.isValid = false;
return;
}
this.location = new Location(((MultiverseCore) plugin).getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
this.location = new Location(((MultiverseCore) plugin).getWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
if (!parsed.get(2).matches(this.coordRegex)) {
this.isValid = false;

View File

@ -42,7 +42,7 @@ public class ExactDestination implements MVDestination {
}
// If it's not a MV world
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).getWorldManager().isMVWorld(parsed.get(1))) {
return false;
}
@ -92,11 +92,11 @@ public class ExactDestination implements MVDestination {
return;
}
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).getWorldManager().isMVWorld(parsed.get(1))) {
this.isValid = false;
return;
}
this.location = new Location(((MultiverseCore) plugin).getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
this.location = new Location(((MultiverseCore) plugin).getWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
if (!parsed.get(2).matches(this.coordRegex)) {
this.isValid = false;

View File

@ -0,0 +1,30 @@
package com.onarandombox.utils;
import java.io.File;
public class FileUtils {
/*
* Delete a folder Courtesy of: lithium3141
*
* @param file The folder to delete
*
* @return true if success
*/
public static boolean deleteFolder(File file) {
if (file.exists()) {
// If the file exists, and it has more than one file in it.
if (file.isDirectory()) {
for (File f : file.listFiles()) {
if (!FileUtils.deleteFolder(f)) {
return false;
}
}
}
file.delete();
return !file.exists();
} else {
return false;
}
}
}

View File

@ -25,14 +25,14 @@ public class WorldDestination implements MVDestination {
if (items.length > 3) {
return false;
}
if (items.length == 1 && ((MultiverseCore) plugin).isMVWorld(items[0])) {
if (items.length == 1 && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[0])) {
// This case is: world
return true;
}
if (items.length == 2 && ((MultiverseCore) plugin).isMVWorld(items[0])) {
if (items.length == 2 && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[0])) {
// This case is: world:n
return true;
} else if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).isMVWorld(items[1])) {
} else if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[1])) {
// This case is: w:world
// and w:world:ne
return true;
@ -70,18 +70,18 @@ public class WorldDestination implements MVDestination {
isValid = false;
return;
}
if (items.length == 1 && ((MultiverseCore) plugin).isMVWorld(items[0])) {
if (items.length == 1 && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[0])) {
isValid = true;
this.world = ((MultiverseCore) plugin).getMVWorld(items[0]);
this.world = ((MultiverseCore) plugin).getWorldManager().getMVWorld(items[0]);
return;
}
if (items.length == 2 && ((MultiverseCore) plugin).isMVWorld(items[0])) {
this.world = ((MultiverseCore) plugin).getMVWorld(items[0]);
if (items.length == 2 && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[0])) {
this.world = ((MultiverseCore) plugin).getWorldManager().getMVWorld(items[0]);
this.yaw = LocationManipulation.getYaw(items[1]);
return;
}
if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).isMVWorld(items[1])) {
this.world = ((MultiverseCore) plugin).getMVWorld(items[1]);
if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getWorldManager().isMVWorld(items[1])) {
this.world = ((MultiverseCore) plugin).getWorldManager().getMVWorld(items[1]);
isValid = true;
if (items.length == 3) {
this.yaw = LocationManipulation.getYaw(items[2]);

View File

@ -0,0 +1,333 @@
package com.onarandombox.utils;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.Configuration;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class WorldManager {
private MultiverseCore plugin;
private PurgeWorlds worldPurger;
private HashMap<String, MVWorld> worlds;
private Configuration configWorlds = null;
public WorldManager(MultiverseCore core) {
this.plugin = core;
this.worlds = new HashMap<String, MVWorld>();
this.worldPurger = new PurgeWorlds(this.plugin);
}
/**
* Add a new World to the Multiverse Setup.
* <p/>
* Isn't there a prettier way to do this??!!?!?!
*
* @param name World Name
* @param env Environment Type
*/
public boolean addWorld(String name, Environment env, String seedString, String generator) {
plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + generator);
Long seed = null;
if (seedString != null && seedString.length() > 0) {
try {
seed = Long.parseLong(seedString);
} catch (NumberFormatException numberformatexception) {
seed = (long) seedString.hashCode();
}
}
String generatorID = null;
String generatorName = null;
if (generator != null) {
String[] split = generator.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
generatorName = split[0];
generatorID = id;
}
ChunkGenerator customGenerator = getChunkGenerator(generatorName, generatorID, name);
if (customGenerator == null && generator != null && (generator.length() > 0)) {
if (!pluginExists(generatorName)) {
this.plugin.log(Level.WARNING, "Could not find plugin: " + generatorName);
} else {
this.plugin.log(Level.WARNING, "Found plugin: " + generatorName + ", but did not find generatorID: " + generatorID);
}
return false;
}
World world = null;
if (seed != null) {
if (customGenerator != null) {
world = this.plugin.getServer().createWorld(name, env, seed, customGenerator);
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed + " & Custom Generator: " + generator);
} else {
world = this.plugin.getServer().createWorld(name, env, seed);
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " with seed: " + seed);
}
} else {
if (customGenerator != null) {
world = this.plugin.getServer().createWorld(name, env, customGenerator);
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env + " & Custom Generator: " + generator);
} else {
world = this.plugin.getServer().createWorld(name, env);
this.plugin.log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
}
}
if (world == null) {
this.plugin.log(Level.SEVERE, "Failed to Create/Load the world '" + name + "'");
return false;
}
MVWorld mvworld = new MVWorld(world, this.configWorlds, this.plugin, seed, generator);
this.worldPurger.purgeWorld(null, mvworld);
this.worlds.put(name, mvworld);
return true;
}
private boolean pluginExists(String generator) {
Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
return plugin != null;
}
private ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName) {
if (generator == null) {
return null;
}
Plugin plugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
if (plugin == null) {
return null;
} else {
return plugin.getDefaultWorldGenerator(worldName, generatorID);
}
}
/**
* Remove the world from the Multiverse list and from the config
*
* @param name The name of the world to remove
* @return True if success, false if failure.
*/
public boolean removeWorldFromConfig(String name) {
if (this.configWorlds.getProperty("worlds." + name) != null) {
removeWorldFromList(name);
this.plugin.log(Level.INFO, "World " + name + " was removed from config.yml");
this.configWorlds.removeProperty("worlds." + name);
this.configWorlds.save();
return true;
} else {
this.plugin.log(Level.INFO, "World " + name + " was already removed from config.yml");
}
return false;
}
/**
* Remove the world from the Multiverse list
*
* @param name The name of the world to remove
* @return True if success, false if failure.
*/
public boolean removeWorldFromList(String name) {
if (this.worlds.containsKey(name)) {
this.worlds.remove(name);
this.plugin.log(Level.INFO, "World " + name + " was unloaded from memory.");
this.unloadWorld(name, true);
return true;
} else if (this.plugin.getServer().getWorld(name) != null) {
this.plugin.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's still loaded in memory.");
this.plugin.log(Level.WARNING, "To be on the safe side, you should import it then try unloading again...");
} else {
this.plugin.log(Level.INFO, "The world " + name + " was already unloaded/did not exist.");
}
return false;
}
/**
* Remove the world from the Multiverse list, from the config and deletes the folder
*
* @param name The name of the world to remove
* @return True if success, false if failure.
*/
public Boolean deleteWorld(String name) {
if (this.plugin.getServer().getWorld(name) != null) {
if (!unloadWorld(name, false)) {
// If the world was loaded, and we couldn't unload it, return false. DON"T DELTEE
return false;
}
}
removeWorldFromConfig(name);
try {
File serverFolder = new File(this.plugin.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
File worldFile = new File(serverFolder.getAbsolutePath() + File.separator + name);
if (name.equalsIgnoreCase("plugins")) {
this.plugin.log(Level.SEVERE, "Really? Are you high? This would delete your plugins folder. Luckily the MV2 devs are crazy smart or you're server would be ended...");
return false;
} else if (name.toLowerCase().contains("plugins")) {
this.plugin.log(Level.SEVERE, "I'm sorry, did you mean to type: 'rm plugins" + File.separator + "Essential*'? I could do that for you if you'd like...");
return false;
} else if (name.contains("..")) {
this.plugin.log(Level.SEVERE, "Uh yea... No way i'm going to delete a parent directory for you. You can go do 'rm -rf *.*' on your own time...");
return false;
} else if (name.equals(".")) {
this.plugin.log(Level.SEVERE, "Why on earth would you want to use Multiverse-Core to delete your Bukkit Server! How many beers have you had tonight... Give the keys to a friend.");
return false;
} else if (!worldFile.isDirectory()) {
this.plugin.log(Level.SEVERE, "C'mon man... Really?!?! Multiverse-Core is a great way to get players from A to B, but not to manage your files. To delete this file type:");
this.plugin.log(Level.SEVERE, "stop");
this.plugin.log(Level.SEVERE, "rm " + worldFile.getAbsolutePath());
return false;
}
boolean deletedWorld = FileUtils.deleteFolder(worldFile);
if (deletedWorld)
{
this.plugin.log(Level.INFO, "World " + name + " was DELETED.");
} else {
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 (Exception e) {
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.");
System.out.print(e);
return false;
}
}
private boolean unloadWorld(String name, boolean safely) {
this.removePlayersFromWorld(name);
return this.plugin.getServer().unloadWorld(name, safely);
}
private void removePlayersFromWorld(String name) {
World w = this.plugin.getServer().getWorld(name);
if (w != null) {
World safeWorld = this.plugin.getServer().getWorlds().get(0);
List<Player> ps = w.getPlayers();
for (Player p : ps) {
p.teleport(safeWorld.getSpawnLocation());
}
}
}
public Collection<MVWorld> getMVWorlds() {
return this.worlds.values();
}
public MVWorld getMVWorld(String name) {
if (this.worlds.containsKey(name)) {
return this.worlds.get(name);
}
return this.getMVWorldByAlias(name);
}
private MVWorld getMVWorldByAlias(String alias) {
for (MVWorld w : this.worlds.values()) {
if (w.getAlias().equalsIgnoreCase(alias)) {
return w;
}
}
return null;
}
public boolean isMVWorld(String name) {
return (this.worlds.containsKey(name) || isMVWorldAlias(name));
}
/**
* This method ONLY checks the alias of each world.
*
* @param name
* @return
*/
private boolean isMVWorldAlias(String name) {
for (MVWorld w : this.worlds.values()) {
if (w.getAlias().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
/**
* Load the Worlds & Settings from the configuration file.
*/
public void loadWorlds(boolean forceLoad) {
// Basic Counter to count how many Worlds we are loading.
int count = 0;
// Grab all the Worlds from the Config.
List<String> worldKeys = this.configWorlds.getKeys("worlds");
// 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 (MVWorld w : this.worlds.values()) {
// Remove this world from the master list
if (allAccess != null) {
allAccess.getChildren().remove(w.getPermission().getName());
}
if (allExempt != null) {
allExempt.getChildren().remove(w.getPermission().getName());
}
this.plugin.getServer().getPluginManager().removePermission(w.getPermission().getName());
this.plugin.getServer().getPluginManager().removePermission(w.getExempt().getName());
}
// Recalc the all permission
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allExempt);
this.worlds.clear();
}
// Check that the list is not null.
if (worldKeys != null) {
for (String worldKey : worldKeys) {
// Check if the World is already loaded within the Plugin.
if (this.worlds.containsKey(worldKey)) {
continue;
}
// Grab the initial values from the config file.
String environment = this.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
String seedString = this.configWorlds.getString("worlds." + worldKey + ".seed", "");
String generatorstring = this.configWorlds.getString("worlds." + worldKey + ".generator");
addWorld(worldKey, this.plugin.getEnvFromString(environment), seedString, generatorstring);
// Increment the world count
count++;
}
}
// Simple Output to the Console to show how many Worlds were loaded.
this.plugin.log(Level.INFO, count + " - World(s) loaded.");
}
public PurgeWorlds getWorldPurger() {
return this.worldPurger;
}
}