mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-08 16:41:41 +01:00
Much farther with testing. Keep testing...
This commit is contained in:
parent
edb999578a
commit
e45ae8f9dc
@ -56,6 +56,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private File testConfigDirectory;
|
||||
private PluginDescriptionFile testDescriptionFile;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The Multiverse-Core Plugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dumpVersionInfo(String buffer) {
|
||||
@ -94,7 +98,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Configurations
|
||||
private FileConfiguration multiverseConfig = null;
|
||||
|
||||
private WorldManager worldManager = new WorldManager(this);
|
||||
private WorldManager worldManager;
|
||||
|
||||
// Setup the block/player/entity listener.
|
||||
private MVPlayerListener playerListener = new MVPlayerListener(this);
|
||||
@ -158,6 +162,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
System.out.println("Enabling... Found server... " + this.getServer());
|
||||
this.worldManager = new WorldManager(this);
|
||||
// Perform initial checks for AllPay
|
||||
if (!this.validateAllpay() || !this.validateCH()) {
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
@ -477,7 +483,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
if(auths.size() == 0) {
|
||||
if (auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -587,6 +593,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.getTeleporter().safelyTeleport(teleporter, p, l, false);
|
||||
}
|
||||
|
||||
|
||||
public File getServerFolder() {
|
||||
return new File(this.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
|
||||
}
|
||||
|
||||
private void checkServerProps() {
|
||||
File serverFolder = new File(this.getDataFolder().getAbsolutePath()).getParentFile().getParentFile();
|
||||
File serverProperties = new File(serverFolder.getAbsolutePath() + File.separator + "server.properties");
|
||||
|
@ -56,11 +56,12 @@ public class ImportCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (new File(worldName).exists() && env != null) {
|
||||
|
||||
|
||||
if (new File(this.plugin.getServerFolder(), worldName).exists() && env != null) {
|
||||
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
this.worldManager.addWorld(worldName, environment, null, generator);
|
||||
sender.sendMessage(ChatColor.GREEN + "Complete!");
|
||||
return;
|
||||
} else if (env == null) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage("That world type did not exist.");
|
||||
|
@ -25,13 +25,6 @@ public class BlockSafety {
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the given coordinates are above air or not.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isBlockAboveAir(Location l) {
|
||||
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
|
||||
@ -53,21 +46,18 @@ public class BlockSafety {
|
||||
* This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air
|
||||
* etc. This also ensures there is enough space for a player to spawn!
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean playerCanSpawnHereSafely(Location l) {
|
||||
World world = l.getWorld();
|
||||
Location actual = l.clone();
|
||||
Location upOne = l.clone();
|
||||
Location downOne = l.clone();
|
||||
upOne.setY(upOne.getY() + 1);
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
|
||||
if (this.isSolidBlock(actual.getBlock().getType()) || this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
if (this.isSolidBlock(world.getBlockAt(actual).getType()) ||
|
||||
this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
MultiverseCore.staticLog(Level.FINER, "Error Here? (" + actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
|
||||
return false;
|
||||
|
@ -367,6 +367,11 @@ public class WorldManager implements MVWorldManager {
|
||||
// Force the worlds to be loaded, ie don't just load new worlds.
|
||||
if (forceLoad) {
|
||||
// Remove all world permissions.
|
||||
System.out.println(this.plugin);
|
||||
System.out.println("Server2: " + this.plugin.getServer());
|
||||
System.out.println(this.plugin.getServer().getPluginManager());
|
||||
System.out.println(this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"));
|
||||
|
||||
Permission allAccess = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
||||
Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*");
|
||||
for (MultiverseWorld w : this.worlds.values()) {
|
||||
|
@ -0,0 +1,408 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.*;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MockBlock implements Block{
|
||||
private Material type;
|
||||
private Location location;
|
||||
|
||||
|
||||
public MockBlock(Location l, Material type) {
|
||||
this.type = type;
|
||||
this.location = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata for this block
|
||||
*
|
||||
* @return block specific metadata
|
||||
*/
|
||||
@Override
|
||||
public byte getData() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face)} */
|
||||
@Override
|
||||
public Block getFace(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #getRelative(org.bukkit.block.BlockFace face, int distance)} */
|
||||
@Override
|
||||
public Block getFace(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given offsets
|
||||
*
|
||||
* @param modX X-coordinate offset
|
||||
* @param modY Y-coordinate offset
|
||||
* @param modZ Z-coordinate offset
|
||||
*
|
||||
* @return Block at the given offsets
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(int modX, int modY, int modZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given face<br />
|
||||
* <br />
|
||||
* This method is equal to getRelative(face, 1)
|
||||
*
|
||||
* @param face Face of this block to return
|
||||
*
|
||||
* @return Block at the given face
|
||||
*
|
||||
* @see #getRelative(org.bukkit.block.BlockFace, int)
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block at the given distance of the given face<br />
|
||||
* <br />
|
||||
* For example, the following method places water at 100,102,100; two blocks
|
||||
* above 100,100,100.
|
||||
* <pre>
|
||||
* Block block = world.getBlockAt(100,100,100);
|
||||
* Block shower = block.getFace(BlockFace.UP, 2);
|
||||
* shower.setType(Material.WATER);
|
||||
* </pre>
|
||||
*
|
||||
* @param face Face of this block to return
|
||||
* @param distance Distance to get the block at
|
||||
*
|
||||
* @return Block at the given face
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of this block
|
||||
*
|
||||
* @return block type
|
||||
*/
|
||||
@Override
|
||||
public Material getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type-id of this block
|
||||
*
|
||||
* @return block type-id
|
||||
*/
|
||||
@Override
|
||||
public int getTypeId() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the light level between 0-15
|
||||
*
|
||||
* @return light level
|
||||
*/
|
||||
@Override
|
||||
public byte getLightLevel() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world which contains this Block
|
||||
*
|
||||
* @return World containing this block
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x-coordinate of this block
|
||||
*
|
||||
* @return x-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y-coordinate of this block
|
||||
*
|
||||
* @return y-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the z-coordinate of this block
|
||||
*
|
||||
* @return z-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Location of the block
|
||||
*
|
||||
* @return Location of block
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk which contains this block
|
||||
*
|
||||
* @return Containing Chunk
|
||||
*/
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the metadata for this block
|
||||
*
|
||||
* @param data New block specific metadata
|
||||
*/
|
||||
@Override
|
||||
public void setData(byte data) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(byte data, boolean applyPhyiscs) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of this block
|
||||
*
|
||||
* @param type Material to change this block to
|
||||
*/
|
||||
@Override
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type-id of this block
|
||||
*
|
||||
* @param type Type-Id to change this block to
|
||||
*
|
||||
* @return whether the block was changed
|
||||
*/
|
||||
@Override
|
||||
public boolean setTypeId(int type) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeId(int type, boolean applyPhysics) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the face relation of this block compared to the given block<br />
|
||||
* <br />
|
||||
* For example:
|
||||
* <pre>
|
||||
* Block current = world.getBlockAt(100, 100, 100);
|
||||
* Block target = world.getBlockAt(100, 101, 100);
|
||||
*
|
||||
* current.getFace(target) == BlockFace.Up;
|
||||
* </pre>
|
||||
* <br />
|
||||
* If the given block is not connected to this block, null may be returned
|
||||
*
|
||||
* @param block Block to compare against this block
|
||||
*
|
||||
* @return BlockFace of this block which has the requested block, or null
|
||||
*/
|
||||
@Override
|
||||
public BlockFace getFace(Block block) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the current state of this block. You may then cast that state
|
||||
* into any accepted type, such as Furnace or Sign.
|
||||
* <p/>
|
||||
* The returned object will never be updated, and you are not guaranteed that
|
||||
* (for example) a sign is still a sign after you capture its state.
|
||||
*
|
||||
* @return BlockState with the current state of this block.
|
||||
*/
|
||||
@Override
|
||||
public BlockState getState() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the biome that this block resides in
|
||||
*
|
||||
* @return Biome type containing this block
|
||||
*/
|
||||
@Override
|
||||
public Biome getBiome() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block is being powered by Redstone.
|
||||
*
|
||||
* @return True if the block is powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockPowered() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block is being indirectly powered by Redstone.
|
||||
*
|
||||
* @return True if the block is indirectly powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockIndirectlyPowered() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block face is being powered by Redstone.
|
||||
*
|
||||
* @param face The block face
|
||||
*
|
||||
* @return True if the block face is powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFacePowered(BlockFace face) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block face is being indirectly powered by Redstone.
|
||||
*
|
||||
* @param face The block face
|
||||
*
|
||||
* @return True if the block face is indirectly powered.
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redstone power being provided to this block face
|
||||
*
|
||||
* @param face the face of the block to query or BlockFace.SELF for the block itself
|
||||
*
|
||||
* @return The power level.
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower(BlockFace face) {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redstone power being provided to this block
|
||||
*
|
||||
* @return The power level.
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this block is empty.
|
||||
* <p/>
|
||||
* A block is considered empty when {@link #getType()} returns {@link org.bukkit.Material#AIR}.
|
||||
*
|
||||
* @return true if this block is empty
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.type == Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this block is liquid.
|
||||
* <p/>
|
||||
* A block is considered liquid when {@link #getType()} returns {@link org.bukkit.Material#WATER}, {@link
|
||||
* org.bukkit.Material#STATIONARY_WATER}, {@link org.bukkit.Material#LAVA} or {@link
|
||||
* org.bukkit.Material#STATIONARY_LAVA}.
|
||||
*
|
||||
* @return true if this block is liquid
|
||||
*/
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temperature of the biome of this block
|
||||
*
|
||||
* @return Temperature of this block
|
||||
*/
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the humidity of the biome of this block
|
||||
*
|
||||
* @return Humidity of this block
|
||||
*/
|
||||
@Override
|
||||
public double getHumidity() {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reaction of the block when moved by a piston
|
||||
*
|
||||
* @return reaction
|
||||
*/
|
||||
@Override
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class TestCommandSender implements CommandSender {
|
||||
|
||||
private Server server;
|
||||
private boolean isOp;
|
||||
|
||||
public TestCommandSender(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this sender a message
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
System.out.println(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server instance that this command is running on
|
||||
*
|
||||
* @return Server instance
|
||||
*/
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this command sender
|
||||
*
|
||||
* @return Name of the sender
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object contains an override for the specified permission, by fully qualified name
|
||||
*
|
||||
* @param name Name of the permission
|
||||
*
|
||||
* @return true if the permission is set, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object contains an override for the specified {@link org.bukkit.permissions.Permission}
|
||||
*
|
||||
* @param perm Permission to check
|
||||
*
|
||||
* @return true if the permission is set, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the specified permission, if set.
|
||||
* <p/>
|
||||
* If a permission override is not set on this object, the default value of the permission will be returned.
|
||||
*
|
||||
* @param name Name of the permission
|
||||
*
|
||||
* @return Value of the permission
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the specified permission, if set.
|
||||
* <p/>
|
||||
* If a permission override is not set on this object, the default value of the permission will be returned
|
||||
*
|
||||
* @param perm Permission to get
|
||||
*
|
||||
* @return Value of the permission
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new {@link org.bukkit.permissions.PermissionAttachment} with a single permission by name and value
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param name Name of the permission to attach
|
||||
* @param value Value of the permission
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily adds a new {@link org.bukkit.permissions.PermissionAttachment} with a single permission by name and
|
||||
* value
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param name Name of the permission to attach
|
||||
* @param value Value of the permission
|
||||
* @param ticks Amount of ticks to automatically remove this attachment after
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily adds a new empty {@link org.bukkit.permissions.PermissionAttachment} to this object
|
||||
*
|
||||
* @param plugin Plugin responsible for this attachment, may not be null or disabled
|
||||
* @param ticks Amount of ticks to automatically remove this attachment after
|
||||
*
|
||||
* @return The PermissionAttachment that was just created
|
||||
*/
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given {@link org.bukkit.permissions.PermissionAttachment} from this object
|
||||
*
|
||||
* @param attachment Attachment to remove
|
||||
*
|
||||
* @throws IllegalArgumentException Thrown when the specified attachment isn't part of this object
|
||||
*/
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the permissions for this object, if the attachments have changed values.
|
||||
* <p/>
|
||||
* This should very rarely need to be called from a plugin.
|
||||
*/
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set containing all of the permissions currently in effect by this object
|
||||
*
|
||||
* @return Set of currently effective permissions
|
||||
*/
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object is a server operator
|
||||
*
|
||||
* @return true if this is an operator, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return this.isOp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator status of this object
|
||||
*
|
||||
* @param value New operator value
|
||||
*/
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
this.isOp = value;
|
||||
}
|
||||
}
|
@ -1,54 +1,123 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Matchers;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({PluginManager.class, MultiverseCore.class, Permission.class})
|
||||
@PrepareForTest({PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class})
|
||||
public class TestWorldImport {
|
||||
ConsoleCommandSender mockCommandSender;
|
||||
class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
|
||||
private WorldCreator worldCreator;
|
||||
|
||||
public WorldCreatorMatcher(WorldCreator creator) {
|
||||
this.worldCreator = creator;
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
if (!((WorldCreator) creator).name().equals(this.worldCreator.name())) {
|
||||
return false;
|
||||
} else if (!((WorldCreator) creator).environment().equals(this.worldCreator.environment())) {
|
||||
return false;
|
||||
} else if (((WorldCreator) creator).seed() != this.worldCreator.seed()) {
|
||||
return false;
|
||||
} else if (!((WorldCreator) creator).generator().equals(this.worldCreator.generator())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class LocationMatcher extends ArgumentMatcher<Location> {
|
||||
private Location l;
|
||||
|
||||
public LocationMatcher(Location location) {
|
||||
this.l = location;
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
return creator.equals(l);
|
||||
}
|
||||
}
|
||||
|
||||
class LocationMatcherAbove extends LocationMatcher {
|
||||
|
||||
public LocationMatcherAbove(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
if(super.l == null || creator == null) {
|
||||
return false;
|
||||
}
|
||||
return ((Location) creator).getBlockY() > super.l.getBlockY();
|
||||
}
|
||||
}
|
||||
|
||||
class LocationMatcherBelow extends LocationMatcher {
|
||||
|
||||
public LocationMatcherBelow(Location location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
if(super.l == null || creator == null) {
|
||||
return false;
|
||||
}
|
||||
return ((Location) creator).getBlockY() < super.l.getBlockY();
|
||||
}
|
||||
}
|
||||
|
||||
CommandSender mockCommandSender;
|
||||
private World mockWorld;
|
||||
private World mockNetherWorld;
|
||||
private List<World> worldList;
|
||||
private Server mockServer;
|
||||
private PluginManager mockPluginManager;
|
||||
private PluginLoader pluginLoader;
|
||||
private Bukkit mockBukkit;
|
||||
MultiverseCore core;
|
||||
File pluginDirectory;
|
||||
File serverDirectory;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Initialize a fake console.
|
||||
this.mockCommandSender = mock(ConsoleCommandSender.class);
|
||||
|
||||
public TestWorldImport() {
|
||||
// Initialize a fake world and world_nether.
|
||||
this.mockWorld = mock(World.class);
|
||||
when(this.mockWorld.getName()).thenReturn("world");
|
||||
when(this.mockWorld.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
when(this.mockWorld.getSpawnLocation()).thenReturn(new Location(this.mockWorld, 0, 0, 0));
|
||||
// Build a small platform that a player can stand on:
|
||||
LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(this.mockWorld, 0,0,0));
|
||||
LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(this.mockWorld, 0,0,0));
|
||||
when(this.mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(this.mockWorld, 0,0,0), Material.AIR));
|
||||
when(this.mockWorld.getBlockAt(Matchers.argThat(matchWorldBelow))).thenReturn(new MockBlock(new Location(this.mockWorld, 0,0,0), Material.STONE));
|
||||
|
||||
this.mockNetherWorld = mock(World.class);
|
||||
when(this.mockNetherWorld.getName()).thenReturn("world_nether");
|
||||
@ -57,55 +126,127 @@ public class TestWorldImport {
|
||||
// Initialize our fake worldlist.
|
||||
this.worldList = new ArrayList<World>();
|
||||
this.worldList.add(mockWorld);
|
||||
this.worldList.add(mockNetherWorld);
|
||||
|
||||
// Initialize Core. We must do it up here, so that the PluginManager won't return a null ref.
|
||||
this.core = PowerMockito.spy(new MultiverseCore());
|
||||
|
||||
JavaPlugin[] plugins = new JavaPlugin[]{core};
|
||||
|
||||
PowerMockito.whenNew(Permission.class).withArguments("Test").thenThrow(new Exception("Permission created exception"));
|
||||
Method addPermissionMethod = PowerMockito.method(PluginManager.class, "addPermission", Permission.class);
|
||||
Constructor permissionConst = PowerMockito.constructor(Permission.class, String.class, String.class, PermissionDefault.class);
|
||||
PowerMockito.suppress(permissionConst);
|
||||
Permission p = new Permission("Test", "test", PermissionDefault.OP);
|
||||
|
||||
// Add Core to the list of loaded plugins
|
||||
JavaPlugin[] plugins = new JavaPlugin[]{this.core};
|
||||
|
||||
// Mock the Plugin Manager
|
||||
this.mockPluginManager = PowerMockito.mock(PluginManager.class);
|
||||
when(this.mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(this.mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
|
||||
when(this.mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(this.core);
|
||||
|
||||
mockPluginManager.addPermission(new Permission(""));
|
||||
|
||||
|
||||
// Initialize our server.
|
||||
// Initialize the Mock server.
|
||||
this.mockServer = mock(Server.class);
|
||||
when(this.mockServer.getWorld("world")).thenReturn(mockWorld);
|
||||
when(this.mockServer.getWorld("worldNether")).thenReturn(mockNetherWorld);
|
||||
when(this.mockServer.getWorlds()).thenReturn(worldList);
|
||||
when(this.mockServer.getPluginManager()).thenReturn(this.mockPluginManager);
|
||||
when(this.mockServer.getName()).thenReturn("FernCraft");
|
||||
|
||||
WorldCreatorMatcher matchWorld = new WorldCreatorMatcher(new WorldCreator("world"));
|
||||
when(this.mockServer.createWorld(Matchers.argThat(matchWorld))).thenReturn(this.mockWorld);
|
||||
Logger logger = Logger.getLogger("Multiverse-Core-Test");
|
||||
when(this.mockServer.getLogger()).thenReturn(logger);
|
||||
|
||||
|
||||
// Initialize a fake console.
|
||||
this.mockCommandSender = PowerMockito.spy(new TestCommandSender(this.mockServer));
|
||||
|
||||
// Override some methods that bukkit normally provides us with for Core
|
||||
doReturn(this.mockServer).when(this.core).getServer();
|
||||
|
||||
// Let's let all MV files go to bin/test
|
||||
pluginDirectory = new File("bin/test/server/plugins/coretest");
|
||||
serverDirectory = new File("bin/test/server");
|
||||
|
||||
doReturn(pluginDirectory).when(this.core).getDataFolder();
|
||||
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.1-Test", "com.onarandombox.MultiverseCore.MultiverseCore");
|
||||
this.core = PowerMockito.spy(new MultiverseCore());
|
||||
doReturn(this.mockServer).when(core).getServer();
|
||||
doReturn(new File(".")).when(core).getDataFolder();
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
core.onLoad();
|
||||
doReturn(pdf).when(this.core).getDescription();
|
||||
|
||||
// Wish there was a good/easy way to teardown Bukkit
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
|
||||
Field serverField = Bukkit.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(Class.forName("org.bukkit.Bukkit"), null);
|
||||
if (serverDirectory.exists()) {
|
||||
serverDirectory.delete();
|
||||
FileUtils.deleteFolder(serverDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!serverDirectory.exists()) {
|
||||
serverDirectory.mkdirs();
|
||||
}
|
||||
|
||||
if (!pluginDirectory.exists()) {
|
||||
pluginDirectory.mkdirs();
|
||||
}
|
||||
Bukkit.setServer(this.mockServer);
|
||||
// Load Multiverse Core
|
||||
this.core.onLoad();
|
||||
|
||||
// Enable it.
|
||||
core.onEnable();
|
||||
|
||||
this.core.onEnable();
|
||||
|
||||
// Make sure it knows it's enabled.
|
||||
doReturn(true).when(this.core).isEnabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestWorldImport() {
|
||||
|
||||
|
||||
public void testWorldImportWithNoFolder() {
|
||||
// Start actual testing.
|
||||
// Create a core instance.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = this.mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
// Make sure core is actually a multiverse core
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
String[] normalArgs = new String[]{"import", "world", "normal"};
|
||||
|
||||
// Ensure we have a fresh copy of MV, 0 worlds.
|
||||
Assert.assertEquals(0, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the first world. The world folder does not exist.
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
verify(this.mockCommandSender).sendMessage(ChatColor.RED + "FAILED.");
|
||||
verify(this.mockCommandSender).sendMessage("That world folder does not exist...");
|
||||
|
||||
// We should still have no worlds.
|
||||
Assert.assertEquals(0, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldImport() {
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = this.mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make a fake server folder to fool MV into thinking a world folder exists.
|
||||
File serverDirectory = new File(this.core.getServerFolder(), "world");
|
||||
serverDirectory.mkdirs();
|
||||
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
@ -113,11 +254,15 @@ public class TestWorldImport {
|
||||
String[] normalArgs = new String[]{"import", "world", "normal"};
|
||||
String[] netherArgs = new String[]{"import", "world_nether", "nether"};
|
||||
|
||||
// Ensure we have a fresh copy of MV, 0 worlds.
|
||||
Assert.assertEquals(0, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the first world.
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
verify(this.mockCommandSender).sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
verify(this.mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!");
|
||||
|
||||
// We should now have one world imported!
|
||||
Assert.assertEquals(1, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user