five seconds before breaking saplings.

This commit is contained in:
Brianna O'Keefe 2018-12-05 05:26:10 -05:00
parent 3a0b05c987
commit 6123a7465b
4 changed files with 48 additions and 2 deletions

22
.gitignore vendored
View File

@ -72,3 +72,25 @@ target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles\.ls
target/UltimateTimber\.jar target/UltimateTimber\.jar
UltimateTimber\.iml 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

View File

@ -20,6 +20,7 @@ public class DefaultConfig {
Also they are easier to refer to using an IDE. 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 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 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 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"; 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 configuration = plugin.getConfig();
configuration.addDefault(AXES_ONLY, true); configuration.addDefault(AXES_ONLY, true);
configuration.addDefault(TIMEOUT_BREAK, true);
configuration.addDefault(SNEAK_ONLY, false); configuration.addDefault(SNEAK_ONLY, false);
configuration.addDefault(ACCURATE_AXE_DURABILITY, true); configuration.addDefault(ACCURATE_AXE_DURABILITY, true);
configuration.addDefault(CREATIVE_DISALLOWED, true); configuration.addDefault(CREATIVE_DISALLOWED, true);

View File

@ -21,10 +21,17 @@ public class TreeFallEvent implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onTreeBreak(BlockBreakEvent event) { 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; if (!EventFilter.eventIsValid(event)) return;
TreeChecker treeChecker = new TreeChecker(); TreeChecker treeChecker = new TreeChecker();
HashSet<Block> blocks = treeChecker.validTreeHandler(event.getBlock()); HashSet<Block> blocks = treeChecker.validTreeHandler(event.getBlock());
/* /*
Previous list will be null if no valid tree is found 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 Everything beyond this point assumes that the tree was valid
*/ */
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY)) if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY))
AxeDurability.adjustAxeDamage(blocks, event.getPlayer()); AxeDurability.adjustAxeDamage(blocks, event.getPlayer());
@ -49,7 +55,6 @@ public class TreeFallEvent implements Listener {
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)); event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH));
} }
} }
} }

View File

@ -2,18 +2,26 @@ package com.songoda.ultimatetimber.treefall;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.configurations.DefaultConfig; import com.songoda.ultimatetimber.configurations.DefaultConfig;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class TreeReplant { public class TreeReplant {
private static List<Location> timeout = new ArrayList<>();
public static void replaceOriginalBlock(Block block) { public static void replaceOriginalBlock(Block block) {
boolean isTimeout = UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.TIMEOUT_BREAK);
if (!UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.REPLANT_SAPLING)) { if (!UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.REPLANT_SAPLING)) {
block.setType(Material.AIR); block.setType(Material.AIR);
return; return;
@ -27,6 +35,11 @@ public class TreeReplant {
Material material = block.getType(); Material material = block.getType();
if (isTimeout) {
timeout.add(block.getLocation());
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateTimber.getInstance(), () -> timeout.remove(block.getLocation()), 20 * 5);
}
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -107,4 +120,8 @@ public class TreeReplant {
} }
public static boolean isTimeout(Block block) {
return timeout.contains(block.getLocation());
}
} }