diff --git a/.gitignore b/.gitignore index 83befcb..a39a7a2 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,25 @@ target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles\.ls target/UltimateTimber\.jar UltimateTimber\.iml + +\.idea/compiler\.xml + +\.idea/encodings\.xml + +\.idea/vcs\.xml + +target/classes/com/songoda/ultimatetimber/treefall/CustomLoot\.class + +target/classes/com/songoda/ultimatetimber/treefall/NoAnimationTreeDestroyer\.class + +target/classes/com/songoda/ultimatetimber/utils/LeafToSaplingConverter\.class + +target/classes/com/songoda/ultimatetimber/utils/LeafToSaplingConverter\$1\.class + +target/classes/com/songoda/ultimatetimber/utils/LogToLeafConverter\.class + +target/classes/com/songoda/ultimatetimber/utils/LogToLeafConverter\$1\.class + +target/classes/com/songoda/ultimatetimber/utils/Methods\.class + +target/classes/config\.yml diff --git a/src/main/java/com/songoda/ultimatetimber/configurations/DefaultConfig.java b/src/main/java/com/songoda/ultimatetimber/configurations/DefaultConfig.java index df4e764..14e1c8e 100644 --- a/src/main/java/com/songoda/ultimatetimber/configurations/DefaultConfig.java +++ b/src/main/java/com/songoda/ultimatetimber/configurations/DefaultConfig.java @@ -20,6 +20,7 @@ public class DefaultConfig { Also they are easier to refer to using an IDE. */ public static final String AXES_ONLY = "Only topple down trees cut down using axes"; + public static final String TIMEOUT_BREAK = "Five second time out before you can break saplings"; public static final String SNEAK_ONLY = "Only topple down trees cut down while sneaking"; public static final String ACCURATE_AXE_DURABILITY = "Lower durability proportionately to the amount of blocks toppled down"; public static final String CREATIVE_DISALLOWED = "Players in creative mode can't topple down trees"; @@ -39,6 +40,7 @@ public class DefaultConfig { Configuration configuration = plugin.getConfig(); configuration.addDefault(AXES_ONLY, true); + configuration.addDefault(TIMEOUT_BREAK, true); configuration.addDefault(SNEAK_ONLY, false); configuration.addDefault(ACCURATE_AXE_DURABILITY, true); configuration.addDefault(CREATIVE_DISALLOWED, true); diff --git a/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java b/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java index 09cec22..c0c22ed 100644 --- a/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java +++ b/src/main/java/com/songoda/ultimatetimber/treefall/TreeFallEvent.java @@ -21,10 +21,17 @@ public class TreeFallEvent implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onTreeBreak(BlockBreakEvent event) { + FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig(); + + if (event.getBlock() != null && event.getBlock().getType().name().contains("SAPLING") && + fileConfiguration.getBoolean(DefaultConfig.TIMEOUT_BREAK) && TreeReplant.isTimeout(event.getBlock())) + event.setCancelled(true); + if (!EventFilter.eventIsValid(event)) return; TreeChecker treeChecker = new TreeChecker(); HashSet blocks = treeChecker.validTreeHandler(event.getBlock()); + /* Previous list will be null if no valid tree is found */ @@ -34,7 +41,6 @@ public class TreeFallEvent implements Listener { /* Everything beyond this point assumes that the tree was valid */ - FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig(); if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY)) AxeDurability.adjustAxeDamage(blocks, event.getPlayer()); @@ -49,7 +55,6 @@ public class TreeFallEvent implements Listener { event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)); } - } } diff --git a/src/main/java/com/songoda/ultimatetimber/treefall/TreeReplant.java b/src/main/java/com/songoda/ultimatetimber/treefall/TreeReplant.java index a60fa4b..1e3e269 100644 --- a/src/main/java/com/songoda/ultimatetimber/treefall/TreeReplant.java +++ b/src/main/java/com/songoda/ultimatetimber/treefall/TreeReplant.java @@ -2,18 +2,26 @@ package com.songoda.ultimatetimber.treefall; import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.configurations.DefaultConfig; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.FallingBlock; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class TreeReplant { + private static List timeout = new ArrayList<>(); + public static void replaceOriginalBlock(Block block) { + boolean isTimeout = UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.TIMEOUT_BREAK); + if (!UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.REPLANT_SAPLING)) { block.setType(Material.AIR); return; @@ -27,6 +35,11 @@ public class TreeReplant { Material material = block.getType(); + if (isTimeout) { + timeout.add(block.getLocation()); + Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateTimber.getInstance(), () -> timeout.remove(block.getLocation()), 20 * 5); + } + new BukkitRunnable() { @Override public void run() { @@ -107,4 +120,8 @@ public class TreeReplant { } + public static boolean isTimeout(Block block) { + return timeout.contains(block.getLocation()); + } + }