Add a bunch more to the API

This commit is contained in:
Eric Stokes 2011-10-09 11:31:50 -06:00
parent 5386aadbb7
commit 3fde98049f
11 changed files with 199 additions and 32 deletions

View File

@ -19,6 +19,7 @@ import org.bukkit.util.config.Configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@ -48,7 +49,7 @@ public class MVWorld implements MultiverseWorld {
private String respawnWorld; // Contains the name of the World to respawn the player to
private HashMap<String, List<String>> masterList;
private Map<String, List<String>> masterList;
private Double scaling; // How stretched/compressed distances are
private Double price; // How much does it cost to enter this world
@ -60,6 +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;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config;
@ -91,18 +93,19 @@ public class MVWorld implements MultiverseWorld {
this.setScaling(config.getDouble("worlds." + this.name + ".scale", this.getDefaultScale(this.environment)));
this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", ""));
this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true));
this.setDifficulty(config.getString("worlds." + this.name + ".difficulty", "EASY"));
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.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));
this.setHidden(config.getBoolean("worlds." + this.name + ".hidden", false));
this.getMobExceptions();
this.setGameMode(config.getString("worlds." + this.name + ".gamemode", GameMode.SURVIVAL.toString()));
this.setSpawnInMemory(config.getBoolean("worlds." + this.name + ".keepspawninmemory", true));
this.setKeepSpawnInMemory(config.getBoolean("worlds." + this.name + ".keepspawninmemory", true));
this.getWorldBlacklist().addAll(config.getStringList("worlds." + this.name + ".worldblacklist", new ArrayList<String>()));
this.translateTempSpawn(config);
@ -128,7 +131,7 @@ public class MVWorld implements MultiverseWorld {
return 1.0;
}
private void setEnableWeather(boolean weather) {
public void setEnableWeather(boolean weather) {
this.allowWeather = weather;
// Disable any current weather
if (!weather) {
@ -175,7 +178,7 @@ public class MVWorld implements MultiverseWorld {
for (int i = 0; i < 3; i++) {
coords[i] = Integer.parseInt(coordsString[i]);
}
this.setSpawn(new Location(this.getCBWorld(), coords[0], coords[1], coords[2]));
this.setSpawnLocation(new Location(this.getCBWorld(), coords[0], coords[1], coords[2]));
} catch (NumberFormatException e) {
this.plugin.log(Level.WARNING, "A MV1 spawn value was found, but it could not be migrated. Format Error. Sorry.");
}
@ -300,18 +303,21 @@ public class MVWorld implements MultiverseWorld {
} else if (name.equalsIgnoreCase("monsters")) {
this.setMonsters(value);
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
this.setSpawnInMemory(value);
this.setKeepSpawnInMemory(value);
} else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))) {
this.setHunger(value);
} else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) {
this.setEnableWeather(value);
} else if (name.equalsIgnoreCase("hidden")) {
this.setHidden(value);
} else {
return false;
}
return true;
}
private void setSpawnInMemory(boolean value) {
@Override
public void setKeepSpawnInMemory(boolean value) {
this.world.setKeepSpawnInMemory(value);
this.keepSpawnInMemory = value;
this.config.setProperty("worlds." + this.name + ".keepspawninmemory", value);
@ -462,6 +468,30 @@ public class MVWorld implements MultiverseWorld {
saveConfig();
}
/**
* 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.
*
* @return True if the world will be hidden, false if not.
*/
@Override
public boolean isHidden() {
return this.isHidden;
}
/**
* Sets 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.
*
* @param hidden Set
*/
@Override
public void setHidden(boolean hidden) {
this.isHidden = hidden;
this.config.setProperty("worlds." + this.name + ".hidden", hidden);
saveConfig();
}
public void setFakePVPMode(Boolean fakePVPMode) {
this.fakePVP = fakePVPMode;
this.config.setProperty("worlds." + this.name + ".fakepvp", this.fakePVP);
@ -601,26 +631,28 @@ public class MVWorld implements MultiverseWorld {
return this.gameMode;
}
public boolean getWeatherEnabled() {
@Override
public boolean isWeatherEnabled() {
return this.allowWeather;
}
public boolean getKeepSpawnInMemory() {
@Override
public boolean isKeepingSpawnInMemory() {
return this.keepSpawnInMemory;
}
private boolean setHunger(boolean hunger) {
private void setHunger(boolean hunger) {
this.hunger = hunger;
config.setProperty("worlds." + this.name + ".hunger", this.hunger);
saveConfig();
return true;
}
public boolean getHunger() {
return this.hunger;
}
public boolean setSpawn(Location l) {
@Override
public void setSpawnLocation(Location l) {
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
config.setProperty("worlds." + this.name + ".spawn.x", l.getX());
config.setProperty("worlds." + this.name + ".spawn.y", l.getY());
@ -630,8 +662,6 @@ public class MVWorld implements MultiverseWorld {
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
this.spawnLocation = l.clone();
saveConfig();
return true;
}
private void readSpawnFromConfig(World w) {
@ -647,10 +677,12 @@ public class MVWorld implements MultiverseWorld {
return this.spawnLocation;
}
@Override
public Difficulty getDifficulty() {
return this.getCBWorld().getDifficulty();
}
@Override
public boolean setDifficulty(String difficulty) {
Difficulty worlddiff = null;
try {

View File

@ -7,6 +7,8 @@
package com.onarandombox.MultiverseCore.api;
import org.bukkit.Difficulty;
import org.bukkit.Location;
import org.bukkit.World;
/**
@ -150,12 +152,87 @@ public interface MultiverseWorld {
*
* @return True if the world will be hidden, false if not.
*/
public boolean isWorldHidden();
public boolean isHidden();
/**
* Sets 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.
*
* @param hidden Set
*/
public void setHidden(boolean hidden);
/**
* Sets whether or not there will be weather events in a given world.
* If set to false, Multiverse will disable the weather in the world immediately.
*
* @param enableWeather True if weather events should occur in a world, false if not.
*/
public void setEnableWeather(boolean enableWeather);
/**
* Gets whether weather is enabled in this world.
*
* @return True if weather events will occur, false if not.
*/
public boolean isWeatherEnabled();
/**
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
* If not, CraftBukkit will attempt to free memory when players have not used that world.
* This will not happen immediately.
*
* @param keepSpawnInMemory If true, CraftBukkit will keep the spawn chunks loaded in memory.
*/
public void setKeepSpawnInMemory(boolean keepSpawnInMemory);
/**
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
*
* @return True if CraftBukkit is keeping spawn chunks in memory.
*/
public boolean isKeepingSpawnInMemory();
/**
* Sets the difficulty of this world and returns true if success.
* Valid string values are either an integer of difficulty(0-3) or
* the name that resides in the Bukkit enum, ex. PEACEFUL
*
* @param difficulty The difficulty to set the world to as a string.
*
* @return True if success, false if the provided string
* could not be translated to a difficulty.
*/
public boolean setDifficulty(String difficulty);
/**
* Gets the difficulty of this world.
*
* @return The difficulty of this world.
*/
public Difficulty getDifficulty();
/**
* Sets the spawn location for a world.
*
* @param spawnLocation The spawn location for a world.
*/
public void setSpawnLocation(Location spawnLocation);
/**
* Gets the spawn location of this world.
*
* @return The spawn location of this world.
*/
public Location getSpawnLocation();
/**
* Sets whether or not the hunger level of players will go down in a world.
*
* @param hungerEnabled True if hunger will go down, false to keep it at
* the level they entered a world with.
*/
public void setHunger(boolean hungerEnabled);
public void
}

View File

@ -126,9 +126,9 @@ public class InfoCommand extends MultiverseCommand {
message = new ArrayList<FancyText>();
message.add(new FancyHeader("More World Settings", colors));
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
message.add(new FancyMessage("Weather: ", world.getWeatherEnabled() + "", colors));
message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors));
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
message.add(new FancyMessage("Keep spawn in memory: ", world.getKeepSpawnInMemory() + "", 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("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));

View File

@ -40,6 +40,9 @@ public class ListCommand extends MultiverseCommand {
String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n";
for (MVWorld world : this.plugin.getMVWorldManager().getMVWorlds()) {
if (world.isHidden()) {
continue;
}
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
continue;
}

View File

@ -41,7 +41,7 @@ public class SetSpawnCommand extends MultiverseCommand {
World w = p.getWorld();
MVWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
if (foundWorld != null) {
foundWorld.setSpawn(p.getLocation());
foundWorld.setSpawnLocation(p.getLocation());
sender.sendMessage("Spawn was set to: " + LocationManipulation.strCoords(p.getLocation()));
} else {
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());

View File

@ -48,11 +48,14 @@ public class WhoCommand extends MultiverseCommand {
List<MVWorld> worlds = new ArrayList<MVWorld>();
if (args.size() > 0) {
MVWorld world = this.worldManager.getMVWorld(args.get(0));
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
showAll = true;
worlds = new ArrayList<MVWorld>(this.worldManager.getMVWorlds());
} else if (this.worldManager.isMVWorld(args.get(0))) {
worlds.add(this.worldManager.getMVWorld(args.get(0)));
} else if (world != null) {
if (!world.isHidden()) {
worlds.add(world);
}
} else {
sender.sendMessage(ChatColor.RED + "World does not exist");
return;

View File

@ -0,0 +1,15 @@
/******************************************************************************
* 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.enums;
/**
* Multiverse 2
*/
public enum ConfigProperty {
messagecooldown, teleportcooldown, worldnameprefix, useworldaccess, disableautoheal, fakepvp, bedrespawn
}

View File

@ -13,5 +13,7 @@ package com.onarandombox.MultiverseCore.enums;
* @author fernferret
*/ // Color == Aliascolor
public enum SetProperties {
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm, gamemode, mode, hunger, difficulty, diff
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn,
currency, curr, price, scale, spawnmemory, memory, weather, storm,
gamemode, mode, hunger, difficulty, diff, hidden
}

View File

@ -26,7 +26,7 @@ public class MVWeatherListener extends WeatherListener {
MVWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) {
// If it's going to start raining and we have weather disabled
event.setCancelled((event.toWeatherState() && !world.getWeatherEnabled()));
event.setCancelled((event.toWeatherState() && !world.isWeatherEnabled()));
}
}
@ -36,7 +36,7 @@ public class MVWeatherListener extends WeatherListener {
MVWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld().getName());
if (world != null) {
// If it's going to start raining and we have weather disabled
event.setCancelled((event.toThunderState() && !world.getWeatherEnabled()));
event.setCancelled((event.toThunderState() && !world.isWeatherEnabled()));
}
}
}

View File

@ -0,0 +1,39 @@
/******************************************************************************
* 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.utils;
/**
* Multiverse 2
* Currently Unused
*/
public class WorldProperty<T> {
private Class<T> type;
private Object value;
public WorldProperty(Class<T> type, Object two, String propertyLocation) {
this.type = type;
this.value = two;
}
public Class<T> getType() {
return this.type;
}
public Object getValue() {
return this.value;
}
public boolean setValue(Object value) {
if (value.getClass().equals(this.type)) {
this.value = value;
return true;
}
return false;
}
}

View File

@ -15,12 +15,8 @@ teleportcooldown: 5000
# won't touch your chat
worldnameprefix: true
# If Multiverse does not find permissions should it automatically fall back to
# people defined in ops.txt? Remember, if you use ops based permissions
# the awesome Multiverse devs get to decide which commands require op!
# (Which is why we highly recommend a permissions plugin! You shouldn't trust us this much...)
opfallback: true
# If value is set to false, Multiverse will NOT enforce permissions
useworldaccess: false
# If you have a world(s) that has monsters = false, and you want to disable the built
# in autohealing, set this to true. This will have NO EFFECT if monsters = true for a given world.
@ -36,4 +32,4 @@ bedrespawn: true
# This just signifies the version number so we can see what version of config you have.
# NEVER TOUCH THIS VALUE
version: 2.1
version: 2.2