Bug Fixes

This commit is contained in:
Brian 2018-12-18 16:12:26 +02:00
parent cbf4f1ba0e
commit 5ea8dfe9e6
3 changed files with 37 additions and 47 deletions

View File

@ -7,6 +7,7 @@ import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
import com.songoda.ultimatetimber.treefall.TreeFallEvent;
import com.songoda.ultimatetimber.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
@ -31,7 +32,11 @@ public class UltimateTimber extends JavaPlugin {
@Override
public void onEnable() {
if (!checkVersion()) return;
INSTANCE = this;
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
@ -82,4 +87,20 @@ public class UltimateTimber extends JavaPlugin {
public String getPrefix() {
return prefix;
}
private boolean checkVersion() {
int workingVersion = 13;
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
.getPackage().getName().split("\\.")[3].split("_")[1]);
if (currentVersion < workingVersion) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(String.format("%sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s.", ChatColor.RED, workingVersion, this.getDescription().getName(), currentVersion, this.getDescription().getName()));
Bukkit.getConsoleSender().sendMessage("");
}, 20L);
return false;
}
return true;
}
}

View File

@ -17,7 +17,7 @@ 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, Block minedLog) {
public static void destroyTree(HashSet<Block> blocks, boolean hasBonusLoot, boolean hasSilkTouch) {
Material leavesType = null;
@ -27,17 +27,10 @@ public class NoAnimationTreeDestroyer {
} 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;
@ -45,15 +38,6 @@ public class NoAnimationTreeDestroyer {
ItemStack toDrop = getItem(material);
if (hasSilkTouch) {
if (hasBonusLoot)
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
CustomLoot.doCustomItemDrop(block.getLocation());
block.setType(Material.AIR);
continue;
}
if (material.equals(Material.ACACIA_SAPLING) ||
material.equals(Material.BIRCH_SAPLING) ||
material.equals(Material.DARK_OAK_SAPLING) ||
@ -77,6 +61,15 @@ public class NoAnimationTreeDestroyer {
}
if (hasSilkTouch) {
if (hasBonusLoot)
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
CustomLoot.doCustomItemDrop(block.getLocation());
block.setType(Material.AIR);
continue;
}
if (hasBonusLoot)
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
block.getWorld().dropItem(block.getLocation(), toDrop.clone());
@ -85,38 +78,14 @@ public class NoAnimationTreeDestroyer {
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();
if(leavesType != null){
TreeReplant.replaceOriginalBlock(block, leavesType);
} else{
TreeReplant.replaceOriginalBlock(block);
}
}
}
return toReturn;
}

View File

@ -53,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.getBlock());
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH));
}
}