Improved EnglishChatColor and added the "style" world-property.
Closes #732.
This commit is contained in:
parent
a2a2594f5a
commit
8cb4f22467
|
@ -16,6 +16,7 @@ import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
|
||||||
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
||||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
|
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||||
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
||||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||||
|
@ -357,6 +358,8 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||||
private String alias;
|
private String alias;
|
||||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
||||||
private EnglishChatColor color;
|
private EnglishChatColor color;
|
||||||
|
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
|
||||||
|
private EnglishChatStyle style;
|
||||||
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||||
private VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() {
|
private VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -637,6 +640,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||||
this.hidden = false;
|
this.hidden = false;
|
||||||
this.alias = new String();
|
this.alias = new String();
|
||||||
this.color = EnglishChatColor.WHITE;
|
this.color = EnglishChatColor.WHITE;
|
||||||
|
this.style = EnglishChatStyle.NORMAL;
|
||||||
this.scale = getDefaultScale(environment);
|
this.scale = getDefaultScale(environment);
|
||||||
this.respawnWorld = new String();
|
this.respawnWorld = new String();
|
||||||
this.allowWeather = true;
|
this.allowWeather = true;
|
||||||
|
@ -712,10 +716,17 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||||
if (alias.length() == 0) {
|
if (alias.length() == 0) {
|
||||||
alias = this.getName();
|
alias = this.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((color == null) || (color.getColor() == null)) {
|
if ((color == null) || (color.getColor() == null)) {
|
||||||
this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE);
|
this.setPropertyValueUnchecked("color", EnglishChatColor.WHITE);
|
||||||
}
|
}
|
||||||
return color.getColor() + alias + ChatColor.WHITE;
|
|
||||||
|
StringBuilder nameBuilder = new StringBuilder().append(color.getColor());
|
||||||
|
if (style.getColor() != null)
|
||||||
|
nameBuilder.append(style.getColor());
|
||||||
|
nameBuilder.append(alias).append(ChatColor.WHITE).toString();
|
||||||
|
|
||||||
|
return nameBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1369,6 +1380,22 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||||
this.setPropertyValueUnchecked("portalForm", portalType);
|
this.setPropertyValueUnchecked("portalForm", portalType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ChatColor getStyle() {
|
||||||
|
return style.getColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean setStyle(String style) {
|
||||||
|
return this.setPropertyUnchecked("style", style);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder toStringBuilder = new StringBuilder();
|
StringBuilder toStringBuilder = new StringBuilder();
|
||||||
|
|
|
@ -288,6 +288,21 @@ public interface MultiverseWorld {
|
||||||
*/
|
*/
|
||||||
boolean setColor(String color);
|
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.
|
||||||
|
*/
|
||||||
|
ChatColor 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells you if someone entered a valid color.
|
* Tells you if someone entered a valid color.
|
||||||
*
|
*
|
||||||
|
|
|
@ -11,49 +11,33 @@ import org.bukkit.ChatColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A regular {@link ChatColor} represented by an english string.
|
* A regular {@link ChatColor} represented by an english string.
|
||||||
|
* @see ChatColor
|
||||||
*/
|
*/
|
||||||
public enum EnglishChatColor {
|
public enum EnglishChatColor {
|
||||||
/*
|
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||||
* I know. this is quite ugly.
|
AQUA(ChatColor.AQUA),
|
||||||
*/
|
BLACK(ChatColor.BLACK),
|
||||||
/** AQUA. */
|
BLUE(ChatColor.BLUE),
|
||||||
AQUA("AQUA", ChatColor.AQUA),
|
DARKAQUA(ChatColor.DARK_AQUA),
|
||||||
/** BLACK. */
|
DARKBLUE(ChatColor.DARK_BLUE),
|
||||||
BLACK("BLACK", ChatColor.BLACK),
|
DARKGRAY(ChatColor.DARK_GRAY),
|
||||||
/** BLUE. */
|
DARKGREEN(ChatColor.DARK_GREEN),
|
||||||
BLUE("BLUE", ChatColor.BLUE),
|
DARKPURPLE(ChatColor.DARK_PURPLE),
|
||||||
/** DARKAQUA. */
|
DARKRED(ChatColor.DARK_RED),
|
||||||
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA),
|
GOLD(ChatColor.GOLD),
|
||||||
/** DARKBLUE. */
|
GRAY(ChatColor.GRAY),
|
||||||
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE),
|
GREEN(ChatColor.GREEN),
|
||||||
/** DARKGRAY. */
|
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
|
||||||
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY),
|
RED(ChatColor.RED),
|
||||||
/** DARKGREEN. */
|
YELLOW(ChatColor.YELLOW),
|
||||||
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN),
|
WHITE(ChatColor.WHITE);
|
||||||
/** DARKPURPLE. */
|
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||||
DARKPURPLE("DARKPURPLE", ChatColor.DARK_PURPLE),
|
|
||||||
/** DARKRED. */
|
|
||||||
DARKRED("DARKRED", ChatColor.DARK_RED),
|
|
||||||
/** GOLD. */
|
|
||||||
GOLD("GOLD", ChatColor.GOLD),
|
|
||||||
/** GRAY. */
|
|
||||||
GRAY("GRAY", ChatColor.GRAY),
|
|
||||||
/** GREEN. */
|
|
||||||
GREEN("GREEN", ChatColor.GREEN),
|
|
||||||
/** LIGHTPURPLE. */
|
|
||||||
LIGHTPURPLE("LIGHTPURPLE", ChatColor.LIGHT_PURPLE),
|
|
||||||
/** RED. */
|
|
||||||
RED("RED", ChatColor.RED),
|
|
||||||
/** YELLOW. */
|
|
||||||
YELLOW("YELLOW", ChatColor.YELLOW),
|
|
||||||
/** WHITE. */
|
|
||||||
WHITE("WHITE", ChatColor.WHITE);
|
|
||||||
private ChatColor color;
|
|
||||||
private String text;
|
|
||||||
|
|
||||||
EnglishChatColor(String name, ChatColor color) {
|
private final ChatColor color;
|
||||||
|
//private final String text;
|
||||||
|
|
||||||
|
EnglishChatColor(ChatColor color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.text = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +45,7 @@ public enum EnglishChatColor {
|
||||||
* @return The text.
|
* @return The text.
|
||||||
*/
|
*/
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return this.text;
|
return this.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +76,7 @@ public enum EnglishChatColor {
|
||||||
public static EnglishChatColor fromString(String text) {
|
public static EnglishChatColor fromString(String text) {
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
for (EnglishChatColor c : EnglishChatColor.values()) {
|
for (EnglishChatColor c : EnglishChatColor.values()) {
|
||||||
if (text.equalsIgnoreCase(c.text)) {
|
if (text.equalsIgnoreCase(c.name())) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.onarandombox.MultiverseCore.enums;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A regular {@link ChatColor} represented by an english string.
|
||||||
|
* @see ChatColor
|
||||||
|
*/
|
||||||
|
public enum EnglishChatStyle {
|
||||||
|
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||||
|
/** No style. */
|
||||||
|
NORMAL(null),
|
||||||
|
MAGIC(ChatColor.MAGIC),
|
||||||
|
BOLD(ChatColor.BOLD),
|
||||||
|
STRIKETHROUGH(ChatColor.STRIKETHROUGH),
|
||||||
|
UNDERLINE(ChatColor.UNDERLINE),
|
||||||
|
ITALIC(ChatColor.ITALIC);
|
||||||
|
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||||
|
|
||||||
|
private final ChatColor color;
|
||||||
|
|
||||||
|
EnglishChatStyle(ChatColor color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the color.
|
||||||
|
* @return The color as {@link ChatColor}.
|
||||||
|
*/
|
||||||
|
public ChatColor getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an {@link EnglishChatStyle} from a {@link String}.
|
||||||
|
* @param text The {@link String}.
|
||||||
|
* @return The {@link EnglishChatStyle}.
|
||||||
|
*/
|
||||||
|
public static EnglishChatStyle fromString(String text) {
|
||||||
|
if (text != null) {
|
||||||
|
for (EnglishChatStyle c : EnglishChatStyle.values()) {
|
||||||
|
if (text.equalsIgnoreCase(c.name())) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue