Skip to content

Commit

Permalink
Backwards compatibility for redstone particle
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed May 19, 2024
1 parent 0edcbd7 commit a2d3926
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.popcraft.chunkyborder.util.BorderColor;
import org.popcraft.chunkyborder.util.Particles;
import org.popcraft.chunkyborder.util.PluginMessage;
import util.EnumUtil;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
Expand All @@ -59,6 +60,10 @@
public final class ChunkyBorderBukkit extends JavaPlugin implements Listener {
private static final String PLAY_BORDER_PACKET_ID = "chunky:border";
private static final List<String> HEADER = Arrays.asList("ChunkyBorder Configuration", "https://github.com/pop4959/ChunkyBorder/wiki/Configuration");
@SuppressWarnings("ExcessiveLambdaUsage")
private static final Particle DUST_PARTICLE = EnumUtil
.valueOf(Particle.class, "REDSTONE") // 1.20.4 and prior
.orElseGet(() -> Particle.DUST); // 1.20.5 and above
private ChunkyBorder chunkyBorder;

@Override
Expand Down Expand Up @@ -179,7 +184,7 @@ private void startVisualizer() {
for (final Vector3 location : particleLocations) {
final org.bukkit.Location bukkitLocation = new org.bukkit.Location(bukkitWorld, location.getX(), location.getY(), location.getZ());
if (Folia.isFolia()) {
bukkitPlayer.spawnParticle(Particle.DUST, bukkitLocation, 1, visualizerOptions);
bukkitPlayer.spawnParticle(DUST_PARTICLE, bukkitLocation, 1, visualizerOptions);
} else {
final Block block = bukkitWorld.getBlockAt(bukkitLocation);
final boolean fullyOccluded = block.getType().isOccluding()
Expand All @@ -188,7 +193,7 @@ private void startVisualizer() {
&& block.getRelative(BlockFace.SOUTH).getType().isOccluding()
&& block.getRelative(BlockFace.WEST).getType().isOccluding();
if (!fullyOccluded) {
bukkitPlayer.spawnParticle(Particle.DUST, bukkitLocation, 1, visualizerOptions);
bukkitPlayer.spawnParticle(DUST_PARTICLE, bukkitLocation, 1, visualizerOptions);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions bukkit/src/main/java/util/EnumUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package util;

import java.util.Optional;

public class EnumUtil {
public static <T extends Enum<T>> Optional<T> valueOf(final Class<T> enumClass, final String name) {
try {
return Optional.of(Enum.valueOf(enumClass, name));
} catch (IllegalArgumentException | NullPointerException e) {
return Optional.empty();
}
}
}

0 comments on commit a2d3926

Please sign in to comment.