Skip to content

Commit f2e9d2b

Browse files
Prevent players from getting doors as observers (#1488)
Signed-off-by: OhPointFive <[email protected]> Signed-off-by: Half <[email protected]> Signed-off-by: Pablo Herrera <[email protected]> Co-authored-by: Pablo Herrera <[email protected]>
1 parent a8ffa02 commit f2e9d2b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

core/src/main/java/tc/oc/pgm/spawns/states/Observing.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package tc.oc.pgm.spawns.states;
22

3-
import java.util.EnumSet;
4-
import java.util.Set;
53
import org.bukkit.GameMode;
64
import org.bukkit.Location;
7-
import org.bukkit.Material;
85
import org.bukkit.block.Block;
96
import org.bukkit.event.entity.EntityDamageEvent;
107
import org.bukkit.event.inventory.InventoryClickEvent;
118
import org.bukkit.event.inventory.InventoryType;
129
import org.bukkit.event.player.PlayerRespawnEvent;
1310
import org.bukkit.inventory.ItemStack;
1411
import org.bukkit.inventory.PlayerInventory;
15-
import org.bukkit.material.Door;
1612
import tc.oc.pgm.api.match.event.MatchStartEvent;
1713
import tc.oc.pgm.api.party.Competitor;
1814
import tc.oc.pgm.api.player.MatchPlayer;
@@ -26,11 +22,6 @@
2622

2723
public class Observing extends State {
2824

29-
// A set of item types which, when used to interact with the match environment by non-playing
30-
// users, can potentially cause client-server de-sync
31-
private static final Set<Material> BAD_TYPES =
32-
EnumSet.of(Materials.LILY_PAD, Material.BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET);
33-
3425
private static final double VOID_HEIGHT = -64;
3526

3627
private final boolean reset;
@@ -131,7 +122,7 @@ public void onEvent(InventoryClickEvent event) {
131122
|| event.getCursor() == null) return;
132123

133124
ItemStack item = event.getCursor();
134-
if (BAD_TYPES.contains(item.getType()) || item.getData() instanceof Door) {
125+
if (Materials.FORBIDDEN_OBSERVER_TYPES.matches(item)) {
135126
event.setCancelled(true);
136127
}
137128
}

util/src/main/java/tc/oc/pgm/util/material/Materials.java

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ public interface Materials {
5252
.addNullable(Material.getMaterial("MACE"))
5353
.build();
5454

55+
MaterialMatcher DOOR_ITEMS = MaterialMatcher.builder()
56+
.addAll(m -> m.name().contains("_DOOR") && !m.isBlock())
57+
.build();
58+
59+
// A set of item types which, when used to interact with the match environment by non-playing
60+
// users, can potentially cause client-server de-sync
61+
MaterialMatcher FORBIDDEN_OBSERVER_TYPES = MaterialMatcher.builder()
62+
.add(DOOR_ITEMS)
63+
.addAll(Materials.LILY_PAD, Material.BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET)
64+
.build();
65+
5566
MaterialMatcher SOLID_EXCLUSIONS = MaterialMatcher.builder()
5667
.add(parse("SIGN_POST", "LEGACY_SIGN_POST")) // on modern, it's just *_SIGN
5768
.addAll(m -> m.name().endsWith("_PLATE") || m.name().endsWith("_SIGN"))

0 commit comments

Comments
 (0)