mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Some flag fixes
Use ItemType for the flags, since they accept items, not blocks. Fixes #2571
This commit is contained in:
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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 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);
|
||||
|
@ -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<BlockState> block, boolean notifyPerms) {
|
||||
Location location, Supplier<ItemType> 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<Set<BlockType>> use = plot.getFlag(Flags.USE);
|
||||
Optional<Set<ItemType>> use = plot.getFlag(Flags.USE);
|
||||
if (use.isPresent()) {
|
||||
Set<BlockType> value = use.get();
|
||||
if (value.contains(BlockTypes.AIR) || value
|
||||
.contains(block.get())) {
|
||||
Set<ItemType> value = use.get();
|
||||
if (value.contains(ItemTypes.AIR) || value
|
||||
.contains(item.get())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
|
||||
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK);
|
||||
if (destroy.isPresent()) {
|
||||
Set<BlockType> value = destroy.get();
|
||||
if (value.contains(BlockTypes.AIR) || value
|
||||
.contains(block.get())) {
|
||||
Set<ItemType> 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<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<BlockType> value = flagValue.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<ItemType> 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<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||
Set<BlockType> value = flagValue.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||
Set<ItemType> 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<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<BlockType> value = flagValue.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<ItemType> 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<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<BlockType> value = flagValue.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
|
||||
Set<ItemType> 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<Set<BlockType>> flag = plot.getFlag(Flags.USE);
|
||||
Set<BlockType> value = flag.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flag = plot.getFlag(Flags.USE);
|
||||
Set<ItemType> 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<Set<BlockType>> flag = plot.getFlag(Flags.USE);
|
||||
Set<BlockType> value = flag.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flag = plot.getFlag(Flags.USE);
|
||||
Set<ItemType> 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<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||
Set<BlockType> value = flagValue.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
|
||||
Set<ItemType> 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<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
|
||||
Set<BlockType> value = flag.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
|
||||
Set<ItemType> 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<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
|
||||
Set<BlockType> value = flag.orElse(null);
|
||||
if (value == null || !value.contains(BlockTypes.AIR) && !value
|
||||
.contains(block.get())) {
|
||||
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
|
||||
Set<ItemType> 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)) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<? extends Collection<?>> use = Flags.USE;
|
||||
|
||||
@Before public void setUp() throws Exception {
|
||||
@ -37,11 +39,11 @@ public class FlagTest {
|
||||
Optional<? extends Collection> 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<Set<BlockType>> flag2 = plot.getFlag(Flags.USE);
|
||||
Optional<Set<ItemType>> flag2 = plot.getFlag(Flags.USE);
|
||||
if (flag2.isPresent()) {
|
||||
// assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock));
|
||||
}
|
||||
|
Reference in New Issue
Block a user