mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-09-27 13:22:39 +02:00
Add setting to scatter tree blocks on the ground
This commit is contained in:
parent
82e8c064f4
commit
5c3ac55fde
@ -16,8 +16,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import com.songoda.ultimatetimber.commands.CommandHandler;
|
import com.songoda.ultimatetimber.commands.CommandHandler;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||||
import com.songoda.ultimatetimber.hooks.HookManager;
|
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.CustomLoot;
|
||||||
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
||||||
import com.songoda.ultimatetimber.treefall.TreeFallListener;
|
import com.songoda.ultimatetimber.treefall.TreeFallListener;
|
||||||
|
@ -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 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 CUSTOM_AUDIO = "Use custom sounds for trees falling";
|
||||||
public static final String SHOW_ANIMATION = "Show tree fall animation";
|
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_LIST = "Custom loot";
|
||||||
public static final String CUSTOM_LOOT_ITEM = "Material:GOLDEN_APPLE,Chance:1";
|
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(REPLANT_FROM_LEAVES, true);
|
||||||
configuration.addDefault(CUSTOM_AUDIO, true);
|
configuration.addDefault(CUSTOM_AUDIO, true);
|
||||||
configuration.addDefault(SHOW_ANIMATION, true);
|
configuration.addDefault(SHOW_ANIMATION, true);
|
||||||
|
configuration.addDefault(SCATTER_FALLEN_BLOCKS, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add all worlds that exist in the world at startup
|
Add all worlds that exist in the world at startup
|
||||||
|
@ -2,6 +2,7 @@ package com.songoda.ultimatetimber.treefall;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -27,6 +28,7 @@ public class TreeFallAnimation implements Listener, Runnable {
|
|||||||
Register all instances of falling trees.
|
Register all instances of falling trees.
|
||||||
*/
|
*/
|
||||||
private static ArrayList<TreeFallAnimation> treeFallAnimationInstances = new ArrayList<>();
|
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
|
This field gets updated based on player permissions, doubles loot from trees
|
||||||
*/
|
*/
|
||||||
@ -251,12 +253,19 @@ public class TreeFallAnimation implements Listener, Runnable {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void blockDrop(EntityChangeBlockEvent event) {
|
public void blockDrop(EntityChangeBlockEvent event) {
|
||||||
|
|
||||||
if (!(event.getEntity() instanceof FallingBlock)) return;
|
if (!(event.getEntity() instanceof FallingBlock)) return;
|
||||||
if (!isInTreeFallInstance((FallingBlock) event.getEntity())) return;
|
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
|
||||||
|
if (!isInTreeFallInstance(fallingBlock)) return;
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
|
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) {
|
private void runFallingBlockImpact(FallingBlock fallingBlock) {
|
||||||
|
@ -16,8 +16,6 @@ import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
|||||||
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
||||||
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
||||||
import com.songoda.ultimatetimber.hooks.HookManager;
|
import com.songoda.ultimatetimber.hooks.HookManager;
|
||||||
import com.songoda.ultimatetimber.hooks.JobsRebornHook;
|
|
||||||
import com.songoda.ultimatetimber.hooks.McMMOHook;
|
|
||||||
|
|
||||||
public class TreeFallListener implements Listener {
|
public class TreeFallListener implements Listener {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user