Finalize API v5

This commit is contained in:
Eric Stokes 2011-10-09 16:36:05 -06:00
parent 980381194b
commit 2759d75125
7 changed files with 181 additions and 54 deletions

View File

@ -61,7 +61,7 @@ public class MVWorld implements MultiverseWorld {
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
private boolean allowWeather;
private Location spawnLocation;
private boolean isHidden;
private boolean isHidden = false;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config;
@ -87,7 +87,7 @@ public class MVWorld implements MultiverseWorld {
// Set local values that CAN be changed by the user
this.setAlias(config.getString("worlds." + this.name + ".alias.name", ""));
this.setAliasColor(config.getString("worlds." + this.name + ".alias.color", ChatColor.WHITE.toString()));
this.setColor(config.getString("worlds." + this.name + ".alias.color", ChatColor.WHITE.toString()));
this.setFakePVPMode(config.getBoolean("worlds." + this.name + ".fakepvp", false));
this.setPVPMode(config.getBoolean("worlds." + this.name + ".pvp", true));
this.setScaling(config.getDouble("worlds." + this.name + ".scale", this.getDefaultScale(this.environment)));
@ -95,8 +95,8 @@ public class MVWorld implements MultiverseWorld {
this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true));
this.setDifficulty(config.getString("worlds." + this.name + ".difficulty", "1"));
this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
this.setAllowAnimalSpawn(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
this.setAllowMonsterSpawn(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
this.setPrice(config.getDouble("worlds." + this.name + ".entryfee.amount", 0.0));
this.setCurrency(config.getInt("worlds." + this.name + ".entryfee.currency", -1));
this.setHunger(config.getBoolean("worlds." + this.name + ".hunger", true));
@ -191,7 +191,7 @@ public class MVWorld implements MultiverseWorld {
}
public String getColoredWorldString() {
return this.getAliasColor() + this.getAlias() + ChatColor.WHITE;
return this.getColor() + this.getAlias() + ChatColor.WHITE;
}
private void getMobExceptions() {
@ -299,9 +299,9 @@ public class MVWorld implements MultiverseWorld {
if (name.equalsIgnoreCase("pvp")) {
this.setPVPMode(value);
} else if (name.equalsIgnoreCase("animals")) {
this.setAnimals(value);
this.setAllowAnimalSpawn(value);
} else if (name.equalsIgnoreCase("monsters")) {
this.setMonsters(value);
this.setAllowMonsterSpawn(value);
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
this.setKeepSpawnInMemory(value);
} else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))) {
@ -338,7 +338,7 @@ public class MVWorld implements MultiverseWorld {
return true;
}
if (name.equalsIgnoreCase("aliascolor") || name.equalsIgnoreCase("color")) {
this.setAliasColor(value);
this.setColor(value);
return true;
}
if (name.equalsIgnoreCase("currency") || name.equalsIgnoreCase("curr")) {
@ -358,7 +358,8 @@ public class MVWorld implements MultiverseWorld {
}
if (name.equalsIgnoreCase("scale") || name.equalsIgnoreCase("scaling")) {
try {
return this.setScaling(Double.parseDouble(value));
this.setScaling(Double.parseDouble(value));
return true;
} catch (Exception e) {
return false;
}
@ -379,6 +380,7 @@ public class MVWorld implements MultiverseWorld {
}
}
@Override
public Environment getEnvironment() {
return this.environment;
}
@ -420,11 +422,12 @@ public class MVWorld implements MultiverseWorld {
}
@Override
public boolean allowAnimalSpawning() {
public boolean canAnimalsSpawn() {
return this.allowAnimals;
}
private void setAnimals(Boolean animals) {
@Override
public void setAllowAnimalSpawn(boolean animals) {
this.allowAnimals = animals;
// If animals are a boolean, then we can turn them on or off on the server
// If there are ANY exceptions, there will be something spawning, so turn them on
@ -433,15 +436,18 @@ public class MVWorld implements MultiverseWorld {
this.syncMobs();
}
@Override
public List<String> getAnimalList() {
return this.masterList.get("animals");
}
public boolean allowMonsterSpawning() {
@Override
public boolean canMonstersSpawn() {
return this.allowMonsters;
}
private void setMonsters(Boolean monsters) {
@Override
public void setAllowMonsterSpawn(boolean monsters) {
this.allowMonsters = monsters;
// If monsters are a boolean, then we can turn them on or off on the server
// If there are ANY exceptions, there will be something spawning, so turn them on
@ -450,11 +456,13 @@ public class MVWorld implements MultiverseWorld {
this.syncMobs();
}
@Override
public List<String> getMonsterList() {
return this.masterList.get("monsters");
}
public Boolean getPvp() {
@Override
public boolean isPVPEnabled() {
return this.pvp;
}
@ -506,11 +514,13 @@ public class MVWorld implements MultiverseWorld {
return this.masterList.get("worldblacklist");
}
public Double getScaling() {
@Override
public double getScaling() {
return this.scaling;
}
public boolean setScaling(Double scaling) {
@Override
public void setScaling(double scaling) {
if (scaling <= 0) {
// Disallow negative or 0 scalings.
scaling = 1.0;
@ -518,25 +528,26 @@ public class MVWorld implements MultiverseWorld {
this.scaling = scaling;
this.config.setProperty("worlds." + this.name + ".scale", scaling);
saveConfig();
return true;
}
public void setAliasColor(String aliasColor) {
@Override
public boolean setColor(String aliasColor) {
EnglishChatColor color = EnglishChatColor.fromString(aliasColor);
if (color == null) {
color = EnglishChatColor.WHITE;
return false;
}
this.aliasColor = color.getColor();
this.config.setProperty("worlds." + this.name + ".alias.color", color.getText());
saveConfig();
return;
return true;
}
public boolean isValidAliasColor(String aliasColor) {
return (EnglishChatColor.fromString(aliasColor) != null);
}
public ChatColor getAliasColor() {
@Override
public ChatColor getColor() {
return this.aliasColor;
}
@ -571,6 +582,7 @@ public class MVWorld implements MultiverseWorld {
return false;
}
@Override
public Permission getAccessPermission() {
return this.permission;
}
@ -703,6 +715,7 @@ public class MVWorld implements MultiverseWorld {
this.spawnLocation = new Location(w, x, y, z, yaw, pitch);
}
@Override
public Location getSpawnLocation() {
return this.spawnLocation;
}

View File

@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.generator.ChunkGenerator;
@ -100,6 +101,15 @@ public interface MVWorldManager {
*/
public MVWorld getMVWorld(String name);
/**
* Returns a {@link MVWorld} if it exists, and null if it does not.
*
* @param world The Bukkit world to check.
*
* @return A {@link MVWorld} or null.
*/
public MVWorld getMVWorld(World world);
/**
* Checks to see if the given name is a valid {@link MVWorld}
*
@ -109,6 +119,15 @@ public interface MVWorldManager {
*/
public boolean isMVWorld(String name);
/**
* Checks to see if the given world is a valid {@link MVWorld}
*
* @param world The Bukkit world to check.
*
* @return True if the world has been loaded into MV2, false if not.
*/
public boolean isMVWorld(World world);
/**
* Load the Worlds & Settings from the configuration file.
*

View File

@ -7,12 +7,11 @@
package com.onarandombox.MultiverseCore.api;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.permissions.Permission;
import java.util.List;
/**
* The API for a Multiverse Handled World.
* <p/>
@ -120,6 +119,22 @@ public interface MultiverseWorld {
*/
public void setAlias(String alias);
/**
* Sets the color that this world's name/alias will display as.
*
* @param color A valid color name.
*
* @return True if the color was set, false if not.
*/
public boolean setColor(String color);
/**
* Gets the color that this world's name/alias will display as.
*
* @return The color of this world.
*/
public ChatColor getColor();
/**
* Returns a very nicely colored string (using Alias and Color if they are set).
*
@ -132,14 +147,14 @@ public interface MultiverseWorld {
*
* @return True if ANY animal can, false if no animals can spawn.
*/
public boolean allowAnimalSpawning();
public boolean canAnimalsSpawn();
/**
* Gets whether or not monsters are allowed to spawn in this world.
*
* @return True if ANY monster can, false if no monsters can spawn.
*/
public boolean allowMonsterSpawning();
public boolean canMonstersSpawn();
/**
* Turn pvp on or off. This setting is used to set the world's PVP mode, and thus relies on fakePVP
@ -148,6 +163,13 @@ public interface MultiverseWorld {
*/
public void setPVPMode(boolean pvpMode);
/**
* Gets whether or not PVP is enabled in this world in some form (fake or not).
*
* @return True if players can take damage from other players.
*/
public boolean isPVPEnabled();
/**
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
* access permissions to go to this world.
@ -321,4 +343,60 @@ public interface MultiverseWorld {
* @return A world that exists on the server.
*/
public World getRespawnToWorld();
/**
* Sets the scale of this world. Really only has an effect if you use
* Multiverse-NetherPortals.
*
* @param scaling A scaling value, cannot be negative or 0.
*/
public void setScaling(double scaling);
/**
* Gets the scaling value of this world.Really only has an effect if you use
* Multiverse-NetherPortals.
*
* @return This world's non-negative, non-zero scale.
*/
public double getScaling();
/**
* Gets a list of all the worlds that players CANNOT travel to from this world,
* regardless of their access permissions.
*
* @return A List of world names.
*/
public List<String> getWorldBlacklist();
/**
* Returns a list of animals. This list always negates the {@link #canAnimalsSpawn()} result.
*
* @return A list of animals that will spawn if {@link #canAnimalsSpawn()} is false.
*/
public List<String> getAnimalList();
/**
* Sets whether or not animals can spawn.
* If there are values in {@link #getAnimalList()} and this is false,
* those animals become the exceptions, and will spawn
*
* @param allowAnimalSpawn True to allow spawning of monsters, false to prevent.
*/
public void setAllowAnimalSpawn(boolean allowAnimalSpawn);
/**
* Returns a list of monsters. This list always negates the {@link #canMonstersSpawn()} ()} result.
*
* @return A list of monsters that will spawn if {@link #canMonstersSpawn()} is false.
*/
public List<String> getMonsterList();
/**
* Sets whether or not monsters can spawn.
* If there are values in {@link #getMonsterList()} and this is false,
* those monsters become the exceptions, and will spawn
*
* @param allowMonsterSpawn True to allow spawning of monsters, false to prevent.
*/
public void setAllowMonsterSpawn(boolean allowMonsterSpawn);
}

View File

@ -104,7 +104,7 @@ public class InfoCommand extends MultiverseCommand {
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
Location spawn = world.getSpawnLocation();
message.add(new FancyMessage("Spawn Location: ", LocationManipulation.strCoords(spawn), colors));
message.add(new FancyMessage("World Scale: ", world.getScaling().toString(), colors));
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
if (world.getPrice() > 0) {
message.add(new FancyMessage("Price to enter this world: ", this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency()), colors));
} else {
@ -130,43 +130,43 @@ public class InfoCommand extends MultiverseCommand {
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
message.add(new FancyMessage("Keep spawn in memory: ", world.isKeepingSpawnInMemory() + "", colors));
message.add(new FancyHeader("PVP Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.getPvp().toString(), colors));
message.add(new FancyMessage("Multiverse Setting: ", world.isPVPEnabled() + "", colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));
message.add(new FancyMessage("Fake PVP Enabled: ", world.getFakePVP() + "", colors));
worldInfo.add(message);
// Page 3
message = new ArrayList<FancyText>();
message.add(new FancyHeader("Monster Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.allowMonsterSpawning() + "", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors));
if (MultiverseCore.MobsDisabledInDefaultWorld) {
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Monsters WILL NOT SPAWN IN THIS WORLD.", colors));
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Check your server log for more details.", colors));
}
if (world.getMonsterList().size() > 0) {
if (world.allowMonsterSpawning()) {
if (world.canMonstersSpawn()) {
message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
} else {
message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
}
} else {
message.add(new FancyMessage("Monsters that CAN spawn: ", world.allowMonsterSpawning() ? "ALL" : "NONE", colors));
message.add(new FancyMessage("Monsters that CAN spawn: ", world.canMonstersSpawn() ? "ALL" : "NONE", colors));
}
worldInfo.add(message);
// Page 4
message = new ArrayList<FancyText>();
message.add(new FancyHeader("Animal Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.allowAnimalSpawning() + "", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.canAnimalsSpawn() + "", colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors));
if (world.getMonsterList().size() > 0) {
if (world.allowMonsterSpawning()) {
if (world.canMonstersSpawn()) {
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors));
} else {
message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors));
}
} else {
message.add(new FancyMessage("Animals that CAN spawn: ", world.allowAnimalSpawning() ? "ALL" : "NONE", colors));
message.add(new FancyMessage("Animals that CAN spawn: ", world.canAnimalsSpawn() ? "ALL" : "NONE", colors));
}
worldInfo.add(message);

View File

@ -59,8 +59,8 @@ public class MVEntityListener extends EntityListener {
if (event.isCancelled()) {
return;
}
Entity attacker = null;
Entity defender = null;
Entity attacker;
Entity defender;
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
attacker = sub.getDamager();
@ -82,10 +82,8 @@ public class MVEntityListener extends EntityListener {
MVWorld world = this.worldManager.getMVWorld(w.getName());
if (attacker instanceof Player) {
Player pattacker = (Player) attacker;
if (!world.getPvp() && this.plugin.getConfig().getBoolean("fakepvp", false)) {
pattacker.sendMessage(ChatColor.RED + "PVP is disabled in this World.");
if (!world.isPVPEnabled() && this.plugin.getConfig().getBoolean("fakepvp", false)) {
((Player) attacker).sendMessage(ChatColor.RED + "PVP is disabled in this World.");
event.setCancelled(true);
}
}
@ -136,13 +134,13 @@ public class MVEntityListener extends EntityListener {
* Animal Handling
*/
if (event.getEntity() instanceof Animals || event.getEntity() instanceof Squid) {
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.allowAnimalSpawning(), creature.toString().toUpperCase()));
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.canAnimalsSpawn(), creature.toString().toUpperCase()));
}
/**
* Monster Handling
*/
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime) {
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.allowMonsterSpawning(), creature.toString().toUpperCase()));
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.canMonstersSpawn(), creature.toString().toUpperCase()));
}
}
@ -156,13 +154,13 @@ public class MVEntityListener extends EntityListener {
} else if (creatureList.contains(creature) && allowCreatureSpawning) {
// 3. There ARE exceptions and animals ARE allowed. Kill it.
return true;
} else if (!creatureList.contains(creature.toString().toUpperCase()) && allowCreatureSpawning) {
} else if (!creatureList.contains(creature.toUpperCase()) && allowCreatureSpawning) {
// 4. There ARE exceptions and animals ARE NOT allowed. SAVE it.
return false;
} else if (creatureList.contains(creature.toString().toUpperCase()) && !allowCreatureSpawning) {
} else if (creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) {
// 5. No animals are allowed to be spawned, BUT this one can stay...
return false;
} else if (!creatureList.contains(creature.toString().toUpperCase()) && !allowCreatureSpawning) {
} else if (!creatureList.contains(creature.toUpperCase()) && !allowCreatureSpawning) {
// 6. Animals are NOT allowed to spawn, and this creature is not in the save list... KILL IT
return true;
}

View File

@ -51,7 +51,7 @@ public class PurgeWorlds {
}
ArrayList<String> allMobs = new ArrayList<String>(world.getAnimalList());
allMobs.addAll(world.getMonsterList());
purgeWorld(sender, world, allMobs, !world.allowAnimalSpawning(), !world.allowMonsterSpawning());
purgeWorld(sender, world, allMobs, !world.canAnimalsSpawn(), !world.canMonstersSpawn());
}
public void purgeWorld(CommandSender sender, MVWorld mvworld, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {

View File

@ -168,8 +168,8 @@ public class WorldManager implements MVWorldManager {
}
public boolean loadWorld(String name) {
// Check if the World is already loaded
if (this.worlds.containsKey(name)) {
// Check if the World is already loaded
if (this.worlds.containsKey(name)) {
return true;
}
@ -186,9 +186,8 @@ public class WorldManager implements MVWorldManager {
addWorld(name, this.plugin.getEnvFromString(environment), seedString, generatorString);
return true;
}
else {
return false;
} else {
return false;
}
}
@ -289,6 +288,14 @@ public class WorldManager implements MVWorldManager {
return this.getMVWorldByAlias(name);
}
@Override
public MVWorld getMVWorld(World world) {
if (world != null) {
return this.getMVWorld(world.getName());
}
return null;
}
/**
* Returns a {@link MVWorld} if it exists, and null if it does not. This will search ONLY alias.
*
@ -317,6 +324,18 @@ public class WorldManager implements MVWorldManager {
return (this.worlds.containsKey(name) || isMVWorldAlias(name));
}
/**
* Checks to see if the given world is a valid {@link com.onarandombox.MultiverseCore.MVWorld}
*
* @param world The Bukkit world to check.
*
* @return True if the world has been loaded into MV2, false if not.
*/
@Override
public boolean isMVWorld(World world) {
return world != null && this.isMVWorld(world.getName());
}
/**
* This method ONLY checks the alias of each world.
*