Fix UseBlockFlag for multiple uses at the same time, add windburst-flag

This commit is contained in:
Joo200 2024-06-26 22:30:33 +02:00
parent 83298796ab
commit a5ea5115f9
7 changed files with 16 additions and 49 deletions

View File

@ -55,23 +55,6 @@ public static int getPotionEffectBits(ItemStack item) {
return item.getDurability() & 0x3F;
}
/**
* Get a blacklist target for the given block.
*
* @param block the block
* @param effectiveMaterial The effective material, if different
* @return a target
*/
public static Target createTarget(Block block, Material effectiveMaterial) {
checkNotNull(block);
checkNotNull(block.getType());
if (block.getType() == effectiveMaterial) {
return createTarget(block.getType());
} else {
return createTarget(effectiveMaterial);
}
}
/**
* Get a blacklist target for the given block.
*

View File

@ -96,7 +96,7 @@ public void onBreakBlock(final BreakBlockEvent event) {
event.filter(target -> {
if (!wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target),
createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false)) {
createTarget(target.getBlock())), false, false)) {
return false;
} else if (!wcfg.getBlacklist().check(
new ItemDestroyWithBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target),
@ -124,7 +124,7 @@ public void onPlaceBlock(final PlaceBlockEvent event) {
final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
event.filter(target -> wcfg.getBlacklist().check(new BlockPlaceBlacklistEvent(
localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false));
localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false));
}
@EventHandler(ignoreCancelled = true)
@ -143,7 +143,7 @@ public void onUseBlock(final UseBlockEvent event) {
final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
event.filter(target -> wcfg.getBlacklist().check(new BlockInteractBlacklistEvent(
localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false));
localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock())), false, false));
}
@EventHandler(ignoreCancelled = true)

View File

@ -101,12 +101,14 @@ public void onUseBlock(final UseBlockEvent event) {
if (rootCause instanceof Player) {
final Player player = (Player) rootCause;
final Material material = event.getEffectiveMaterial();
if (!hasBuildPermission(player, "block." + material.name().toLowerCase() + ".interact")
&& !hasBuildPermission(player, "block.interact." + material.name().toLowerCase())) {
boolean blocked = event.filter(loc -> {
String blacklistName = loc.getBlock().getType().name().toLowerCase();
return hasBuildPermission(player, "block." + blacklistName + ".interact") ||
hasBuildPermission(player, "block.interact." + blacklistName);
}, true);
if (blocked && !event.isSilent()) {
tellErrorMessage(player, event.getWorld());
event.setCancelled(true);
}
}
}

View File

@ -152,7 +152,6 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@ -360,16 +359,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (entity instanceof AbstractWindCharge) {
Iterator<Block> it = event.blockList().iterator();
while (it.hasNext()) {
Block block = it.next();
UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), block);
useEvent.setSilent(true);
Bukkit.getServer().getPluginManager().callEvent(useEvent);
if (useEvent.isCancelled()) {
it.remove();
}
}
UseBlockEvent useEvent = new UseBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR);
useEvent.getRelevantFlags().add(Flags.WIND_CHARGE_BURST);
useEvent.setSilent(true);
Events.fireBulkEventToCancel(event, useEvent);
return;
}
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));

View File

@ -244,13 +244,13 @@ public void onUseBlock(final UseBlockEvent event) {
if (!isRegionSupportEnabled(event.getWorld())) return; // Region support disabled
if (isWhitelisted(event.getCause(), event.getWorld(), false)) return; // Whitelisted cause
final Material type = event.getEffectiveMaterial();
final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
final RegionAssociable associable = createRegionAssociable(event.getCause());
event.filter((Predicate<Location>) target -> {
boolean canUse;
String what;
final Material type = target.getBlock().getType();
/* Saplings, etc. */
if (Materials.isConsideredBuildingIfUsed(type)) {
@ -278,7 +278,7 @@ public void onUseBlock(final UseBlockEvent event) {
what = "sleep";
/* Respawn Anchors */
} else if(type == Material.RESPAWN_ANCHOR) {
} else if(target.getBlock().getType() == Material.RESPAWN_ANCHOR) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.RESPAWN_ANCHORS));
what = "use anchors";

View File

@ -44,7 +44,6 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.AbstractWindCharge;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderCrystal;
@ -523,16 +522,6 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}
}
} else if (ent instanceof AbstractWindCharge) {
if (wcfg.useRegions) {
for (Block block : event.blockList()) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.WIND_CHARGE_BURST)) {
event.blockList().clear();
event.setCancelled(true);
return;
}
}
}
} else {
// unhandled entity
if (wcfg.blockOtherExplosions) {

View File

@ -835,7 +835,6 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
MATERIAL_FLAGS.put(Material.ARMADILLO_SCUTE, 0);
MATERIAL_FLAGS.put(Material.WOLF_ARMOR, 0);
MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0);
// 1.21
MATERIAL_FLAGS.put(Material.CHISELED_TUFF, 0);
@ -876,6 +875,7 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
MATERIAL_FLAGS.put(Material.VAULT, 0);
MATERIAL_FLAGS.put(Material.OMINOUS_BOTTLE, 0);
MATERIAL_FLAGS.put(Material.BREEZE_ROD, 0);
MATERIAL_FLAGS.put(Material.WIND_CHARGE, 0);
putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.ITEMS_BOATS, 0);