mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-06-26 06:34:50 +02:00
Fixes 5 bugs.
Fixes SD-683 Fixes SD-810 Fixes SD-757 Added Mooshroom replant Fixes SD-809
This commit is contained in:
parent
765d3c41b8
commit
624211fe0b
|
@ -1,6 +1,8 @@
|
||||||
package com.songoda.ultimatetimber.treefall;
|
package com.songoda.ultimatetimber.treefall;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
|
import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
|
||||||
|
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.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -13,7 +15,13 @@ public class NoAnimationTreeDestroyer {
|
||||||
/*
|
/*
|
||||||
Only ever triggers when people have tree falling animations off in the config
|
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) {
|
||||||
|
|
||||||
|
Block mainLog = getMainLog(minedLog.getLocation());
|
||||||
|
|
||||||
|
Material oldMaterial = mainLog.getType();
|
||||||
|
Byte oldData = mainLog.getData();
|
||||||
|
Location mainLogLocation = mainLog.getLocation().clone();
|
||||||
|
|
||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
|
|
||||||
|
@ -22,10 +30,12 @@ public class NoAnimationTreeDestroyer {
|
||||||
if (material.equals(Material.AIR)) continue;
|
if (material.equals(Material.AIR)) continue;
|
||||||
if (material.equals(Material.VINE)) continue;
|
if (material.equals(Material.VINE)) continue;
|
||||||
|
|
||||||
|
ItemStack toDrop = getItem(material);
|
||||||
|
|
||||||
if (hasSilkTouch) {
|
if (hasSilkTouch) {
|
||||||
if (hasBonusLoot)
|
if (hasBonusLoot)
|
||||||
block.getWorld().dropItem(block.getLocation(), new ItemStack(block.getType(), 1));
|
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
|
||||||
block.getWorld().dropItem(block.getLocation(), new ItemStack(block.getType(), 1));
|
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
|
||||||
CustomLoot.doCustomItemDrop(block.getLocation());
|
CustomLoot.doCustomItemDrop(block.getLocation());
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
continue;
|
continue;
|
||||||
|
@ -40,9 +50,9 @@ public class NoAnimationTreeDestroyer {
|
||||||
|
|
||||||
if (ThreadLocalRandom.current().nextDouble() < 0.05) {
|
if (ThreadLocalRandom.current().nextDouble() < 0.05) {
|
||||||
if (hasBonusLoot) {
|
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);
|
block.setType(Material.AIR);
|
||||||
CustomLoot.doCustomItemDrop(block.getLocation());
|
CustomLoot.doCustomItemDrop(block.getLocation());
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,13 +65,60 @@ public class NoAnimationTreeDestroyer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasBonusLoot)
|
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);
|
block.setType(Material.AIR);
|
||||||
CustomLoot.doCustomItemDrop(block.getLocation());
|
CustomLoot.doCustomItemDrop(block.getLocation());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mainLogLocation.getBlock().getType() == Material.AIR) {
|
||||||
|
TreeReplant.replaceOriginalBlock(mainLogLocation.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,15 @@ public class TreeChecker {
|
||||||
|
|
||||||
boolean containsLeaves = false;
|
boolean containsLeaves = false;
|
||||||
|
|
||||||
for (Block localBlock : blocks)
|
for (Block localBlock : blocks) {
|
||||||
if (TreeChecker.validTreeMaterials.contains(localBlock.getType())) {
|
if (TreeChecker.validTreeMaterials.contains(localBlock.getType())) {
|
||||||
containsLeaves = true;
|
containsLeaves = true;
|
||||||
break;
|
break;
|
||||||
|
} else if(TreeChecker.validMaterials.contains(localBlock.getType())){
|
||||||
|
containsLeaves = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!containsLeaves)
|
if (!containsLeaves)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ 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.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
@ -52,7 +53,7 @@ public class TreeFallEvent implements Listener {
|
||||||
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
|
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
|
||||||
} else {
|
} else {
|
||||||
NoAnimationTreeDestroyer.destroyTree(blocks, event.getPlayer().hasPermission("ultimatetimber.bonusloot"),
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,12 @@ public class TreeReplant {
|
||||||
case STRIPPED_SPRUCE_LOG:
|
case STRIPPED_SPRUCE_LOG:
|
||||||
block.setType(Material.SPRUCE_SAPLING);
|
block.setType(Material.SPRUCE_SAPLING);
|
||||||
return;
|
return;
|
||||||
|
case BROWN_MUSHROOM_BLOCK:
|
||||||
|
block.setType(Material.BROWN_MUSHROOM);
|
||||||
|
return;
|
||||||
|
case RED_MUSHROOM_BLOCK:
|
||||||
|
block.setType(Material.RED_MUSHROOM);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.songoda.ultimatetimber.treefall;
|
package com.songoda.ultimatetimber.treefall;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
|
@ -8,11 +9,22 @@ public class TreeSounds {
|
||||||
|
|
||||||
public static void tipOverNoise(Location location) {
|
public static void tipOverNoise(Location location) {
|
||||||
|
|
||||||
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 3F, 0.1F);
|
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) {
|
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)
|
if (fallingBlock.getTicksLived() < 20)
|
||||||
fallingBlock.getWorld().playSound(fallingBlock.getLocation(), Sound.BLOCK_ANVIL_FALL, 3F, 0.1F);
|
fallingBlock.getWorld().playSound(fallingBlock.getLocation(), Sound.BLOCK_ANVIL_FALL, 3F, 0.1F);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user