TF-WorldGuardExtraFlagsPlugin/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/CustomSetFlag.java

45 lines
1.2 KiB
Java
Raw Normal View History

2018-11-12 18:48:17 +00:00
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6;
2016-12-12 19:33:07 +00:00
import java.util.Set;
import com.google.common.collect.Sets;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import com.sk89q.worldguard.protection.flags.SetFlag;
public class CustomSetFlag<T> extends SetFlag<T>
{
public CustomSetFlag(String name, Flag<T> subFlag)
{
super(name, subFlag);
}
@Override
public Set<T> parseInput(FlagContext context) throws InvalidFlagFormat
{
String input = context.getUserInput();
if (input.isEmpty())
{
return Sets.newHashSet();
}
else
{
Set<T> items = Sets.newHashSet();
for (String str : input.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1))
{
if (str.startsWith("\"") && str.endsWith("\""))
{
str = str.substring(1, str.length() - 1);
}
2018-11-12 18:48:17 +00:00
2016-12-12 19:33:07 +00:00
FlagContext copy = context.copyWith(null, str, null);
items.add(this.getType().parseInput(copy));
}
return items;
}
}
}