Fix permission spam on tab complete, make wood materials drop logs

This commit is contained in:
Esophose 2019-02-09 14:27:43 -07:00
parent bcfdeabb2c
commit 6c788c216e
5 changed files with 62 additions and 17 deletions

View File

@ -59,15 +59,15 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
List<String> completions = new ArrayList<>(); List<String> completions = new ArrayList<>();
if (!(commandSender instanceof Player) || args.length == 0 || args.length > 1) if (args.length == 0 || args.length > 1)
return completions; return completions;
Set<String> possibleCompletions = new HashSet<>(); Set<String> possibleCompletions = new HashSet<>();
if (permCheck((Player) commandSender, "ultimatetimber.reload")) if (commandSender.hasPermission("ultimatetimber.reload"))
possibleCompletions.add("reload"); possibleCompletions.add("reload");
if (permCheck((Player) commandSender, "ultimatetimber.toggle")) if (commandSender.hasPermission("ultimatetimber.toggle") && commandSender instanceof Player)
possibleCompletions.add("toggle"); possibleCompletions.add("toggle");
StringUtil.copyPartialMatches(args[0], possibleCompletions, completions); StringUtil.copyPartialMatches(args[0], possibleCompletions, completions);

View File

@ -38,7 +38,7 @@ public class DefaultConfig {
Configuration configuration = plugin.getConfig(); Configuration configuration = plugin.getConfig();
configuration.addDefault(MAX_BRANCH_BLOCKS, 75); configuration.addDefault(MAX_BRANCH_BLOCKS, 100);
configuration.addDefault(LEAVES_FOR_TREE, 5); configuration.addDefault(LEAVES_FOR_TREE, 5);
configuration.addDefault(ONLY_BREAK_LOGS_UPWARDS, true); configuration.addDefault(ONLY_BREAK_LOGS_UPWARDS, true);
configuration.addDefault(ALLOW_MIXED_TREE_TYPES, false); configuration.addDefault(ALLOW_MIXED_TREE_TYPES, false);

View File

@ -1,9 +1,6 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.treefall;
import com.songoda.ultimatetimber.UltimateTimber; import java.util.HashSet;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.events.TreeFallEvent;
import com.songoda.ultimatetimber.events.TreeFellEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -14,7 +11,10 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; 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 { public class TreeFallListener implements Listener {
@ -27,8 +27,10 @@ public class TreeFallListener implements Listener {
FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig(); FileConfiguration fileConfiguration = UltimateTimber.getInstance().getConfig();
if (event.getBlock() != null && event.getBlock().getType().name().contains("SAPLING") && Block block = event.getBlock();
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); event.setCancelled(true);
if (!EventFilter.eventIsValid(event)) return; if (!EventFilter.eventIsValid(event)) return;
if (fileConfiguration.getBoolean(DefaultConfig.SNEAK_ONLY) && !event.getPlayer().isSneaking()) 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; if (!UltimateTimber.getInstance().isChopping(event.getPlayer())) return;
TreeChecker treeChecker = new TreeChecker(); 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 Previous list will be null if no valid tree is found
@ -45,7 +47,7 @@ public class TreeFallListener implements Listener {
return; return;
//Call event that tree will fall //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); Bukkit.getPluginManager().callEvent(treeFallEvent);
if (treeFallEvent.isCancelled()) return; if (treeFallEvent.isCancelled()) return;
@ -59,18 +61,18 @@ public class TreeFallListener implements Listener {
if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY)) if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY))
AxeDurability.adjustAxeDamage(blocks, event.getPlayer()); AxeDurability.adjustAxeDamage(blocks, event.getPlayer());
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO)) if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))
TreeSounds.tipOverNoise(event.getBlock().getLocation()); TreeSounds.tipOverNoise(block.getLocation());
if (fileConfiguration.getBoolean(DefaultConfig.SHOW_ANIMATION)) { if (fileConfiguration.getBoolean(DefaultConfig.SHOW_ANIMATION)) {
TreeFallAnimation treeFallAnimation = new TreeFallAnimation(); TreeFallAnimation treeFallAnimation = new TreeFallAnimation();
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer()); treeFallAnimation.startAnimation(block, 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));
} }
//Call event that a tree has fell //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); Bukkit.getPluginManager().callEvent(treeFellEvent);
} }

View File

@ -9,6 +9,7 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.songoda.ultimatetimber.utils.LeafToSaplingConverter; import com.songoda.ultimatetimber.utils.LeafToSaplingConverter;
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
class TreeLoot { class TreeLoot {
@ -75,7 +76,8 @@ class TreeLoot {
break; break;
default: default:
world.dropItem(location, new ItemStack(material, 1)); Material dropMaterial = WoodToLogConverter.convert(material);
world.dropItem(location, new ItemStack(dropMaterial, 1));
break; break;
} }
} }

View File

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