mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-21 18:15:26 +01:00
Merge branch 'master' of github.com:Multiverse/Multiverse-Core into generate-structures
This commit is contained in:
commit
b39839b216
8
pom.xml
8
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.onarandombox.multiversecore</groupId>
|
||||
<artifactId>Multiverse-Core</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.4</version>
|
||||
<name>Multiverse-Core</name>
|
||||
<description>World Management Plugin</description>
|
||||
<properties>
|
||||
@ -180,7 +180,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.1-R3</version>
|
||||
<version>1.1-R5-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@ -196,7 +196,7 @@
|
||||
<dependency>
|
||||
<groupId>me.main__.util</groupId>
|
||||
<artifactId>SerializationConfig</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>1.3</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@ -205,7 +205,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fernferret.allpay</groupId>
|
||||
<artifactId>AllPay</artifactId>
|
||||
<version>6</version>
|
||||
<version>8</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
@ -206,7 +206,11 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.permission);
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.exempt);
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.ignoreperm);
|
||||
addToUpperLists(this.permission);
|
||||
// Add the permission and exempt to parents.
|
||||
this.addToUpperLists(this.permission);
|
||||
|
||||
// Add ignore to it's parent:
|
||||
this.ignoreperm.addParent("mv.bypass.gamemode.*", true);
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ import java.util.logging.Logger;
|
||||
* The implementation of the Multiverse-{@link Core}.
|
||||
*/
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private static final int PROTOCOL = 13;
|
||||
private static final int PROTOCOL = 14;
|
||||
// TODO: Investigate if this one is really needed to be static.
|
||||
// Doubt it. -- FernFerret
|
||||
private static Map<String, String> teleportQueue = new HashMap<String, String>();
|
||||
@ -859,7 +859,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
/**
|
||||
* This method is currently used by other plugins.
|
||||
* It will be removed in 2.4
|
||||
* @return
|
||||
* @return The Multiverse config.
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Deprecated
|
||||
public static MultiverseCoreConfiguration getStaticConfig() {
|
||||
|
@ -45,7 +45,7 @@ public interface MVDestination {
|
||||
boolean isThisType(JavaPlugin plugin, String destination);
|
||||
|
||||
/**
|
||||
* Returns the location a specific entity will spawn at.
|
||||
* Returns the location a specific entity will spawn at when being teleported to this Destination.
|
||||
* <p>
|
||||
* To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return
|
||||
* null back to you if you do this. It is always safer to pass an actual entity. This is used so things like
|
||||
|
@ -40,7 +40,7 @@ public interface MVWorldManager {
|
||||
* @param generator The Custom generator plugin to use.
|
||||
* @return True if the world is added, false if not.
|
||||
*/
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures,
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator);
|
||||
|
||||
/**
|
||||
@ -57,7 +57,7 @@ public interface MVWorldManager {
|
||||
* @param useSpawnAdjust If true, multiverse will search for a safe spawn. If not, It will not modify the level.dat.
|
||||
* @return True if the world is added, false if not.
|
||||
*/
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures,
|
||||
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator, boolean useSpawnAdjust);
|
||||
|
||||
/**
|
||||
|
@ -45,18 +45,13 @@ public class CheckCommand extends MultiverseCommand {
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage("You asked if '" + args.get(0) + "' could go to " + ChatColor.GREEN + args.get(0) + ChatColor.WHITE + ",");
|
||||
sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,",
|
||||
args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE));
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
if (perms.canEnterDestination(p, dest)) {
|
||||
sender.sendMessage(ChatColor.GREEN + args.get(0) + ChatColor.WHITE + " can travel to " + ChatColor.GREEN + args.get(1));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.AQUA + args.get(0) + ChatColor.RED + " CANNOT travel to " + ChatColor.AQUA + args.get(1));
|
||||
sender.sendMessage("Please turn debug mode to 3 then watch the console to find out why!");
|
||||
sender.sendMessage("Use: " + ChatColor.GREEN + "/mv debug 3");
|
||||
}
|
||||
perms.tellMeWhyICantDoThis(sender, p, dest);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@ -33,14 +32,14 @@ public class ImportCommand extends MultiverseCommand {
|
||||
public ImportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Import World");
|
||||
this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV} " + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n] -t [TYPE] -a [true|false]");
|
||||
this.setArgRange(1, 9); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]");
|
||||
this.setArgRange(1, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvimport");
|
||||
this.addKey("mvim");
|
||||
this.addKey("mv import");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether");
|
||||
this.addCommandExample("To import a world that uses a generator, you'll need the generator:");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator");
|
||||
this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
@ -128,12 +127,6 @@ public class ImportCommand extends MultiverseCommand {
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
|
||||
String generator = CommandHandler.getFlag("-g", args);
|
||||
String typeString = CommandHandler.getFlag("-t", args);
|
||||
boolean allowStructures = true;
|
||||
String structureString = CommandHandler.getFlag("-a", args);
|
||||
if (structureString != null) {
|
||||
allowStructures = Boolean.parseBoolean(structureString);
|
||||
}
|
||||
boolean useSpawnAdjust = true;
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-n")) {
|
||||
@ -149,20 +142,9 @@ public class ImportCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// If they didn't specify a type, default to NORMAL
|
||||
if (typeString == null) {
|
||||
typeString = "NORMAL";
|
||||
}
|
||||
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldFile.exists() && env != null) {
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, type, allowStructures, generator, useSpawnAdjust))
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
|
@ -64,7 +64,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
if (this.worldManager.isMVWorld(args.get(0))) {
|
||||
// then we have a world!
|
||||
worldName = args.get(0);
|
||||
} else if(this.worldManager.getUnloadedWorlds().contains(args.get(0))){
|
||||
} else if (this.worldManager.getUnloadedWorlds().contains(args.get(0))) {
|
||||
sender.sendMessage("That world exists, but it is unloaded!");
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, args.get(0)));
|
||||
return;
|
||||
@ -75,7 +75,8 @@ public class InfoCommand extends MultiverseCommand {
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(0)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
pageNum = 0;
|
||||
sender.sendMessage("That world does not exist.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -28,11 +27,14 @@ public class WhoCommand extends MultiverseCommand {
|
||||
public WhoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Who?");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv who");
|
||||
this.addKey("mvw");
|
||||
this.addKey("mvwho");
|
||||
this.addCommandExample("/mv who");
|
||||
this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN));
|
||||
this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD));
|
||||
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
@ -48,57 +50,57 @@ public class WhoCommand extends MultiverseCommand {
|
||||
showAll = false;
|
||||
}
|
||||
|
||||
List<MultiverseWorld> worlds = new ArrayList<MultiverseWorld>();
|
||||
|
||||
if (args.size() > 0) {
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
||||
showAll = true;
|
||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
||||
} else if (world != null) {
|
||||
if (!world.isHidden()) {
|
||||
worlds.add(world);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "World does not exist");
|
||||
// single world mode
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That world does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(p, world)) {
|
||||
sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
|
||||
world.getColoredWorldString(), ChatColor.AQUA));
|
||||
sender.sendMessage(buildPlayerString(world));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
||||
}
|
||||
|
||||
if (worlds.size() == 0) {
|
||||
sender.sendMessage("Multiverse does not know about any of your worlds :(");
|
||||
} else if (worlds.size() == 1) {
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Players in" + worlds.get(0).getColoredWorldString() + ChatColor.AQUA + " ---");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.AQUA + "--- There are players in ---");
|
||||
}
|
||||
|
||||
for (MultiverseWorld world : worlds) {
|
||||
if (!(this.worldManager.isMVWorld(world.getName()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
|
||||
continue;
|
||||
}
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
|
||||
String result = "";
|
||||
if (players.size() <= 0 && !showAll) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (players.size() <= 0) {
|
||||
result = "Empty";
|
||||
} else {
|
||||
for (Player player : players) {
|
||||
result += player.getDisplayName() + " " + ChatColor.WHITE;
|
||||
// multiworld mode
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players ---");
|
||||
boolean shownOne = false;
|
||||
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
|
||||
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
|
||||
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
|
||||
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world)));
|
||||
shownOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shownOne) {
|
||||
sender.sendMessage("No worlds found.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(world.getColoredWorldString() + ChatColor.WHITE + " - " + result);
|
||||
private String buildPlayerString(MultiverseWorld world) {
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
if (players.size() == 0) {
|
||||
return "No players found.";
|
||||
} else {
|
||||
StringBuilder playerBuilder = new StringBuilder();
|
||||
for (Player player : players) {
|
||||
playerBuilder.append(player.getDisplayName()).append(", ");
|
||||
}
|
||||
String bString = playerBuilder.toString();
|
||||
return bString.substring(0, bString.length() - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.LoggablePlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/*
|
||||
* This is a mess, so I'm just going to suppress all warnings here.
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated This isn't used any more, is it?
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class MVConfigMigrator {
|
||||
|
||||
public List<String> createdDefaults = new ArrayList<String>();
|
||||
|
||||
public abstract boolean migrate(String name, File folder);
|
||||
|
||||
protected final void migrateListItem(Configuration newConfig, Configuration oldConfig, String key, String oldProperty, String newProperty) {
|
||||
List<String> list = Arrays.asList(oldConfig.getString("worlds." + key + oldProperty).split(","));
|
||||
if (list.size() > 0) {
|
||||
if (list.get(0).length() == 0) {
|
||||
list = new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
newConfig.setProperty("worlds." + key + newProperty, list);
|
||||
}
|
||||
|
||||
protected final File detectMultiverseFolders(File folder, LoggablePlugin mvPlugin) {
|
||||
File oldFolder = null;
|
||||
mvPlugin.log(Level.INFO, "Starting Multiverse Configuration Migrator(MVCM)!");
|
||||
// They still have MV 1 installed! Good!
|
||||
if (mvPlugin.getServer().getPluginManager().getPlugin("MultiVerse") != null) {
|
||||
mvPlugin.log(Level.INFO, "Found MultiVerse 1. Starting Config Migration...");
|
||||
Plugin plugin = mvPlugin.getServer().getPluginManager().getPlugin("MultiVerse");
|
||||
oldFolder = plugin.getDataFolder();
|
||||
} else {
|
||||
// They didn't have MV 1 enabled... let's try and find the folder...
|
||||
File[] folders = folder.getParentFile().listFiles();
|
||||
List<File> folderList = Arrays.asList(folders);
|
||||
for (File f : folderList) {
|
||||
if (f.getName().equalsIgnoreCase("MultiVerse")) {
|
||||
mvPlugin.log(Level.INFO, "Found the MultiVerse 1 config folder. Starting Config Migration...");
|
||||
oldFolder = f;
|
||||
}
|
||||
}
|
||||
if (oldFolder == null) {
|
||||
mvPlugin.log(Level.INFO, "Did not find the MV1 Folder. If you did not have MultiVerse 1 installed and this is the FIRST time you're running MV2, this message is GOOD. ");
|
||||
mvPlugin.log(Level.INFO, "If you did, your configs were **NOT** migrated! Go Here: INSERTURLFORHELP");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return oldFolder;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* END CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
@ -115,7 +115,6 @@ public class WorldDestination implements MVDestination {
|
||||
this.world = ((MultiverseCore) plugin).getMVWorldManager().getMVWorld(items[1]);
|
||||
isValid = true;
|
||||
if (items.length == 3) {
|
||||
// TODO: oh my god, what should we do here?
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[2]);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ public class MVConfigReloadEvent extends Event {
|
||||
private List<String> configsLoaded;
|
||||
|
||||
public MVConfigReloadEvent(List<String> configsLoaded) {
|
||||
super("MVConfigReload");
|
||||
this.configsLoaded = configsLoaded;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
|
||||
private boolean isCancelled;
|
||||
|
||||
public MVPlayerTouchedPortalEvent(Player p, Location l) {
|
||||
super("MVPlayerTouchedPortalEvent");
|
||||
this.p = p;
|
||||
this.l = l;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ public class MVRespawnEvent extends Event {
|
||||
|
||||
|
||||
public MVRespawnEvent(Location spawningAt, Player p, String respawnMethod) {
|
||||
super("MVRespawn");
|
||||
this.player = p;
|
||||
this.location = spawningAt;
|
||||
this.respawnMethod = respawnMethod;
|
||||
|
@ -28,7 +28,6 @@ public class MVTeleportEvent extends Event implements Cancellable {
|
||||
private boolean isCancelled;
|
||||
|
||||
public MVTeleportEvent(MVDestination dest, Player teleportee, CommandSender teleporter, boolean safeTeleport) {
|
||||
super("SafeTTeleporter");
|
||||
this.teleportee = teleportee;
|
||||
this.teleporter = teleporter;
|
||||
this.dest = dest;
|
||||
|
@ -11,8 +11,7 @@ public class MVVersionEvent extends Event {
|
||||
private final StringBuilder versionInfoBuilder;
|
||||
|
||||
public MVVersionEvent(String versionInfo) {
|
||||
super("MVVersionEvent");
|
||||
versionInfoBuilder = new StringBuilder(versionInfo);
|
||||
this.versionInfoBuilder = new StringBuilder(versionInfo);
|
||||
}
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@ -38,7 +37,7 @@ public class MVVersionEvent extends Event {
|
||||
* @return The version-info.
|
||||
*/
|
||||
public String getVersionInfo() {
|
||||
return versionInfoBuilder.toString();
|
||||
return this.versionInfoBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,6 +45,6 @@ public class MVVersionEvent extends Event {
|
||||
* @param moreVersionInfo The version-info to add. Should end with '\n'.
|
||||
*/
|
||||
public void appendVersionInfo(String moreVersionInfo) {
|
||||
versionInfoBuilder.append(moreVersionInfo);
|
||||
this.versionInfoBuilder.append(moreVersionInfo);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ public class MVWorldDeleteEvent extends Event implements Cancellable {
|
||||
private final boolean removeFromConfig;
|
||||
|
||||
public MVWorldDeleteEvent(MultiverseWorld world, boolean removeFromConfig) {
|
||||
super("MVWorldDeleteEvent");
|
||||
|
||||
if (world == null)
|
||||
throw new IllegalArgumentException("world can't be null!");
|
||||
|
||||
|
@ -29,7 +29,6 @@ public class MVWorldPropertyChangeEvent extends Event implements Cancellable {
|
||||
private String name;
|
||||
|
||||
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, String value) {
|
||||
super("MVWorldPropertyChange");
|
||||
this.world = world;
|
||||
this.changer = changer;
|
||||
this.name = name;
|
||||
|
@ -86,7 +86,8 @@ public class MVEntityListener implements Listener {
|
||||
@EventHandler
|
||||
public void creatureSpawn(CreatureSpawnEvent event) {
|
||||
// Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour.
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM || event.getSpawnReason() == SpawnReason.EGG) {
|
||||
// TODO: Allow the egg thing to be a config param. Doubt this will be per world; seems silly.
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM || event.getSpawnReason() == SpawnReason.SPAWNER_EGG) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -126,14 +126,19 @@ public class MVPlayerListener implements Listener {
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (!p.hasPlayedBefore()) {
|
||||
this.plugin.log(Level.FINE, "Player joined first!");
|
||||
this.plugin.log(Level.FINER, "Player joined for the FIRST time!");
|
||||
if (plugin.getMVConfig().getFirstSpawnOverride()) {
|
||||
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): " + worldManager.getFirstSpawnWorld().getSpawnLocation());
|
||||
this.spawnNewPlayer(p);
|
||||
this.plugin.log(Level.FINE, String.format("Moving NEW player to(firstspawnoverride): %s",
|
||||
worldManager.getFirstSpawnWorld().getSpawnLocation()));
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player joined AGAIN!");
|
||||
this.plugin.log(Level.FINER, "Player joined AGAIN!");
|
||||
if (!this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
|
||||
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
}
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
@ -164,8 +169,9 @@ public class MVPlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerTeleport(PlayerTeleportEvent event) {
|
||||
this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
|
||||
|
||||
this.plugin.log(Level.FINER, String.format(
|
||||
"Got teleport event for player '%s' with cause '%s'",
|
||||
event.getPlayer().getName(), event.getCause()));
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
@ -174,41 +180,56 @@ public class MVPlayerListener implements Listener {
|
||||
String teleporterName = MultiverseCore.getPlayerTeleporter(teleportee.getName());
|
||||
if (teleporterName != null) {
|
||||
if (teleporterName.equals("CONSOLE")) {
|
||||
this.plugin.log(Level.FINEST, "We know the teleporter is the console! Magical!");
|
||||
this.plugin.log(Level.FINER, "We know the teleporter is the console! Magical!");
|
||||
teleporter = this.plugin.getServer().getConsoleSender();
|
||||
} else {
|
||||
teleporter = this.plugin.getServer().getPlayer(teleporterName);
|
||||
}
|
||||
}
|
||||
this.plugin.log(Level.FINEST, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'",
|
||||
this.plugin.log(Level.FINER, String.format("Inferred sender '%s' from name '%s', fetched from name '%s'",
|
||||
teleporter, teleporterName, teleportee.getName()));
|
||||
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
|
||||
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
|
||||
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||
// The player is Teleporting to the same world.
|
||||
this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world.");
|
||||
this.plugin.log(Level.FINER, String.format("Player '%s' is teleporting to the same world.",
|
||||
teleportee.getName()));
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
return;
|
||||
}
|
||||
// TODO: Refactor these lines.
|
||||
// Charge the teleporter
|
||||
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.",
|
||||
teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName()));
|
||||
this.plugin.log(Level.FINE, String.format(
|
||||
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have the FUNDS required to enter it.",
|
||||
teleportee.getName(), toWorld.getAlias(), teleporter.getName()));
|
||||
|
||||
return;
|
||||
}
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
|
||||
teleportee.getName(), event.getTo().getWorld().getName(), teleporter.getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, String.format(
|
||||
"Player '%s' was DENIED ACCESS to '%s' because '%s' don't have: multiverse.access.%s",
|
||||
teleportee.getName(), toWorld.getAlias(), teleporter.getName(),
|
||||
event.getTo().getWorld().getName()));
|
||||
} else {
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, String.format("Player '%s' was allowed to go to '%s' because enforceaccess is off.",
|
||||
teleportee.getName(), event.getTo().getWorld().getName()));
|
||||
this.plugin.log(Level.FINE, String.format(
|
||||
"Player '%s' was allowed to go to '%s' because enforceaccess is off.",
|
||||
teleportee.getName(), toWorld.getAlias()));
|
||||
}
|
||||
}
|
||||
|
||||
private void stateSuccess(String playerName, String worldName) {
|
||||
this.plugin.log(Level.FINE, String.format(
|
||||
"MV-Core is allowing Player '%s' to go to '%s'.",
|
||||
playerName, worldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to adjust the portal location to the actual portal location (and not
|
||||
* right outside of it.
|
||||
@ -274,8 +295,8 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnNewPlayer(final Player player) {
|
||||
// Spawn the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
||||
private void sendPlayerToDefaultWorld(final Player player) {
|
||||
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
@ -302,15 +323,16 @@ public class MVPlayerListener implements Listener {
|
||||
// We perform this task one tick later to MAKE SURE that the player actually reaches the
|
||||
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
|
||||
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
this.plugin.log(Level.FINE, "Handeling gamemode for player: " + player.getName());
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||
if (player.getWorld() == world.getCBWorld()) {
|
||||
MultiverseCore.staticLog(Level.FINE, "Handling gamemode for player: " + player.getName() + ", " + world.getGameMode().toString());
|
||||
MultiverseCore.staticLog(Level.FINE, "PWorld: " + player.getWorld());
|
||||
MultiverseCore.staticLog(Level.FINE, "AWorld: " + world);
|
||||
MultiverseCore.staticLog(Level.FINE, String.format(
|
||||
"Handling gamemode for player: %s, Changing to %s",
|
||||
player.getName(), world.getGameMode().toString()));
|
||||
MultiverseCore.staticLog(Level.FINEST, "From World: " + player.getWorld());
|
||||
MultiverseCore.staticLog(Level.FINEST, "To World: " + world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
} else {
|
||||
MultiverseCore.staticLog(Level.FINE,
|
||||
@ -320,7 +342,7 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
}, 1L);
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
this.plugin.log(Level.FINE, String.format("Player: %s is IMMUNE to gamemode changes!", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,10 @@ public class MVPortalListener implements Listener {
|
||||
return;
|
||||
}
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, event.getPortalType()));
|
||||
// We have to do it like this due to a bug in 1.1-R3
|
||||
if (this.cancelPortalEvent(world, event.getPortalType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,13 +59,17 @@ public class MVPortalListener implements Listener {
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(b.getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, PortalType.NETHER));
|
||||
return;
|
||||
if (this.cancelPortalEvent(world, PortalType.NETHER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If We're here, then the Portal was an Ender type:
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
event.setCancelled(this.cancelPortalEvent(world, PortalType.ENDER));
|
||||
if (this.cancelPortalEvent(world, PortalType.ENDER)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
|
||||
|
@ -249,7 +249,6 @@ public class LocationManipulation {
|
||||
}
|
||||
float speed = getSpeed(v);
|
||||
float halfSpeed = (float) (speed / 2.0);
|
||||
// TODO: Mathmatacize this:
|
||||
if (direction.equalsIgnoreCase("n")) {
|
||||
return new Vector(0, 0, -1 * speed);
|
||||
} else if (direction.equalsIgnoreCase("ne")) {
|
||||
|
@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.pneumaticraft.commandhandler.PermissionsInterface;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -43,10 +44,6 @@ public class MVPermissions implements PermissionsInterface {
|
||||
* @return True if they should bypass restrictions.
|
||||
*/
|
||||
public boolean canIgnoreGameModeRestriction(Player p, MultiverseWorld w) {
|
||||
if (p.hasPermission("mv.bypass.gamemode.*")) {
|
||||
this.plugin.log(Level.FINER, "Player has mv.bypass.gamemode.* their gamemode is ignored!");
|
||||
return true;
|
||||
}
|
||||
return p.hasPermission("mv.bypass.gamemode." + w.getName());
|
||||
}
|
||||
|
||||
@ -143,6 +140,87 @@ public class MVPermissions implements PermissionsInterface {
|
||||
return this.hasPermission(p, d.getRequiredPermission(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells a {@link CommandSender} why another {@link CommandSender} can or can not access a certain {@link MVDestination}.
|
||||
* @param asker The {@link CommandSender} that's asking.
|
||||
* @param playerInQuestion The {@link CommandSender} whose permissions we want to know.
|
||||
* @param d The {@link MVDestination}.
|
||||
*/
|
||||
public void tellMeWhyICantDoThis(CommandSender asker, CommandSender playerInQuestion, MVDestination d) {
|
||||
boolean cango = true;
|
||||
if (!(playerInQuestion instanceof Player)) {
|
||||
asker.sendMessage(String.format("The console can do %severything%s.", ChatColor.RED, ChatColor.WHITE));
|
||||
return;
|
||||
}
|
||||
Player p = (Player) playerInQuestion;
|
||||
if (d == null) {
|
||||
asker.sendMessage(String.format("The provided Destination is %sNULL%s, and therefore %sINVALID%s.",
|
||||
ChatColor.RED, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
// We know it'll be a player here due to the first line of this method.
|
||||
if (d.getLocation(p) == null) {
|
||||
asker.sendMessage(String.format(
|
||||
"The player will spawn at an %sindeterminate location%s. Talk to the MV Devs if you see this",
|
||||
ChatColor.RED, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
String worldName = d.getLocation(p).getWorld().getName();
|
||||
if (!this.worldMgr.isMVWorld(worldName)) {
|
||||
asker.sendMessage(String.format("The destination resides in a world(%s%s%s) that is not managed by Multiverse.",
|
||||
ChatColor.AQUA, worldName, ChatColor.WHITE));
|
||||
asker.sendMessage(String.format("Type %s/mv import ?%s to see the import command's help page.",
|
||||
ChatColor.DARK_AQUA, ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.access." + worldName, false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required world entry permission (%s%s%s) to go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.access." + worldName, ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (!this.hasPermission(p, d.getRequiredPermission(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required entry permission (%s%s%s) to go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, d.getRequiredPermission(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
cango = false;
|
||||
}
|
||||
if (cango) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) CAN go to the destination (%s%s%s).",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) cannot access the destination %s%s%s. Therefore they can't use mvtp at all for this.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
return;
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.teleport.self." + d.getIdentifier(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to use %s/mvtp %s%s.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) has the required teleport permission (%s%s%s) to use %s/mvtp %s%s.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
}
|
||||
if (!this.hasPermission(p, "multiverse.teleport.other." + d.getIdentifier(), false)) {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
} else {
|
||||
asker.sendMessage(String.format("The player (%s%s%s) has required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.",
|
||||
ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE,
|
||||
ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE,
|
||||
ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a player has a permission.
|
||||
*
|
||||
@ -164,17 +242,8 @@ public class MVPermissions implements PermissionsInterface {
|
||||
if (node.equals("")) {
|
||||
return true;
|
||||
}
|
||||
boolean hasPermission = checkActualPermission(sender, node);
|
||||
|
||||
// I consider this a workaround. At the moment, when we add a node AND recalc the permissions, until the perms
|
||||
// plugin reloads, when MV asks the API if a player has a perm, it reports that they do NOT.
|
||||
// For the moment, we're going to check all of this node's parents to see if the user has those. It stops
|
||||
// when if finds a true or there are no more parents. --FF
|
||||
// if (!hasPermission) {
|
||||
// hasPermission = this.hasAnyParentPermission(sender, node);
|
||||
// }
|
||||
|
||||
return hasPermission;
|
||||
return checkActualPermission(sender, node);
|
||||
}
|
||||
|
||||
// TODO: Better player checks, most likely not needed, but safer.
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class PurgeWorlds {
|
||||
/**
|
||||
* Convenience method for {@link #purgeWorld(CommandSender, MultiverseWorld, List, boolean, boolean)} that takes the settings from the world-config.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that initiated the action (TODO: Do we really need this?)
|
||||
* @param sender The {@link CommandSender} that initiated the action
|
||||
* @param world The {@link MultiverseWorld}.
|
||||
*/
|
||||
public void purgeWorld(CommandSender sender, MultiverseWorld world) {
|
||||
@ -70,7 +70,7 @@ public class PurgeWorlds {
|
||||
|
||||
/**
|
||||
* Clear all animals/monsters that do not belong to a world according to the config.
|
||||
* @param sender The {@link CommandSender} that initiated the action. (TODO: Do we really need this?)
|
||||
* @param sender The {@link CommandSender} that initiated the action.
|
||||
* @param mvworld The {@link MultiverseWorld}.
|
||||
* @param thingsToKill A {@link List} of animals/monsters to be killed.
|
||||
* @param negateAnimals Whether the monsters in the list should be negated.
|
||||
@ -127,14 +127,13 @@ public class PurgeWorlds {
|
||||
*/
|
||||
private boolean killMonster(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = "";
|
||||
//TODO: Fixme once either Rigby puts his awesome thing in OR Enderdragon gets a toString, OR both.
|
||||
if (e instanceof EnderDragon) {
|
||||
entityName = "ENDERDRAGON";
|
||||
} else {
|
||||
entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
}
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast || e instanceof EnderDragon) {
|
||||
this.plugin.log(Level.FINER, "Looking at a monster: " + e);
|
||||
this.plugin.log(Level.FINEST, "Looking at a monster: " + e);
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
|
@ -63,7 +63,6 @@ public class SafeTTeleporter {
|
||||
*/
|
||||
public Location getSafeLocation(Location l, int tolerance, int radius) {
|
||||
// Check around the player first in a configurable radius:
|
||||
// TODO: Make this configurable
|
||||
Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
|
||||
if (safe != null) {
|
||||
safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
|
@ -14,11 +14,7 @@ import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Squid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -71,23 +67,58 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (mvworld == null) {
|
||||
return;
|
||||
}
|
||||
World world = this.plugin.getServer().getWorld(mvworld.getName());
|
||||
World world = mvworld.getCBWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int entitiesKilled = 0;
|
||||
boolean specifiedAll = thingsToKill.contains("ALL");
|
||||
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||
for (Entity e : world.getEntities()) {
|
||||
this.plugin.log(Level.FINEST, "Entity list (aval for purge) from WORLD < " + mvworld.getName() + " >: " + e.toString());
|
||||
|
||||
// Check against Monsters
|
||||
if (killMonster(mvworld, e, thingsToKill, negateMonsters)) {
|
||||
boolean negate;
|
||||
boolean specified = false;
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
// it's an animal
|
||||
if (specifiedAnimals && !negateAnimals) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
if (specifiedAnimals)
|
||||
specified = true;
|
||||
negate = negateAnimals;
|
||||
} else {
|
||||
// it's a monster
|
||||
if (specifiedMonsters && !negateMonsters) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
if (specifiedMonsters)
|
||||
specified = true;
|
||||
negate = negateMonsters;
|
||||
}
|
||||
for (String s : thingsToKill) {
|
||||
if (e.getType().getName().equalsIgnoreCase(s)) {
|
||||
specified = true;
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!specified && negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
// Check against Animals
|
||||
if (this.killCreature(mvworld, e, thingsToKill, negateAnimals)) {
|
||||
entitiesKilled++;
|
||||
}
|
||||
}
|
||||
if (sender != null) {
|
||||
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'");
|
||||
@ -101,53 +132,4 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
public void purgeWorld(MultiverseWorld mvworld, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {
|
||||
purgeWorld(mvworld, thingsToKill, negateAnimals, negateMonsters, null);
|
||||
}
|
||||
|
||||
private boolean killCreature(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("ANIMALS")) {
|
||||
if (!negate) {
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Will kill the monster if it's in the list UNLESS the NEGATE boolean is set, then it will kill it if it's NOT.
|
||||
*/
|
||||
private boolean killMonster(MultiverseWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = "";
|
||||
//TODO: Fixme once either Rigby puts his awesome thing in OR Enderdragon gets a toString, OR both.
|
||||
if (e instanceof EnderDragon) {
|
||||
entityName = "ENDERDRAGON";
|
||||
} else {
|
||||
entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
}
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast || e instanceof EnderDragon) {
|
||||
this.plugin.log(Level.FINER, "Looking at a monster: " + e);
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class WorldManager implements MVWorldManager {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures,
|
||||
public boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator) {
|
||||
return this.addWorld(name, env, seedString, type, generateStructures, generator, true);
|
||||
}
|
||||
@ -93,9 +93,8 @@ public class WorldManager implements MVWorldManager {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean addWorld(String name, Environment env, String seedString, WorldType type, boolean generateStructures,
|
||||
public boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
|
||||
String generator, boolean useSpawnAdjust) {
|
||||
plugin.log(Level.FINE, "Adding world with: " + name + ", " + env.toString() + ", " + seedString + ", " + type.toString() + ", " + generator);
|
||||
Long seed = null;
|
||||
WorldCreator c = new WorldCreator(name);
|
||||
if (seedString != null && seedString.length() > 0) {
|
||||
@ -112,8 +111,12 @@ public class WorldManager implements MVWorldManager {
|
||||
c.generator(generator);
|
||||
}
|
||||
c.environment(env);
|
||||
c.type(type);
|
||||
c.generateStructures(generateStructures);
|
||||
if (type != null) {
|
||||
c.type(type);
|
||||
}
|
||||
if (generateStructures != null) {
|
||||
c.generateStructures(generateStructures);
|
||||
}
|
||||
|
||||
World world;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@ -524,7 +527,7 @@ public class WorldManager implements MVWorldManager {
|
||||
this.plugin.getServer().getPluginManager().removePermission(w.getAccessPermission().getName());
|
||||
this.plugin.getServer().getPluginManager().removePermission(w.getExemptPermission().getName());
|
||||
// Special namespace for gamemodes
|
||||
this.plugin.getServer().getPluginManager().removePermission("mv.gamemode.bypass." + w.getName());
|
||||
this.plugin.getServer().getPluginManager().removePermission("mv.bypass.gamemode." + w.getName());
|
||||
}
|
||||
// Recalc the all permission
|
||||
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);
|
||||
|
@ -308,6 +308,7 @@ public class TestWorldProperties {
|
||||
mockPlayer = mock(Player.class);
|
||||
when(mockPlayer.getWorld()).thenReturn(mvWorld.getCBWorld());
|
||||
when(mockPlayer.hasPlayedBefore()).thenReturn(true);
|
||||
when(mockPlayer.hasPermission("multiverse.access.world")).thenReturn(true);
|
||||
playerChatEvent = PowerMockito.mock(PlayerChatEvent.class);
|
||||
when(playerChatEvent.getPlayer()).thenReturn(mockPlayer);
|
||||
when(playerChatEvent.getFormat()).thenReturn("format");
|
||||
|
@ -0,0 +1,121 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ MultiverseCore.class })
|
||||
public class TestWorldPurger {
|
||||
TestInstanceCreator creator;
|
||||
MultiverseCore core;
|
||||
WorldPurger purger;
|
||||
|
||||
MultiverseWorld mvWorld;
|
||||
World cbworld;
|
||||
|
||||
Sheep sheep;
|
||||
Zombie zombie;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertTrue(creator.setUp());
|
||||
core = creator.getCore();
|
||||
purger = core.getMVWorldManager().getTheWorldPurger();
|
||||
core.getMVConfig().setGlobalDebug(3);
|
||||
mvWorld = mock(MultiverseWorld.class);
|
||||
cbworld = mock(World.class);
|
||||
when(mvWorld.getCBWorld()).thenReturn(cbworld);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// test 1: purge ALL without negations ==> both should be removed
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 2: purge ALL with one negation ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), false, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 3: purge ALL with both negations ==> everybody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ALL"), true, true);
|
||||
verify(sheep, never()).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 4: purge ANIMALS without negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ANIMALS"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 5: purge MONSTERS with one negation ==> nobody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("MONSTERS"), true, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 6: purge MONSTERS both negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("MONSTERS"), true, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 7: purge SHEEP without negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("SHEEP"), false, false);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// test 8: purge SHEEP with one negation ==> nobody should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("SHEEP"), false, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie).remove();
|
||||
|
||||
// test 9: purge ZOMBIE with both negations ==> the zombie should survive
|
||||
createAnimals();
|
||||
purger.purgeWorld(mvWorld, Arrays.asList("ZOMBIE"), true, true);
|
||||
verify(sheep).remove();
|
||||
verify(zombie, never()).remove();
|
||||
|
||||
// I like sheep.
|
||||
}
|
||||
|
||||
private void createAnimals() {
|
||||
sheep = mock(Sheep.class);
|
||||
when(sheep.getType()).thenReturn(EntityType.SHEEP);
|
||||
zombie = mock(Zombie.class);
|
||||
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
|
||||
when(cbworld.getEntities()).thenReturn(Arrays.asList((Entity) sheep, (Entity) zombie));
|
||||
}
|
||||
}
|
@ -1,330 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.test.utils;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*/
|
||||
public class MockBlock implements Block{
|
||||
private Material type;
|
||||
private Location location;
|
||||
|
||||
|
||||
public MockBlock(Location l, Material type) {
|
||||
this.type = type;
|
||||
this.location = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public byte getData() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getFace(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getFace(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(int modX, int modY, int modZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int distance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Material getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getTypeId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public byte getLightLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLightFromSky() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLightFromBlocks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setData(byte data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(byte data, boolean applyPhyiscs) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setType(Material type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setTypeId(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeId(int type, boolean applyPhysics) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setTypeIdAndData(int type, byte data, boolean applyPhyiscs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BlockFace getFace(Block block) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BlockState getState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Biome getBiome() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockPowered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockIndirectlyPowered() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFacePowered(BlockFace face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower(BlockFace face) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getBlockPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.type == Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public double getTemperature() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public double getHumidity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakNaturally(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user