Add setting to scatter tree blocks on the ground

This commit is contained in:
Esophose 2019-02-16 01:08:34 -07:00
parent 82e8c064f4
commit 5c3ac55fde
4 changed files with 15 additions and 8 deletions

View File

@ -16,8 +16,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.songoda.ultimatetimber.commands.CommandHandler;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.hooks.HookManager;
import com.songoda.ultimatetimber.hooks.JobsRebornHook;
import com.songoda.ultimatetimber.hooks.McMMOHook;
import com.songoda.ultimatetimber.treefall.CustomLoot;
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
import com.songoda.ultimatetimber.treefall.TreeFallListener;

View File

@ -31,6 +31,7 @@ public class DefaultConfig {
public static final String REPLANT_FROM_LEAVES = "Fallen leaves have a chance to plant saplings";
public static final String CUSTOM_AUDIO = "Use custom sounds for trees falling";
public static final String SHOW_ANIMATION = "Show tree fall animation";
public static final String SCATTER_FALLEN_BLOCKS = "Scatter fallen tree blocks on the ground when animated";
public static final String CUSTOM_LOOT_LIST = "Custom loot";
public static final String CUSTOM_LOOT_ITEM = "Material:GOLDEN_APPLE,Chance:1";
@ -55,6 +56,7 @@ public class DefaultConfig {
configuration.addDefault(REPLANT_FROM_LEAVES, true);
configuration.addDefault(CUSTOM_AUDIO, true);
configuration.addDefault(SHOW_ANIMATION, true);
configuration.addDefault(SCATTER_FALLEN_BLOCKS, false);
/*
Add all worlds that exist in the world at startup

View File

@ -2,6 +2,7 @@ package com.songoda.ultimatetimber.treefall;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
@ -27,6 +28,7 @@ public class TreeFallAnimation implements Listener, Runnable {
Register all instances of falling trees.
*/
private static ArrayList<TreeFallAnimation> treeFallAnimationInstances = new ArrayList<>();
private static Random random = new Random();
/*
This field gets updated based on player permissions, doubles loot from trees
*/
@ -251,12 +253,19 @@ public class TreeFallAnimation implements Listener, Runnable {
*/
@EventHandler
public void blockDrop(EntityChangeBlockEvent event) {
if (!(event.getEntity() instanceof FallingBlock)) return;
if (!isInTreeFallInstance((FallingBlock) event.getEntity())) return;
event.setCancelled(true);
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
if (!isInTreeFallInstance(fallingBlock)) return;
if (UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.SCATTER_FALLEN_BLOCKS)) {
boolean isLeaf = fallingBlock.getBlockData().getMaterial().name().endsWith("LEAVES");
if (!isLeaf || (isLeaf && random.nextDouble() > 0.5)) { // Only let about half the leafs turn back into blocks
getTreeFallAnimation(fallingBlock).unregisterFallingBlock(fallingBlock);
return;
}
}
event.setCancelled(true);
}
private void runFallingBlockImpact(FallingBlock fallingBlock) {

View File

@ -16,8 +16,6 @@ import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.events.TreeFallEvent;
import com.songoda.ultimatetimber.events.TreeFellEvent;
import com.songoda.ultimatetimber.hooks.HookManager;
import com.songoda.ultimatetimber.hooks.JobsRebornHook;
import com.songoda.ultimatetimber.hooks.McMMOHook;
public class TreeFallListener implements Listener {