Continue updating API. Fix squids not being monitored, Closes #181

This commit is contained in:
Eric Stokes 2011-10-09 15:38:18 -06:00
parent 8370a72776
commit 980381194b
4 changed files with 151 additions and 39 deletions

View File

@ -343,8 +343,7 @@ public class MVWorld implements MultiverseWorld {
} }
if (name.equalsIgnoreCase("currency") || name.equalsIgnoreCase("curr")) { if (name.equalsIgnoreCase("currency") || name.equalsIgnoreCase("curr")) {
try { try {
int intValue = Integer.parseInt(value); this.setCurrency(Integer.parseInt(value));
this.setCurrency(intValue);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
@ -352,16 +351,14 @@ public class MVWorld implements MultiverseWorld {
} }
if (name.equalsIgnoreCase("price")) { if (name.equalsIgnoreCase("price")) {
try { try {
double doubValue = Double.parseDouble(value); this.setPrice(Double.parseDouble(value));
return this.setPrice(doubValue);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
if (name.equalsIgnoreCase("scale") || name.equalsIgnoreCase("scaling")) { if (name.equalsIgnoreCase("scale") || name.equalsIgnoreCase("scaling")) {
try { try {
double doubValue = Double.parseDouble(value); return this.setScaling(Double.parseDouble(value));
return this.setScaling(doubValue);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
@ -369,16 +366,14 @@ public class MVWorld implements MultiverseWorld {
if (name.equalsIgnoreCase("gamemode") || name.equalsIgnoreCase("mode")) { if (name.equalsIgnoreCase("gamemode") || name.equalsIgnoreCase("mode")) {
try { try {
GameMode mode = GameMode.valueOf(value.toUpperCase()); return this.setGameMode(GameMode.valueOf(value.toUpperCase()));
return this.setGameMode(mode);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
try { try {
boolean boolValue = Boolean.parseBoolean(value); return this.setVariable(name, Boolean.parseBoolean(value));
return this.setVariable(name, boolValue);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
@ -388,22 +383,27 @@ public class MVWorld implements MultiverseWorld {
return this.environment; return this.environment;
} }
@Override
public void setEnvironment(Environment environment) { public void setEnvironment(Environment environment) {
this.environment = environment; this.environment = environment;
} }
@Override
public Long getSeed() { public Long getSeed() {
return this.seed; return this.seed;
} }
@Override
public void setSeed(Long seed) { public void setSeed(Long seed) {
this.seed = seed; this.seed = seed;
} }
@Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
@Override
public String getAlias() { public String getAlias() {
if (this.alias == null || this.alias.length() == 0) { if (this.alias == null || this.alias.length() == 0) {
return this.name; return this.name;
@ -412,12 +412,14 @@ public class MVWorld implements MultiverseWorld {
} }
@Override
public void setAlias(String alias) { public void setAlias(String alias) {
this.alias = alias; this.alias = alias;
this.config.setProperty("worlds." + this.name + ".alias.name", alias); this.config.setProperty("worlds." + this.name + ".alias.name", alias);
saveConfig(); saveConfig();
} }
@Override
public boolean allowAnimalSpawning() { public boolean allowAnimalSpawning() {
return this.allowAnimals; return this.allowAnimals;
} }
@ -553,47 +555,58 @@ public class MVWorld implements MultiverseWorld {
return this.fakePVP; return this.fakePVP;
} }
public String getRespawnToWorld() { @Override
return this.respawnWorld; public World getRespawnToWorld() {
return (this.plugin.getServer().getWorld(this.respawnWorld));
} }
public void setRespawnToWorld(String respawnToWorld) { @Override
this.respawnWorld = respawnToWorld; public boolean setRespawnToWorld(String respawnToWorld) {
this.config.setProperty("worlds." + this.name + ".respawnworld", respawnToWorld); if (this.plugin.getServer().getWorld(respawnToWorld) != null) {
saveConfig(); this.respawnWorld = respawnToWorld;
this.config.setProperty("worlds." + this.name + ".respawnworld", respawnToWorld);
saveConfig();
return true;
}
return false;
} }
public Permission getPermission() { public Permission getAccessPermission() {
return this.permission; return this.permission;
} }
@Override
public int getCurrency() { public int getCurrency() {
return this.currency; return this.currency;
} }
@Override
public double getPrice() { public double getPrice() {
return this.price; return this.price;
} }
private boolean setCurrency(int currency) { @Override
public void setCurrency(int currency) {
this.currency = currency; this.currency = currency;
config.setProperty("worlds." + this.name + ".entryfee.currency", currency); config.setProperty("worlds." + this.name + ".entryfee.currency", currency);
saveConfig(); saveConfig();
return true;
} }
private boolean setPrice(double price) { @Override
public void setPrice(double price) {
this.price = price; this.price = price;
config.setProperty("worlds." + this.name + ".entryfee.amount", price); config.setProperty("worlds." + this.name + ".entryfee.amount", price);
saveConfig(); saveConfig();
return true;
} }
/** This method really isn't needed */
@Deprecated
public boolean isExempt(Player p) { public boolean isExempt(Player p) {
return (this.plugin.getMVPerms().hasPermission(p, this.exempt.getName(), true)); return (this.plugin.getMVPerms().hasPermission(p, this.exempt.getName(), true));
} }
public Permission getExempt() { @Override
public Permission getExemptPermission() {
return this.exempt; return this.exempt;
} }
@ -603,13 +616,28 @@ public class MVWorld implements MultiverseWorld {
} }
} }
private boolean setGameMode(String strMode) { @Override
GameMode mode = GameMode.SURVIVAL; public boolean setGameMode(String gameMode) {
GameMode mode = null;
try { try {
mode = GameMode.valueOf(strMode); mode = GameMode.valueOf(gameMode.toUpperCase());
} catch (Exception e) { } catch (Exception e) {
try {
int modeInt = Integer.parseInt(gameMode);
mode = GameMode.getByValue(modeInt);
} catch (Exception e2) {
return false;
}
} }
return this.setGameMode(mode); if (mode == null) {
return false;
}
this.setGameMode(mode);
config.setProperty("worlds." + this.name + ".gamemode", mode.getValue());
saveConfig();
return true;
} }
private boolean setGameMode(GameMode mode) { private boolean setGameMode(GameMode mode) {
@ -641,12 +669,14 @@ public class MVWorld implements MultiverseWorld {
return this.keepSpawnInMemory; return this.keepSpawnInMemory;
} }
@Override
public void setHunger(boolean hunger) { public void setHunger(boolean hunger) {
this.hunger = hunger; this.hunger = hunger;
config.setProperty("worlds." + this.name + ".hunger", this.hunger); config.setProperty("worlds." + this.name + ".hunger", this.hunger);
saveConfig(); saveConfig();
} }
@Override
public boolean getHunger() { public boolean getHunger() {
return this.hunger; return this.hunger;
} }
@ -690,15 +720,15 @@ public class MVWorld implements MultiverseWorld {
} catch (Exception e) { } catch (Exception e) {
try { try {
int diff = Integer.parseInt(difficulty); int diff = Integer.parseInt(difficulty);
if (diff >= 0 && diff <= 3) { worlddiff = Difficulty.getByValue(diff);
worlddiff = Difficulty.getByValue(diff);
} else {
return false;
}
} catch (Exception e2) { } catch (Exception e2) {
return false; return false;
} }
} }
if (worlddiff == null) {
return false;
}
this.getCBWorld().setDifficulty(worlddiff); this.getCBWorld().setDifficulty(worlddiff);
config.setProperty("worlds." + this.name + ".difficulty", worlddiff.getValue()); config.setProperty("worlds." + this.name + ".difficulty", worlddiff.getValue());
saveConfig(); saveConfig();

View File

@ -8,8 +8,10 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.permissions.Permission;
/** /**
* The API for a Multiverse Handled World. * The API for a Multiverse Handled World.
@ -240,4 +242,83 @@ public interface MultiverseWorld {
* @return True if it will go down, false if it will remain steady. * @return True if it will go down, false if it will remain steady.
*/ */
public boolean getHunger(); public boolean getHunger();
/**
* Sets the game mode of this world
*
* @param gameMode A valid game mode string (either
* an int ex. 0 or a string ex. creative).
*
* @return True if the game mode was successfully changed, false if not.
*/
public boolean setGameMode(String gameMode);
/**
* Gets the GameMode of this world.
*
* @return The GameMode of this world.
*/
public GameMode getGameMode();
/**
* Gets the permission required to enter this world.
*
* @return The permission required to be exempt from charges to/from this world.
*/
public Permission getAccessPermission();
/**
* Gets the permission required to be exempt when entering.
*
* @return The permission required to be exempt when entering.
*/
public Permission getExemptPermission();
/**
* Sets the price for entry to this world.
* You can think of this like an amount.
* The type can be set with {@link #setCurrency(int)}
*
* @param price The Amount of money/item to enter the world.
*/
public void setPrice(double price);
/**
* Gets the amount of currency it requires to enter this world.
*
* @return The amount it costs to enter this world.
*/
public double getPrice();
/**
* Sets the type of item that will be required given the price is not 0.
* Use -1 to use an AllPay economy, or any valid itemid
*
* @param item The Type of currency that will be used when users enter this world.
*/
public void setCurrency(int item);
/**
* Gets the Type of currency that will be used when users enter this world.
*
* @return The Type of currency that will be used when users enter this world.
*/
public int getCurrency();
/**
* Sets the world players will respawn in if they die in this one.
* Returns true upon success, false upon failure.
*
* @param respawnWorld The name of a world that exists on the server.
*
* @return True if respawnWorld existed, false if not.
*/
public boolean setRespawnToWorld(String respawnWorld);
/**
* Gets the world players will respawn in if they die in this one.
*
* @return A world that exists on the server.
*/
public World getRespawnToWorld();
} }

View File

@ -34,6 +34,9 @@ public class MVEntityListener extends EntityListener {
@Override @Override
public void onFoodLevelChange(FoodLevelChangeEvent event) { public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity(); Player p = (Player) event.getEntity();
MVWorld w = this.plugin.getMVWorldManager().getMVWorld(p.getWorld().getName()); MVWorld w = this.plugin.getMVWorldManager().getMVWorld(p.getWorld().getName());
@ -78,13 +81,12 @@ public class MVEntityListener extends EntityListener {
} }
MVWorld world = this.worldManager.getMVWorld(w.getName()); MVWorld world = this.worldManager.getMVWorld(w.getName());
if (attacker != null && attacker instanceof Player) { if (attacker instanceof Player) {
Player pattacker = (Player) attacker; Player pattacker = (Player) attacker;
if (!world.getPvp() && this.plugin.getConfig().getBoolean("fakepvp", false)) { if (!world.getPvp() && this.plugin.getConfig().getBoolean("fakepvp", false)) {
pattacker.sendMessage(ChatColor.RED + "PVP is disabled in this World."); pattacker.sendMessage(ChatColor.RED + "PVP is disabled in this World.");
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
} }
@ -98,7 +100,6 @@ public class MVEntityListener extends EntityListener {
RegainReason reason = event.getRegainReason(); RegainReason reason = event.getRegainReason();
if (reason == RegainReason.REGEN && this.plugin.getConfig().getBoolean("disableautoheal", false)) { if (reason == RegainReason.REGEN && this.plugin.getConfig().getBoolean("disableautoheal", false)) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -134,7 +135,7 @@ public class MVEntityListener extends EntityListener {
/** /**
* Animal Handling * Animal Handling
*/ */
if (event.getEntity() instanceof Animals) { 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.allowAnimalSpawning(), creature.toString().toUpperCase()));
} }
/** /**

View File

@ -352,13 +352,13 @@ public class WorldManager implements MVWorldManager {
for (MVWorld w : this.worlds.values()) { for (MVWorld w : this.worlds.values()) {
// Remove this world from the master list // Remove this world from the master list
if (allAccess != null) { if (allAccess != null) {
allAccess.getChildren().remove(w.getPermission().getName()); allAccess.getChildren().remove(w.getAccessPermission().getName());
} }
if (allExempt != null) { if (allExempt != null) {
allExempt.getChildren().remove(w.getPermission().getName()); allExempt.getChildren().remove(w.getAccessPermission().getName());
} }
this.plugin.getServer().getPluginManager().removePermission(w.getPermission().getName()); this.plugin.getServer().getPluginManager().removePermission(w.getAccessPermission().getName());
this.plugin.getServer().getPluginManager().removePermission(w.getExempt().getName()); this.plugin.getServer().getPluginManager().removePermission(w.getExemptPermission().getName());
} }
// Recalc the all permission // Recalc the all permission
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess); this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess);