From 765a021ecdbf86ad3996546ec9d5a67a04d8550d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 12 Nov 2019 20:38:18 +0000 Subject: [PATCH] Some flag fixes Use ItemType for the flags, since they accept items, not blocks. Fixes #2571 --- .../bukkit/listeners/PlayerEvents.java | 35 +++---- .../bukkit/object/BukkitBlockUtil.java | 9 +- .../bukkit/object/BukkitPlayer.java | 3 +- .../plotsquared/plot/commands/Music.java | 2 +- .../plotsquared/plot/flag/Flags.java | 6 +- .../plot/flag/ItemTypeListFlag.java | 39 ++++++++ .../plot/listener/PlotListener.java | 4 +- .../plotsquared/plot/util/EventUtil.java | 92 ++++++++++--------- .../plot/util/world/BlockUtil.java | 2 +- .../plotsquared/plot/util/world/ItemUtil.java | 10 ++ .../plotsquared/plot/FlagTest.java | 8 +- 11 files changed, 133 insertions(+), 77 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ItemTypeListFlag.java diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index c66d9fa1a..29db0c471 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -31,6 +31,7 @@ import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.item.ItemType; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -1099,10 +1100,10 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asBlockType(block.getType()))) { + .contains(BukkitAdapter.asItemType(block.getType()))) { return; } if (Permissions @@ -1384,10 +1385,10 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(BukkitBlockUtil.get(block)) || Permissions + .contains(BukkitAdapter.asItemType(block.getType())) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } @@ -1914,8 +1915,8 @@ import java.util.regex.Pattern; Location location = BukkitUtil.getLocation(block.getLocation()); Material finalType = type; if (!EventUtil.manager - .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asBlockType( - finalType).getDefaultState(), true)) { + .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asItemType( + finalType), true)) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); } @@ -1933,14 +1934,14 @@ import java.util.regex.Pattern; return; } PlayerBlockEventType eventType = null; - Supplier lb; + Supplier lazyItem; Location location; Action action = event.getAction(); switch (action) { case PHYSICAL: { eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; Block block = event.getClickedBlock(); - lb = BukkitBlockUtil.supply(block); + lazyItem = BukkitBlockUtil.supplyItem(block); location = BukkitUtil.getLocation(block.getLocation()); break; } @@ -2109,7 +2110,7 @@ import java.util.regex.Pattern; eventType = PlayerBlockEventType.INTERACT_BLOCK; } } - lb = BukkitBlockUtil.supply(block); + lazyItem = BukkitBlockUtil.supplyItem(block); if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK || !player.isSneaking())) { break; @@ -2128,7 +2129,7 @@ import java.util.regex.Pattern; type = offType; } // in the following, lb needs to have the material of the item in hand i.e. type - lb = BukkitBlockUtil.supply(type); + lazyItem = BukkitBlockUtil.supplyItem(type); if (type.isBlock()) { location = BukkitUtil .getLocation(block.getRelative(event.getBlockFace()).getLocation()); @@ -2211,7 +2212,7 @@ import java.util.regex.Pattern; Block block = event.getClickedBlock(); location = BukkitUtil.getLocation(block.getLocation()); eventType = PlayerBlockEventType.BREAK_BLOCK; - lb = BukkitBlockUtil.supply(block); + lazyItem = BukkitBlockUtil.supplyItem(block); break; default: return; @@ -2222,7 +2223,7 @@ import java.util.regex.Pattern; return; } } - if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) { + if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lazyItem, true)) { event.setCancelled(true); } } @@ -2470,7 +2471,7 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { - if (Flags.USE.contains(plot, BukkitBlockUtil.get(block))) { + if (Flags.USE.contains(plot, BukkitAdapter.asItemType(block.getType()))) { return; } if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2530,9 +2531,9 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> use = plot.getFlag(Flags.USE); + Optional> use = plot.getFlag(Flags.USE); Block block = event.getBlockClicked(); - if (use.isPresent() && use.get().contains(BukkitBlockUtil.get(block))) { + if (use.isPresent() && use.get().contains(BukkitAdapter.asItemType(block.getType()))) { return; } if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -3088,10 +3089,10 @@ import java.util.regex.Pattern; return; } } else if (!plot.isAdded(pp.getUUID())) { - Set place = plot.getFlag(Flags.PLACE, null); + Set place = plot.getFlag(Flags.PLACE, null); if (place != null) { Block block = event.getBlock(); - if (place.contains(BukkitBlockUtil.get(block))) { + if (place.contains(BukkitAdapter.asItemType(block.getType()))) { return; } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java index 1730ebd51..bd86b5068 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitBlockUtil.java @@ -2,18 +2,19 @@ package com.github.intellectualsites.plotsquared.bukkit.object; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.item.ItemType; import org.bukkit.Material; import org.bukkit.block.Block; import java.util.function.Supplier; public class BukkitBlockUtil { - public static Supplier supply(Block block) { - return () -> BukkitAdapter.asBlockType(block.getType()).getDefaultState(); + public static Supplier supplyItem(Block block) { + return () -> BukkitAdapter.asItemType(block.getType()); } - public static Supplier supply(Material type) { - return () -> BukkitAdapter.asBlockType(type).getDefaultState(); + public static Supplier supplyItem(Material type) { + return () -> BukkitAdapter.asItemType(type); } public static BlockState get(Block block) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index f09ecb968..5ee2960ca 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; import io.papermc.lib.PaperLib; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -283,7 +284,7 @@ public class BukkitPlayer extends PlotPlayer { } @Override public void playMusic(@NotNull final Location location, @NotNull final ItemType id) { - if (id.getBlockType().getMaterial().isAir()) { + if (id == ItemTypes.AIR) { // Let's just stop all the discs because why not? for (final Sound sound : Arrays.stream(Sound.values()) .filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java index e60ee9ba1..482a1f050 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java @@ -44,7 +44,7 @@ import java.util.Locale; plot.removeFlag(Flags.MUSIC); Captions.FLAG_REMOVED.send(player); } else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) { - plot.setFlag(Flags.MUSIC, item); + plot.setFlag(Flags.MUSIC, item.getType().getId()); Captions.FLAG_ADDED.send(player); } else { Captions.FLAG_NOT_ADDED.send(player); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 6df44dca7..3347fad8b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -58,9 +58,9 @@ public final class Flags { public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry"); public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); - public static final BlockStateListFlag USE = new BlockStateListFlag("use"); - public static final BlockStateListFlag BREAK = new BlockStateListFlag("break"); - public static final BlockStateListFlag PLACE = new BlockStateListFlag("place"); + public static final ItemTypeListFlag USE = new ItemTypeListFlag("use"); + public static final ItemTypeListFlag BREAK = new ItemTypeListFlag("break"); + public static final ItemTypeListFlag PLACE = new ItemTypeListFlag("place"); public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact"); public static final BooleanFlag VEHICLE_BREAK = new BooleanFlag("vehicle-break"); public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ItemTypeListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ItemTypeListFlag.java new file mode 100644 index 000000000..2e9d80a38 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ItemTypeListFlag.java @@ -0,0 +1,39 @@ +package com.github.intellectualsites.plotsquared.plot.flag; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; +import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; + +import java.util.Arrays; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +public class ItemTypeListFlag extends ListFlag> { + + public ItemTypeListFlag(String name) { + super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); + } + + @Override public String valueToString(Object value) { + return StringMan.join((Set) value, ","); + } + + @Override public Set parseValue(final String value) { + return Arrays.stream(ItemUtil.parse(value)).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + @Override public String getValueDescription() { + return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated(); + } + + public boolean contains(Plot plot, BlockState value) { + return contains(plot, value.getBlockType().getItemType()); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index ef9b25406..1422821dd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -152,12 +152,12 @@ public class PlotListener { Location location = player.getLocation(); Location lastLocation = player.getMeta("music"); if (lastLocation != null) { - player.playMusic(lastLocation, ItemTypes.AIR); + player.playMusic(lastLocation, item); if (item == ItemTypes.AIR) { player.deleteMeta("music"); } } - if (!(item == ItemTypes.AIR)) { + if (item != ItemTypes.AIR) { try { player.setMeta("music", location); player.playMusic(location, item); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index dc8830769..7af028759 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -17,6 +17,8 @@ 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.ItemTypes; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -103,7 +105,7 @@ public abstract class EventUtil { } public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type, - Location location, Supplier block, boolean notifyPerms) { + Location location, Supplier item, boolean notifyPerms) { PlotArea area = location.getPlotArea(); assert area != null; Plot plot = area.getPlot(location); @@ -129,19 +131,19 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> use = plot.getFlag(Flags.USE); + Optional> use = plot.getFlag(Flags.USE); if (use.isPresent()) { - Set value = use.get(); - if (value.contains(BlockTypes.AIR) || value - .contains(block.get())) { + Set value = use.get(); + if (value.contains(ItemTypes.AIR) || value + .contains(item.get())) { return true; } } - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); if (destroy.isPresent()) { - Set value = destroy.get(); - if (value.contains(BlockTypes.AIR) || value - .contains(block.get())) { + Set value = destroy.get(); + if (value.contains(ItemTypes.AIR) || value + .contains(item.get())) { return true; } } @@ -223,10 +225,10 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { return Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) || !(!notifyPerms || MainUtil @@ -246,10 +248,10 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_BUILD_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.PLACE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_BUILD_OTHER.getTranslated(), false)) { return true; @@ -273,10 +275,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -300,10 +302,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -329,10 +331,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.USE); - Set value = flag.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flag = plot.getFlag(Flags.USE); + Set value = flag.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -359,10 +361,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.USE); - Set value = flag.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flag = plot.getFlag(Flags.USE); + Set value = flag.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -389,10 +391,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.PLACE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -419,10 +421,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.PLACE); - Set value = flag.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flag = plot.getFlag(Flags.PLACE); + Set value = flag.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -450,10 +452,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.PLACE); - Set value = flag.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(block.get())) { + Optional> flag = plot.getFlag(Flags.PLACE); + Set value = flag.orElse(null); + if (value == null || !value.contains(ItemTypes.AIR) && !value + .contains(item.get())) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java index 14ff2652c..ca5b8f777 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/BlockUtil.java @@ -42,7 +42,7 @@ public final class BlockUtil { return FuzzyBlockState.builder().type(BlockTypes.AIR).build(); } id = id.toLowerCase(); - BlockType type = BlockType.REGISTRY.get(id); + BlockType type = BlockTypes.get(id); if (type != null) { return type.getDefaultState(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java index 415df8fe1..2d906a73a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/ItemUtil.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util.world; import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; @@ -27,4 +28,13 @@ public final class ItemUtil { if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input; return ItemTypes.get(input); } + + public static final ItemType[] parse(String commaDelimited) { + String[] split = commaDelimited.split(",(?![^\\(\\[]*[\\]\\)])"); + ItemType[] result = new ItemType[split.length]; + for (int i = 0; i < split.length; i++) { + result[i] = get(split[i]); + } + return result; + } } diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index 8bbc1193f..f5748b644 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -10,6 +10,8 @@ import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest; import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil; import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.item.ItemTypes; import org.junit.Before; import org.junit.Test; @@ -22,7 +24,7 @@ import static org.junit.Assert.assertEquals; public class FlagTest { - private Object testBlock; + private ItemType testBlock; private Flag> use = Flags.USE; @Before public void setUp() throws Exception { @@ -37,11 +39,11 @@ public class FlagTest { Optional flag = plot.getFlag(use); if (flag.isPresent()) { System.out.println(Flags.USE.valueToString(flag.get())); - testBlock = BlockUtil.get((short) 1, (byte) 0); + testBlock = ItemTypes.BONE_BLOCK; flag.get().add(testBlock); } flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); - Optional> flag2 = plot.getFlag(Flags.USE); + Optional> flag2 = plot.getFlag(Flags.USE); if (flag2.isPresent()) { // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); }