Use specific dependencies in SimpleMVWorldManager and SimpleMVWorld.

This commit is contained in:
Jeremy Wood 2023-03-08 07:39:18 -05:00
parent b6a0d272df
commit e6f304fd25
No known key found for this signature in database
GPG Key ID: C5BAD04C77B91B4B
7 changed files with 176 additions and 99 deletions

View File

@ -4,10 +4,12 @@ import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.jvnet.hk2.annotations.Contract;
/**
* Used to remove animals from worlds that don't belong there.
*/
@Contract
public interface WorldPurger {
/**
* Synchronizes the given worlds with their settings.

View File

@ -9,6 +9,7 @@ import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
import io.vavr.control.Option;
import io.vavr.control.Try;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
@ -35,14 +36,19 @@ public final class MVCoreConfigProvider {
private volatile MultiverseCoreConfiguration config;
private final Plugin plugin;
private final MVWorldManager worldManager;
private final PluginManager pluginManager;
private final Provider<MVWorldManager> worldManagerProvider; // TODO remove this dependency
@Inject
public MVCoreConfigProvider(MultiverseCore plugin, MVWorldManager worldManager, PluginManager pluginManager) {
public MVCoreConfigProvider(
MultiverseCore plugin,
PluginManager pluginManager,
Provider<MVWorldManager> worldManagerProvider
) {
this.plugin = plugin;
this.worldManager = worldManager;
this.pluginManager = pluginManager;
this.worldManagerProvider = worldManagerProvider;
}
@NotNull
@ -103,7 +109,7 @@ public final class MVCoreConfigProvider {
}
private void loadWorldConfigs() {
worldManager.loadWorldConfig(new File(plugin.getDataFolder(), WORLDS_CONFIG_FILE));
worldManagerProvider.get().loadWorldConfig(new File(plugin.getDataFolder(), WORLDS_CONFIG_FILE));
}
private void setDebugLevelFromConfig(@NotNull MVConfig config) {

View File

@ -17,6 +17,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@ -39,18 +40,22 @@ import org.jvnet.hk2.annotations.Service;
@Service
public class MVPlayerListener implements Listener {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final Provider<MVWorldManager> worldManagerProvider;
private final PermissionTools pt;
private final Map<String, String> playerWorld = new ConcurrentHashMap<String, String>();
@Inject
public MVPlayerListener(MultiverseCore plugin) {
public MVPlayerListener(MultiverseCore plugin, Provider<MVWorldManager> worldManagerProvider) {
this.plugin = plugin;
worldManager = plugin.getMVWorldManager();
this.worldManagerProvider = worldManagerProvider;
pt = new PermissionTools(plugin);
}
private MVWorldManager getWorldManager() {
return worldManagerProvider.get();
}
/**
* @return the playerWorld-map
*/
@ -65,7 +70,7 @@ public class MVPlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void playerRespawn(PlayerRespawnEvent event) {
World world = event.getPlayer().getWorld();
MVWorld mvWorld = this.worldManager.getMVWorld(world.getName());
MVWorld mvWorld = getWorldManager().getMVWorld(world.getName());
// If it's not a World MV manages we stop.
if (mvWorld == null) {
return;
@ -78,8 +83,8 @@ public class MVPlayerListener implements Listener {
// Get the instance of the World the player should respawn at.
MVWorld respawnWorld = null;
if (this.worldManager.isMVWorld(mvWorld.getRespawnToWorld())) {
respawnWorld = this.worldManager.getMVWorld(mvWorld.getRespawnToWorld());
if (getWorldManager().isMVWorld(mvWorld.getRespawnToWorld())) {
respawnWorld = getWorldManager().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.
@ -96,7 +101,7 @@ public class MVPlayerListener implements Listener {
}
private Location getMostAccurateRespawnLocation(World w) {
MVWorld mvw = this.worldManager.getMVWorld(w.getName());
MVWorld mvw = getWorldManager().getMVWorld(w.getName());
if (mvw != null) {
return mvw.getSpawnLocation();
}
@ -114,7 +119,7 @@ public class MVPlayerListener implements Listener {
Logging.finer("Player joined for the FIRST time!");
if (plugin.getMVConfig().getFirstSpawnOverride()) {
Logging.fine("Moving NEW player to(firstspawnoverride): "
+ worldManager.getFirstSpawnWorld().getSpawnLocation());
+ getWorldManager().getFirstSpawnWorld().getSpawnLocation());
this.sendPlayerToDefaultWorld(p);
}
return;
@ -166,8 +171,8 @@ public class MVPlayerListener implements Listener {
}
Logging.finer("Inferred sender '" + teleporter + "' from name '"
+ teleporterName + "', fetched from name '" + teleportee.getName() + "'");
MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
MVWorld fromWorld = getWorldManager().getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = getWorldManager().getMVWorld(event.getTo().getWorld().getName());
if (toWorld == null) {
Logging.fine("Player '" + teleportee.getName() + "' is teleporting to world '"
+ event.getTo().getWorld().getName() + "' which is not managed by Multiverse-Core. No further "
@ -270,8 +275,8 @@ public class MVPlayerListener implements Listener {
if (event.getTo() == null) {
return;
}
MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
MVWorld fromWorld = getWorldManager().getMVWorld(event.getFrom().getWorld().getName());
MVWorld toWorld = getWorldManager().getMVWorld(event.getTo().getWorld().getName());
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
// The player is Portaling to the same world.
Logging.finer("Player '" + event.getPlayer().getName() + "' is portaling to the same world.");
@ -315,7 +320,7 @@ public class MVPlayerListener implements Listener {
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.
private void handleGameModeAndFlight(Player player, World world) {
MVWorld mvWorld = this.worldManager.getMVWorld(world.getName());
MVWorld mvWorld = getWorldManager().getMVWorld(world.getName());
if (mvWorld != null) {
this.handleGameModeAndFlight(player, mvWorld);
} else {

View File

@ -13,12 +13,15 @@ import java.util.Map;
import java.util.UUID;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType;
import com.onarandombox.MultiverseCore.world.configuration.EnglishChatColor;
import com.onarandombox.MultiverseCore.world.configuration.SpawnLocation;
@ -33,6 +36,7 @@ import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
@ -50,20 +54,55 @@ public class SimpleMVWorld implements MVWorld {
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16;
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
private final MultiverseCore plugin; // Hold the Plugin Instance.
private final MVWorldManager worldManager;
private final WorldPurger worldPurger;
private final MVPlayerListener playerListener;
private final BlockSafety blockSafety;
private final SafeTTeleporter safeTTeleporter;
private final LocationManipulation locationManipulation;
private final Server server;
private final String name; // The Worlds Name, EG its folder name.
private final UUID worldUID;
private final WorldProperties props;
public SimpleMVWorld(MultiverseCore plugin, World world, WorldProperties properties) {
this(plugin, world, properties, true);
public SimpleMVWorld(
MVWorldManager worldManager,
WorldPurger worldPurger,
MVPlayerListener playerListener,
BlockSafety blockSafety,
SafeTTeleporter safeTTeleporter,
LocationManipulation locationManipulation,
Server server,
World world,
WorldProperties properties
) {
this(worldManager, worldPurger, playerListener, blockSafety, safeTTeleporter,
locationManipulation, server, world, properties, true);
}
/*
* We have to use setCBWorld(), setPlugin() and initPerms() to prepare this object for use.
*/
public SimpleMVWorld(MultiverseCore plugin, World world, WorldProperties properties, boolean fixSpawn) {
this.plugin = plugin;
public SimpleMVWorld(
MVWorldManager worldManager,
WorldPurger worldPurger,
MVPlayerListener playerListener,
BlockSafety blockSafety,
SafeTTeleporter safeTTeleporter,
LocationManipulation locationManipulation,
Server server,
World world,
WorldProperties properties,
boolean fixSpawn
) {
this.worldManager = worldManager;
this.worldPurger = worldPurger;
this.playerListener = playerListener;
this.blockSafety = blockSafety;
this.safeTTeleporter = safeTTeleporter;
this.locationManipulation = locationManipulation;
this.server = server;
this.name = world.getName();
this.worldUID = world.getUID();
this.props = properties;
@ -228,7 +267,7 @@ public class SimpleMVWorld implements MVWorld {
@Override
public String validateChange(String property, String newValue, String oldValue,
SimpleMVWorld object) throws ChangeDeniedException {
if (!newValue.isEmpty() && !plugin.getMVWorldManager().isMVWorld(newValue))
if (!newValue.isEmpty() && !worldManager.isMVWorld(newValue))
throw new ChangeDeniedException();
return super.validateChange(property, newValue, oldValue, object);
}
@ -283,7 +322,7 @@ public class SimpleMVWorld implements MVWorld {
world.setSpawnFlags(allowMonsters, allowAnimals);
}
if (MultiverseCoreConfiguration.getInstance().isAutoPurgeEnabled()) {
plugin.getMVWorldManager().getTheWorldPurger().purgeWorld(SimpleMVWorld.this);
worldPurger.purgeWorld(SimpleMVWorld.this);
}
return super.validateChange(property, newValue, oldValue, object);
}
@ -296,10 +335,10 @@ public class SimpleMVWorld implements MVWorld {
@Override
public GameMode validateChange(String property, GameMode newValue, GameMode oldValue,
SimpleMVWorld object) throws ChangeDeniedException {
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
for (Player p : server.getWorld(getName()).getPlayers()) {
Logging.finer(String.format("Setting %s's GameMode to %s",
p.getName(), newValue.toString()));
plugin.getPlayerListener().handleGameModeAndFlight(p, SimpleMVWorld.this);
playerListener.handleGameModeAndFlight(p, SimpleMVWorld.this);
}
return super.validateChange(property, newValue, oldValue, object);
}
@ -315,20 +354,18 @@ public class SimpleMVWorld implements MVWorld {
if (newValue == null)
throw new ChangeDeniedException();
if (props.getAdjustSpawn()) {
BlockSafety bs = plugin.getBlockSafety();
// verify that the location is safe
if (!bs.playerCanSpawnHereSafely(newValue)) {
if (!blockSafety.playerCanSpawnHereSafely(newValue)) {
// it's not ==> find a better one!
Logging.warning(String.format("Somebody tried to set the spawn location for '%s' to an unsafe value! Adjusting...", getAlias()));
Logging.warning("Old Location: " + plugin.getLocationManipulation().strCoordsRaw(oldValue));
Logging.warning("New (unsafe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
SafeTTeleporter teleporter = plugin.getSafeTTeleporter();
newValue = teleporter.getSafeLocation(newValue, SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
Logging.warning("Old Location: " + locationManipulation.strCoordsRaw(oldValue));
Logging.warning("New (unsafe) Location: " + locationManipulation.strCoordsRaw(newValue));
newValue = safeTTeleporter.getSafeLocation(newValue, SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
if (newValue == null) {
Logging.warning("Couldn't fix the location. I have to abort the spawn location-change :/");
throw new ChangeDeniedException();
}
Logging.warning("New (safe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
Logging.warning("New (safe) Location: " + locationManipulation.strCoordsRaw(newValue));
}
}
return super.validateChange(property, newValue, oldValue, object);
@ -399,10 +436,10 @@ public class SimpleMVWorld implements MVWorld {
this.limitbypassperm = new Permission("mv.bypass.playerlimit." + this.getName(),
"A player who can enter this world regardless of wether its full", PermissionDefault.OP);
try {
this.plugin.getServer().getPluginManager().addPermission(this.permission);
this.plugin.getServer().getPluginManager().addPermission(this.exempt);
this.plugin.getServer().getPluginManager().addPermission(this.ignoreperm);
this.plugin.getServer().getPluginManager().addPermission(this.limitbypassperm);
this.server.getPluginManager().addPermission(this.permission);
this.server.getPluginManager().addPermission(this.exempt);
this.server.getPluginManager().addPermission(this.ignoreperm);
this.server.getPluginManager().addPermission(this.limitbypassperm);
// Add the permission and exempt to parents.
this.addToUpperLists(this.permission);
@ -418,9 +455,8 @@ public class SimpleMVWorld implements MVWorld {
private Location readSpawnFromWorld(World w) {
Location location = w.getSpawnLocation();
// Set the worldspawn to our configspawn
BlockSafety bs = this.plugin.getBlockSafety();
// Verify that location was safe
if (!bs.playerCanSpawnHereSafely(location)) {
if (!blockSafety.playerCanSpawnHereSafely(location)) {
if (!this.getAdjustSpawn()) {
Logging.fine("Spawn location from world.dat file was unsafe!!");
Logging.fine("NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
@ -429,25 +465,24 @@ public class SimpleMVWorld implements MVWorld {
return location;
}
// If it's not, find a better one.
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
Logging.warning("Spawn location from world.dat file was unsafe. Adjusting...");
Logging.warning("Original Location: " + plugin.getLocationManipulation().strCoordsRaw(location));
Location newSpawn = teleporter.getSafeLocation(location,
Logging.warning("Original Location: " + locationManipulation.strCoordsRaw(location));
Location newSpawn = safeTTeleporter.getSafeLocation(location,
SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
// I think we could also do this, as I think this is what Notch does.
// Not sure how it will work in the nether...
//Location newSpawn = this.spawnLocation.getWorld().getHighestBlockAt(this.spawnLocation).getLocation();
if (newSpawn != null) {
Logging.info("New Spawn for '%s' is located at: %s",
this.getName(), plugin.getLocationManipulation().locationToString(newSpawn));
this.getName(), locationManipulation.locationToString(newSpawn));
return newSpawn;
} else {
// If it's a standard end world, let's check in a better place:
Location newerSpawn;
newerSpawn = bs.getTopBlock(new Location(w, 0, 0, 0));
newerSpawn = blockSafety.getTopBlock(new Location(w, 0, 0, 0));
if (newerSpawn != null) {
Logging.info("New Spawn for '%s' is located at: %s",
this.getName(), plugin.getLocationManipulation().locationToString(newerSpawn));
this.getName(), locationManipulation.locationToString(newerSpawn));
return newerSpawn;
} else {
Logging.severe("Safe spawn NOT found!!!");
@ -458,29 +493,29 @@ public class SimpleMVWorld implements MVWorld {
}
private void addToUpperLists(Permission perm) {
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
Permission allExemption = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
Permission all = this.server.getPluginManager().getPermission("multiverse.*");
Permission allWorlds = this.server.getPluginManager().getPermission("multiverse.access.*");
Permission allExemption = this.server.getPluginManager().getPermission("multiverse.exempt.*");
if (allWorlds == null) {
allWorlds = new Permission("multiverse.access.*");
this.plugin.getServer().getPluginManager().addPermission(allWorlds);
this.server.getPluginManager().addPermission(allWorlds);
}
allWorlds.getChildren().put(perm.getName(), true);
if (allExemption == null) {
allExemption = new Permission("multiverse.exempt.*");
this.plugin.getServer().getPluginManager().addPermission(allExemption);
this.server.getPluginManager().addPermission(allExemption);
}
allExemption.getChildren().put(this.exempt.getName(), true);
if (all == null) {
all = new Permission("multiverse.*");
this.plugin.getServer().getPluginManager().addPermission(all);
this.server.getPluginManager().addPermission(all);
}
all.getChildren().put("multiverse.access.*", true);
all.getChildren().put("multiverse.exempt.*", true);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds);
this.server.getPluginManager().recalculatePermissionDefaults(all);
this.server.getPluginManager().recalculatePermissionDefaults(allWorlds);
}
/**
@ -504,7 +539,7 @@ public class SimpleMVWorld implements MVWorld {
*/
@Override
public World getCBWorld() {
final World world = plugin.getServer().getWorld(worldUID);
final World world = server.getWorld(worldUID);
if (world == null) {
throw new IllegalStateException("Lost reference to bukkit world '" + name + "'");
}
@ -900,7 +935,7 @@ public class SimpleMVWorld implements MVWorld {
*/
@Override
public World getRespawnToWorld() {
return this.plugin.getServer().getWorld(props.getRespawnToWorld());
return this.server.getWorld(props.getRespawnToWorld());
}
/**
@ -908,7 +943,7 @@ public class SimpleMVWorld implements MVWorld {
*/
@Override
public boolean setRespawnToWorld(String respawnToWorld) {
if (!this.plugin.getMVWorldManager().isMVWorld(respawnToWorld)) return false;
if (!this.worldManager.isMVWorld(respawnToWorld)) return false;
return this.props.setRespawnToWorld(respawnToWorld);
}

View File

@ -27,16 +27,21 @@ import java.util.stream.Collectors;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
import com.onarandombox.MultiverseCore.utils.file.FileUtils;
import jakarta.inject.Inject;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
@ -57,6 +62,12 @@ import org.jvnet.hk2.annotations.Service;
@Service
public class SimpleMVWorldManager implements MVWorldManager {
private final MultiverseCore plugin;
private final MVPlayerListener playerListener;
private final BlockSafety blockSafety;
private final SafeTTeleporter safeTTeleporter;
private final LocationManipulation locationManipulation;
private final UnsafeCallWrapper unsafeCallWrapper;
private final Server server;
private final WorldPurger worldPurger;
private final Map<String, MVWorld> worlds;
private Map<String, WorldProperties> worldsFromTheConfig;
@ -65,11 +76,27 @@ public class SimpleMVWorldManager implements MVWorldManager {
private String firstSpawn;
@Inject
public SimpleMVWorldManager(MultiverseCore core) {
this.plugin = core;
public SimpleMVWorldManager(
MultiverseCore plugin,
MVPlayerListener playerListener,
BlockSafety blockSafety,
SafeTTeleporter safeTTeleporter,
LocationManipulation locationManipulation,
UnsafeCallWrapper unsafeCallWrapper,
WorldPurger worldPurger,
Server server
) {
this.plugin = plugin;
this.playerListener = playerListener;
this.blockSafety = blockSafety;
this.safeTTeleporter = safeTTeleporter;
this.locationManipulation = locationManipulation;
this.unsafeCallWrapper = unsafeCallWrapper;
this.worldPurger = worldPurger;
this.server = server;
this.worldsFromTheConfig = new HashMap<String, WorldProperties>();
this.worlds = new ConcurrentHashMap<String, MVWorld>();
this.worldPurger = new SimpleWorldPurger(plugin);
}
/**
@ -126,8 +153,8 @@ public class SimpleMVWorldManager implements MVWorldManager {
return false;
}
final File oldWorldFile = new File(this.plugin.getServer().getWorldContainer(), oldName);
final File newWorldFile = new File(this.plugin.getServer().getWorldContainer(), newName);
final File oldWorldFile = new File(this.server.getWorldContainer(), oldName);
final File newWorldFile = new File(this.server.getWorldContainer(), newName);
final List<String> ignoreFiles = new ArrayList<>(Arrays.asList("session.lock", "uid.dat"));
// Make sure the new world doesn't exist outside of multiverse.
@ -139,7 +166,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
// Load the old world... but just the metadata.
boolean wasJustLoaded = false;
boolean wasLoadSpawn = false;
if (this.plugin.getServer().getWorld(oldName) == null) {
if (this.server.getWorld(oldName) == null) {
wasJustLoaded = true;
WorldProperties props = this.worldsFromTheConfig.get(oldName);
wasLoadSpawn = props.isKeepingSpawnInMemory();
@ -150,7 +177,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
if (!this.loadWorld(oldName)) {
return false;
}
this.plugin.getServer().getWorld(oldName).setAutoSave(false);
this.server.getWorld(oldName).setAutoSave(false);
}
// Grab a bit of metadata from the old world.
@ -298,11 +325,11 @@ public class SimpleMVWorldManager implements MVWorldManager {
return null;
}
final Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
final Plugin myPlugin = this.server.getPluginManager().getPlugin(generator);
if (myPlugin == null) {
return null;
} else {
return plugin.getUnsafeCallWrapper().wrap(new Callable<ChunkGenerator>() {
return unsafeCallWrapper.wrap(new Callable<ChunkGenerator>() {
@Override
public ChunkGenerator call() throws Exception {
return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
@ -336,8 +363,8 @@ public class SimpleMVWorldManager implements MVWorldManager {
*/
@Override
public void setFirstSpawnWorld(String world) {
if ((world == null) && (this.plugin.getServer().getWorlds().size() > 0)) {
this.firstSpawn = this.plugin.getServer().getWorlds().get(0).getName();
if ((world == null) && (this.server.getWorlds().size() > 0)) {
this.firstSpawn = this.server.getWorlds().get(0).getName();
} else {
this.firstSpawn = world;
}
@ -353,7 +380,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
// If the spawn world was unloaded, get the default world
Logging.warning("The world specified as the spawn world (" + this.firstSpawn + ") did not exist!!");
try {
return this.getMVWorld(this.plugin.getServer().getWorlds().get(0));
return this.getMVWorld(this.server.getWorlds().get(0));
} catch (IndexOutOfBoundsException e) {
// This should only happen in tests.
return null;
@ -388,10 +415,10 @@ public class SimpleMVWorldManager implements MVWorldManager {
} else {
Logging.warning("World '%s' could not be unloaded from Bukkit. Is it a default world?", name);
}
} else if (this.plugin.getServer().getWorld(name) != null) {
} else if (this.server.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());
Logging.warning("/mv import %s %s", name, this.server.getWorld(name).getEnvironment().toString());
} else if (this.worldsFromTheConfig.containsKey(name)) {
return true; // it's already unloaded
} else {
@ -448,7 +475,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
boolean generatorSuccess = true;
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
generatorSuccess = null != plugin.getUnsafeCallWrapper().wrap(new Callable<Object>() {
generatorSuccess = null != unsafeCallWrapper.wrap(new Callable<Object>() {
@Override
public Object call() throws Exception {
creator.generator(world.getGenerator());
@ -466,7 +493,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
if (worlds.containsKey(worldName))
throw new IllegalArgumentException("That world is already loaded!");
if (!ignoreExists && !new File(this.plugin.getServer().getWorldContainer(), worldName).exists() && !new File(this.plugin.getServer().getWorldContainer().getParent(), worldName).exists()) {
if (!ignoreExists && !new File(this.server.getWorldContainer(), worldName).exists() && !new File(this.server.getWorldContainer().getParent(), worldName).exists()) {
Logging.warning("WorldManager: Can't load this world because the folder was deleted/moved: " + worldName);
Logging.warning("Use '/mv remove' to remove it from the config!");
return false;
@ -485,7 +512,8 @@ public class SimpleMVWorldManager implements MVWorldManager {
nullWorld(worldName);
return false;
}
SimpleMVWorld world = new SimpleMVWorld(plugin, cbworld, mvworld);
SimpleMVWorld world = new SimpleMVWorld(this, worldPurger, playerListener, blockSafety, safeTTeleporter,
locationManipulation, server, cbworld, mvworld);
if (MultiverseCoreConfiguration.getInstance().isAutoPurgeEnabled()) {
this.worldPurger.purgeWorld(world);
}
@ -505,7 +533,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
}
}
World world = this.plugin.getServer().getWorld(name);
World world = this.server.getWorld(name);
if (world == null) {
// We can only delete loaded worlds
return false;
@ -513,7 +541,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
// call the event!
MVWorldDeleteEvent mvwde = new MVWorldDeleteEvent(getMVWorld(name), removeFromConfig);
this.plugin.getServer().getPluginManager().callEvent(mvwde);
this.server.getPluginManager().callEvent(mvwde);
if (mvwde.isCancelled()) {
Logging.fine("Tried to delete a world, but the event was cancelled!");
return false;
@ -576,7 +604,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
*/
private boolean unloadWorldFromBukkit(String name, boolean safely) {
this.removePlayersFromWorld(name);
return this.plugin.getServer().unloadWorld(name, safely);
return this.server.unloadWorld(name, safely);
}
/**
@ -584,14 +612,13 @@ public class SimpleMVWorldManager implements MVWorldManager {
*/
@Override
public void removePlayersFromWorld(String name) {
World w = this.plugin.getServer().getWorld(name);
World w = this.server.getWorld(name);
if (w != null) {
World safeWorld = this.plugin.getServer().getWorlds().get(0);
World safeWorld = this.server.getWorlds().get(0);
List<Player> ps = w.getPlayers();
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
for (Player p : ps) {
// We're removing players forcefully from a world, they'd BETTER spawn safely.
teleporter.safelyTeleport(null, p, safeWorld.getSpawnLocation(), true);
this.safeTTeleporter.safelyTeleport(null, p, safeWorld.getSpawnLocation(), true);
}
}
}
@ -698,7 +725,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
@Override
public void loadDefaultWorlds() {
this.ensureConfigIsPrepared();
List<World> myWorlds = this.plugin.getServer().getWorlds();
List<World> myWorlds = this.server.getWorlds();
for (World w : myWorlds) {
String name = w.getName();
if (!worldsFromTheConfig.containsKey(name)) {
@ -731,8 +758,8 @@ public class SimpleMVWorldManager implements MVWorldManager {
// 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.*");
Permission allAccess = this.server.getPluginManager().getPermission("multiverse.access.*");
Permission allExempt = this.server.getPluginManager().getPermission("multiverse.exempt.*");
for (MVWorld w : this.worlds.values()) {
// Remove this world from the master list
if (allAccess != null) {
@ -741,14 +768,14 @@ public class SimpleMVWorldManager implements MVWorldManager {
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());
this.server.getPluginManager().removePermission(w.getAccessPermission().getName());
this.server.getPluginManager().removePermission(w.getExemptPermission().getName());
// Special namespace for gamemodes
this.plugin.getServer().getPluginManager().removePermission("mv.bypass.gamemode." + w.getName());
this.server.getPluginManager().removePermission("mv.bypass.gamemode." + w.getName());
}
// Recalc the all permission
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allExempt);
this.server.getPluginManager().recalculatePermissionDefaults(allAccess);
this.server.getPluginManager().recalculatePermissionDefaults(allExempt);
this.worlds.clear();
}
@ -769,10 +796,10 @@ public class SimpleMVWorldManager implements MVWorldManager {
}
private void ensureSecondNamespaceIsPrepared() {
Permission special = this.plugin.getServer().getPluginManager().getPermission("mv.bypass.gamemode.*");
Permission special = this.server.getPluginManager().getPermission("mv.bypass.gamemode.*");
if (special == null) {
special = new Permission("mv.bypass.gamemode.*", PermissionDefault.FALSE);
this.plugin.getServer().getPluginManager().addPermission(special);
this.server.getPluginManager().addPermission(special);
}
}
@ -861,7 +888,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
*/
@Override
public MVWorld getSpawnWorld() {
return this.getMVWorld(this.plugin.getServer().getWorlds().get(0));
return this.getMVWorld(this.server.getWorlds().get(0));
}
/**
@ -954,10 +981,9 @@ public class SimpleMVWorldManager implements MVWorldManager {
}
// Send all players that were in the old world, BACK to it!
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
Location newSpawn = world.getSpawnLocation();
for (Player p : ps) {
teleporter.safelyTeleport(null, p, newSpawn, true);
this.safeTTeleporter.safelyTeleport(null, p, newSpawn, true);
}
return true;
@ -1000,7 +1026,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
*/
@Override
public Collection<String> getPotentialWorlds() {
File worldContainer = this.plugin.getServer().getWorldContainer();
File worldContainer = this.server.getWorldContainer();
if (worldContainer == null) {
return Collections.emptyList();
}

View File

@ -24,6 +24,7 @@ import org.bukkit.entity.Phantom;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import org.jvnet.hk2.annotations.Service;
import java.util.ArrayList;
import java.util.Iterator;
@ -32,14 +33,12 @@ import java.util.List;
/**
* Utility class that removes animals from worlds that don't belong there.
*/
@Service
public class SimpleWorldPurger implements WorldPurger {
private MultiverseCore plugin;
private Class<Entity> ambientClass = null;
public SimpleWorldPurger(MultiverseCore plugin) {
this.plugin = plugin;
public SimpleWorldPurger() {
try {
Class entityClass = Class.forName("org.bukkit.entity.Ambient");
if (Entity.class.isAssignableFrom(entityClass)) {

View File

@ -204,16 +204,20 @@ public class TestInstanceCreator {
serverfield.set(core, mockServer);
// Set worldManager
/* This block is preserved for the transition to MV5, just in case
SimpleMVWorldManager wm = spy(new SimpleMVWorldManager(core));
Field worldmanagerfield = MultiverseCore.class.getDeclaredField("worldManager");
worldmanagerfield.setAccessible(true);
worldmanagerfield.set(core, wm);
*/
// Set playerListener
/* This block is preserved for the transition to MV5, just in case
MVPlayerListener pl = spy(new MVPlayerListener(core));
Field playerlistenerfield = MultiverseCore.class.getDeclaredField("playerListener");
playerlistenerfield.setAccessible(true);
playerlistenerfield.set(core, pl);
*/
// Set entityListener
MVEntityListener el = spy(new MVEntityListener(core));