Fix some flag issues

This commit is contained in:
MattBDev 2019-11-18 11:09:32 -05:00
parent a26ede4dae
commit 8b7414770f
15 changed files with 32 additions and 38 deletions

View file

@ -18,8 +18,8 @@ public class BlockStateListFlag extends ListFlag<Set<BlockType>> {
super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); super(Captions.FLAG_CATEGORY_BLOCK_LIST, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Set<BlockType> value) {
return StringMan.join((Set<BlockType>) value, ","); return StringMan.join(value, ",");
} }
@Override public Set<BlockType> parseValue(final String value) { @Override public Set<BlockType> parseValue(final String value) {

View file

@ -9,8 +9,8 @@ public class BooleanFlag extends Flag<Boolean> {
super(Captions.FLAG_CATEGORY_BOOLEAN, name); super(Captions.FLAG_CATEGORY_BOOLEAN, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Boolean value) {
return value + ""; return value.toString();
} }
@Override public Boolean parseValue(String value) { @Override public Boolean parseValue(String value) {

View file

@ -8,7 +8,7 @@ public class DoubleFlag extends Flag<Double> {
super(Captions.FLAG_CATEGORY_DECIMAL, name); super(Captions.FLAG_CATEGORY_DECIMAL, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Double value) {
return value.toString(); return value.toString();
} }

View file

@ -15,8 +15,8 @@ public class EnumFlag extends Flag<String> {
this.values = new HashSet<>(Arrays.asList(values)); this.values = new HashSet<>(Arrays.asList(values));
} }
@Override public String valueToString(Object value) { @Override public String valueToString(String value) {
return value.toString(); return value;
} }
@Override public String parseValue(String value) { @Override public String parseValue(String value) {

View file

@ -44,7 +44,7 @@ public abstract class Flag<V> implements StringComparison.StringComparable {
Flags.registerFlag(this); Flags.registerFlag(this);
} }
public abstract String valueToString(Object value); public abstract String valueToString(V value);
@Override public final String toString() { @Override public final String toString() {
return "Flag { name='" + getName() + "'}"; return "Flag { name='" + getName() + "'}";

View file

@ -2,37 +2,38 @@ package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
public class GameModeFlag extends Flag<PlotGameMode> { public class GameModeFlag extends Flag<GameMode> {
public GameModeFlag(String name) { public GameModeFlag(String name) {
super(Captions.FLAG_CATEGORY_GAMEMODE, name); super(Captions.FLAG_CATEGORY_GAMEMODE, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(GameMode value) {
return ((PlotGameMode) value).getName(); return value.getName();
} }
@Override public PlotGameMode parseValue(String value) { @Override public GameMode parseValue(String value) {
switch (value.toLowerCase()) { switch (value.toLowerCase()) {
case "survival":
case "s":
case "0":
return PlotGameMode.SURVIVAL;
case "creative": case "creative":
case "c": case "c":
case "1": case "1":
return PlotGameMode.CREATIVE; return GameModes.CREATIVE;
case "adventure": case "adventure":
case "a": case "a":
case "2": case "2":
return PlotGameMode.ADVENTURE; return GameModes.ADVENTURE;
case "spectator": case "spectator":
case "sp": case "sp":
case "3": case "3":
return PlotGameMode.SPECTATOR; return GameModes.SPECTATOR;
case "survival":
case "s":
case "0":
default: default:
return PlotGameMode.NOT_SET; return GameModes.SURVIVAL;
} }
} }

View file

@ -13,7 +13,7 @@ public class IntegerFlag extends Flag<Integer> {
return Captions.FLAG_ERROR_INTEGER.getTranslated(); return Captions.FLAG_ERROR_INTEGER.getTranslated();
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Integer value) {
return value.toString(); return value.toString();
} }

View file

@ -13,8 +13,8 @@ public class IntegerListFlag extends ListFlag<List<Integer>> {
super(Captions.FLAG_CATEGORY_INTEGER_LIST, name); super(Captions.FLAG_CATEGORY_INTEGER_LIST, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(List<Integer> value) {
return StringMan.join((List<Integer>) value, ","); return StringMan.join(value, ",");
} }
@Override public List<Integer> parseValue(String value) { @Override public List<Integer> parseValue(String value) {

View file

@ -11,7 +11,7 @@ public class IntervalFlag extends Flag<IntervalFlag.Interval> {
super(Captions.FLAG_CATEGORY_INTERVALS, name); super(Captions.FLAG_CATEGORY_INTERVALS, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(IntervalFlag.Interval value) {
return value.toString(); return value.toString();
} }

View file

@ -21,8 +21,8 @@ public class ItemTypeListFlag extends ListFlag<Set<ItemType>> {
super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); super(Captions.FLAG_CATEGORY_BLOCK_LIST, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Set<ItemType> value) {
return StringMan.join((Set<BlockType>) value, ","); return StringMan.join(value, ",");
} }
@Override public Set<ItemType> parseValue(final String value) { @Override public Set<ItemType> parseValue(final String value) {
@ -32,8 +32,4 @@ public class ItemTypeListFlag extends ListFlag<Set<ItemType>> {
@Override public String getValueDescription() { @Override public String getValueDescription() {
return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated(); return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated();
} }
public boolean contains(Plot plot, BlockState value) {
return contains(plot, value.getBlockType().getItemType());
}
} }

View file

@ -16,7 +16,7 @@ public class LongFlag extends Flag<Long> {
} }
} }
@Override public String valueToString(Object value) { @Override public String valueToString(Long value) {
return value.toString(); return value.toString();
} }

View file

@ -9,7 +9,7 @@ public class PlotWeatherFlag extends Flag<PlotWeather> {
super(Captions.FLAG_CATEGORY_WEATHER, name); super(Captions.FLAG_CATEGORY_WEATHER, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(PlotWeather value) {
return value.toString(); return value.toString();
} }

View file

@ -8,7 +8,7 @@ public class StringFlag extends Flag<String> {
super(Captions.FLAG_CATEGORY_STRING, name); super(Captions.FLAG_CATEGORY_STRING, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(String value) {
return value.toString(); return value.toString();
} }

View file

@ -13,8 +13,8 @@ public class StringListFlag extends ListFlag<List<String>> {
super(Captions.FLAG_CATEGORY_STRING_LIST, name); super(Captions.FLAG_CATEGORY_STRING_LIST, name);
} }
@Override public String valueToString(Object value) { @Override public String valueToString(List<String> value) {
return StringMan.join((List<String>) value, ","); return StringMan.join(value, ",");
} }
@Override public List<String> parseValue(String value) { @Override public List<String> parseValue(String value) {

View file

@ -14,9 +14,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.Rating; import com.github.intellectualsites.plotsquared.plot.object.Rating;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;