Skip to content

Commit

Permalink
remove matcher compat
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed May 13, 2024
1 parent f01ec79 commit af46610
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.popcraft.bolt.matcher.Match;
import org.popcraft.bolt.util.EnumUtil;

import java.util.Collections;
import java.util.Set;

public class FrogspawnMatcher implements BlockMatcher {
private static final Material FROGSPAWN = EnumUtil.valueOf(Material.class, "FROGSPAWN").orElse(null);
private boolean enabled;

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
// Future: Replace with Material.FROGSPAWN
if (FROGSPAWN == null) {
enabled = false;
} else {
enabled = protectableBlocks.contains(FROGSPAWN);
}
enabled = protectableBlocks.contains(Material.FROGSPAWN);
}

@Override
Expand All @@ -37,7 +30,7 @@ public boolean canMatch(Block block) {
@Override
public Match findMatch(Block block) {
final Block above = block.getRelative(BlockFace.UP);
if (above.getType().equals(FROGSPAWN)) {
if (Material.FROGSPAWN.equals(above.getType())) {
return Match.ofBlocks(Collections.singleton(above));
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.popcraft.bolt.matcher.Match;
import org.popcraft.bolt.util.EnumUtil;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

public class GrassMatcher implements BlockMatcher {
private static final Material SHORT_GRASS_OLD = EnumUtil.valueOf(Material.class, "GRASS").orElse(null);
private static final Material SHORT_GRASS = EnumUtil.valueOf(Material.class, "SHORT_GRASS").orElse(null);
private static final EnumSet<Material> GRASS = EnumSet.of(Material.FERN, Material.SEAGRASS, Material.NETHER_SPROUTS, Material.WARPED_ROOTS, Material.CRIMSON_ROOTS);
private static final EnumSet<Material> GRASS = EnumSet.of(Material.SHORT_GRASS, Material.FERN, Material.SEAGRASS, Material.NETHER_SPROUTS, Material.WARPED_ROOTS, Material.CRIMSON_ROOTS);
private boolean enabled;

static {
// Future: Replace with Material.SHORT_GRASS
if (SHORT_GRASS_OLD != null) {
GRASS.add(SHORT_GRASS_OLD);
}
if (SHORT_GRASS != null) {
GRASS.add(SHORT_GRASS);
}
}

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
enabled = protectableBlocks.stream().anyMatch(GRASS::contains);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.popcraft.bolt.matcher.block;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -13,17 +11,11 @@
import java.util.Set;

public class HangingSignMatcher implements BlockMatcher {
private static final Tag<Material> CEILING_HANGING_SIGNS = Bukkit.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft("ceiling_hanging_signs"), Material.class);
private boolean enabled;

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
// Future: Replace with Tag.CEILING_HANGING_SIGNS
if (CEILING_HANGING_SIGNS == null) {
enabled = false;
} else {
enabled = protectableBlocks.stream().anyMatch(CEILING_HANGING_SIGNS::isTagged);
}
enabled = protectableBlocks.stream().anyMatch(Tag.CEILING_HANGING_SIGNS::isTagged);
}

@Override
Expand All @@ -38,12 +30,9 @@ public boolean canMatch(Block block) {

@Override
public Match findMatch(Block block) {
if (CEILING_HANGING_SIGNS == null) {
return null;
}
final Set<Block> blocks = new HashSet<>();
Block below = block;
while (CEILING_HANGING_SIGNS.isTagged((below = below.getRelative(BlockFace.DOWN)).getType())) {
while (Tag.CEILING_HANGING_SIGNS.isTagged((below = below.getRelative(BlockFace.DOWN)).getType())) {
blocks.add(below);
}
return Match.ofBlocks(blocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.popcraft.bolt.matcher.Match;
import org.popcraft.bolt.util.EnumUtil;

import java.util.Collections;
import java.util.Set;

public class MangrovePropaguleMatcher implements BlockMatcher {
private static final Material MANGROVE_PROPAGULE = EnumUtil.valueOf(Material.class, "MANGROVE_PROPAGULE").orElse(null);
private boolean enabled;

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
// Future: Replace with Material.MANGROVE_PROPAGULE
if (MANGROVE_PROPAGULE == null) {
enabled = false;
} else {
enabled = protectableBlocks.contains(MANGROVE_PROPAGULE);
}
enabled = protectableBlocks.contains(Material.MANGROVE_PROPAGULE);
}

@Override
Expand All @@ -37,7 +30,7 @@ public boolean canMatch(Block block) {
@Override
public Match findMatch(Block block) {
final Block below = block.getRelative(BlockFace.DOWN);
if (below.getType().equals(MANGROVE_PROPAGULE)) {
if (Material.MANGROVE_PROPAGULE.equals(below.getType())) {
return Match.ofBlocks(Collections.singleton(below));
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.popcraft.bolt.matcher.Match;
import org.popcraft.bolt.util.EnumUtil;

import java.util.Collections;
import java.util.Set;

public class PinkPetalsMatcher implements BlockMatcher {
private static final Material PINK_PETALS = EnumUtil.valueOf(Material.class, "PINK_PETALS").orElse(null);
private boolean enabled;

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
// Future: Replace with Material.PINK_PETALS
if (PINK_PETALS == null) {
enabled = false;
} else {
enabled = protectableBlocks.contains(PINK_PETALS);
}
enabled = protectableBlocks.contains(Material.PINK_PETALS);
}

@Override
Expand All @@ -37,7 +30,7 @@ public boolean canMatch(Block block) {
@Override
public Match findMatch(Block block) {
final Block above = block.getRelative(BlockFace.UP);
if (above.getType().equals(PINK_PETALS)) {
if (Material.PINK_PETALS.equals(above.getType())) {
return Match.ofBlocks(Collections.singleton(above));
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
import org.bukkit.block.data.MultipleFacing;
import org.bukkit.entity.EntityType;
import org.popcraft.bolt.matcher.Match;
import org.popcraft.bolt.util.EnumUtil;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;

public class SkulkVeinMatcher implements BlockMatcher {
private static final Material SCULK_VEIN = EnumUtil.valueOf(Material.class, "SCULK_VEIN").orElse(null);
private static final EnumSet<BlockFace> CARTESIAN_FACES = EnumSet.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
private boolean enabled;

@Override
public void initialize(Set<Material> protectableBlocks, Set<EntityType> protectableEntities) {
// Future: Replace with Material.SCULK_VEIN
if (SCULK_VEIN == null) {
enabled = false;
} else {
enabled = protectableBlocks.contains(SCULK_VEIN);
}
enabled = protectableBlocks.contains(Material.SCULK_VEIN);
}

@Override
Expand All @@ -42,7 +35,7 @@ public Match findMatch(Block block) {
final Set<Block> blocks = new HashSet<>();
for (final BlockFace blockFace : CARTESIAN_FACES) {
final Block adjacent = block.getRelative(blockFace);
if (adjacent.getType().equals(SCULK_VEIN) && adjacent.getBlockData() instanceof final MultipleFacing multipleFacing && multipleFacing.getFaces().contains(blockFace.getOppositeFace())) {
if (Material.SCULK_VEIN.equals(adjacent.getType()) && adjacent.getBlockData() instanceof final MultipleFacing multipleFacing && multipleFacing.getFaces().contains(blockFace.getOppositeFace())) {
blocks.add(adjacent);
}
}
Expand Down

0 comments on commit af46610

Please sign in to comment.