Fixes 5 bugs.

Fixes SD-683
Fixes SD-810
Fixes SD-757
Added Mooshroom replant
Fixes SD-809
This commit is contained in:
Brian 2018-12-13 19:06:17 +01:00 committed by TheCreeperCow
parent 765d3c41b8
commit 624211fe0b
No known key found for this signature in database
GPG Key ID: C06A784885981FBD
5 changed files with 90 additions and 11 deletions

View File

@ -1,6 +1,8 @@
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;
@ -13,7 +15,13 @@ 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) {
Block mainLog = getMainLog(minedLog.getLocation());
Material oldMaterial = mainLog.getType();
Byte oldData = mainLog.getData();
Location mainLogLocation = mainLog.getLocation().clone();
for (Block block : blocks) {
@ -22,10 +30,12 @@ public class NoAnimationTreeDestroyer {
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 +50,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 +65,60 @@ 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());
}
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);
}
}

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;

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;
@ -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

@ -68,6 +68,12 @@ public class TreeReplant {
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);
}

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) {
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) {
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