mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Some flag fixes
Use ItemType for the flags, since they accept items, not blocks. Fixes #2571
This commit is contained in:
parent
7e21107120
commit
765a021ecd
@ -31,6 +31,7 @@ import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility;
|
|||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -1099,10 +1100,10 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
|
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK);
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (destroy.isPresent() && destroy.get()
|
if (destroy.isPresent() && destroy.get()
|
||||||
.contains(BukkitAdapter.asBlockType(block.getType()))) {
|
.contains(BukkitAdapter.asItemType(block.getType()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Permissions
|
if (Permissions
|
||||||
@ -1384,10 +1385,10 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
|
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK);
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (destroy.isPresent() && destroy.get()
|
if (destroy.isPresent() && destroy.get()
|
||||||
.contains(BukkitBlockUtil.get(block)) || Permissions
|
.contains(BukkitAdapter.asItemType(block.getType())) || Permissions
|
||||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1914,8 +1915,8 @@ import java.util.regex.Pattern;
|
|||||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||||
Material finalType = type;
|
Material finalType = type;
|
||||||
if (!EventUtil.manager
|
if (!EventUtil.manager
|
||||||
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asBlockType(
|
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asItemType(
|
||||||
finalType).getDefaultState(), true)) {
|
finalType), true)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.setUseItemInHand(Event.Result.DENY);
|
event.setUseItemInHand(Event.Result.DENY);
|
||||||
}
|
}
|
||||||
@ -1933,14 +1934,14 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerBlockEventType eventType = null;
|
PlayerBlockEventType eventType = null;
|
||||||
Supplier<BlockState> lb;
|
Supplier<ItemType> lazyItem;
|
||||||
Location location;
|
Location location;
|
||||||
Action action = event.getAction();
|
Action action = event.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PHYSICAL: {
|
case PHYSICAL: {
|
||||||
eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
|
eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
lb = BukkitBlockUtil.supply(block);
|
lazyItem = BukkitBlockUtil.supplyItem(block);
|
||||||
location = BukkitUtil.getLocation(block.getLocation());
|
location = BukkitUtil.getLocation(block.getLocation());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2109,7 +2110,7 @@ import java.util.regex.Pattern;
|
|||||||
eventType = PlayerBlockEventType.INTERACT_BLOCK;
|
eventType = PlayerBlockEventType.INTERACT_BLOCK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lb = BukkitBlockUtil.supply(block);
|
lazyItem = BukkitBlockUtil.supplyItem(block);
|
||||||
if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
|
if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
|
||||||
|| !player.isSneaking())) {
|
|| !player.isSneaking())) {
|
||||||
break;
|
break;
|
||||||
@ -2128,7 +2129,7 @@ import java.util.regex.Pattern;
|
|||||||
type = offType;
|
type = offType;
|
||||||
}
|
}
|
||||||
// in the following, lb needs to have the material of the item in hand i.e. type
|
// 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()) {
|
if (type.isBlock()) {
|
||||||
location = BukkitUtil
|
location = BukkitUtil
|
||||||
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||||
@ -2211,7 +2212,7 @@ import java.util.regex.Pattern;
|
|||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
location = BukkitUtil.getLocation(block.getLocation());
|
location = BukkitUtil.getLocation(block.getLocation());
|
||||||
eventType = PlayerBlockEventType.BREAK_BLOCK;
|
eventType = PlayerBlockEventType.BREAK_BLOCK;
|
||||||
lb = BukkitBlockUtil.supply(block);
|
lazyItem = BukkitBlockUtil.supplyItem(block);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -2222,7 +2223,7 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) {
|
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lazyItem, true)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2470,7 +2471,7 @@ import java.util.regex.Pattern;
|
|||||||
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
|
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.isAdded(pp.getUUID())) {
|
} else if (!plot.isAdded(pp.getUUID())) {
|
||||||
if (Flags.USE.contains(plot, BukkitBlockUtil.get(block))) {
|
if (Flags.USE.contains(plot, BukkitAdapter.asItemType(block.getType()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
@ -2530,9 +2531,9 @@ import java.util.regex.Pattern;
|
|||||||
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
|
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
Optional<Set<BlockType>> use = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> use = plot.getFlag(Flags.USE);
|
||||||
Block block = event.getBlockClicked();
|
Block block = event.getBlockClicked();
|
||||||
if (use.isPresent() && use.get().contains(BukkitBlockUtil.get(block))) {
|
if (use.isPresent() && use.get().contains(BukkitAdapter.asItemType(block.getType()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
@ -3088,10 +3089,10 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!plot.isAdded(pp.getUUID())) {
|
} else if (!plot.isAdded(pp.getUUID())) {
|
||||||
Set<BlockType> place = plot.getFlag(Flags.PLACE, null);
|
Set<ItemType> place = plot.getFlag(Flags.PLACE, null);
|
||||||
if (place != null) {
|
if (place != null) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (place.contains(BukkitBlockUtil.get(block))) {
|
if (place.contains(BukkitAdapter.asItemType(block.getType()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,19 @@ package com.github.intellectualsites.plotsquared.bukkit.object;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class BukkitBlockUtil {
|
public class BukkitBlockUtil {
|
||||||
public static Supplier<BlockState> supply(Block block) {
|
public static Supplier<ItemType> supplyItem(Block block) {
|
||||||
return () -> BukkitAdapter.asBlockType(block.getType()).getDefaultState();
|
return () -> BukkitAdapter.asItemType(block.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Supplier<BlockState> supply(Material type) {
|
public static Supplier<ItemType> supplyItem(Material type) {
|
||||||
return () -> BukkitAdapter.asBlockType(type).getDefaultState();
|
return () -> BukkitAdapter.asItemType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState get(Block block) {
|
public static BlockState get(Block block) {
|
||||||
|
@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
|||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Sound;
|
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) {
|
@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?
|
// Let's just stop all the discs because why not?
|
||||||
for (final Sound sound : Arrays.stream(Sound.values())
|
for (final Sound sound : Arrays.stream(Sound.values())
|
||||||
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
|
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
|
||||||
|
@ -44,7 +44,7 @@ import java.util.Locale;
|
|||||||
plot.removeFlag(Flags.MUSIC);
|
plot.removeFlag(Flags.MUSIC);
|
||||||
Captions.FLAG_REMOVED.send(player);
|
Captions.FLAG_REMOVED.send(player);
|
||||||
} else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) {
|
} 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);
|
Captions.FLAG_ADDED.send(player);
|
||||||
} else {
|
} else {
|
||||||
Captions.FLAG_NOT_ADDED.send(player);
|
Captions.FLAG_NOT_ADDED.send(player);
|
||||||
|
@ -58,9 +58,9 @@ public final class Flags {
|
|||||||
public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition");
|
public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition");
|
||||||
public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry");
|
public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry");
|
||||||
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
|
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
|
||||||
public static final BlockStateListFlag USE = new BlockStateListFlag("use");
|
public static final ItemTypeListFlag USE = new ItemTypeListFlag("use");
|
||||||
public static final BlockStateListFlag BREAK = new BlockStateListFlag("break");
|
public static final ItemTypeListFlag BREAK = new ItemTypeListFlag("break");
|
||||||
public static final BlockStateListFlag PLACE = new BlockStateListFlag("place");
|
public static final ItemTypeListFlag PLACE = new ItemTypeListFlag("place");
|
||||||
public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact");
|
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_BREAK = new BooleanFlag("vehicle-break");
|
||||||
public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place");
|
public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place");
|
||||||
|
@ -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<Set<ItemType>> {
|
||||||
|
|
||||||
|
public ItemTypeListFlag(String name) {
|
||||||
|
super(Captions.FLAG_CATEGORY_BLOCK_LIST, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String valueToString(Object value) {
|
||||||
|
return StringMan.join((Set<BlockType>) value, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public Set<ItemType> 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());
|
||||||
|
}
|
||||||
|
}
|
@ -152,12 +152,12 @@ public class PlotListener {
|
|||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
Location lastLocation = player.getMeta("music");
|
Location lastLocation = player.getMeta("music");
|
||||||
if (lastLocation != null) {
|
if (lastLocation != null) {
|
||||||
player.playMusic(lastLocation, ItemTypes.AIR);
|
player.playMusic(lastLocation, item);
|
||||||
if (item == ItemTypes.AIR) {
|
if (item == ItemTypes.AIR) {
|
||||||
player.deleteMeta("music");
|
player.deleteMeta("music");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(item == ItemTypes.AIR)) {
|
if (item != ItemTypes.AIR) {
|
||||||
try {
|
try {
|
||||||
player.setMeta("music", location);
|
player.setMeta("music", location);
|
||||||
player.playMusic(location, item);
|
player.playMusic(location, item);
|
||||||
|
@ -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.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
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 org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -103,7 +105,7 @@ public abstract class EventUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type,
|
public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type,
|
||||||
Location location, Supplier<BlockState> block, boolean notifyPerms) {
|
Location location, Supplier<ItemType> item, boolean notifyPerms) {
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
assert area != null;
|
assert area != null;
|
||||||
Plot plot = area.getPlot(location);
|
Plot plot = area.getPlot(location);
|
||||||
@ -129,19 +131,19 @@ public abstract class EventUtil {
|
|||||||
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
|
||||||
notifyPerms);
|
notifyPerms);
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> use = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> use = plot.getFlag(Flags.USE);
|
||||||
if (use.isPresent()) {
|
if (use.isPresent()) {
|
||||||
Set<BlockType> value = use.get();
|
Set<ItemType> value = use.get();
|
||||||
if (value.contains(BlockTypes.AIR) || value
|
if (value.contains(ItemTypes.AIR) || value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
|
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK);
|
||||||
if (destroy.isPresent()) {
|
if (destroy.isPresent()) {
|
||||||
Set<BlockType> value = destroy.get();
|
Set<ItemType> value = destroy.get();
|
||||||
if (value.contains(BlockTypes.AIR) || value
|
if (value.contains(ItemTypes.AIR) || value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,10 +225,10 @@ public abstract class EventUtil {
|
|||||||
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
|
||||||
notifyPerms);
|
notifyPerms);
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||||
Set<BlockType> value = flagValue.orElse(null);
|
Set<ItemType> value = flagValue.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
return Permissions.hasPermission(player,
|
return Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)
|
||||||
|| !(!notifyPerms || MainUtil
|
|| !(!notifyPerms || MainUtil
|
||||||
@ -246,10 +248,10 @@ public abstract class EventUtil {
|
|||||||
Captions.PERMISSION_ADMIN_BUILD_UNOWNED.getTranslated(),
|
Captions.PERMISSION_ADMIN_BUILD_UNOWNED.getTranslated(),
|
||||||
notifyPerms);
|
notifyPerms);
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
|
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||||
Set<BlockType> value = flagValue.orElse(null);
|
Set<ItemType> value = flagValue.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_BUILD_OTHER.getTranslated(), false)) {
|
Captions.PERMISSION_ADMIN_BUILD_OTHER.getTranslated(), false)) {
|
||||||
return true;
|
return true;
|
||||||
@ -273,10 +275,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) {
|
if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||||
Set<BlockType> value = flagValue.orElse(null);
|
Set<ItemType> value = flagValue.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -300,10 +302,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) {
|
if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||||
Set<BlockType> value = flagValue.orElse(null);
|
Set<ItemType> value = flagValue.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -329,10 +331,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) {
|
if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flag = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flag = plot.getFlag(Flags.USE);
|
||||||
Set<BlockType> value = flag.orElse(null);
|
Set<ItemType> value = flag.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -359,10 +361,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) {
|
if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flag = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flag = plot.getFlag(Flags.USE);
|
||||||
Set<BlockType> value = flag.orElse(null);
|
Set<ItemType> value = flag.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -389,10 +391,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) {
|
if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
|
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||||
Set<BlockType> value = flagValue.orElse(null);
|
Set<ItemType> value = flagValue.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -419,10 +421,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) {
|
if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
|
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
|
||||||
Set<BlockType> value = flag.orElse(null);
|
Set<ItemType> value = flag.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
@ -450,10 +452,10 @@ public abstract class EventUtil {
|
|||||||
if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) {
|
if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
|
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
|
||||||
Set<BlockType> value = flag.orElse(null);
|
Set<ItemType> value = flag.orElse(null);
|
||||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
if (value == null || !value.contains(ItemTypes.AIR) && !value
|
||||||
.contains(block.get())) {
|
.contains(item.get())) {
|
||||||
if (Permissions.hasPermission(player,
|
if (Permissions.hasPermission(player,
|
||||||
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
|
||||||
false)) {
|
false)) {
|
||||||
|
@ -42,7 +42,7 @@ public final class BlockUtil {
|
|||||||
return FuzzyBlockState.builder().type(BlockTypes.AIR).build();
|
return FuzzyBlockState.builder().type(BlockTypes.AIR).build();
|
||||||
}
|
}
|
||||||
id = id.toLowerCase();
|
id = id.toLowerCase();
|
||||||
BlockType type = BlockType.REGISTRY.get(id);
|
BlockType type = BlockTypes.get(id);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
return type.getDefaultState();
|
return type.getDefaultState();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.util.world;
|
package com.github.intellectualsites.plotsquared.plot.util.world;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
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.ItemType;
|
||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
@ -27,4 +28,13 @@ public final class ItemUtil {
|
|||||||
if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input;
|
if (!input.split("\\[", 2)[0].contains(":")) input = "minecraft:" + input;
|
||||||
return ItemTypes.get(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.EventUtilTest;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -22,7 +24,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
public class FlagTest {
|
public class FlagTest {
|
||||||
|
|
||||||
private Object testBlock;
|
private ItemType testBlock;
|
||||||
private Flag<? extends Collection<?>> use = Flags.USE;
|
private Flag<? extends Collection<?>> use = Flags.USE;
|
||||||
|
|
||||||
@Before public void setUp() throws Exception {
|
@Before public void setUp() throws Exception {
|
||||||
@ -37,11 +39,11 @@ public class FlagTest {
|
|||||||
Optional<? extends Collection> flag = plot.getFlag(use);
|
Optional<? extends Collection> flag = plot.getFlag(use);
|
||||||
if (flag.isPresent()) {
|
if (flag.isPresent()) {
|
||||||
System.out.println(Flags.USE.valueToString(flag.get()));
|
System.out.println(Flags.USE.valueToString(flag.get()));
|
||||||
testBlock = BlockUtil.get((short) 1, (byte) 0);
|
testBlock = ItemTypes.BONE_BLOCK;
|
||||||
flag.get().add(testBlock);
|
flag.get().add(testBlock);
|
||||||
}
|
}
|
||||||
flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection)));
|
flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection)));
|
||||||
Optional<Set<BlockType>> flag2 = plot.getFlag(Flags.USE);
|
Optional<Set<ItemType>> flag2 = plot.getFlag(Flags.USE);
|
||||||
if (flag2.isPresent()) {
|
if (flag2.isPresent()) {
|
||||||
// assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock));
|
// assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user