Skip to content

Commit 4e486f9

Browse files
committed
fix: allow cauldron in use flag to behave as expected
1 parent 6f0fa19 commit 4e486f9

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 -> {
@@ -1380,6 +1395,16 @@ public void onBucketEmpty(PlayerBucketEmptyEvent event) {
13801395
}
13811396
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
13821397
Plot plot = area.getPlot(location);
1398+
final List<BlockTypeWrapper> use =
1399+
Optional.ofNullable(plot).map(p -> p.getFlag(UseFlag.class)).orElse(area.isRoadFlags() ?
1400+
area.getFlag(UseFlag.class) : Collections.emptyList());
1401+
BlockType type = BukkitAdapter.asBlockType(block.getType());
1402+
for (final BlockTypeWrapper blockTypeWrapper : use) {
1403+
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper
1404+
.accepts(type)) {
1405+
return;
1406+
}
1407+
}
13831408
if (plot == null) {
13841409
if (pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
13851410
return;
@@ -1451,6 +1476,16 @@ public void onBucketFill(PlayerBucketFillEvent event) {
14511476
Player player = event.getPlayer();
14521477
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
14531478
Plot plot = area.getPlot(location);
1479+
final List<BlockTypeWrapper> use =
1480+
Optional.ofNullable(plot).map(p -> p.getFlag(UseFlag.class)).orElse(area.isRoadFlags() ?
1481+
area.getFlag(UseFlag.class) : Collections.emptyList());
1482+
BlockType type = BukkitAdapter.asBlockType(blockClicked.getType());
1483+
for (final BlockTypeWrapper blockTypeWrapper : use) {
1484+
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper
1485+
.accepts(type)) {
1486+
return;
1487+
}
1488+
}
14541489
if (plot == null) {
14551490
if (plotPlayer.hasPermission(Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
14561491
return;

0 commit comments

Comments
 (0)