2020-10-30 21:00:23 +01:00
|
|
|
package com.songoda.ultimatetimber.utils;
|
|
|
|
|
|
|
|
import com.songoda.core.compatibility.ServerVersion;
|
|
|
|
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Particle;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.data.BlockData;
|
|
|
|
import org.bukkit.entity.FallingBlock;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
public class ParticleUtils {
|
|
|
|
public static void playFallingParticles(ITreeBlock treeBlock) {
|
|
|
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
|
|
|
BlockData blockData;
|
|
|
|
if (treeBlock.getBlock() instanceof Block) {
|
|
|
|
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
|
|
|
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
|
|
|
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
2023-06-29 14:31:22 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-30 21:00:23 +01:00
|
|
|
|
|
|
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
|
|
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockData);
|
|
|
|
|
2023-06-29 14:31:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-10-30 21:00:23 +01:00
|
|
|
|
2023-06-29 14:31:22 +02:00
|
|
|
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
|
|
|
if (!blockDrops.iterator().hasNext()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
|
|
|
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
|
|
|
|
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
|
|
|
} else {
|
|
|
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockDrops.iterator().next().getData());
|
2020-10-30 21:00:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void playLandingParticles(ITreeBlock treeBlock) {
|
|
|
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
|
|
|
BlockData blockData;
|
|
|
|
if (treeBlock.getBlock() instanceof Block) {
|
|
|
|
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
|
|
|
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
|
|
|
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
2023-06-29 14:31:22 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-30 21:00:23 +01:00
|
|
|
|
|
|
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
|
|
|
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockData);
|
|
|
|
|
2023-06-29 14:31:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
|
|
|
if (!blockDrops.iterator().hasNext()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
|
|
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
|
|
|
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockDrops.iterator().next().getData());
|
|
|
|
} else {
|
|
|
|
location.getWorld().playEffect(location, Effect.SMOKE, 4);
|
2020-10-30 21:00:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|