small changes to flags

- flag key should be only alphabetic characters
- flags should be case insensitive
This commit is contained in:
boy0001 2014-09-24 10:56:03 +10:00
parent 29d77320c3
commit f8e096a02b
3 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils;
/**
* Created by Citymonstret on 2014-09-23.
*/
@ -8,7 +10,11 @@ public class AbstractFlag {
private final String key;
public AbstractFlag(String key) {
this.key = key;
if (!StringUtils.isAlpha(key))
throw new IllegalArgumentException("Flag must be alphabetic characters");
if (key.length()>16)
throw new IllegalArgumentException("Key must be <= 16 characters");
this.key = key.toLowerCase();
}
public String getKey() {

View File

@ -7,10 +7,8 @@ public class Flag {
private AbstractFlag key;
private String value;
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumeric(ChatColor.stripColor(value).replace(" ", "")))
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value)))
throw new IllegalArgumentException("Flag must be alphanumerical");
/*if (key.length()>16)
throw new IllegalArgumentException("Key must be <= 16 characters");*/
if (value.length()>48)
throw new IllegalArgumentException("Value must be <= 48 characters");
this.key = key;
@ -39,7 +37,7 @@ public class Flag {
if (getClass() != obj.getClass())
return false;
Flag other = (Flag) obj;
return (this.key==other.key && this.value == other.value);
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
}
@Override
public int hashCode() {

View File

@ -119,7 +119,7 @@ public class Set extends SubCommand{
}
try {
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length)," ");
Flag flag = new Flag(args[1], value);
Flag flag = new Flag(new AbstractFlag(args[1]), value);
PlotFlagAddEvent event = new PlotFlagAddEvent(flag,plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if(event.isCancelled()) {