mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
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.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import me.main__.util.SerializationConfig.ChangeDeniedException;
|
||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||
@ -357,6 +358,8 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
private String alias;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
||||
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)
|
||||
private VirtualProperty<Boolean> pvp = new VirtualProperty<Boolean>() {
|
||||
@Override
|
||||
@ -637,6 +640,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
this.hidden = false;
|
||||
this.alias = new String();
|
||||
this.color = EnglishChatColor.WHITE;
|
||||
this.style = EnglishChatStyle.NORMAL;
|
||||
this.scale = getDefaultScale(environment);
|
||||
this.respawnWorld = new String();
|
||||
this.allowWeather = true;
|
||||
@ -712,10 +716,17 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
if (alias.length() == 0) {
|
||||
alias = this.getName();
|
||||
}
|
||||
|
||||
if ((color == null) || (color.getColor() == null)) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ChatColor getStyle() {
|
||||
return style.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setStyle(String style) {
|
||||
return this.setPropertyUnchecked("style", style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder toStringBuilder = new StringBuilder();
|
||||
|
@ -288,6 +288,21 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -11,49 +11,33 @@ import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* A regular {@link ChatColor} represented by an english string.
|
||||
* @see ChatColor
|
||||
*/
|
||||
public enum EnglishChatColor {
|
||||
/*
|
||||
* I know. this is quite ugly.
|
||||
*/
|
||||
/** AQUA. */
|
||||
AQUA("AQUA", ChatColor.AQUA),
|
||||
/** BLACK. */
|
||||
BLACK("BLACK", ChatColor.BLACK),
|
||||
/** BLUE. */
|
||||
BLUE("BLUE", ChatColor.BLUE),
|
||||
/** DARKAQUA. */
|
||||
DARKAQUA("DARKAQUA", ChatColor.DARK_AQUA),
|
||||
/** DARKBLUE. */
|
||||
DARKBLUE("DARKBLUE", ChatColor.DARK_BLUE),
|
||||
/** DARKGRAY. */
|
||||
DARKGRAY("DARKGRAY", ChatColor.DARK_GRAY),
|
||||
/** DARKGREEN. */
|
||||
DARKGREEN("DARKGREEN", ChatColor.DARK_GREEN),
|
||||
/** DARKPURPLE. */
|
||||
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;
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
AQUA(ChatColor.AQUA),
|
||||
BLACK(ChatColor.BLACK),
|
||||
BLUE(ChatColor.BLUE),
|
||||
DARKAQUA(ChatColor.DARK_AQUA),
|
||||
DARKBLUE(ChatColor.DARK_BLUE),
|
||||
DARKGRAY(ChatColor.DARK_GRAY),
|
||||
DARKGREEN(ChatColor.DARK_GREEN),
|
||||
DARKPURPLE(ChatColor.DARK_PURPLE),
|
||||
DARKRED(ChatColor.DARK_RED),
|
||||
GOLD(ChatColor.GOLD),
|
||||
GRAY(ChatColor.GRAY),
|
||||
GREEN(ChatColor.GREEN),
|
||||
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
|
||||
RED(ChatColor.RED),
|
||||
YELLOW(ChatColor.YELLOW),
|
||||
WHITE(ChatColor.WHITE);
|
||||
// END CHECKSTYLE-SUPPRESSION: JavadocVariable
|
||||
|
||||
EnglishChatColor(String name, ChatColor color) {
|
||||
private final ChatColor color;
|
||||
//private final String text;
|
||||
|
||||
EnglishChatColor(ChatColor color) {
|
||||
this.color = color;
|
||||
this.text = name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +45,7 @@ public enum EnglishChatColor {
|
||||
* @return The text.
|
||||
*/
|
||||
public String getText() {
|
||||
return this.text;
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +76,7 @@ public enum EnglishChatColor {
|
||||
public static EnglishChatColor fromString(String text) {
|
||||
if (text != null) {
|
||||
for (EnglishChatColor c : EnglishChatColor.values()) {
|
||||
if (text.equalsIgnoreCase(c.text)) {
|
||||
if (text.equalsIgnoreCase(c.name())) {
|
||||
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
Block a user