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

This commit is contained in:
main() 2012-04-30 14:31:06 +02:00
commit 77480915a1
40 changed files with 379 additions and 143 deletions

12
pom.xml
View File

@ -180,18 +180,20 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.1-R5-SNAPSHOT</version>
<version>1.2.5-R1.0</version>
<!-- If you want the lates, use this -->
<!-- <version>LATEST</version> -->
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- Bukkit Dependency -->
<!-- Start of Spout -->
<!-- Start of Spout (disabled because we aren't using it)
<dependency>
<groupId>org.getspout</groupId>
<artifactId>spoutpluginapi</artifactId>
<version>dev-SNAPSHOT</version>
</dependency>
<!-- End of Spout -->
End of Spout -->
<!-- SerializationConfig Dependency -->
<dependency>
<groupId>me.main__.util</groupId>
@ -205,7 +207,7 @@
<dependency>
<groupId>com.fernferret.allpay</groupId>
<artifactId>AllPay</artifactId>
<version>8</version>
<version>10</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
@ -214,7 +216,7 @@
<dependency>
<groupId>com.pneumaticraft.commandhandler</groupId>
<artifactId>CommandHandler</artifactId>
<version>6</version>
<version>7</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -192,7 +192,9 @@ public class MVWorld implements MultiverseWorld {
// Things I haven't converted yet.
this.getMobExceptions();
this.getWorldBlacklist().addAll(worldSection.getList("worldblacklist", new ArrayList<String>()));
List<String> tempWorldBlacklist = worldSection.getStringList("worldblacklist");
if (tempWorldBlacklist != null)
this.getWorldBlacklist().addAll(tempWorldBlacklist);
// Enable and do the save.
this.canSave = true;
@ -348,16 +350,19 @@ public class MVWorld implements MultiverseWorld {
// TODO: Migrate this method.
private void getMobExceptions() {
List<String> temp;
temp = this.worldSection.getList("animals.exceptions", new ArrayList<String>());
temp = this.worldSection.getStringList("animals.exceptions");
// Add Animals to the exclusion list
for (String s : temp) {
this.masterList.get("animals").add(s.toUpperCase());
if (temp != null) {
for (String s : temp) {
this.masterList.get("animals").add(s.toUpperCase());
}
}
temp = this.worldSection.getList("monsters.exceptions", new ArrayList<String>());
temp = this.worldSection.getStringList("monsters.exceptions");
// Add Monsters to the exclusion list
for (String s : temp) {
this.masterList.get("monsters").add(s.toUpperCase());
if (temp != null) {
for (String s : temp) {
this.masterList.get("monsters").add(s.toUpperCase());
}
}
}

View File

@ -70,7 +70,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private AnchorManager anchorManager = new AnchorManager(this);
// TODO please let's make this non-static
private static MultiverseCoreConfiguration config;
private MultiverseCoreConfiguration config;
/**
* This method is used to find out who is teleporting a player.
@ -159,7 +159,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private AllPay banker;
private int pluginCount;
private DestinationFactory destFactory;
private SpoutInterface spoutInterface = null;
//private SpoutInterface spoutInterface = null;
private MultiverseMessaging messaging;
private BlockSafety blockSafety;
private LocationManipulation locationManipulation;
@ -253,11 +253,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// A test that had no worlds loaded was being run. This should never happen in production
}
this.saveMVConfig();
/*
// Check to see if spout was already loaded (most likely):
if (this.getServer().getPluginManager().getPlugin("Spout") != null) {
this.setSpout();
this.log(Level.INFO, "Spout integration enabled.");
}
*/
}
private void initializeDestinationFactory() {
@ -489,13 +491,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* @param msg The message to log.
*/
public static void staticLog(Level level, String msg) {
if (level == Level.FINE && config.getGlobalDebug() >= 1) {
if (level == Level.FINE && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 1) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level == Level.FINER && config.getGlobalDebug() >= 2) {
} else if (level == Level.FINER && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 2) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level == Level.FINEST && config.getGlobalDebug() >= 3) {
} else if (level == Level.FINEST && MultiverseCoreConfiguration.getInstance().getGlobalDebug() >= 3) {
staticDebugLog(Level.INFO, msg);
return;
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
@ -522,7 +524,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
@Override
public String getAuthors() {
String authors = "";
ArrayList<String> auths = this.getDescription().getAuthors();
List<String> auths = this.getDescription().getAuthors();
if (auths.size() == 0) {
return "";
}
@ -662,9 +664,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.serverFolder = newServerFolder;
}
/*
/**
* Initializes Spout.
*/
* /
public void setSpout() {
this.spoutInterface = new SpoutInterface();
this.commandHandler.registerCommand(new SpoutCommand(this));
@ -674,10 +677,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* Gets our {@link SpoutInterface}.
*
* @return The {@link SpoutInterface} we're using.
*/
* /
public SpoutInterface getSpout() {
return this.spoutInterface;
}
*/
/**
* {@inheritDoc}
@ -864,6 +868,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
*/
@Deprecated
public static MultiverseCoreConfiguration getStaticConfig() {
return config;
return MultiverseCoreConfiguration.getInstance();
}
}

View File

@ -11,6 +11,26 @@ import me.main__.util.SerializationConfig.SerializationConfig;
* Our configuration.
*/
public class MultiverseCoreConfiguration extends SerializationConfig implements MultiverseCoreConfig {
private static MultiverseCoreConfiguration instance;
/**
* Sets the statically saved instance.
* @param instance The new instance.
*/
public static void setInstance(MultiverseCoreConfiguration instance) {
MultiverseCoreConfiguration.instance = instance;
}
/**
* Gets the statically saved instance.
* @return The statically saved instance.
*/
public static MultiverseCoreConfiguration getInstance() {
if (instance == null)
throw new IllegalStateException("The instance wasn't set!");
return instance;
}
@Property
private boolean enforceaccess;
@Property
@ -34,10 +54,12 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
public MultiverseCoreConfiguration() {
super();
MultiverseCoreConfiguration.setInstance(this);
}
public MultiverseCoreConfiguration(Map<String, Object> values) {
super(values);
MultiverseCoreConfiguration.setInstance(this);
}
/**

View File

@ -566,8 +566,8 @@ public interface MultiverseWorld {
String getTime();
/**
* Gets the type of this world. As of 1.1-R1 this will be:
* FLAT or NORMAL
* Gets the type of this world. As of 1.2 this will be:
* FLAT, NORMAL or VERSION_1_1
* <p>
* This is *not* the generator.
*

View File

@ -53,8 +53,8 @@ public class EnvironmentCommand extends MultiverseCommand {
*/
public static void showWorldTypes(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
sender.sendMessage(String.format("%sNORMAL %sor %sFLAT",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA));
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT %sor %sVERSION_1_1",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.GOLD));
}
@Override

View File

@ -52,7 +52,7 @@ public class ImportCommand extends MultiverseCommand {
* @param worldFolder The File that may be a world.
* @return True if it looks like a world, false if not.
*/
private boolean checkIfIsWorld(File worldFolder) {
private static boolean checkIfIsWorld(File worldFolder) {
if (worldFolder.isDirectory()) {
File[] files = worldFolder.listFiles(new FilenameFilter() {
@Override

View File

@ -190,7 +190,7 @@ public class InfoCommand extends MultiverseCommand {
return worldInfo;
}
private String toCommaSeperated(List<String> list) {
private static String toCommaSeperated(List<String> list) {
if (list == null || list.size() == 0) {
return "";
}
@ -216,7 +216,7 @@ public class InfoCommand extends MultiverseCommand {
return positive ? ChatColor.GREEN : ChatColor.RED;
}
private void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
private static void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
page = page < 0 ? 0 : page;
page = page > doc.size() - 1 ? doc.size() - 1 : page;
boolean altColor = false;

View File

@ -65,7 +65,7 @@ public class PurgeCommand extends MultiverseCommand {
}
if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) {
((MultiverseCore) this.plugin).showNotMVWorldMessage(sender, worldName);
this.plugin.showNotMVWorldMessage(sender, worldName);
sender.sendMessage("It cannot be purged.");
return;
}

View File

@ -4,7 +4,7 @@
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
/*
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -21,7 +21,7 @@ import java.util.List;
/**
* Edit a world with spout.
*/
* /
public class SpoutCommand extends MultiverseCommand {
public SpoutCommand(MultiverseCore plugin) {
@ -51,7 +51,7 @@ public class SpoutCommand extends MultiverseCommand {
}
PopupScreen pop = new GenericPopup();
GenericButton button = new GenericButton("Fish");
// TODO maybe use constants for these
// TO-DO maybe use constants for these
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
button.setX(50);
button.setY(50);
@ -63,3 +63,4 @@ public class SpoutCommand extends MultiverseCommand {
p.getMainScreen().attachPopupScreen(pop);
}
}
*/

View File

@ -50,12 +50,8 @@ public class TeleportCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player.
CommandSender teleporter = sender;
Player teleportee = null;
if (sender instanceof Player) {
teleporter = (Player) sender;
}
String destinationName;

View File

@ -9,10 +9,13 @@ package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.utils.webpaste.BitlyURLShortener;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortener;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -25,6 +28,7 @@ import java.util.logging.Level;
* Dumps version info to the console.
*/
public class VersionCommand extends MultiverseCommand {
private static final URLShortener SHORTENER = new BitlyURLShortener();
public VersionCommand(MultiverseCore plugin) {
super(plugin);
@ -39,7 +43,7 @@ public class VersionCommand extends MultiverseCommand {
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
public void runCommand(final CommandSender sender, final List<String> args) {
// Check if the command was sent from a Player.
if (sender instanceof Player) {
sender.sendMessage("Version info dumped to console. Please check your server logs.");
@ -69,25 +73,30 @@ public class VersionCommand extends MultiverseCommand {
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
// log to console
String data = versionEvent.getVersionInfo();
final String data = versionEvent.getVersionInfo();
String[] lines = data.split("\n");
for (String line : lines) {
this.plugin.log(Level.INFO, line);
}
if (args.size() == 1) {
String pasteUrl = "";
if (args.get(0).equalsIgnoreCase("-p")) {
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
} else if (args.get(0).equalsIgnoreCase("-b")) {
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
} else {
return;
}
this.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(this.plugin, new Runnable() {
@Override
public void run() {
if (args.size() == 1) {
String pasteUrl;
if (args.get(0).equalsIgnoreCase("-p")) {
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
} else if (args.get(0).equalsIgnoreCase("-b")) {
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
} else {
return;
}
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
this.plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
}
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
}
}
});
}
/**
@ -100,7 +109,7 @@ public class VersionCommand extends MultiverseCommand {
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData) {
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
try {
return ps.postData(ps.encodeData(pasteData), ps.getPostURL());
return SHORTENER.shorten(ps.postData(ps.encodeData(pasteData), ps.getPostURL()));
} catch (PasteFailedException e) {
System.out.print(e);
return "Error posting to service";

View File

@ -90,7 +90,7 @@ public class WhoCommand extends MultiverseCommand {
return;
}
private String buildPlayerString(MultiverseWorld world) {
private static String buildPlayerString(MultiverseWorld world) {
List<Player> players = world.getCBWorld().getPlayers();
if (players.size() == 0) {
return "No players found.";

View File

@ -54,7 +54,7 @@ public class DestinationFactory {
Class<? extends MVDestination> myClass = this.destList.get(idenChar);
try {
MVDestination mydest = myClass.newInstance();
if (!mydest.isThisType((MultiverseCore) this.plugin, destination)) {
if (!mydest.isThisType(this.plugin, destination)) {
return new InvalidDestination();
}
mydest.setDestination(this.plugin, destination);

View File

@ -70,7 +70,7 @@ public class WorldDestination implements MVDestination {
return spawnLoc;
}
private Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
if (world != null) {
return world.getSpawnLocation();
} else {

View File

@ -16,7 +16,6 @@ import java.util.List;
* Called when the Multiverse-config should be reloaded.
*/
public class MVConfigReloadEvent extends Event {
private static final long serialVersionUID = 3647950355746345397L;
private List<String> configsLoaded;
public MVConfigReloadEvent(List<String> configsLoaded) {

View File

@ -20,6 +20,7 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
private Player p;
private Location l;
private boolean isCancelled;
private boolean canUse = true;
public MVPlayerTouchedPortalEvent(Player p, Location l) {
this.p = p;
@ -60,6 +61,26 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
return this.p;
}
/**
* Gets whether or not the player in this event can use this portal.
*
* @return True if the player can use this portal.
*/
public boolean canUseThisPortal() {
return this.canUse;
}
/**
* Sets whether or not the player in this event can use this portal.
* <p>
* Setting this to false will cause the player to bounce back!
*
* @param canUse Whether or not the user can go through this portal.
*/
public void setCanUseThisPortal(boolean canUse) {
this.canUse = canUse;
}
@Override
public boolean isCancelled() {
return this.isCancelled;

View File

@ -12,7 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
@ -99,14 +99,13 @@ public class MVEntityListener implements Listener {
if (!(this.worldManager.isMVWorld(world.getName())))
return;
CreatureType creature = event.getCreatureType();
EntityType type = event.getEntityType();
MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
/**
* Handle people with non-standard animals: ie a patched craftbukkit.
*/
if (creature == null) {
if (type == null) {
this.plugin.log(Level.FINER, "Found a null typed creature.");
return;
}
@ -114,18 +113,18 @@ public class MVEntityListener implements Listener {
/**
* Animal Handling
*/
if (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid) {
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), creature.toString().toUpperCase()));
if (!event.isCancelled() && (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid)) {
event.setCancelled(shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), type.getName().toUpperCase()));
}
/**
* Monster Handling
*/
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime) {
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), creature.toString().toUpperCase()));
if (!event.isCancelled() && (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime)) {
event.setCancelled(shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), type.getName().toUpperCase()));
}
}
private boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
private static boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
if (creatureList.isEmpty() && allowCreatureSpawning) {
// 1. There are no exceptions and animals are allowed. Save it.
return false;

View File

@ -135,7 +135,8 @@ public class MVPlayerListener implements Listener {
return;
} else {
this.plugin.log(Level.FINER, "Player joined AGAIN!");
if (!this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access!
&& !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
this.sendPlayerToDefaultWorld(p);
}
@ -237,7 +238,6 @@ public class MVPlayerListener implements Listener {
*/
@EventHandler(priority = EventPriority.LOWEST)
public void playerPortalCheck(PlayerPortalEvent event) {
this.plugin.log(Level.FINE, "CALLING CORE-ADJUST!!!");
if (event.isCancelled() || event.getFrom() == null) {
return;
}
@ -311,6 +311,9 @@ public class MVPlayerListener implements Listener {
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
if (mvWorld != null) {
this.handleGameMode(player, mvWorld);
} else {
this.plugin.log(Level.FINER, String.format(
"Not handling gamemode for world '%s' not managed by Multiverse.", world.getName()));
}
}

View File

@ -16,7 +16,6 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import java.util.Arrays;
import java.util.logging.Level;
/**
* Multiverse's Plugin {@link Listener}.
@ -40,10 +39,12 @@ public class MVPluginListener implements Listener {
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
}
/*
if (event.getPlugin().getDescription().getName().equals("Spout")) {
this.plugin.setSpout();
this.plugin.log(Level.INFO, "Spout integration enabled.");
}
*/
}
/**

View File

@ -41,7 +41,7 @@ public class MVPortalListener implements Listener {
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
// We have to do it like this due to a bug in 1.1-R3
if (this.cancelPortalEvent(world, event.getPortalType())) {
if (cancelPortalEvent(world, event.getPortalType())) {
event.setCancelled(true);
}
}
@ -59,7 +59,7 @@ public class MVPortalListener implements Listener {
for (Block b : event.getBlocks()) {
if (b.getType() == Material.PORTAL) {
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(b.getWorld());
if (this.cancelPortalEvent(world, PortalType.NETHER)) {
if (cancelPortalEvent(world, PortalType.NETHER)) {
event.setCancelled(true);
return;
}
@ -67,12 +67,12 @@ public class MVPortalListener implements Listener {
}
// If We're here, then the Portal was an Ender type:
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
if (this.cancelPortalEvent(world, PortalType.ENDER)) {
if (cancelPortalEvent(world, PortalType.ENDER)) {
event.setCancelled(true);
}
}
private boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
private static boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
if (world.getAllowedPortals() == AllowedPortalType.NONE) {
return true;
} else if (world.getAllowedPortals() != AllowedPortalType.ALL) {

View File

@ -20,9 +20,11 @@ public class FancyMessage implements FancyText {
/**
* Allows easy creation of an alternating colored list.
* TODO: Documentation! Why does CheckStyle just ignore this?
*
* @param title
* @param message
* @param scheme
*/
public FancyMessage(String title, String message, FancyColorScheme scheme) {
this.title = title;

View File

@ -25,19 +25,16 @@ public class FileUtils {
*/
public static boolean deleteFolder(File file) {
if (file.exists()) {
boolean ret = true;
// If the file exists, and it has more than one file in it.
if (file.isDirectory()) {
for (File f : file.listFiles()) {
if (!FileUtils.deleteFolder(f)) {
return false;
}
ret = ret && deleteFolder(f);
}
}
file.delete();
return !file.exists();
return ret && file.delete();
} else {
return false;
}
}
}

View File

@ -51,17 +51,17 @@ public class MVMessaging implements MultiverseMessaging {
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
if (!(sender instanceof Player) || ignoreCooldown) {
this.sendMessages(sender, messages);
sendMessages(sender, messages);
return true;
}
if (!this.sentList.containsKey(sender.getName())) {
this.sendMessages(sender, messages);
sendMessages(sender, messages);
this.sentList.put(sender.getName(), System.currentTimeMillis());
return true;
} else {
long time = System.currentTimeMillis();
if (time >= this.sentList.get(sender.getName()) + this.cooldown) {
this.sendMessages(sender, messages);
sendMessages(sender, messages);
this.sentList.put(sender.getName(), System.currentTimeMillis());
return true;
}
@ -77,7 +77,7 @@ public class MVMessaging implements MultiverseMessaging {
return this.sendMessages(sender, messages.toArray(new String[0]), ignoreCooldown);
}
private void sendMessages(CommandSender sender, String[] messages) {
private static void sendMessages(CommandSender sender, String[] messages) {
for (String s : messages) {
sender.sendMessage(s);
}

View File

@ -244,6 +244,7 @@ public class MVPermissions implements PermissionsInterface {
* @param isOpRequired @Deprecated. This is not used for anything anymore.
* @return True if they have that permission or any parent.
*/
@Override
public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) {
if (!(sender instanceof Player)) {
return true;
@ -266,10 +267,15 @@ public class MVPermissions implements PermissionsInterface {
Player player = (Player) sender;
boolean hasPermission = sender.hasPermission(node);
if (!sender.isPermissionSet(node)) {
this.plugin.log(Level.FINER, String.format("The node [%s%s%s] was %sNOT%s set for [%s%s%s].",
ChatColor.RED, node, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.AQUA,
player.getDisplayName(), ChatColor.WHITE));
}
if (hasPermission) {
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
} else {
this.plugin.log(Level.FINEST, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
}
return hasPermission;
}
@ -283,6 +289,7 @@ public class MVPermissions implements PermissionsInterface {
* @param node The permission node to check (possibly already a parent).
* @return True if they have any parent perm, false if none.
*/
// TODO remove this...?
private boolean hasAnyParentPermission(CommandSender sender, String node) {
String parentPerm = this.pullOneLevelOff(node);
// Base case
@ -303,7 +310,7 @@ public class MVPermissions implements PermissionsInterface {
* @param node The root node to check.
* @return The parent of the node
*/
private String pullOneLevelOff(String node) {
private static String pullOneLevelOff(String node) {
if (node == null) {
return null;
}
@ -408,7 +415,7 @@ public class MVPermissions implements PermissionsInterface {
/**
* If the given permission was 'multiverse.core.tp.self', this would return 'multiverse.core.tp.*'.
*/
private String getParentPerm(String[] seperated) {
private static String getParentPerm(String[] seperated) {
if (seperated.length == 1) {
return null;
}
@ -418,5 +425,4 @@ public class MVPermissions implements PermissionsInterface {
}
return returnString + "*";
}
}

View File

@ -78,7 +78,7 @@ public class PermissionTools {
* @param separatedPermissionString The array of a dot separated perm string.
* @return The dot separated parent permission string.
*/
private String getParentPerm(String[] separatedPermissionString) {
private static String getParentPerm(String[] separatedPermissionString) {
if (separatedPermissionString.length == 1) {
return null;
}

View File

@ -65,24 +65,24 @@ public class SimpleBlockSafety implements BlockSafety {
upOne.setY(upOne.getY() + 1);
downOne.setY(downOne.getY() - 1);
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|| this.isSolidBlock(upOne.getBlock().getType())) {
if (isSolidBlock(world.getBlockAt(actual).getType())
|| isSolidBlock(upOne.getBlock().getType())) {
MultiverseCore.staticLog(Level.FINER, "Error Here (Actual)? ("
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
+ actual.getBlock().getType() + ")[" + isSolidBlock(actual.getBlock().getType()) + "]");
MultiverseCore.staticLog(Level.FINER, "Error Here (upOne)? ("
+ upOne.getBlock().getType() + ")[" + this.isSolidBlock(upOne.getBlock().getType()) + "]");
+ upOne.getBlock().getType() + ")[" + isSolidBlock(upOne.getBlock().getType()) + "]");
return false;
}
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
MultiverseCore.staticLog(Level.FINER, "Error Here (downOne)? ("
+ downOne.getBlock().getType() + ")[" + this.isSolidBlock(downOne.getBlock().getType()) + "]");
+ downOne.getBlock().getType() + ")[" + isSolidBlock(downOne.getBlock().getType()) + "]");
return false;
}
if (downOne.getBlock().getType() == Material.FIRE) {
MultiverseCore.staticLog(Level.FINER, "There's fire below! ("
+ actual.getBlock().getType() + ")[" + this.isSolidBlock(actual.getBlock().getType()) + "]");
+ actual.getBlock().getType() + ")[" + isSolidBlock(actual.getBlock().getType()) + "]");
return false;
}
@ -129,7 +129,7 @@ public class SimpleBlockSafety implements BlockSafety {
/*
* If someone has a better way of this... Please either tell us, or submit a pull request!
*/
private boolean isSolidBlock(Material type) {
private static boolean isSolidBlock(Material type) {
switch (type) {
case AIR:
return false;

View File

@ -15,6 +15,10 @@ import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Squid;
import java.util.ArrayList;
@ -76,7 +80,7 @@ public class SimpleWorldPurger implements WorldPurger {
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
for (Entity e : world.getEntities()) {
boolean negate;
boolean negate = false;
boolean specified = false;
if (e instanceof Squid || e instanceof Animals) {
// it's an animal
@ -89,7 +93,7 @@ public class SimpleWorldPurger implements WorldPurger {
if (specifiedAnimals)
specified = true;
negate = negateAnimals;
} else {
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
// it's a monster
if (specifiedMonsters && !negateMonsters) {
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
@ -102,7 +106,8 @@ public class SimpleWorldPurger implements WorldPurger {
negate = negateMonsters;
}
for (String s : thingsToKill) {
if (e.getType().getName().equalsIgnoreCase(s)) {
EntityType type = EntityType.fromName(s);
if (type != null && type.equals(e.getType())) {
specified = true;
if (!negate) {
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);

View File

@ -4,14 +4,14 @@
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
/*
package com.onarandombox.MultiverseCore.utils;
import org.getspout.spoutapi.SpoutManager;
/**
* A helper-class holding the {@link SpoutManager}.
*/
* /
public class SpoutInterface {
private SpoutManager spoutManager;
@ -22,8 +22,9 @@ public class SpoutInterface {
/**
* Gets the {@link SpoutManager}.
* @return The {@link SpoutManager}.
*/
* /
public SpoutManager getManager() {
return this.spoutManager;
}
}
*/

View File

@ -69,7 +69,7 @@ public class WorldManager implements MVWorldManager {
return s.equalsIgnoreCase("bukkit.yml");
}
});
if (files.length == 1) {
if (files != null && files.length == 1) {
FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(files[0]);
if (bukkitConfig.isConfigurationSection("worlds")) {
Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
@ -77,6 +77,8 @@ public class WorldManager implements MVWorldManager {
defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
}
}
} else {
this.plugin.log(Level.WARNING, "Could not read 'bukkit.yml'. Any Default worldgenerators will not be loaded!");
}
}
@ -155,18 +157,6 @@ public class WorldManager implements MVWorldManager {
return true;
}
/**
* Verifies that a given Plugin generator string exists.
*
* @param generator The name of the generator plugin. This should be something like CleanRoomGenerator.
* @return True if the plugin exists and is enabled, false if not.
*/
// TODO maybe remove this since it's unused?
private boolean pluginExists(String generator) {
Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
return myPlugin != null && myPlugin.isEnabled();
}
/**
* {@inheritDoc}
*/

View File

@ -0,0 +1,34 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import java.io.IOException;
/**
* An {@link URLShortener} using {@code bit.ly}.
*/
public class BitlyURLShortener extends HttpAPIClient implements URLShortener {
private static final String GENERIC_BITLY_REQUEST_FORMAT = "https://api-ssl.bitly.com/v3/shorten?format=txt&apiKey=%s&login=%s&longUrl=%s";
// I think it's no problem that these are public
private static final String USERNAME = "multiverse2";
private static final String API_KEY = "R_9dbff4862a3bc0c4218a7d78cc10d0e0";
public BitlyURLShortener() {
super(String.format(GENERIC_BITLY_REQUEST_FORMAT, API_KEY, USERNAME, "%s"));
}
/**
* {@inheritDoc}
*/
@Override
public String shorten(String longUrl) {
try {
String result = this.exec(longUrl);
if (!result.startsWith("http://j.mp/")) // ... then it's failed :/
throw new IOException(result);
return result;
} catch (IOException e) {
e.printStackTrace();
return longUrl; // sorry ...
}
}
}

View File

@ -0,0 +1,41 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
/**
* HTTP API-client.
*/
public abstract class HttpAPIClient {
/**
* The URL for this API-request.
*/
protected final String urlFormat;
public HttpAPIClient(String urlFormat) {
this.urlFormat = urlFormat;
}
/**
* Executes this API-Request.
* @param args Format-args.
* @return The result (as text).
* @throws IOException When the I/O-operation failed.
*/
protected final String exec(Object... args) throws IOException {
URLConnection conn = new URL(String.format(this.urlFormat, args)).openConnection();
conn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while (!reader.ready()); // wait until reader is ready, may not be necessary, SUPPRESS CHECKSTYLE: EmptyStatement
StringBuilder ret = new StringBuilder();
while (reader.ready()) {
ret.append(reader.readLine()).append('\n');
}
reader.close();
return ret.toString();
}
}

View File

@ -8,7 +8,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.regex.Pattern;
/**
* Pastes to {@code pastebin.com}.
@ -75,18 +74,4 @@ public class PastebinPasteService implements PasteService {
throw new PasteFailedException(e);
}
}
// TODO maybe remove this?
private Pattern getURLMatchingPattern() {
if (this.isPrivate) {
return Pattern.compile(".*http://pastie.org/.*key=([0-9a-z]+).*");
} else {
return Pattern.compile(".*http://pastie.org/([0-9]+).*");
}
}
// TODO maybe remove this?
private String formatURL(String pastieID) {
return "http://pastie.org/" + (this.isPrivate ? "private/" : "") + pastieID;
}
}

View File

@ -0,0 +1,13 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
/**
* URL-Shortener.
*/
public interface URLShortener {
/**
* Shorten an URL.
* @param longUrl The long form.
* @return The shortened URL.
*/
String shorten(String longUrl);
}

View File

@ -20,6 +20,7 @@ import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@ -33,7 +34,7 @@ import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class })
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
public class TestDebugMode {
TestInstanceCreator creator;
Server mockServer;

View File

@ -0,0 +1,94 @@
package com.onarandombox.MultiverseCore.test;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.verification.VerificationModeFactory;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Field;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
public class TestWorldCreation {
private TestInstanceCreator creator;
private MultiverseCore core;
private CommandSender mockCommandSender;
@Before
public void setUp() throws Exception {
this.creator = new TestInstanceCreator();
assertTrue(this.creator.setUp());
this.core = this.creator.getCore();
this.mockCommandSender = this.creator.getCommandSender();
}
@After
public void tearDown() throws Exception {
creator.tearDown();
}
@Test
@Ignore
public void test() {
// Initialize a fake command
Command mockCommand = mock(Command.class);
when(mockCommand.getName()).thenReturn("mv");
// Try to create a world that exists
String[] normalArgs = new String[] { "create", "world", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", normalArgs);
verify(mockCommandSender).sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
verify(mockCommandSender).sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
// Try to create a world that is new
String[] newArgs = new String[] { "create", "world2", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", newArgs);
verify(mockCommandSender).sendMessage("Starting creation of world 'world2'...");
String[] dottedWorld = new String[] { "create", "fish.world", "normal" };
core.onCommand(mockCommandSender, mockCommand, "", dottedWorld);
verify(mockCommandSender).sendMessage("Starting creation of world 'fish.world'...");
verify(mockCommandSender, VerificationModeFactory.times(2)).sendMessage("Complete!");
// Grab the Config
Field worldConfigField = null;
ConfigurationSection worldsSection = null;
try {
worldConfigField = WorldManager.class.getDeclaredField("configWorlds");
worldConfigField.setAccessible(true);
Configuration rootConfig = (Configuration) worldConfigField.get(this.core.getMVWorldManager());
worldsSection = rootConfig.getConfigurationSection("worlds");
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
// Verify that the world was added to the configs
// TODO: Expand this.
assertNotNull(worldsSection);
assertEquals(2, worldsSection.getKeys(false).size());
assertTrue(worldsSection.getKeys(false).contains("world2"));
// TODO: Uncomment once this is fixed!!!
//assertTrue(worldsSection.getKeys(false).contains("'fish.world'"));
// Worlds with .s are a special case, verify that they work.
}
}

View File

@ -20,7 +20,7 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
@ -31,10 +31,10 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.internal.verification.VerificationModeFactory;
@ -52,9 +52,8 @@ import com.onarandombox.MultiverseCore.utils.WorldManager;
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
WeatherChangeEvent.class, ThunderChangeEvent.class, PlayerChatEvent.class,
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
FoodLevelChangeEvent.class, WorldManager.class })
FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class })
public class TestWorldProperties {
private TestInstanceCreator creator;
private MultiverseCore core;
private CommandSender mockCommandSender;
@ -71,7 +70,7 @@ public class TestWorldProperties {
private PlayerJoinEvent playerJoinEvent;
private PlayerRespawnEvent playerRespawnBed;
private PlayerRespawnEvent playerRespawnNormal;
private Entity mockEntity;
private HumanEntity mockHumanEntity;
private EntityRegainHealthEvent entityRegainHealthEvent;
private FoodLevelChangeEvent entityFoodLevelChangeEvent;
private FoodLevelChangeEvent entityFoodLevelRiseEvent;
@ -327,17 +326,17 @@ public class TestWorldProperties {
when(playerRespawnNormal.getPlayer()).thenReturn(mockPlayer);
when(playerRespawnNormal.isBedSpawn()).thenReturn(false);
//// Entity events
mockEntity = mock(Entity.class);
mockHumanEntity = mock(HumanEntity.class);
// entity regain health
entityRegainHealthEvent = PowerMockito.mock(EntityRegainHealthEvent.class);
when(entityRegainHealthEvent.getRegainReason()).thenReturn(RegainReason.REGEN);
when(mockEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
when(entityRegainHealthEvent.getEntity()).thenReturn(mockEntity);
when(mockHumanEntity.getLocation()).thenReturn(new Location(mvWorld.getCBWorld(), 0, 0, 0));
when(entityRegainHealthEvent.getEntity()).thenReturn(mockHumanEntity);
// entity food level change event
entityFoodLevelChangeEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
// this won't do anything since we're not mocking a player,
// but the plugin should be able to handle this!
when(entityFoodLevelChangeEvent.getEntity()).thenReturn(mockEntity);
when(entityFoodLevelChangeEvent.getEntity()).thenReturn(mockHumanEntity);
entityFoodLevelRiseEvent = PowerMockito.mock(FoodLevelChangeEvent.class);
when(mockPlayer.getFoodLevel()).thenReturn(2);
when(entityFoodLevelRiseEvent.getEntity()).thenReturn(mockPlayer);

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Zombie;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -23,7 +24,7 @@ import com.onarandombox.MultiverseCore.api.WorldPurger;
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MultiverseCore.class })
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
public class TestWorldPurger {
TestInstanceCreator creator;
MultiverseCore core;

View File

@ -18,6 +18,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
@ -34,7 +35,7 @@ import static junit.framework.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class })
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class, PluginDescriptionFile.class })
public class TestWorldStuff {
private TestInstanceCreator creator;

View File

@ -35,6 +35,7 @@ import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.MockGateway;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@ -58,14 +59,17 @@ public class TestInstanceCreator {
pluginDirectory.mkdirs();
Assert.assertTrue(pluginDirectory.exists());
MockGateway.MOCK_STANDARD_METHODS = false;
core = PowerMockito.spy(new MultiverseCore());
// Let's let all MV files go to bin/test
doReturn(pluginDirectory).when(core).getDataFolder();
// Return a fake PDF file.
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
"com.onarandombox.MultiverseCore.MultiverseCore");
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
"com.onarandombox.MultiverseCore.MultiverseCore"));
when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
doReturn(pdf).when(core).getDescription();
doReturn(true).when(core).isEnabled();
core.setServerFolder(serverDirectory);