From 7dea898d7e896fb0be8333e0fa3d567a248ea55c Mon Sep 17 00:00:00 2001 From: Th3Shadowbroker Date: Tue, 9 May 2023 18:04:02 +0200 Subject: [PATCH 1/3] Implement age check for plants --- .../ouroboros/mines/util/MaterialManager.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/MaterialManager.java b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/MaterialManager.java index 68ef8b8..d9c2ed9 100644 --- a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/MaterialManager.java +++ b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/MaterialManager.java @@ -26,6 +26,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; import java.util.ArrayList; import java.util.List; @@ -68,8 +69,20 @@ public Optional getMaterialProperties(Block block, Material ma .findFirst(); Optional regionCustomMineableMaterial = reducedMaterials(regionConfiguration.get().getMaterialList()).stream().filter(m -> validateCustom(block, m)).findFirst(); - if (regionCustomMineableMaterial.isPresent()) return regionCustomMineableMaterial; - if (regionMineableMaterial.isPresent()) return regionMineableMaterial; + if (regionCustomMineableMaterial.isPresent()) { + if (!canBeHarvested(block, regionCustomMineableMaterial.get())) + return Optional.empty(); + + return regionCustomMineableMaterial; + } + + if (regionMineableMaterial.isPresent()) { + if (!canBeHarvested(block, regionMineableMaterial.get())) + return Optional.empty(); + + return regionMineableMaterial; + } + if (!regionConfiguration.get().isInheritingDefaults()) return Optional.empty(); } @@ -86,6 +99,16 @@ private boolean validateCustom(Block block, MineableMaterial mineableMaterial) { return event.isCustom(); } + private boolean canBeHarvested(Block block, MineableMaterial material) { + if (block.getBlockData() instanceof Ageable ageable) { + if (material.hasProperties() && material.getProperties().containsKey("age")) { + var requiredAge = material.getProperties().get("age"); + return ageable.getAge() >= (int) requiredAge; + } + } + return true; + } + public List getMineableMaterials() { return minableMaterials; } From 26a5ebbfed980e15180e5e15b07d41a26f48c674 Mon Sep 17 00:00:00 2001 From: Th3Shadowbroker Date: Thu, 11 May 2023 18:08:57 +0200 Subject: [PATCH 2/3] Implement material properties --- .../mines/listeners/BlockBreakListener.java | 2 +- .../ouroboros/mines/util/ReplacementTask.java | 19 ++++++++++++++----- .../ouroboros/mines/util/WorldUtils.java | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/th3shadowbroker/ouroboros/mines/listeners/BlockBreakListener.java b/src/main/java/dev/th3shadowbroker/ouroboros/mines/listeners/BlockBreakListener.java index 49562be..124d41b 100644 --- a/src/main/java/dev/th3shadowbroker/ouroboros/mines/listeners/BlockBreakListener.java +++ b/src/main/java/dev/th3shadowbroker/ouroboros/mines/listeners/BlockBreakListener.java @@ -107,7 +107,7 @@ public void onBlockBreak(BlockBreakEvent event) { //If richness was never set or hit 0 if (!plugin.getTaskManager().hasPendingReplacementTask(event.getBlock())) { long cooldown = minedMaterial.get().getCooldown(); - new ReplacementTask(event.getBlock().getLocation(), event.getBlock().getType(), cooldown) + new ReplacementTask(event.getBlock().getLocation(), event.getBlock().getType(), cooldown, minedMaterial.get().getProperties()) .withMaterialIdentifier(minedMaterial.get().getMaterialIdentifier()); // Bamboo or Sugar cane? diff --git a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/ReplacementTask.java b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/ReplacementTask.java index 6776e99..2c1cfcc 100644 --- a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/ReplacementTask.java +++ b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/ReplacementTask.java @@ -21,17 +21,17 @@ import dev.th3shadowbroker.ouroboros.mines.OuroborosMines; import dev.th3shadowbroker.ouroboros.mines.events.thirdparty.itemsadder.PlaceCustomBlockEvent; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Ageable; import org.bukkit.block.data.BlockData; import org.bukkit.event.EventException; -import org.bukkit.plugin.RegisteredListener; import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; +import java.util.Map; import java.util.Optional; public class ReplacementTask implements Runnable { @@ -48,24 +48,28 @@ public class ReplacementTask implements Runnable { private MaterialIdentifier materialIdentifier; + private final Map properties; + private final OuroborosMines plugin = OuroborosMines.INSTANCE; - public ReplacementTask(Location blockLocation, Material material, long cooldownSeconds) { + public ReplacementTask(Location blockLocation, Material material, long cooldownSeconds, Map properties) { this.location = blockLocation; this.minedMaterial = material; this.task = plugin.getServer().getScheduler().runTaskLater(plugin, this, cooldownSeconds); this.plugin.getTaskManager().register(this); this.blockData = blockLocation.getBlock().getState().getBlockData(); this.isAttachableBlock = BlockUtils.isAttachable(location.getBlock()); + this.properties = properties; } - private ReplacementTask(Location blockLocation, Material material, BlockData blockData, long cooldownSeconds) { + private ReplacementTask(Location blockLocation, Material material, BlockData blockData, long cooldownSeconds, Map properties) { this.location = blockLocation; this.minedMaterial = material; this.task = plugin.getServer().getScheduler().runTaskLater(plugin, this, cooldownSeconds); this.plugin.getTaskManager().register(this); this.blockData = blockData; this.isAttachableBlock = BlockUtils.isAttachable(location.getBlock()); + this.properties = properties; } @Override @@ -89,6 +93,11 @@ public void run() { var identifier = Optional.ofNullable(materialIdentifier); if (identifier.isEmpty() || identifier.get().isInDefaultNamespace()) { location.getBlock().setType(minedMaterial); + + if (properties != null && properties.containsKey("resetAge")) { + var resetAge = (boolean) properties.get("resetAge"); + if (resetAge && blockData instanceof Ageable ageable) ageable.setAge(0); + } location.getBlock().setBlockData(blockData); } else { // Call has to be forced to guarantee execution after /stop command @@ -112,7 +121,7 @@ public void run() { } public void retryLater() { - new ReplacementTask(location, minedMaterial, blockData, plugin.getConfig().getInt("retryInterval", 5)); + new ReplacementTask(location, minedMaterial, blockData, plugin.getConfig().getInt("retryInterval", 5), properties); plugin.getTaskManager().unregister(this); } diff --git a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/WorldUtils.java b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/WorldUtils.java index e971686..eb5593a 100644 --- a/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/WorldUtils.java +++ b/src/main/java/dev/th3shadowbroker/ouroboros/mines/util/WorldUtils.java @@ -23,6 +23,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicLong; @@ -31,7 +32,7 @@ public class WorldUtils { public static void replaceInSequence(long offset, Material material, List blocks) { AtomicLong currentOffset = new AtomicLong(offset); for (Block block : blocks) { - new ReplacementTask(block.getLocation(), material, currentOffset.incrementAndGet()); + new ReplacementTask(block.getLocation(), material, currentOffset.incrementAndGet(), Collections.emptyMap()); } } From fec290c05de7debac7f5160078878e6535e76eb8 Mon Sep 17 00:00:00 2001 From: Th3Shadowbroker Date: Thu, 11 May 2023 18:09:33 +0200 Subject: [PATCH 3/3] Bump 1.12.3 -> 1.13.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e1023ed..6ec9b89 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ dev.th3shadowbroker.spigot OuroborosMines - 1.12.3-SNAPSHOT + 1.13.0-SNAPSHOT ${project.artifactId}