Tree animation disintegrate added

This commit is contained in:
Esophose 2019-03-30 15:56:22 -06:00
parent fdac6ef040
commit d00668bfbb
5 changed files with 108 additions and 26 deletions

View File

@ -13,6 +13,7 @@ import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
@ -94,27 +95,39 @@ public class CurrentAdapter implements VersionAdapter {
}
@Override
public void playFallingParticles(TreeBlockSet<Block> treeBlocks) {
for (ITreeBlock<Block> treeBlock : treeBlocks.getAllTreeBlocks()) {
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, treeBlock.getBlock().getBlockData());
}
}
public void playFallingParticles(ITreeBlock treeBlock) {
BlockData blockData;
if (treeBlock.getBlock() instanceof Block) {
blockData = ((Block)treeBlock.getBlock()).getBlockData();
} else if (treeBlock.getBlock() instanceof FallingBlock) {
blockData = ((FallingBlock)treeBlock.getBlock()).getBlockData();
} else return;
@Override
public void playLandingParticles(FallingTreeBlock treeBlock) {
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, treeBlock.getBlock().getBlockData());
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, 0.25, 0.25, 0.25, blockData);
}
@Override
public void playFallingSound(TreeBlockSet<Block> treeBlocks) {
Location location = treeBlocks.getInitialLogBlock().getLocation();
public void playLandingParticles(ITreeBlock treeBlock) {
BlockData blockData;
if (treeBlock.getBlock() instanceof Block) {
blockData = ((Block)treeBlock.getBlock()).getBlockData();
} else if (treeBlock.getBlock() instanceof FallingBlock) {
blockData = ((FallingBlock)treeBlock.getBlock()).getBlockData();
} 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);
}
@Override
public void playFallingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 3F, 0.1F);
}
@Override
public void playLandingSound(FallingTreeBlock treeBlock) {
public void playLandingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
location.getWorld().playSound(location, Sound.BLOCK_WOOD_FALL, 3F, 0.1F);
}

View File

@ -59,18 +59,18 @@ public class LegacyAdapter implements VersionAdapter {
}
@Override
public void playFallingParticles(TreeBlockSet<Block> treeBlocks) {
public void playFallingParticles(ITreeBlock treeBlock) {
}
@Override
public void playLandingParticles(FallingTreeBlock treeBlock) {
public void playLandingParticles(ITreeBlock treeBlock) {
}
@Override
public void playFallingSound(TreeBlockSet<Block> treeBlocks) {
Location location = treeBlocks.getInitialLogBlock().getLocation();
public void playFallingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 3F, 0.1F);
} else {
@ -79,7 +79,7 @@ public class LegacyAdapter implements VersionAdapter {
}
@Override
public void playLandingSound(FallingTreeBlock treeBlock) {
public void playLandingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_WOOD_FALL, 3F, 0.1F);

View File

@ -75,27 +75,31 @@ public interface VersionAdapter {
void removeItemInHand(Player player);
/**
* Plays particles to indicate a tree has started falling
* Plays particles to indicate a tree block has started falling
*
* @param treeBlock The TreeBlock to play the particles for
*/
void playFallingParticles(TreeBlockSet<Block> treeBlocks);
void playFallingParticles(ITreeBlock treeBlock);
/**
* Plays particles to indicate a tree block has hit the ground
*
* @param treeBlock The TreeBlock to play the particles for
*/
void playLandingParticles(FallingTreeBlock treeBlock);
void playLandingParticles(ITreeBlock treeBlock);
/**
* Plays a sound to indicate a tree block has started falling
*
* @param treeBlocks The TreeBlocks to play the sound for
* @param treeBlock The TreeBlock to play the sound for
*/
void playFallingSound(TreeBlockSet<Block> treeBlocks);
void playFallingSound(ITreeBlock treeBlock);
/**
* Plays a sound to indicate a tree block has hit the ground
*
* @param treeBlock The FallingTreeBlock to play the sound for
* @param treeBlock The TreeBlock to play the sound for
*/
void playLandingSound(FallingTreeBlock treeBlock);
void playLandingSound(ITreeBlock treeBlock);
}

View File

@ -1,10 +1,19 @@
package com.songoda.ultimatetimber.animation;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.manager.ConfigurationManager;
import com.songoda.ultimatetimber.manager.TreeDefinitionManager;
import com.songoda.ultimatetimber.tree.DetectedTree;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
public class TreeAnimationDisintegrate extends TreeAnimation {
@ -14,7 +23,62 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
@Override
public void playAnimation(Runnable whenFinished) {
UltimateTimber ultimateTimber = UltimateTimber.getInstance();
TreeDefinitionManager treeDefinitionManager = ultimateTimber.getTreeDefinitionManager();
VersionAdapter versionAdapter = ultimateTimber.getVersionAdapter();
boolean useCustomSound = ConfigurationManager.Setting.USE_CUSTOM_SOUNDS.getBoolean();
boolean useCustomParticles = ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean();
if (useCustomSound)
versionAdapter.playFallingSound(this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
List<ITreeBlock<Block>> orderedLogBlocks = new ArrayList<>(this.detectedTree.getDetectedTreeBlocks().getLogBlocks());
orderedLogBlocks.sort(Comparator.comparingInt(x -> x.getLocation().getBlockY()));
List<ITreeBlock<Block>> leafBlocks = new ArrayList<>(this.detectedTree.getDetectedTreeBlocks().getLeafBlocks());
Collections.shuffle(leafBlocks);
Player p = this.player;
TreeDefinition td = this.detectedTree.getTreeDefinition();
new BukkitRunnable() {
@Override
public void run() {
List<ITreeBlock<Block>> toDestroy = new ArrayList<>();
if (!orderedLogBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = orderedLogBlocks.get(0);
orderedLogBlocks.remove(treeBlock);
toDestroy.add(treeBlock);
} else if (!leafBlocks.isEmpty()) {
ITreeBlock<Block> treeBlock = leafBlocks.get(0);
leafBlocks.remove(treeBlock);
toDestroy.add(treeBlock);
if (!leafBlocks.isEmpty()) {
treeBlock = leafBlocks.get(0);
leafBlocks.remove(treeBlock);
toDestroy.add(treeBlock);
}
}
if (!toDestroy.isEmpty()) {
ITreeBlock<Block> first = toDestroy.get(0);
if (useCustomSound)
versionAdapter.playLandingSound(first);
for (ITreeBlock<Block> treeBlock : toDestroy) {
if (useCustomParticles)
versionAdapter.playFallingParticles(treeBlock);
treeDefinitionManager.dropTreeLoot(td, treeBlock, p);
TreeAnimationDisintegrate.this.replaceBlock(treeBlock.getBlock());
}
} else {
this.cancel();
}
}
}.runTaskTimer(ultimateTimber, 0, 1);
}
}

View File

@ -23,10 +23,11 @@ public class TreeAnimationNone extends TreeAnimation {
VersionAdapter versionAdapter = UltimateTimber.getInstance().getVersionAdapter();
if (ConfigurationManager.Setting.USE_CUSTOM_SOUNDS.getBoolean())
versionAdapter.playFallingSound(this.detectedTree.getDetectedTreeBlocks());
versionAdapter.playFallingSound(this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
if (ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean())
versionAdapter.playFallingParticles(this.detectedTree.getDetectedTreeBlocks());
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks())
versionAdapter.playFallingParticles(treeBlock);
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks()) {
treeDefinitionManager.dropTreeLoot(this.detectedTree.getTreeDefinition(), treeBlock, this.player);