diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java index 8b44af9f..f11a92bf 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java @@ -29,6 +29,7 @@ import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.mechanic.totem.block.property.AxisImpl; import net.momirealms.customfishing.mechanic.totem.block.property.FaceImpl; import net.momirealms.customfishing.mechanic.totem.block.TotemBlock; +import net.momirealms.customfishing.mechanic.totem.block.property.HalfImpl; import net.momirealms.customfishing.mechanic.totem.block.property.TotemBlockProperty; import net.momirealms.customfishing.mechanic.totem.block.type.TypeCondition; import net.momirealms.customfishing.mechanic.totem.particle.DustParticleSetting; @@ -37,6 +38,7 @@ import net.momirealms.customfishing.util.LocationUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Bisected; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Event; @@ -393,14 +395,21 @@ public class TotemManagerImpl implements TotemManager, Listener { String key = split[0]; String value = split[1]; switch (key) { + // Block face case "face" -> { BlockFace blockFace = BlockFace.valueOf(value.toUpperCase(Locale.ENGLISH)); propertyList.add(new FaceImpl(blockFace)); } + // Block axis case "axis" -> { Axis axis = Axis.valueOf(value.toUpperCase(Locale.ENGLISH)); propertyList.add(new AxisImpl(axis)); } + // Slab, Stair half + case "half" -> { + Bisected.Half half = Bisected.Half.valueOf(value.toUpperCase(Locale.ENGLISH)); + propertyList.add(new HalfImpl(half)); + } } } } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/TotemBlock.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/TotemBlock.java index b97717b9..b189c62f 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/TotemBlock.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/TotemBlock.java @@ -67,6 +67,10 @@ public class TotemBlock implements Serializable { } } + /** + * Returns the raw text of the totem block. + * @return The raw text of the totem block. + */ @Override public String toString() { StringJoiner stringJoiner = new StringJoiner(";"); diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/AxisImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/AxisImpl.java index 449a9970..c242ae28 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/AxisImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/AxisImpl.java @@ -37,6 +37,10 @@ public class AxisImpl implements TotemBlockProperty, Serializable { return this; } + /** + * Rotates the block axis 90 degrees. (X -> Z, Z -> X) + * @return The rotated block axis. + */ @Override public TotemBlockProperty rotate90() { if (this.axis == Axis.X) { @@ -47,6 +51,11 @@ public class AxisImpl implements TotemBlockProperty, Serializable { return this; } + /** + * Checks if the block has the property. + * @param block The block to check. + * @return True if the block has the property. + */ @Override public boolean isPropertyMet(Block block) { if (block.getBlockData() instanceof Orientable orientable) { diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/FaceImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/FaceImpl.java index 1aea4fbf..171508bb 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/FaceImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/FaceImpl.java @@ -33,6 +33,11 @@ public class FaceImpl implements TotemBlockProperty, Serializable { this.blockFace = blockFace; } + /** + * Mirrors the block face if the axis is X or Z. + * @param axis The axis to mirror. + * @return The mirrored block face. + */ @Override public TotemBlockProperty mirror(Axis axis) { if (axis == Axis.X) { diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/HalfImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/HalfImpl.java new file mode 100644 index 00000000..2fa82d42 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/HalfImpl.java @@ -0,0 +1,57 @@ +package net.momirealms.customfishing.mechanic.totem.block.property; + +import org.bukkit.Axis; +import org.bukkit.block.Block; +import org.bukkit.block.data.Bisected; + +import java.io.Serializable; +import java.util.Locale; + +public class HalfImpl implements TotemBlockProperty, Serializable { + private final Bisected.Half half; + + public HalfImpl(Bisected.Half half) { + this.half = half; + } + + /** + * half is not affected by mirroring. + * @param axis The axis to mirror. + * @return this + */ + @Override + public TotemBlockProperty mirror(Axis axis) { + return this; + } + + /** + * half is not affected by rotation. + * @return this + */ + @Override + public TotemBlockProperty rotate90() { + return this; + } + + /** + * Checks if the block's half is the same as the half of this property. + * @param block The block to check. + * @return true if the block's half is the same as the half of this property. + */ + @Override + public boolean isPropertyMet(Block block) { + if (block.getBlockData() instanceof Bisected bisected) { + return bisected.getHalf().equals(this.half); + } + return false; + } + + /** + * Returns the raw text of the half property. + * @return The raw text of the half property. + */ + @Override + public String getRawText() { + return "half=" + half.name().toLowerCase(Locale.ENGLISH); + } +} diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/TotemBlockProperty.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/TotemBlockProperty.java index 43c02903..22a554bf 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/TotemBlockProperty.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/totem/block/property/TotemBlockProperty.java @@ -22,12 +22,29 @@ import org.bukkit.block.Block; public interface TotemBlockProperty { - + /** + * Mirrors the block face if the axis is X or Z. + * @param axis The axis to mirror. + * @return The mirrored block face. + */ TotemBlockProperty mirror(Axis axis); + /** + * Rotates the block face 90 degrees. + * @return The rotated block face. + */ TotemBlockProperty rotate90(); + /** + * Checks if the block has the property. + * @param block The block to check. + * @return True if the block has the property. + */ boolean isPropertyMet(Block block); + /** + * Gets the raw text of the property. + * @return The raw text of the property. + */ String getRawText(); } diff --git a/plugin/src/main/resources/contents/totem/default.yml b/plugin/src/main/resources/contents/totem/default.yml index 72aa7177..79f01737 100644 --- a/plugin/src/main/resources/contents/totem/default.yml +++ b/plugin/src/main/resources/contents/totem/default.yml @@ -5,7 +5,7 @@ double_loot_totem: core: 3,1,2 # layer:3 line:1 index:2 -> CRYING_OBSIDIAN layer: 4: - - '*_STAIRS{face=east} OBSERVER{face=south} *_STAIRS{face=west}' + - '*_STAIRS{face=east;half=top} OBSERVER{face=south} *_STAIRS{face=west;half=top}' 3: - 'AIR CRYING_OBSIDIAN AIR' 2: