Skip to content

Commit 70bc029

Browse files
authored
fix: allow cauldron in use flag to behave as expected (#4673)
1 parent 3ec7e99 commit 70bc029

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@
6464
import com.plotsquared.core.plot.flag.implementations.TamedInteractFlag;
6565
import com.plotsquared.core.plot.flag.implementations.TileDropFlag;
6666
import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
67+
import com.plotsquared.core.plot.flag.implementations.UseFlag;
6768
import com.plotsquared.core.plot.flag.implementations.VehicleBreakFlag;
6869
import com.plotsquared.core.plot.flag.implementations.VehicleUseFlag;
6970
import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag;
71+
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
7072
import com.plotsquared.core.plot.world.PlotAreaManager;
7173
import com.plotsquared.core.util.EventDispatcher;
7274
import com.plotsquared.core.util.MathMan;
@@ -78,6 +80,7 @@
7880
import com.sk89q.worldedit.WorldEdit;
7981
import com.sk89q.worldedit.bukkit.BukkitAdapter;
8082
import com.sk89q.worldedit.world.block.BlockType;
83+
import com.sk89q.worldedit.world.block.BlockTypes;
8184
import io.papermc.lib.PaperLib;
8285
import net.kyori.adventure.text.Component;
8386
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -152,9 +155,11 @@
152155
import org.checkerframework.checker.nullness.qual.NonNull;
153156

154157
import java.lang.reflect.Field;
158+
import java.util.Collections;
155159
import java.util.HashSet;
156160
import java.util.List;
157161
import java.util.Locale;
162+
import java.util.Optional;
158163
import java.util.Set;
159164
import java.util.UUID;
160165

@@ -179,6 +184,7 @@ public class PlayerEventListener implements Listener {
179184
Material.WRITTEN_BOOK
180185
);
181186
private static final Set<String> DYES;
187+
182188
static {
183189
Set<String> mutableDyes = new HashSet<>(Set.of(
184190
"WHITE_DYE",
@@ -213,7 +219,7 @@ public class PlayerEventListener implements Listener {
213219
// "temporary" fix for https://hub.spigotmc.org/jira/browse/SPIGOT-7813
214220
// can (and should) be removed when 1.21 support is dropped
215221
// List of all interactable 1.21 materials
216-
INTERACTABLE_MATERIALS = Material.CHEST.isInteractable() ? null : Set.of(
222+
INTERACTABLE_MATERIALS = Material.CHEST.isInteractable() ? null : Set.of(
217223
"REDSTONE_ORE", "DEEPSLATE_REDSTONE_ORE", "CHISELED_BOOKSHELF", "DECORATED_POT", "CHEST", "CRAFTING_TABLE",
218224
"FURNACE", "JUKEBOX", "OAK_FENCE", "SPRUCE_FENCE", "BIRCH_FENCE", "JUNGLE_FENCE", "ACACIA_FENCE", "CHERRY_FENCE",
219225
"DARK_OAK_FENCE", "MANGROVE_FENCE", "BAMBOO_FENCE", "CRIMSON_FENCE", "WARPED_FENCE", "PUMPKIN",
@@ -531,12 +537,14 @@ public void onConnect(PlayerJoinEvent event) {
531537
// Delayed
532538

533539
// Async
534-
TaskManager.runTaskLaterAsync(() -> {
535-
if (!player.hasPlayedBefore() && player.isOnline()) {
536-
player.saveData();
537-
}
538-
this.eventDispatcher.doJoinTask(pp);
539-
}, TaskTime.seconds(1L));
540+
TaskManager.runTaskLaterAsync(
541+
() -> {
542+
if (!player.hasPlayedBefore() && player.isOnline()) {
543+
player.saveData();
544+
}
545+
this.eventDispatcher.doJoinTask(pp);
546+
}, TaskTime.seconds(1L)
547+
);
540548

541549
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS
542550
&& PremiumVerification.isPremium() && UpdateUtility.hasUpdate) {
@@ -597,7 +605,9 @@ public void onTeleport(PlayerTeleportEvent event) {
597605
// to is identical to the plot's home location, and untrusted-visit is true
598606
// i.e. untrusted-visit can override deny-teleport
599607
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
600-
if (result || (plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous().equals(BukkitUtil.adaptComplete(to)))) {
608+
if (result || (plot.getFlag(UntrustedVisitFlag.class) && plot
609+
.getHomeSynchronous()
610+
.equals(BukkitUtil.adaptComplete(to)))) {
601611
// returns false if the player is not allowed to enter the plot (if they are denied, for example)
602612
// don't let the move event cancel the entry after teleport, but rather catch and cancel early (#4647)
603613
if (!plotListener.plotEntry(pp, plot)) {
@@ -941,12 +951,15 @@ public void onChat(AsyncPlayerChatEvent event) {
941951
builder.tag("plot_id", Tag.inserting(Component.text(id.toString())));
942952
builder.tag("sender", Tag.inserting(Component.text(sender)));
943953
if (plotPlayer.hasPermission("plots.chat.color")) {
944-
builder.tag("msg", Tag.inserting(MiniMessage.miniMessage().deserialize(
945-
message,
946-
TagResolver.resolver(StandardTags.color(), StandardTags.gradient(),
947-
StandardTags.rainbow(), StandardTags.decorations()
948-
)
949-
)));
954+
builder.tag(
955+
"msg", Tag.inserting(MiniMessage.miniMessage().deserialize(
956+
message,
957+
TagResolver.resolver(
958+
StandardTags.color(), StandardTags.gradient(),
959+
StandardTags.rainbow(), StandardTags.decorations()
960+
)
961+
))
962+
);
950963
} else {
951964
builder.tag("msg", Tag.inserting(Component.text(message)));
952965
}
@@ -1255,7 +1268,9 @@ public void onInteract(PlayerInteractEvent event) {
12551268
eventType = PlayerBlockEventType.INTERACT_BLOCK;
12561269
blocktype1 = BukkitAdapter.asBlockType(block.getType());
12571270

1258-
if (INTERACTABLE_MATERIALS != null ? INTERACTABLE_MATERIALS.contains(blockType.name()) : blockType.isInteractable()) {
1271+
if (INTERACTABLE_MATERIALS != null
1272+
? INTERACTABLE_MATERIALS.contains(blockType.name())
1273+
: blockType.isInteractable()) {
12591274
if (!player.isSneaking()) {
12601275
break;
12611276
}
@@ -1273,7 +1288,7 @@ public void onInteract(PlayerInteractEvent event) {
12731288
// in the following, lb needs to have the material of the item in hand i.e. type
12741289
switch (type.toString()) {
12751290
case "REDSTONE", "STRING", "PUMPKIN_SEEDS", "MELON_SEEDS", "COCOA_BEANS", "WHEAT_SEEDS", "BEETROOT_SEEDS",
1276-
"SWEET_BERRIES", "GLOW_BERRIES" -> {
1291+
"SWEET_BERRIES", "GLOW_BERRIES" -> {
12771292
return;
12781293
}
12791294
default -> {
@@ -1391,6 +1406,16 @@ public void onBucketEmpty(PlayerBucketEmptyEvent event) {
13911406
}
13921407
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
13931408
Plot plot = area.getPlot(location);
1409+
final List<BlockTypeWrapper> use =
1410+
Optional.ofNullable(plot).map(p -> p.getFlag(UseFlag.class)).orElse(area.isRoadFlags() ?
1411+
area.getFlag(UseFlag.class) : Collections.emptyList());
1412+
BlockType type = BukkitAdapter.asBlockType(block.getType());
1413+
for (final BlockTypeWrapper blockTypeWrapper : use) {
1414+
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper
1415+
.accepts(type)) {
1416+
return;
1417+
}
1418+
}
13941419
if (plot == null) {
13951420
if (pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
13961421
return;
@@ -1462,6 +1487,16 @@ public void onBucketFill(PlayerBucketFillEvent event) {
14621487
Player player = event.getPlayer();
14631488
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
14641489
Plot plot = area.getPlot(location);
1490+
final List<BlockTypeWrapper> use =
1491+
Optional.ofNullable(plot).map(p -> p.getFlag(UseFlag.class)).orElse(area.isRoadFlags() ?
1492+
area.getFlag(UseFlag.class) : Collections.emptyList());
1493+
BlockType type = BukkitAdapter.asBlockType(blockClicked.getType());
1494+
for (final BlockTypeWrapper blockTypeWrapper : use) {
1495+
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper
1496+
.accepts(type)) {
1497+
return;
1498+
}
1499+
}
14651500
if (plot == null) {
14661501
if (plotPlayer.hasPermission(Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
14671502
return;

0 commit comments

Comments
 (0)