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

View File

@ -8,8 +8,10 @@
package com.onarandombox.MultiverseCore.api;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.permissions.Permission;
/**
* 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.
*/
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
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity();
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());
if (attacker != null && attacker instanceof Player) {
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.");
event.setCancelled(true);
return;
}
}
}
@ -98,7 +100,6 @@ public class MVEntityListener extends EntityListener {
RegainReason reason = event.getRegainReason();
if (reason == RegainReason.REGEN && this.plugin.getConfig().getBoolean("disableautoheal", false)) {
event.setCancelled(true);
return;
}
}
@ -134,7 +135,7 @@ public class MVEntityListener extends EntityListener {
/**
* 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()));
}
/**

View File

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