Some flag fixes

Use ItemType for the flags, since they accept items, not blocks.
Fixes #2571
This commit is contained in:
Jesse Boyd
2019-11-12 20:38:18 +00:00
parent 7e21107120
commit 765a021ecd
11 changed files with 133 additions and 77 deletions

View File

@ -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<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
Optional<Set<ItemType>> 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<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
Optional<Set<ItemType>> 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<BlockState> lb;
Supplier<ItemType> 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<Set<BlockType>> use = plot.getFlag(Flags.USE);
Optional<Set<ItemType>> 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<BlockType> place = plot.getFlag(Flags.PLACE, null);
Set<ItemType> 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;
}
}

View File

@ -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<BlockState> supply(Block block) {
return () -> BukkitAdapter.asBlockType(block.getType()).getDefaultState();
public static Supplier<ItemType> supplyItem(Block block) {
return () -> BukkitAdapter.asItemType(block.getType());
}
public static Supplier<BlockState> supply(Material type) {
return () -> BukkitAdapter.asBlockType(type).getDefaultState();
public static Supplier<ItemType> supplyItem(Material type) {
return () -> BukkitAdapter.asItemType(type);
}
public static BlockState get(Block block) {

View File

@ -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())) {