mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-12-01 14:23:24 +01:00
Fix permission spam on tab complete, make wood materials drop logs
This commit is contained in:
parent
bcfdeabb2c
commit
6c788c216e
@ -59,15 +59,15 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (!(commandSender instanceof Player) || args.length == 0 || args.length > 1)
|
||||
if (args.length == 0 || args.length > 1)
|
||||
return completions;
|
||||
|
||||
Set<String> possibleCompletions = new HashSet<>();
|
||||
|
||||
if (permCheck((Player) commandSender, "ultimatetimber.reload"))
|
||||
if (commandSender.hasPermission("ultimatetimber.reload"))
|
||||
possibleCompletions.add("reload");
|
||||
|
||||
if (permCheck((Player) commandSender, "ultimatetimber.toggle"))
|
||||
if (commandSender.hasPermission("ultimatetimber.toggle") && commandSender instanceof Player)
|
||||
possibleCompletions.add("toggle");
|
||||
|
||||
StringUtil.copyPartialMatches(args[0], possibleCompletions, completions);
|
||||
|
@ -38,7 +38,7 @@ public class DefaultConfig {
|
||||
|
||||
Configuration configuration = plugin.getConfig();
|
||||
|
||||
configuration.addDefault(MAX_BRANCH_BLOCKS, 75);
|
||||
configuration.addDefault(MAX_BRANCH_BLOCKS, 100);
|
||||
configuration.addDefault(LEAVES_FOR_TREE, 5);
|
||||
configuration.addDefault(ONLY_BREAK_LOGS_UPWARDS, true);
|
||||
configuration.addDefault(ALLOW_MIXED_TREE_TYPES, false);
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.songoda.ultimatetimber.treefall;
|
||||
|
||||
import com.songoda.ultimatetimber.UltimateTimber;
|
||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
||||
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
@ -14,7 +11,10 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import com.songoda.ultimatetimber.UltimateTimber;
|
||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||
import com.songoda.ultimatetimber.events.TreeFallEvent;
|
||||
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
||||
|
||||
public class TreeFallListener implements Listener {
|
||||
|
||||
@ -26,9 +26,11 @@ public class TreeFallListener implements Listener {
|
||||
public void onTreeBreak(BlockBreakEvent event) {
|
||||
|
||||
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (event.getBlock() != null && event.getBlock().getType().name().contains("SAPLING") &&
|
||||
fileConfiguration.getBoolean(DefaultConfig.TIMEOUT_BREAK) && TreeReplant.isTimeout(event.getBlock()))
|
||||
if (block != null && block.getType().name().contains("SAPLING") &&
|
||||
fileConfiguration.getBoolean(DefaultConfig.TIMEOUT_BREAK) && TreeReplant.isTimeout(block))
|
||||
event.setCancelled(true);
|
||||
if (!EventFilter.eventIsValid(event)) return;
|
||||
if (fileConfiguration.getBoolean(DefaultConfig.SNEAK_ONLY) && !event.getPlayer().isSneaking()) return;
|
||||
@ -36,7 +38,7 @@ public class TreeFallListener implements Listener {
|
||||
if (!UltimateTimber.getInstance().isChopping(event.getPlayer())) return;
|
||||
|
||||
TreeChecker treeChecker = new TreeChecker();
|
||||
HashSet<Block> blocks = treeChecker.parseTree(event.getBlock());
|
||||
HashSet<Block> blocks = treeChecker.parseTree(block);
|
||||
|
||||
/*
|
||||
Previous list will be null if no valid tree is found
|
||||
@ -45,7 +47,7 @@ public class TreeFallListener implements Listener {
|
||||
return;
|
||||
|
||||
//Call event that tree will fall
|
||||
TreeFallEvent treeFallEvent = new TreeFallEvent(event.getPlayer(), treeChecker, event.getBlock());
|
||||
TreeFallEvent treeFallEvent = new TreeFallEvent(event.getPlayer(), treeChecker, block);
|
||||
Bukkit.getPluginManager().callEvent(treeFallEvent);
|
||||
if (treeFallEvent.isCancelled()) return;
|
||||
|
||||
@ -59,18 +61,18 @@ public class TreeFallListener implements Listener {
|
||||
if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY))
|
||||
AxeDurability.adjustAxeDamage(blocks, event.getPlayer());
|
||||
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))
|
||||
TreeSounds.tipOverNoise(event.getBlock().getLocation());
|
||||
TreeSounds.tipOverNoise(block.getLocation());
|
||||
|
||||
if (fileConfiguration.getBoolean(DefaultConfig.SHOW_ANIMATION)) {
|
||||
TreeFallAnimation treeFallAnimation = new TreeFallAnimation();
|
||||
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
|
||||
treeFallAnimation.startAnimation(block, blocks, event.getPlayer());
|
||||
} else {
|
||||
NoAnimationTreeDestroyer.destroyTree(blocks, event.getPlayer().hasPermission("ultimatetimber.bonusloot"),
|
||||
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH));
|
||||
}
|
||||
|
||||
//Call event that a tree has fell
|
||||
TreeFellEvent treeFellEvent = new TreeFellEvent(event.getPlayer(), treeChecker, event.getBlock());
|
||||
TreeFellEvent treeFellEvent = new TreeFellEvent(event.getPlayer(), treeChecker, block);
|
||||
Bukkit.getPluginManager().callEvent(treeFellEvent);
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
|
||||
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
|
||||
|
||||
class TreeLoot {
|
||||
|
||||
@ -75,7 +76,8 @@ class TreeLoot {
|
||||
break;
|
||||
|
||||
default:
|
||||
world.dropItem(location, new ItemStack(material, 1));
|
||||
Material dropMaterial = WoodToLogConverter.convert(material);
|
||||
world.dropItem(location, new ItemStack(dropMaterial, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.songoda.ultimatetimber.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class WoodToLogConverter {
|
||||
|
||||
private static Map<Material, Material> woodToLog;
|
||||
|
||||
static {
|
||||
woodToLog = new HashMap<>();
|
||||
woodToLog.put(Material.ACACIA_WOOD, Material.ACACIA_LOG);
|
||||
woodToLog.put(Material.STRIPPED_ACACIA_WOOD, Material.STRIPPED_ACACIA_LOG);
|
||||
woodToLog.put(Material.BIRCH_WOOD, Material.BIRCH_LOG);
|
||||
woodToLog.put(Material.STRIPPED_BIRCH_WOOD, Material.STRIPPED_BIRCH_LOG);
|
||||
woodToLog.put(Material.DARK_OAK_WOOD, Material.DARK_OAK_LOG);
|
||||
woodToLog.put(Material.STRIPPED_DARK_OAK_WOOD, Material.STRIPPED_DARK_OAK_LOG);
|
||||
woodToLog.put(Material.JUNGLE_WOOD, Material.JUNGLE_LOG);
|
||||
woodToLog.put(Material.STRIPPED_JUNGLE_WOOD, Material.STRIPPED_JUNGLE_LOG);
|
||||
woodToLog.put(Material.OAK_WOOD, Material.OAK_LOG);
|
||||
woodToLog.put(Material.STRIPPED_OAK_WOOD, Material.STRIPPED_OAK_LOG);
|
||||
woodToLog.put(Material.SPRUCE_WOOD, Material.SPRUCE_LOG);
|
||||
woodToLog.put(Material.STRIPPED_SPRUCE_WOOD, Material.STRIPPED_SPRUCE_LOG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Wood Material to its corresponding Log Material
|
||||
*
|
||||
* @param material The wood material
|
||||
* @return The corresonding log material
|
||||
*/
|
||||
public static Material convert(Material material) {
|
||||
Material converted = woodToLog.get(material);
|
||||
if (converted == null)
|
||||
return material;
|
||||
return converted;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user