mirror of
https://github.com/songoda/UltimateTimber.git
synced 2025-02-27 09:01:29 +01: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;
|
||||
|
||||
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
|
||||
@ -137,7 +137,7 @@ public class CurrentAdapter implements VersionAdapter {
|
||||
} else return;
|
||||
|
||||
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
|
||||
|
@ -165,7 +165,7 @@ public class LegacyAdapter implements VersionAdapter {
|
||||
|
||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||
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 {
|
||||
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);
|
||||
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 {
|
||||
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
||||
}
|
||||
|
@ -9,8 +9,13 @@ import java.util.Set;
|
||||
public class TreeBlockSet<BlockType> implements Collection {
|
||||
|
||||
private final ITreeBlock<BlockType> initialLogBlock;
|
||||
private final Set<ITreeBlock<BlockType>> logBlocks;
|
||||
private final Set<ITreeBlock<BlockType>> leafBlocks;
|
||||
private final Set<ITreeBlock<BlockType>> logBlocks, leafBlocks;
|
||||
|
||||
public TreeBlockSet() {
|
||||
this.initialLogBlock = null;
|
||||
this.logBlocks = new HashSet<>();
|
||||
this.leafBlocks = new HashSet<>();
|
||||
}
|
||||
|
||||
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
||||
this.initialLogBlock = initialLogBlock;
|
||||
@ -154,6 +159,25 @@ public class TreeBlockSet<BlockType> implements Collection {
|
||||
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
|
||||
public boolean containsAll(Collection c) {
|
||||
for (Object o : c)
|
||||
|
@ -32,7 +32,7 @@ public abstract class TreeAnimation {
|
||||
ItemStack itemInHand = UltimateTimber.getInstance().getVersionAdapter().getItemInHand(player);
|
||||
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),
|
||||
REALISTIC_TOOL_DAMAGE(SettingType.BOOLEAN),
|
||||
PROTECT_TOOL(SettingType.BOOLEAN),
|
||||
ALWAYS_REPLANT_SAPLING(SettingType.BOOLEAN),
|
||||
BREAK_ENTIRE_TREE_BASE(SettingType.BOOLEAN),
|
||||
DESTROY_INITIATED_BLOCK(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) {
|
||||
for (TreeAnimation treeAnimation : this.activeAnimations)
|
||||
for (ITreeBlock<Block> treeBlock : treeAnimation.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks())
|
||||
if (treeBlock.getBlock().getLocation().equals(block.getLocation()))
|
||||
if (treeBlock.getBlock().equals(block))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -273,11 +273,11 @@ public class TreeDefinitionManager extends Manager {
|
||||
// Run looted commands
|
||||
for (String lootedCommand : lootedCommands)
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||
lootedCommand.replace("%player", player.getName())
|
||||
.replace("%type", treeDefinition.getKey())
|
||||
.replace("%xPos", treeBlock.getLocation().getBlockX() + "")
|
||||
.replace("%yPos", treeBlock.getLocation().getBlockY() + "")
|
||||
.replace("%zPos", treeBlock.getLocation().getBlockZ() + ""));
|
||||
lootedCommand.replace("%player%", player.getName())
|
||||
.replace("%type%", treeDefinition.getKey())
|
||||
.replace("%xPos%", treeBlock.getLocation().getBlockX() + "")
|
||||
.replace("%yPos%", treeBlock.getLocation().getBlockY() + "")
|
||||
.replace("%zPos%", treeBlock.getLocation().getBlockZ() + ""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,7 +143,7 @@ public class TreeDetectionManager extends Manager {
|
||||
|
||||
// Remove all leaves if applicable
|
||||
if (!this.destroyLeaves)
|
||||
detectedTreeBlocks.removeAll(detectedTreeBlocks.getLeafBlocks());
|
||||
detectedTreeBlocks.removeAll(TreeBlockType.LEAF);
|
||||
|
||||
return new DetectedTree(actualTreeDefinition, detectedTreeBlocks);
|
||||
}
|
||||
|
@ -53,31 +53,45 @@ public class TreeFallManager extends Manager implements Listener {
|
||||
}
|
||||
|
||||
// Condition checks
|
||||
boolean isValid = true;
|
||||
|
||||
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))
|
||||
return;
|
||||
isValid = false;
|
||||
|
||||
if (ConfigurationManager.Setting.ONLY_TOPPLE_WHILE_SNEAKING.getBoolean() && !player.isSneaking())
|
||||
return;
|
||||
isValid = false;
|
||||
|
||||
if (ConfigurationManager.Setting.REQUIRE_CHOP_PERMISSION.getBoolean() && !player.hasPermission("ultimatetimber.chop"))
|
||||
return;
|
||||
isValid = false;
|
||||
|
||||
if (!choppingManager.isChopping(player))
|
||||
return;
|
||||
isValid = false;
|
||||
|
||||
if (treeAnimationManager.isBlockInAnimation(block))
|
||||
return;
|
||||
isValid = false;
|
||||
|
||||
if (!treeDefinitionManager.isToolValidForAnyTreeDefinition(tool))
|
||||
isValid = false;
|
||||
|
||||
boolean alwaysReplantSapling = ConfigurationManager.Setting.ALWAYS_REPLANT_SAPLING.getBoolean();
|
||||
if (!isValid && !alwaysReplantSapling)
|
||||
return;
|
||||
|
||||
DetectedTree detectedTree = treeDetectionManager.detectTree(block);
|
||||
if (detectedTree == null)
|
||||
return;
|
||||
|
||||
if (alwaysReplantSapling) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.ultimateTimber, () ->
|
||||
saplingManager.replantSapling(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock()));
|
||||
|
||||
if (!isValid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool))
|
||||
return;
|
||||
|
||||
|
@ -37,6 +37,10 @@ realistic-tool-damage: true
|
||||
# Default: 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
|
||||
# Default: false
|
||||
break-entire-tree-base: false
|
||||
@ -312,11 +316,11 @@ global-log-loot:
|
||||
material: DIAMOND
|
||||
chance: 0
|
||||
1:
|
||||
command: 'eco give %player 5'
|
||||
command: 'eco give %player% 5'
|
||||
chance: 0
|
||||
2:
|
||||
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
|
||||
|
||||
# Custom loot that is available for all tree types
|
||||
|
@ -38,6 +38,10 @@ realistic-tool-damage: true
|
||||
# Default: 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
|
||||
# Default: false
|
||||
break-entire-tree-base: false
|
||||
@ -294,11 +298,11 @@ global-log-loot:
|
||||
material: DIAMOND
|
||||
chance: 0
|
||||
1:
|
||||
command: 'eco give %player 5'
|
||||
command: 'eco give %player% 5'
|
||||
chance: 0
|
||||
2:
|
||||
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
|
||||
|
||||
# Custom loot that is available for all tree types
|
||||
|
Loading…
Reference in New Issue
Block a user