From fdac6ef04063b44bdf482e196158b9ca95c5fdf7 Mon Sep 17 00:00:00 2001 From: Esophose Date: Sat, 30 Mar 2019 14:50:42 -0600 Subject: [PATCH] Added setting to prevent destroying leaves --- .../manager/ConfigurationManager.java | 13 ++++++++----- .../manager/TreeDetectionManager.java | 12 +++++++----- .../Plugin/src/main/resources/config-current.yml | 4 ++++ .../Plugin/src/main/resources/config-legacy.yml | 4 ++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/ConfigurationManager.java b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/ConfigurationManager.java index 8fa20c1..1c9b8d9 100644 --- a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/ConfigurationManager.java +++ b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/ConfigurationManager.java @@ -2,6 +2,7 @@ package com.songoda.ultimatetimber.manager; import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.adapter.VersionAdapterType; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; @@ -13,6 +14,7 @@ public class ConfigurationManager extends Manager { SERVER_TYPE(SettingType.STRING), DISABLED_WORLDS(SettingType.STRING_LIST), MAX_LOGS_PER_CHOP(SettingType.INT), + DESTROY_LEAVES(SettingType.BOOLEAN), LEAVES_REQUIRED_FOR_TREE(SettingType.INT), REALISTIC_TOOL_DAMAGE(SettingType.BOOLEAN), PROTECT_TOOL(SettingType.BOOLEAN), @@ -109,21 +111,22 @@ public class ConfigurationManager extends Manager { if (this.value != null) return; + FileConfiguration config = UltimateTimber.getInstance().getConfigurationManager().getConfig(); switch (this.settingType) { case BOOLEAN: - this.value = UltimateTimber.getInstance().getConfigurationManager().getConfig().getBoolean(this.getNameAsKey()); + this.value = config.getBoolean(this.getNameAsKey()); break; case INT: - this.value = UltimateTimber.getInstance().getConfigurationManager().getConfig().getInt(this.getNameAsKey()); + this.value = config.getInt(this.getNameAsKey()); break; case DOUBLE: - this.value = UltimateTimber.getInstance().getConfigurationManager().getConfig().getDouble(this.getNameAsKey()); + this.value = config.getDouble(this.getNameAsKey()); break; case STRING: - this.value = UltimateTimber.getInstance().getConfigurationManager().getConfig().getString(this.getNameAsKey()); + this.value = config.getString(this.getNameAsKey()); break; case STRING_LIST: - this.value = UltimateTimber.getInstance().getConfigurationManager().getConfig().getStringList(this.getNameAsKey()); + this.value = config.getStringList(this.getNameAsKey()); break; } } diff --git a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDetectionManager.java b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDetectionManager.java index 2fbe2bd..52e078b 100644 --- a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDetectionManager.java +++ b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDetectionManager.java @@ -16,11 +16,8 @@ public class TreeDetectionManager extends Manager { private final Set VALID_TRUNK_OFFSETS, VALID_BRANCH_OFFSETS, VALID_LEAF_OFFSETS; private TreeDefinitionManager treeDefinitionManager; - private int maxBranchBlocksAllowed; - private int numLeavesRequiredForTree; - private boolean onlyBreakLogsUpwards; - private boolean destroyBaseLog; - private boolean entireTreeBase; + private int maxBranchBlocksAllowed, numLeavesRequiredForTree; + private boolean onlyBreakLogsUpwards, destroyBaseLog, entireTreeBase, destroyLeaves; public TreeDetectionManager(UltimateTimber ultimateTimber) { super(ultimateTimber); @@ -57,6 +54,7 @@ public class TreeDetectionManager extends Manager { this.onlyBreakLogsUpwards = ConfigurationManager.Setting.ONLY_DETECT_LOGS_UPWARDS.getBoolean(); this.destroyBaseLog = ConfigurationManager.Setting.DESTROY_INITIATED_BLOCK.getBoolean(); this.entireTreeBase = ConfigurationManager.Setting.BREAK_ENTIRE_TREE_BASE.getBoolean(); + this.destroyLeaves = ConfigurationManager.Setting.DESTROY_LEAVES.getBoolean(); } @Override @@ -138,6 +136,10 @@ public class TreeDetectionManager extends Manager { if (this.destroyBaseLog) detectedTreeBlocks.remove(initialTreeBlock); + // Remove all leaves if applicable + if (!this.destroyLeaves) + detectedTreeBlocks.removeAll(detectedTreeBlocks.getLeafBlocks()); + return new DetectedTree(actualTreeDefinition, detectedTreeBlocks); } diff --git a/UltimateTimber/Plugin/src/main/resources/config-current.yml b/UltimateTimber/Plugin/src/main/resources/config-current.yml index 6fe2023..9a450ed 100644 --- a/UltimateTimber/Plugin/src/main/resources/config-current.yml +++ b/UltimateTimber/Plugin/src/main/resources/config-current.yml @@ -23,6 +23,10 @@ max-logs-per-chop: 120 # Default: 5 leaves-required-for-tree: 5 +# If leaves should be destroyed +# Default: true +destroy-leaves: true + # Apply realistic damage to the tools based on the number of logs chopped # If false, only one durability will be removed from the tool # Default: true diff --git a/UltimateTimber/Plugin/src/main/resources/config-legacy.yml b/UltimateTimber/Plugin/src/main/resources/config-legacy.yml index a253806..86f4a77 100644 --- a/UltimateTimber/Plugin/src/main/resources/config-legacy.yml +++ b/UltimateTimber/Plugin/src/main/resources/config-legacy.yml @@ -24,6 +24,10 @@ max-logs-per-chop: 120 # Default: 5 leaves-required-for-tree: 5 +# If leaves should be destroyed +# Default: true +destroy-leaves: true + # Apply realistic damage to the tools based on the number of logs chopped # If false, only one durability will be removed from the tool # Default: true