diff --git a/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java b/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java index 747322e33..096e85e84 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java @@ -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() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java index 53d32bdc1..ade3b0b0d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -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() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 682c707ea..f1f937832 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -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()) {