TF-PlotSquared/PlotSquared/src/com/intellectualcrafters/plot/Flag.java

89 lines
2.2 KiB
Java
Raw Normal View History

package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
public class Flag {
2014-09-23 19:02:17 +02:00
private AbstractFlag key;
private String value;
2014-09-25 16:39:13 +10:00
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to register
* it with PlotSquared.
2014-09-25 16:39:13 +10:00
*
* @param key
* AbstractFlag
2014-09-25 16:39:13 +10:00
* @param value
* Value must be alphanumerical (can have spaces) and be <= 48
* characters
* @throws IllegalArgumentException
* if you provide inadequate inputs
2014-09-25 16:39:13 +10:00
*/
2014-09-23 19:02:17 +02:00
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) {
throw new IllegalArgumentException("Flag must be alphanumerical");
}
if (value.length() > 48) {
throw new IllegalArgumentException("Value must be <= 48 characters");
}
2014-09-23 19:02:17 +02:00
this.key = key;
this.value = value;
}
2014-09-25 16:39:13 +10:00
/**
* Get the AbstractFlag used in creating the flag
*
2014-09-25 16:39:13 +10:00
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return this.key;
}
2014-09-25 16:39:13 +10:00
/**
* Get the key for the AbstractFlag
*
2014-09-25 16:39:13 +10:00
* @return String
*/
public String getKey() {
2014-09-23 19:02:17 +02:00
return this.key.getKey();
}
2014-09-25 16:39:13 +10:00
/**
* Get the value
*
2014-09-25 16:39:13 +10:00
* @return String
*/
public String getValue() {
return this.value;
}
@Override
public String toString() {
2014-09-23 19:54:06 +10:00
if (this.value.equals("")) {
2014-09-23 19:02:17 +02:00
return this.key.getKey();
2014-09-23 19:54:06 +10:00
}
return this.key + ":" + this.value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Flag other = (Flag) obj;
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
}
@Override
public int hashCode() {
return this.key.getKey().hashCode();
}
}