From 8cdb221695e28e2068e2fedc23f590d1cc63aabf Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Sun, 11 Nov 2012 12:30:19 -0500 Subject: [PATCH] Added almost all of the world properties. --- .../core/AbstractMultiverseWorld.java | 123 ++++++-------- .../mvplugin/core/api/MultiverseWorld.java | 60 +++---- .../mvplugin/core/api/WorldProperties.java | 153 ++++++++++++++++-- .../core/minecraft/PlayerPosition.java | 2 +- .../mvplugin/core/MultiverseCorePlugin.java | 3 +- 5 files changed, 219 insertions(+), 122 deletions(-) diff --git a/base/src/main/java/com/mvplugin/core/AbstractMultiverseWorld.java b/base/src/main/java/com/mvplugin/core/AbstractMultiverseWorld.java index 0a09033a..2caebfcf 100644 --- a/base/src/main/java/com/mvplugin/core/AbstractMultiverseWorld.java +++ b/base/src/main/java/com/mvplugin/core/AbstractMultiverseWorld.java @@ -30,12 +30,13 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { @Override public Difficulty getDifficulty() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.DIFFICULTY); } @Override - public boolean setDifficulty(Difficulty difficulty) { - return false; //To change body of implemented methods use File | Settings | File Templates. + public boolean setDifficulty(final Difficulty difficulty) { + // TODO Validate? + return getProperties().set(WorldProperties.DIFFICULTY, difficulty); } @Override @@ -78,31 +79,6 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { getProperties().set(WorldProperties.ALIAS, alias != null ? alias : ""); } - @Override - public String getColor() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean setColor(String color) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String getStyle() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean setStyle(String style) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String getColoredWorldString() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - @Override public boolean canAnimalsSpawn() { return false; //To change body of implemented methods use File | Settings | File Templates. @@ -135,12 +111,12 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { @Override public boolean isPVPEnabled() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.PVP); } @Override - public void setPVPMode(boolean pvpMode) { - //To change body of implemented methods use File | Settings | File Templates. + public void setPVPMode(final boolean pvpMode) { + getProperties().set(WorldProperties.PVP, pvpMode); } @Override @@ -154,33 +130,43 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { } @Override - public boolean isWeatherEnabled() { - return false; //To change body of implemented methods use File | Settings | File Templates. + public boolean getPrefixChat() { + return getProperties().get(WorldProperties.PREFIX_CHAT); } @Override - public void setEnableWeather(boolean enableWeather) { - //To change body of implemented methods use File | Settings | File Templates. + public void setPrefixChat(final boolean prefixChat) { + getProperties().set(WorldProperties.PREFIX_CHAT, prefixChat); + } + + @Override + public boolean isWeatherEnabled() { + return getProperties().get(WorldProperties.ALLOW_WEATHER); + } + + @Override + public void setEnableWeather(final boolean enableWeather) { + getProperties().set(WorldProperties.ALLOW_WEATHER, enableWeather); } @Override public boolean isKeepingSpawnInMemory() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.KEEP_SPAWN); } @Override - public void setKeepSpawnInMemory(boolean keepSpawnInMemory) { - //To change body of implemented methods use File | Settings | File Templates. + public void setKeepSpawnInMemory(final boolean keepSpawnInMemory) { + getProperties().set(WorldProperties.KEEP_SPAWN, keepSpawnInMemory); } @Override public PlayerPosition getSpawnLocation() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.SPAWN_LOCATION); } @Override - public void setSpawnLocation(PlayerPosition spawnLocation) { - //To change body of implemented methods use File | Settings | File Templates. + public void setSpawnLocation(final PlayerPosition spawnLocation) { + getProperties().set(WorldProperties.SPAWN_LOCATION, spawnLocation); } @Override @@ -195,62 +181,65 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { @Override public GameMode getGameMode() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.GAME_MODE); } @Override - public boolean setGameMode(GameMode gameMode) { - return false; //To change body of implemented methods use File | Settings | File Templates. + public boolean setGameMode(final GameMode gameMode) { + // Todo validate? + return getProperties().set(WorldProperties.GAME_MODE, gameMode); } @Override public double getPrice() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.ENTRY_FEE).get(WorldProperties.EntryFee.AMOUNT); } @Override - public void setPrice(double price) { - //To change body of implemented methods use File | Settings | File Templates. + public void setPrice(final double price) { + getProperties().get(WorldProperties.ENTRY_FEE).set(WorldProperties.EntryFee.AMOUNT, price); } @Override public int getCurrency() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.ENTRY_FEE).get(WorldProperties.EntryFee.CURRENCY); } @Override - public void setCurrency(int item) { - //To change body of implemented methods use File | Settings | File Templates. + public void setCurrency(final int item) { + getProperties().get(WorldProperties.ENTRY_FEE).set(WorldProperties.EntryFee.CURRENCY, item); } @Override public String getRespawnToWorld() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.RESPAWN_WORLD); } @Override - public boolean setRespawnToWorld(String respawnWorld) { - return false; //To change body of implemented methods use File | Settings | File Templates. + public boolean setRespawnToWorld(final String respawnWorld) { + // TODO validation? + return getProperties().set(WorldProperties.RESPAWN_WORLD, respawnWorld); } @Override public double getScaling() { - return 0; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.SCALE); } @Override - public boolean setScaling(double scaling) { - return false; //To change body of implemented methods use File | Settings | File Templates. + public boolean setScaling(final double scaling) { + // TODO validation? + return getProperties().set(WorldProperties.SCALE, scaling); } @Override public boolean getAutoHeal() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.AUTO_HEAL); } @Override - public void setAutoHeal(boolean heal) { - //To change body of implemented methods use File | Settings | File Templates. + public void setAutoHeal(final boolean heal) { + getProperties().set(WorldProperties.AUTO_HEAL, heal); } @Override @@ -294,23 +283,13 @@ abstract class AbstractMultiverseWorld implements MultiverseWorld { } @Override - public String getTime() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean setTime(String timeAsString) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void allowPortalMaking(PortalType type) { - //To change body of implemented methods use File | Settings | File Templates. + public void allowPortalMaking(final PortalType type) { + getProperties().set(WorldProperties.PORTAL_FORM, type); } @Override public PortalType getAllowedPortals() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return getProperties().get(WorldProperties.PORTAL_FORM); } @Override diff --git a/base/src/main/java/com/mvplugin/core/api/MultiverseWorld.java b/base/src/main/java/com/mvplugin/core/api/MultiverseWorld.java index a56656af..78189d7f 100644 --- a/base/src/main/java/com/mvplugin/core/api/MultiverseWorld.java +++ b/base/src/main/java/com/mvplugin/core/api/MultiverseWorld.java @@ -148,43 +148,6 @@ public interface MultiverseWorld { */ void setAlias(String alias); - /** - * Gets the color that this world's name/alias will display as. - * - * @return The color of this world. - */ - String getColor(); - - /** - * 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. - */ - boolean setColor(String color); - - /** - * Gets the style that this world's name/alias will display as. - * - * @return The style of this world. {@code null} for "normal" style. - */ - String getStyle(); - - /** - * Sets the style that this world's name/alias will display as. - * - * @param style A valid style name. - * @return True if the style was set, false if not. - */ - boolean setStyle(String style); - - /** - * Returns a very nicely colored string (using Alias and Color if they are set). - * - * @return A nicely colored string. - */ - String getColoredWorldString(); - // animals&monster stuff /** * Gets whether or not animals are allowed to spawn in this world. @@ -248,21 +211,40 @@ public interface MultiverseWorld { void setPVPMode(boolean pvpMode); /** - * Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the + * Gets whether or not this world will display in mv who and mv list regardless if a user has the * access permissions to go to this world. * * @return True if the world will be hidden, false if not. + * @see {@link #getPrefixChat()} */ boolean isHidden(); /** - * Sets whether or not this world will display in chat, mvw and mvl regardless if a user has the + * Sets whether or not this world will display in mv who and mv list regardless if a user has the * access permissions to go to this world. * * @param hidden Set */ void setHidden(boolean hidden); + /** + * Gets whether or not this world will display it's name/alias as a prefix in chat. + * + * If the global configuration setting for prefixChat is false, this setting has no effect. + * + * @return True if the world name/alias will be used as a prefix in chat, false if not. + */ + boolean getPrefixChat(); + + /** + * Sets whether or not this world will display it's name/alias as a prefix in chat. + * + * If the global configuration setting for prefixChat is false, this setting has no effect. + * + * @param prefixChat True if the world name/alias will be used as a prefix in chat, false if not. + */ + void setPrefixChat(boolean prefixChat); + /** * Gets whether weather is enabled in this world. * diff --git a/base/src/main/java/com/mvplugin/core/api/WorldProperties.java b/base/src/main/java/com/mvplugin/core/api/WorldProperties.java index 5eedac2c..156f18de 100644 --- a/base/src/main/java/com/mvplugin/core/api/WorldProperties.java +++ b/base/src/main/java/com/mvplugin/core/api/WorldProperties.java @@ -2,9 +2,15 @@ package com.mvplugin.core.api; import com.dumptruckman.minecraft.pluginbase.messaging.Message; import com.dumptruckman.minecraft.pluginbase.properties.ListProperty; +import com.dumptruckman.minecraft.pluginbase.properties.NestedProperties; +import com.dumptruckman.minecraft.pluginbase.properties.NestedProperty; import com.dumptruckman.minecraft.pluginbase.properties.Properties; import com.dumptruckman.minecraft.pluginbase.properties.PropertyFactory; import com.dumptruckman.minecraft.pluginbase.properties.SimpleProperty; +import com.mvplugin.core.minecraft.Difficulty; +import com.mvplugin.core.minecraft.GameMode; +import com.mvplugin.core.minecraft.PlayerPosition; +import com.mvplugin.core.minecraft.PortalType; import com.mvplugin.core.minecraft.WorldEnvironment; /** @@ -15,6 +21,7 @@ public interface WorldProperties extends Properties { SimpleProperty ALIAS = PropertyFactory.newProperty(String.class, "alias", "") .comment("World aliases allow you to name a world differently than what the folder name is.") .comment("This lets you choose fancy names for your worlds while keeping the folders nice and neat.") + .comment("You may add minecraft color and formatting codes here prepended with a &") .description(Descriptions.ALIAS) .build(); @@ -57,33 +64,118 @@ public interface WorldProperties extends Properties { SimpleProperty AUTO_LOAD = PropertyFactory.newProperty(Boolean.class, "autoLoad", true) - .comment("This property dictates whether this world is loaded automatically on startup or not.") + .comment("The autoLoad dictates whether this world is loaded automatically on startup or not.") .description(Descriptions.AUTO_LOAD) .build(); SimpleProperty BED_RESPAWN = PropertyFactory.newProperty(Boolean.class, "bedRespawn", true) - .comment("This property specifies if a player dying in this world should respawn in their bed or not.") + .comment("The bedRespawn property specifies if a player dying in this world should respawn in their bed or not.") .description(Descriptions.BED_RESPAWN) .build(); SimpleProperty HUNGER = PropertyFactory.newProperty(Boolean.class, "hunger", true) - .comment("This property specifies if hunger is depleted in this world") + .comment("The hunger property specifies if hunger is depleted in this world") .description(Descriptions.HUNGER) .build(); ListProperty BLACK_LIST = PropertyFactory.newListProperty(String.class, "worldBlacklist") - .comment("This property allows you to specify worlds that people cannot go to from this specified world.") + .comment("The worldBlackList property allows you to specify worlds that people cannot go to from this specified world.") .description(Descriptions.BLACK_LIST) .build(); + SimpleProperty PVP = PropertyFactory.newProperty(Boolean.class, "pvp", true) + .comment("The pvp property states whether or not players may harm each other in this world. If set to true, they may.") + .comment("Bear in mind, many other plugins may have conflicts with this setting.") + .description(Descriptions.PVP) + .build(); + + SimpleProperty SCALE = PropertyFactory.newProperty(Double.class, "scale", 1D) + .comment("The scale property represents the scaling of worlds when using Multiverse-NetherPortals.") + .comment("Setting this value will have no effect on anything but Multiverse-NetherPortals.") + .description(Descriptions.SCALE) + .build(); + + SimpleProperty RESPAWN_WORLD = PropertyFactory.newProperty(String.class, "respawnWorld", "") + .comment("The respawnWorld property is the world you will respawn to if you die in this world.") + .comment("This value can be the same as this world.") + .description(Descriptions.RESPAWN_WORLD) + .build(); + + SimpleProperty ALLOW_WEATHER = PropertyFactory.newProperty(Boolean.class, "allowWeather", true) + .comment("The allowWeather property specifies whether or not to allow weather events in this world.") + .description(Descriptions.ALLOW_WEATHER) + .build(); + + SimpleProperty DIFFICULTY = PropertyFactory.newProperty(Difficulty.class, "difficulty", Difficulty.EASY) + .comment("The difficulty property allows you to set the difficulty for the world.") + .comment("World difficulty affects spawn rates, hunger rates, and other things that make the game more or less difficult.") + .description(Descriptions.DIFFICULTY) + .build(); + + SimpleProperty AUTO_HEAL = PropertyFactory.newProperty(Boolean.class, "autoHeal", true) + .comment("The autoHeal property will specify whether ot not players will regain health in PEACEFUL difficulty only.") + .comment("This setting has no effect on worlds with a difficulty greater than peaceful or 0.") + .description(Descriptions.AUTO_HEAL) + .build(); + + SimpleProperty PORTAL_FORM = PropertyFactory.newProperty(PortalType.class, "portalForm", PortalType.ALL) + .comment("The portalFrom property allows you to specify which type of portals are allowed to be created in this world.") + .description(Descriptions.PORTAL_FORM) + .build(); + + SimpleProperty GAME_MODE = PropertyFactory.newProperty(GameMode.class, "gameMode", GameMode.SURVIVAL) + .comment("The gameMode property allows you to specify the GameMode for this world.") + .comment("Players entering this world will automatically be switched to this GameMode unless they are exempted.") + .description(Descriptions.GAME_MODE) + .build(); + + SimpleProperty KEEP_SPAWN = PropertyFactory.newProperty(Boolean.class, "keepSpawnInMemory", true) + .comment("The keepSpawnInMemory property specifies whether or not to keep the spawn chunks loaded in memory when players aren't in the spawn area.") + .comment("Setting this to false will potentially save you some memory.") + .description(Descriptions.KEEP_SPAWN) + .build(); + + SimpleProperty SPAWN_LOCATION = PropertyFactory.newProperty(PlayerPosition.class, "spawnLocation", new NullLocation()) + .comment("The spawnLocation property specifies where in the world players will spawn.") + .comment("The world specified here has no effect.") + .description(Descriptions.SPAWN_LOCATION) + .build(); + + public static final class NullLocation extends PlayerPosition { + public NullLocation() { + super(null, 0, 0, 0, 0, 0); + } + } + + NestedProperty ENTRY_FEE = PropertyFactory.newNestedProperty(EntryFee.class, "entryFee") + .build(); + + public static interface EntryFee extends NestedProperties { + + SimpleProperty AMOUNT = PropertyFactory.newProperty(Double.class, "amount", 0D) + .comment("The amount property specifies how much a player has to pay to enter this world.") + .comment("What the player has to pay is specified by the 'currency' property") + .description(Descriptions.AMOUNT) + .build(); + + SimpleProperty CURRENCY = PropertyFactory.newProperty(Integer.class, "currency", -1) + .comment("The currency property specifies what type of currency the player must pay (if any) to enter this world.") + .comment("Currency can be an economy money by specifying -1 or a block type by specifying the block id.") + .description(Descriptions.CURRENCY) + .build(); + } + /** * Houses localized (english) descriptions of the Multiverse world properties. */ public static class Descriptions { + public static void init() { } + public static final Message ALIAS = new Message("world_properties.descriptions.alias", "World aliases allow you to name a world differently than what the folder name is.", - "This lets you choose fancy names for your worlds while keeping the folders nice and neat."); + "This lets you choose fancy names for your worlds while keeping the folders nice and neat.", + "You may add minecraft color and formatting codes here prepended with a &"); public static final Message HIDDEN = new Message("world_properties.descriptions.hidden", "The hidden property allows you to have a world that exists but does not show up in lists."); @@ -108,16 +200,59 @@ public interface WorldProperties extends Properties { "The adjust spawn property determines whether or not Multiverse will make adjustments to the world's spawn location if it is unsafe."); public static final Message AUTO_LOAD = new Message("world_properties.descriptions.autoLoad", - "This value dictates whether this world is loaded automatically on startup or not."); + "The autoLoad property dictates whether this world is loaded automatically on startup or not."); public static final Message BED_RESPAWN = new Message("world_properties.descriptions.bedRespawn", - "This property specifies if a player dying in this world should respawn in their bed or not."); + "The bedRespawn property specifies if a player dying in this world should respawn in their bed or not."); public static final Message HUNGER = new Message("world_properties.descriptions.hunger", - "This property specifies if hunger is depleted in this world"); + "The hunger property specifies if hunger is depleted in this world"); public static final Message BLACK_LIST = new Message("world_properties.descriptions.worldBlacklist", - "This property allows you to specify worlds that people cannot go to from this specified world."); + "The worldBlackList property allows you to specify worlds that people cannot go to from this specified world."); + public static final Message PVP = new Message("world_properties.descriptions.pvp", + "The pvp property states whether or not players may harm each other in this world. If set to true, they may."); + + public static final Message SCALE = new Message("world_properties.descriptions.scale", + "The scale property represents the scaling of worlds when using Multiverse-NetherPortals.", + "Setting this value will have no effect on anything but Multiverse-NetherPortals."); + + public static final Message RESPAWN_WORLD = new Message("world_properties.descriptions.respawnWorld", + "The respawnWorld property is the world you will respawn to if you die in this world.", + "This value can be the same as this world."); + + public static final Message ALLOW_WEATHER = new Message("world_properties.descriptions.allowWeather", + "The allowWeather property specifies whether or not to allow weather events in this world."); + + public static final Message DIFFICULTY = new Message("world_properties.descriptions.difficulty", + "The difficulty property allows you to set the difficulty for the world.", + "World difficulty affects spawn rates, hunger rates, and other things that make the game more or less difficult."); + + public static final Message AUTO_HEAL = new Message("world_properties.descriptions.autoHeal", + "The autoHeal property will specify whether ot not players will regain health in PEACEFUL difficulty only.", + "This setting has no effect on worlds with a difficulty greater than peaceful or 0."); + + public static final Message PORTAL_FORM = new Message("world_properties.descriptions.portalForm", + "The portalFrom property allows you to specify which type of portals are allowed to be created in this world."); + + public static final Message GAME_MODE = new Message("world_properties.descriptions.gameMode", + "The gameMode property allows you to specify the GameMode for this world.", + "Players entering this world will automatically be switched to this GameMode unless they are exempted."); + + public static final Message KEEP_SPAWN = new Message("world_properties.descriptions.keepSpawnInMemory", + "The keepSpawnInMemory property specifies whether or not to keep the spawn chunks loaded in memory when players aren't in the spawn area.", + "Setting this to false will potentially save you some memory."); + + public static final Message SPAWN_LOCATION = new Message("world_properties.descriptions.spawnLocation", + "The spawnLocation property specifies where in the world players will spawn."); + + public static final Message AMOUNT = new Message("world_properties.descriptions.amount", + "The amount property specifies how much a player has to pay to enter this world.", + "What the player has to pay is specified by the 'currency' property"); + + public static final Message CURRENCY = new Message("world_properties.descriptions.currency", + "The currency property specifies what type of currency the player must pay (if any) to enter this world.", + "Currency can be an economy money by specifying -1 or a block type by specifying the block id."); } } diff --git a/base/src/main/java/com/mvplugin/core/minecraft/PlayerPosition.java b/base/src/main/java/com/mvplugin/core/minecraft/PlayerPosition.java index 72c61244..6fce0dd5 100644 --- a/base/src/main/java/com/mvplugin/core/minecraft/PlayerPosition.java +++ b/base/src/main/java/com/mvplugin/core/minecraft/PlayerPosition.java @@ -6,7 +6,7 @@ public class PlayerPosition { private final float pitch, yaw; private final String world; - PlayerPosition(final String world, final double x, + protected PlayerPosition(final String world, final double x, final double y, final double z, final float pitch, final float yaw) { this.world = world; diff --git a/bukkit/src/main/java/com/mvplugin/core/MultiverseCorePlugin.java b/bukkit/src/main/java/com/mvplugin/core/MultiverseCorePlugin.java index 3eae708c..c2b880f8 100644 --- a/bukkit/src/main/java/com/mvplugin/core/MultiverseCorePlugin.java +++ b/bukkit/src/main/java/com/mvplugin/core/MultiverseCorePlugin.java @@ -3,6 +3,7 @@ package com.mvplugin.core; import com.dumptruckman.minecraft.pluginbase.plugin.AbstractBukkitPlugin; import com.mvplugin.core.api.CoreConfig; import com.mvplugin.core.api.MultiverseCore; +import com.mvplugin.core.api.WorldProperties; import com.mvplugin.core.command.ImportCommand; import java.io.IOException; @@ -23,7 +24,7 @@ public class MultiverseCorePlugin extends AbstractBukkitPlugin imple @Override protected void onPluginLoad() { - + WorldProperties.Descriptions.init(); } @Override