Merge branch 'OOP-778-master' into 'master'

Resolve OOP-778 "Master"

Closes OOP-778, SD-683, SD-810, SD-757, and SD-809

See merge request Songoda/ultimatetimber!5
This commit is contained in:
Lars Dormans 2018-12-17 21:56:32 +00:00
commit 9c8229a9dd
15 changed files with 213 additions and 22 deletions

1
.gitignore vendored
View File

@ -104,3 +104,4 @@ target/classes/config\.yml
\.idea/libraries/Maven__org_yaml_snakeyaml_1_18\.xml
target/classes/com/songoda/ultimatetimber/utils/VersionChecker\.class
target/UltimateTimber-maven-version-number.jar

View File

@ -3,11 +3,23 @@ package com.songoda.ultimatetimber.commands;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.treefall.CustomLoot;
import com.songoda.ultimatetimber.utils.Methods;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ReloadCommand {
public static void reloadConfig(CommandSender commandSender) {
if(commandSender instanceof Player){
if(!commandSender.hasPermission("ut.reload")){
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou don't have permission!"));
return;
}
}
UltimateTimber plugin = UltimateTimber.getInstance();
plugin.reloadConfig();
CustomLoot.initializeCustomItems();

View File

@ -31,6 +31,8 @@ public class CustomLoot {
public static void initializeCustomItems() {
itemMap.clear();
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
List<String> arrayList = (List<String>) fileConfiguration.getList(DefaultConfig.CUSTOM_LOOT_LIST);

View File

@ -1,31 +1,54 @@
package com.songoda.ultimatetimber.treefall;
import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import sun.reflect.generics.tree.Tree;
import java.util.HashSet;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class NoAnimationTreeDestroyer {
/*
Only ever triggers when people have tree falling animations off in the config
*/
public static void destroyTree(HashSet<Block> blocks, boolean hasBonusLoot, boolean hasSilkTouch) {
public static void destroyTree(HashSet<Block> blocks, boolean hasBonusLoot, boolean hasSilkTouch, Block minedLog) {
Material leavesType = null;
if(!blocks.stream().filter(b -> b.getType() == Material.BROWN_MUSHROOM_BLOCK).collect(Collectors.toList()).isEmpty()){
leavesType = Material.BROWN_MUSHROOM_BLOCK;
} else if(!blocks.stream().filter(b -> b.getType() == Material.RED_MUSHROOM_BLOCK).collect(Collectors.toList()).isEmpty()){
leavesType = Material.RED_MUSHROOM_BLOCK;
} else {
}
for (Block block : blocks) {
if(leavesType != null){
TreeReplant.replaceOriginalBlock(block, leavesType);
} else{
TreeReplant.replaceOriginalBlock(block);
}
Material material = LeafToSaplingConverter.convertLeaves(block.getType());
if (material.equals(Material.AIR)) continue;
if (material.equals(Material.VINE)) continue;
ItemStack toDrop = getItem(material);
if (hasSilkTouch) {
if (hasBonusLoot)
block.getWorld().dropItem(block.getLocation(), new ItemStack(block.getType(), 1));
block.getWorld().dropItem(block.getLocation(), new ItemStack(block.getType(), 1));
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
CustomLoot.doCustomItemDrop(block.getLocation());
block.setType(Material.AIR);
continue;
@ -40,9 +63,9 @@ public class NoAnimationTreeDestroyer {
if (ThreadLocalRandom.current().nextDouble() < 0.05) {
if (hasBonusLoot) {
block.getWorld().dropItem(block.getLocation(), new ItemStack(material, 1));
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
}
block.getWorld().dropItem(block.getLocation(), new ItemStack(material, 1));
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.setType(Material.AIR);
CustomLoot.doCustomItemDrop(block.getLocation());
continue;
@ -55,13 +78,57 @@ public class NoAnimationTreeDestroyer {
}
if (hasBonusLoot)
block.getWorld().dropItem(block.getLocation(), new ItemStack(material, 1));
block.getWorld().dropItem(block.getLocation(), new ItemStack(material, 1));
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.setType(Material.AIR);
CustomLoot.doCustomItemDrop(block.getLocation());
}
}
static Block getMainLog(Location loc){
int maxHeight = 7;
Location clonedLocation = loc.getBlock().getLocation();
Block toReturn = null;
Location check1 = clonedLocation.clone();
if(check1.add(0,-1,0).getBlock().getType() != loc.getBlock().getType()){
return clonedLocation.getBlock();
}
for(int i = 0; i < maxHeight;i++){
if(clonedLocation.add(0,-1,0).getBlock().getType() == loc.getBlock().getType()){
Location secondClone = clonedLocation.clone();
if(secondClone.add(0,-1,0).getBlock().getType() != loc.getBlock().getType()){
toReturn = clonedLocation.getBlock();
}
}
}
return toReturn;
}
static ItemStack getItem(Material material){
if(material == Material.BROWN_MUSHROOM_BLOCK){
return new ItemStack(Material.BROWN_MUSHROOM, 1);
} else if(material == Material.RED_MUSHROOM_BLOCK){
return new ItemStack(Material.RED_MUSHROOM, 1);
}
return new ItemStack(material, 1);
}
}

View File

@ -24,12 +24,15 @@ public class TreeChecker {
boolean containsLeaves = false;
for (Block localBlock : blocks)
for (Block localBlock : blocks) {
if (TreeChecker.validTreeMaterials.contains(localBlock.getType())) {
containsLeaves = true;
break;
} else if(TreeChecker.validMaterials.contains(localBlock.getType())){
containsLeaves = true;
break;
}
}
if (!containsLeaves)
return null;
@ -54,7 +57,7 @@ public class TreeChecker {
offset determines the search radius around the main trunk
maxheight sets the maximum height the plugin will crawl through to find a tree
*/
int offset = 5;
int offset = 7;
int maxHeight = 31;
/*
@ -138,11 +141,11 @@ public class TreeChecker {
int radMin, radMax;
if (i > 5) {
radMin = -3;
radMax = 4;
radMin = -4;
radMax = 6;
} else {
radMin = -2;
radMax = 3;
radMin = -3;
radMax = 5;
}

View File

@ -128,9 +128,10 @@ public class TreeFallAnimation implements Listener {
for (Block block : blocks) {
FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getBlockData());
FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation().clone().add(0.5,0,0.5), block.getBlockData());
fallingBlock.setDropItem(false);
registerFallingBlock(fallingBlock);
/*

View File

@ -2,6 +2,7 @@ package com.songoda.ultimatetimber.treefall;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
@ -26,12 +27,12 @@ public class TreeFallEvent implements Listener {
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(fileConfiguration.getBoolean(DefaultConfig.SNEAK_ONLY) && !event.getPlayer().isSneaking()) return;
TreeChecker treeChecker = new TreeChecker();
HashSet<Block> blocks = treeChecker.validTreeHandler(event.getBlock());
/*
Previous list will be null if no valid tree is found
*/
@ -52,7 +53,7 @@ public class TreeFallEvent implements Listener {
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
} else {
NoAnimationTreeDestroyer.destroyTree(blocks, event.getPlayer().hasPermission("ultimatetimber.bonusloot"),
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH));
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH), event.getBlock());
}
}

View File

@ -4,6 +4,7 @@ import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
import org.bukkit.Material;
import org.bukkit.entity.FallingBlock;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import java.util.concurrent.ThreadLocalRandom;

View File

@ -20,6 +20,7 @@ public class TreeReplant {
public static void replaceOriginalBlock(Block block) {
boolean isTimeout = UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.TIMEOUT_BREAK);
if (!UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.REPLANT_SAPLING)) {
@ -28,7 +29,71 @@ public class TreeReplant {
}
if (!block.getLocation().clone().subtract(new Vector(0, 1, 0)).getBlock().getType().equals(Material.DIRT) &&
!block.getLocation().clone().subtract(new Vector(0, 1, 0)).getBlock().getType().equals(Material.COARSE_DIRT)) {
!block.getLocation().clone().subtract(new Vector(0, 1, 0)).getBlock().getType().equals(Material.COARSE_DIRT) && !block.getLocation().clone().subtract(new Vector(0,1,0)).getBlock().getType().equals(Material.PODZOL)) {
block.setType(Material.AIR);
return;
}
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() {
switch (material) {
case ACACIA_LOG:
case STRIPPED_ACACIA_LOG:
block.setType(Material.ACACIA_SAPLING);
return;
case BIRCH_LOG:
case STRIPPED_BIRCH_LOG:
block.setType(Material.BIRCH_SAPLING);
return;
case DARK_OAK_LOG:
case STRIPPED_DARK_OAK_LOG:
block.setType(Material.DARK_OAK_SAPLING);
return;
case JUNGLE_LOG:
case STRIPPED_JUNGLE_LOG:
block.setType(Material.JUNGLE_SAPLING);
return;
case OAK_LOG:
case STRIPPED_OAK_LOG:
block.setType(Material.OAK_SAPLING);
return;
case SPRUCE_LOG:
case STRIPPED_SPRUCE_LOG:
block.setType(Material.SPRUCE_SAPLING);
return;
case BROWN_MUSHROOM_BLOCK:
block.setType(Material.BROWN_MUSHROOM);
return;
case RED_MUSHROOM_BLOCK:
block.setType(Material.RED_MUSHROOM);
return;
default:
block.setType(Material.AIR);
}
}
}.runTaskLater(UltimateTimber.getInstance(), 1);
}
public static void replaceOriginalBlock(Block block, Material leavesType) {
boolean isTimeout = UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.TIMEOUT_BREAK);
if (!UltimateTimber.getInstance().getConfig().getBoolean(DefaultConfig.REPLANT_SAPLING)) {
block.setType(Material.AIR);
return;
}
if (!block.getLocation().clone().subtract(new Vector(0, 1, 0)).getBlock().getType().equals(Material.DIRT) &&
!block.getLocation().clone().subtract(new Vector(0, 1, 0)).getBlock().getType().equals(Material.COARSE_DIRT) && !block.getLocation().clone().subtract(new Vector(0,1,0)).getBlock().getType().equals(Material.PODZOL)) {
block.setType(Material.AIR);
return;
}
@ -69,9 +134,15 @@ public class TreeReplant {
block.setType(Material.SPRUCE_SAPLING);
return;
default:
if(leavesType == Material.BROWN_MUSHROOM_BLOCK){
block.setType(Material.BROWN_MUSHROOM);
} else if(leavesType == Material.RED_MUSHROOM_BLOCK){
block.setType(Material.RED_MUSHROOM);
} else{
block.setType(Material.AIR);
}
}
}
}.runTaskLater(UltimateTimber.getInstance(), 1);
}

View File

@ -1,5 +1,6 @@
package com.songoda.ultimatetimber.treefall;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.FallingBlock;
@ -8,11 +9,22 @@ public class TreeSounds {
public static void tipOverNoise(Location location) {
if(Bukkit.getServer().getClass().getPackage().toString().contains("8")){
location.getWorld().playSound(location, Sound.valueOf("CHEST_OPEN"), 3f,0.1f);
} else {
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 3F, 0.1F);
}
}
public static void fallNoise(FallingBlock fallingBlock) {
if(Bukkit.getServer().getClass().getPackage().toString().contains("8")){
fallingBlock.getWorld().playSound(fallingBlock.getLocation(), Sound.valueOf("ANVIL_LAND"), 3F, 0.1F);
return;
}
if (fallingBlock.getTicksLived() < 20)
fallingBlock.getWorld().playSound(fallingBlock.getLocation(), Sound.BLOCK_ANVIL_FALL, 3F, 0.1F);
else

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,2 @@
com\songoda\ultimatetimber\treefall\TreeReplant$3.class
com\songoda\ultimatetimber\utils\VersionChecker.class

View File

@ -0,0 +1,18 @@
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\CustomLoot.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeSounds.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\NoAnimationTreeDestroyer.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\commands\CommandHandler.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeFallEvent.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeFallAnimation.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\configurations\DefaultConfig.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeEntityDamage.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\commands\ReloadCommand.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\utils\Methods.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeLoot.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\utils\VersionChecker.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\utils\LeafToSaplingConverter.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeChecker.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\UltimateTimber.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\AxeDurability.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\TreeReplant.java
G:\work\ultimatetimber\src\main\java\com\songoda\ultimatetimber\treefall\EventFilter.java