2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-11-16 10:48:18 +01:00
|
|
|
package com.intellectualcrafters.plot.flag;
|
2014-09-23 19:02:17 +02:00
|
|
|
|
2015-07-26 20:38:08 +02:00
|
|
|
import com.intellectualcrafters.plot.util.StringMan;
|
2014-09-24 02:56:03 +02:00
|
|
|
|
2014-09-23 19:02:17 +02:00
|
|
|
/**
|
2014-11-16 09:56:42 +01:00
|
|
|
* Created 2014-09-23 for PlotSquared
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
* @author Empire92
|
2014-09-23 19:02:17 +02:00
|
|
|
*/
|
|
|
|
public class AbstractFlag {
|
2015-01-29 10:59:32 +01:00
|
|
|
public final String key;
|
|
|
|
public final FlagValue<?> value;
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-17 19:18:05 +01:00
|
|
|
public AbstractFlag(final String key) {
|
|
|
|
this(key, new FlagValue.StringValue());
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
2015-01-25 05:40:50 +01:00
|
|
|
* AbstractFlag is a parameter used in creating a new Flag<br>
|
2015-03-13 08:26:08 +01:00
|
|
|
* The key must be alphabetical characters and <= 16 characters in length
|
2015-01-25 05:40:50 +01:00
|
|
|
* @param key
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2014-11-17 19:18:05 +01:00
|
|
|
public AbstractFlag(final String key, final FlagValue<?> value) {
|
2015-07-26 20:38:08 +02:00
|
|
|
if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
|
2014-11-05 04:42:08 +01:00
|
|
|
throw new IllegalArgumentException("Flag must be alphabetic characters");
|
|
|
|
}
|
|
|
|
if (key.length() > 16) {
|
|
|
|
throw new IllegalArgumentException("Key must be <= 16 characters");
|
|
|
|
}
|
|
|
|
this.key = key.toLowerCase();
|
2014-11-19 18:05:09 +01:00
|
|
|
if (value == null) {
|
|
|
|
this.value = new FlagValue.StringValue();
|
2014-12-18 03:15:11 +01:00
|
|
|
} else {
|
2014-11-19 18:05:09 +01:00
|
|
|
this.value = value;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-01-29 10:59:32 +01:00
|
|
|
public boolean isList() {
|
|
|
|
return this.value instanceof FlagValue.ListValue;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-01-25 05:40:50 +01:00
|
|
|
public Object parseValueRaw(final String value) {
|
2015-02-02 09:50:49 +01:00
|
|
|
try {
|
|
|
|
return this.value.parse(value);
|
2015-02-20 07:34:19 +01:00
|
|
|
} catch (final Exception e) {
|
2015-02-02 09:50:49 +01:00
|
|
|
return null;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-01-25 05:40:50 +01:00
|
|
|
public String toString(final Object t) {
|
|
|
|
return this.value.toString(t);
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
public String getValueDesc() {
|
2014-11-17 19:18:05 +01:00
|
|
|
return this.value.getDescription();
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* AbstractFlag key
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public String getKey() {
|
|
|
|
return this.key;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return this.key;
|
|
|
|
}
|
2015-06-23 23:44:44 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return this.key.hashCode();
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(final Object other) {
|
|
|
|
if (other == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (other == this) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!(other instanceof AbstractFlag)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final AbstractFlag otherObj = (AbstractFlag) other;
|
|
|
|
return (otherObj.key.equals(this.key));
|
|
|
|
}
|
2014-09-23 19:02:17 +02:00
|
|
|
}
|