Block related flags now refer to javadocs on invalid material and errors on non block materials

This commit is contained in:
isokissa3 2018-12-08 23:51:46 +02:00
parent eb6b63b63f
commit 5c69855195
3 changed files with 35 additions and 9 deletions

View file

@ -13,7 +13,7 @@ import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StringFlag;
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
import net.goldtreeservers.worldguardextraflags.flags.helpers.MaterialFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.BlockMaterialFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag;
@ -58,10 +58,10 @@ public final class Flags
public final static StateFlag NETHER_PORTALS = new StateFlag("nether-portals", true);
public final static SetFlag<Material> ALLOW_BLOCK_PLACE = new SetFlag<Material>("allow-block-place", new MaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_PLACE = new SetFlag<Material>("deny-block-place", new MaterialFlag(null));
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<Material>("allow-block-break", new MaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<Material>("deny-block-break", new MaterialFlag(null));
public final static SetFlag<Material> ALLOW_BLOCK_PLACE = new SetFlag<Material>("allow-block-place", new BlockMaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_PLACE = new SetFlag<Material>("deny-block-place", new BlockMaterialFlag(null));
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<Material>("allow-block-break", new BlockMaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<Material>("deny-block-break", new BlockMaterialFlag(null));
public final static StateFlag GLIDE = new StateFlag("glide", false);

View file

@ -0,0 +1,26 @@
package net.goldtreeservers.worldguardextraflags.flags.helpers;
import org.bukkit.Material;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
public class BlockMaterialFlag extends MaterialFlag
{
public BlockMaterialFlag(String name)
{
super(name);
}
@Override
public Material parseInput(FlagContext context) throws InvalidFlagFormat
{
Material material = super.parseInput(context);
if (!material.isBlock())
{
throw new InvalidFlagFormat("This material isn't seen as 'placable block', use alternative id");
}
return material;
}
}

View file

@ -16,26 +16,26 @@ public class MaterialFlag extends Flag<Material>
@Override
public Object marshal(Material o)
{
return o.toString();
return o.name();
}
@Override
public Material parseInput(FlagContext context) throws InvalidFlagFormat
{
Material material = Material.getMaterial(context.getUserInput().trim().toUpperCase());
Material material = Material.matchMaterial(context.getUserInput());
if (material != null)
{
return material;
}
else
{
throw new InvalidFlagFormat("Unable to find the material!");
throw new InvalidFlagFormat("Unable to find the material! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html for valid ids");
}
}
@Override
public Material unmarshal(Object o)
{
return Material.getMaterial(o.toString());
return Material.matchMaterial(o.toString());
}
}