mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-06-25 22:24:45 +02:00
Placeholder % addition, added setting, bug fixes
This commit is contained in:
parent
1c17042835
commit
bd3097422e
|
@ -124,7 +124,7 @@ public class CurrentAdapter implements VersionAdapter {
|
||||||
} else return;
|
} else return;
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, 0.25, 0.25, 0.25, blockData);
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,7 +137,7 @@ public class CurrentAdapter implements VersionAdapter {
|
||||||
} else return;
|
} else return;
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, 0.25, 0.25, 0.25, blockData);
|
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class LegacyAdapter implements VersionAdapter {
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
if (NMSUtil.getVersionNumber() > 8) {
|
if (NMSUtil.getVersionNumber() > 8) {
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, 0, 0, 0, blockDrops.iterator().next().getData());
|
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockDrops.iterator().next().getData());
|
||||||
} else {
|
} else {
|
||||||
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class LegacyAdapter implements VersionAdapter {
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
if (NMSUtil.getVersionNumber() > 8) {
|
if (NMSUtil.getVersionNumber() > 8) {
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, 0, 0, 0, blockDrops.iterator().next().getData());
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockDrops.iterator().next().getData());
|
||||||
} else {
|
} else {
|
||||||
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,13 @@ import java.util.Set;
|
||||||
public class TreeBlockSet<BlockType> implements Collection {
|
public class TreeBlockSet<BlockType> implements Collection {
|
||||||
|
|
||||||
private final ITreeBlock<BlockType> initialLogBlock;
|
private final ITreeBlock<BlockType> initialLogBlock;
|
||||||
private final Set<ITreeBlock<BlockType>> logBlocks;
|
private final Set<ITreeBlock<BlockType>> logBlocks, leafBlocks;
|
||||||
private final Set<ITreeBlock<BlockType>> leafBlocks;
|
|
||||||
|
public TreeBlockSet() {
|
||||||
|
this.initialLogBlock = null;
|
||||||
|
this.logBlocks = new HashSet<>();
|
||||||
|
this.leafBlocks = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
||||||
this.initialLogBlock = initialLogBlock;
|
this.initialLogBlock = initialLogBlock;
|
||||||
|
@ -154,6 +159,25 @@ public class TreeBlockSet<BlockType> implements Collection {
|
||||||
return removedAll;
|
return removedAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all tree blocks of a given type
|
||||||
|
*
|
||||||
|
* @param treeBlockType The type of tree block to remove
|
||||||
|
* @return If any blocks were removed
|
||||||
|
*/
|
||||||
|
public boolean removeAll(TreeBlockType treeBlockType) {
|
||||||
|
if (treeBlockType.equals(TreeBlockType.LOG)) {
|
||||||
|
boolean removedAny = !this.logBlocks.isEmpty();
|
||||||
|
this.logBlocks.clear();
|
||||||
|
return removedAny;
|
||||||
|
} else if (treeBlockType.equals(TreeBlockType.LEAF)) {
|
||||||
|
boolean removedAny = !this.leafBlocks.isEmpty();
|
||||||
|
this.leafBlocks.clear();
|
||||||
|
return removedAny;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAll(Collection c) {
|
public boolean containsAll(Collection c) {
|
||||||
for (Object o : c)
|
for (Object o : c)
|
||||||
|
|
|
@ -32,7 +32,7 @@ public abstract class TreeAnimation {
|
||||||
ItemStack itemInHand = UltimateTimber.getInstance().getVersionAdapter().getItemInHand(player);
|
ItemStack itemInHand = UltimateTimber.getInstance().getVersionAdapter().getItemInHand(player);
|
||||||
this.hasSilkTouch = itemInHand != null && itemInHand.hasItemMeta() && itemInHand.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH);
|
this.hasSilkTouch = itemInHand != null && itemInHand.hasItemMeta() && itemInHand.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH);
|
||||||
|
|
||||||
this.fallingTreeBlocks = null;
|
this.fallingTreeBlocks = new TreeBlockSet<>(); // Should be overridden in any subclasses that need to use it
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class ConfigurationManager extends Manager {
|
||||||
LEAVES_REQUIRED_FOR_TREE(SettingType.INT),
|
LEAVES_REQUIRED_FOR_TREE(SettingType.INT),
|
||||||
REALISTIC_TOOL_DAMAGE(SettingType.BOOLEAN),
|
REALISTIC_TOOL_DAMAGE(SettingType.BOOLEAN),
|
||||||
PROTECT_TOOL(SettingType.BOOLEAN),
|
PROTECT_TOOL(SettingType.BOOLEAN),
|
||||||
|
ALWAYS_REPLANT_SAPLING(SettingType.BOOLEAN),
|
||||||
BREAK_ENTIRE_TREE_BASE(SettingType.BOOLEAN),
|
BREAK_ENTIRE_TREE_BASE(SettingType.BOOLEAN),
|
||||||
DESTROY_INITIATED_BLOCK(SettingType.BOOLEAN),
|
DESTROY_INITIATED_BLOCK(SettingType.BOOLEAN),
|
||||||
ONLY_DETECT_LOGS_UPWARDS(SettingType.BOOLEAN),
|
ONLY_DETECT_LOGS_UPWARDS(SettingType.BOOLEAN),
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
||||||
public boolean isBlockInAnimation(Block block) {
|
public boolean isBlockInAnimation(Block block) {
|
||||||
for (TreeAnimation treeAnimation : this.activeAnimations)
|
for (TreeAnimation treeAnimation : this.activeAnimations)
|
||||||
for (ITreeBlock<Block> treeBlock : treeAnimation.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<Block> treeBlock : treeAnimation.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks())
|
||||||
if (treeBlock.getBlock().getLocation().equals(block.getLocation()))
|
if (treeBlock.getBlock().equals(block))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,11 +273,11 @@ public class TreeDefinitionManager extends Manager {
|
||||||
// Run looted commands
|
// Run looted commands
|
||||||
for (String lootedCommand : lootedCommands)
|
for (String lootedCommand : lootedCommands)
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
lootedCommand.replace("%player", player.getName())
|
lootedCommand.replace("%player%", player.getName())
|
||||||
.replace("%type", treeDefinition.getKey())
|
.replace("%type%", treeDefinition.getKey())
|
||||||
.replace("%xPos", treeBlock.getLocation().getBlockX() + "")
|
.replace("%xPos%", treeBlock.getLocation().getBlockX() + "")
|
||||||
.replace("%yPos", treeBlock.getLocation().getBlockY() + "")
|
.replace("%yPos%", treeBlock.getLocation().getBlockY() + "")
|
||||||
.replace("%zPos", treeBlock.getLocation().getBlockZ() + ""));
|
.replace("%zPos%", treeBlock.getLocation().getBlockZ() + ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class TreeDetectionManager extends Manager {
|
||||||
|
|
||||||
// Remove all leaves if applicable
|
// Remove all leaves if applicable
|
||||||
if (!this.destroyLeaves)
|
if (!this.destroyLeaves)
|
||||||
detectedTreeBlocks.removeAll(detectedTreeBlocks.getLeafBlocks());
|
detectedTreeBlocks.removeAll(TreeBlockType.LEAF);
|
||||||
|
|
||||||
return new DetectedTree(actualTreeDefinition, detectedTreeBlocks);
|
return new DetectedTree(actualTreeDefinition, detectedTreeBlocks);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,31 +53,45 @@ public class TreeFallManager extends Manager implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Condition checks
|
// Condition checks
|
||||||
|
boolean isValid = true;
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.DISABLED_WORLDS.getStringList().contains(player.getWorld().getName()))
|
if (ConfigurationManager.Setting.DISABLED_WORLDS.getStringList().contains(player.getWorld().getName()))
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (!ConfigurationManager.Setting.ALLOW_CREATIVE_MODE.getBoolean() && player.getGameMode().equals(GameMode.CREATIVE))
|
if (!ConfigurationManager.Setting.ALLOW_CREATIVE_MODE.getBoolean() && player.getGameMode().equals(GameMode.CREATIVE))
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.ONLY_TOPPLE_WHILE_SNEAKING.getBoolean() && !player.isSneaking())
|
if (ConfigurationManager.Setting.ONLY_TOPPLE_WHILE_SNEAKING.getBoolean() && !player.isSneaking())
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.REQUIRE_CHOP_PERMISSION.getBoolean() && !player.hasPermission("ultimatetimber.chop"))
|
if (ConfigurationManager.Setting.REQUIRE_CHOP_PERMISSION.getBoolean() && !player.hasPermission("ultimatetimber.chop"))
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (!choppingManager.isChopping(player))
|
if (!choppingManager.isChopping(player))
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (treeAnimationManager.isBlockInAnimation(block))
|
if (treeAnimationManager.isBlockInAnimation(block))
|
||||||
return;
|
isValid = false;
|
||||||
|
|
||||||
if (!treeDefinitionManager.isToolValidForAnyTreeDefinition(tool))
|
if (!treeDefinitionManager.isToolValidForAnyTreeDefinition(tool))
|
||||||
|
isValid = false;
|
||||||
|
|
||||||
|
boolean alwaysReplantSapling = ConfigurationManager.Setting.ALWAYS_REPLANT_SAPLING.getBoolean();
|
||||||
|
if (!isValid && !alwaysReplantSapling)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DetectedTree detectedTree = treeDetectionManager.detectTree(block);
|
DetectedTree detectedTree = treeDetectionManager.detectTree(block);
|
||||||
if (detectedTree == null)
|
if (detectedTree == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (alwaysReplantSapling) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.ultimateTimber, () ->
|
||||||
|
saplingManager.replantSapling(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock()));
|
||||||
|
|
||||||
|
if (!isValid)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool))
|
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ realistic-tool-damage: true
|
||||||
# Default: false
|
# Default: false
|
||||||
protect-tool: false
|
protect-tool: false
|
||||||
|
|
||||||
|
# Always replant saplings for base tree blocks, regardless of player permissions
|
||||||
|
# Default: false
|
||||||
|
always-replant-sapling: false
|
||||||
|
|
||||||
# Require the entire base of the tree to be broken before it topples
|
# Require the entire base of the tree to be broken before it topples
|
||||||
# Default: false
|
# Default: false
|
||||||
break-entire-tree-base: false
|
break-entire-tree-base: false
|
||||||
|
@ -312,11 +316,11 @@ global-log-loot:
|
||||||
material: DIAMOND
|
material: DIAMOND
|
||||||
chance: 0
|
chance: 0
|
||||||
1:
|
1:
|
||||||
command: 'eco give %player 5'
|
command: 'eco give %player% 5'
|
||||||
chance: 0
|
chance: 0
|
||||||
2:
|
2:
|
||||||
material: GOLDEN_APPLE
|
material: GOLDEN_APPLE
|
||||||
command: 'broadcast %player found a golden apple in a %type tree at %xPos %yPos %zPos!'
|
command: 'broadcast %player% found a golden apple in a %type% tree at %xPos% %yPos% %zPos%!'
|
||||||
chance: 0
|
chance: 0
|
||||||
|
|
||||||
# Custom loot that is available for all tree types
|
# Custom loot that is available for all tree types
|
||||||
|
|
|
@ -38,6 +38,10 @@ realistic-tool-damage: true
|
||||||
# Default: false
|
# Default: false
|
||||||
protect-tool: false
|
protect-tool: false
|
||||||
|
|
||||||
|
# Always replant saplings for base tree blocks, regardless of player permissions
|
||||||
|
# Default: false
|
||||||
|
always-replant-sapling: false
|
||||||
|
|
||||||
# Require the entire base of the tree to be broken before it topples
|
# Require the entire base of the tree to be broken before it topples
|
||||||
# Default: false
|
# Default: false
|
||||||
break-entire-tree-base: false
|
break-entire-tree-base: false
|
||||||
|
@ -294,11 +298,11 @@ global-log-loot:
|
||||||
material: DIAMOND
|
material: DIAMOND
|
||||||
chance: 0
|
chance: 0
|
||||||
1:
|
1:
|
||||||
command: 'eco give %player 5'
|
command: 'eco give %player% 5'
|
||||||
chance: 0
|
chance: 0
|
||||||
2:
|
2:
|
||||||
material: GOLDEN_APPLE
|
material: GOLDEN_APPLE
|
||||||
command: 'broadcast %player found a golden apple in a %type tree at %xPos %yPos %zPos!'
|
command: 'broadcast %player% found a golden apple in a %type% tree at %xPos% %yPos% %zPos%!'
|
||||||
chance: 0
|
chance: 0
|
||||||
|
|
||||||
# Custom loot that is available for all tree types
|
# Custom loot that is available for all tree types
|
||||||
|
|
Loading…
Reference in New Issue
Block a user