Added setting to prevent destroying leaves

This commit is contained in:
Esophose 2019-03-30 14:50:42 -06:00
parent f6a22966da
commit fdac6ef040
4 changed files with 23 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -16,11 +16,8 @@ public class TreeDetectionManager extends Manager {
private final Set<Vector> 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);
}

View File

@ -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

View File

@ -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