mirror of
https://github.com/SimplexDevelopment/ToolAssist.git
synced 2024-12-22 07:57:37 +00:00
Alpha 1.0 RC02
- Adjusted things for QoL purposes. - Added TabCompletion to the tool assist command.
This commit is contained in:
parent
f1989e1bbe
commit
805f765434
@ -9,24 +9,29 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public final class ToolAssist extends JavaPlugin {
|
public final class ToolAssist extends JavaPlugin {
|
||||||
|
|
||||||
private Config config;
|
private Config config;
|
||||||
|
private Command_toolassist command;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
getLogger().info("Initializing configuration...");
|
getLogger().info("Initializing configuration...");
|
||||||
this.config = new Config(this);
|
config = new Config(this);
|
||||||
getLogger().info("Configuration loaded! Registering listener...");
|
getLogger().info("Configuration loaded! Registering listener...");
|
||||||
new MineListener(this);
|
new MineListener(this);
|
||||||
getLogger().info("Listener registered successfully! Loading command...");
|
getLogger().info("Listener registered successfully! Loading command...");
|
||||||
new Command_toolassist(this);
|
command = new Command_toolassist(this);
|
||||||
getLogger().info("Initialization complete!");
|
getLogger().info("Initialization complete!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
this.config.osave();
|
getLogger().info("Saving configuration...");
|
||||||
this.config = null;
|
config.osave();
|
||||||
getLogger().info("Goodbye!");
|
config = null;
|
||||||
|
getLogger().info("Configuration saved successfully. Unregistering the command...");
|
||||||
|
command.unregister();
|
||||||
|
command = null;
|
||||||
|
getLogger().info("Termination complete. Goodbye!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,8 @@ package io.github.simplex.toolassist.data;
|
|||||||
|
|
||||||
import io.github.simplex.toolassist.ToolAssist;
|
import io.github.simplex.toolassist.ToolAssist;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public class BlockIdentifier {
|
|||||||
|
|
||||||
public boolean checkBlock(Block block, ItemStack targetItem) {
|
public boolean checkBlock(Block block, ItemStack targetItem) {
|
||||||
if (plugin.getConfig().getSettings().noConfig()) {
|
if (plugin.getConfig().getSettings().noConfig()) {
|
||||||
return block.isValidTool(targetItem);
|
return block.isValidTool(targetItem) && all.stream().anyMatch(a -> a.isTagged(block.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBlockConfig(block, targetItem);
|
checkBlockConfig(block, targetItem);
|
||||||
@ -71,4 +73,20 @@ public class BlockIdentifier {
|
|||||||
}
|
}
|
||||||
isValid = false;
|
isValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tag<Material>> all = List.of(Tag.COAL_ORES,
|
||||||
|
Tag.COPPER_ORES,
|
||||||
|
Tag.GOLD_ORES,
|
||||||
|
Tag.IRON_ORES,
|
||||||
|
Tag.DIAMOND_ORES,
|
||||||
|
Tag.LAPIS_ORES,
|
||||||
|
Tag.EMERALD_ORES,
|
||||||
|
Tag.REDSTONE_ORES,
|
||||||
|
Tag.SAND,
|
||||||
|
Tag.CAVE_VINES,
|
||||||
|
Tag.WART_BLOCKS,
|
||||||
|
Tag.LOGS,
|
||||||
|
Tag.LOGS_THAT_BURN,
|
||||||
|
Tag.LEAVES,
|
||||||
|
Tag.WARPED_STEMS);
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,16 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class Command_toolassist extends Command implements PluginIdentifiableCommand {
|
public class Command_toolassist extends Command implements PluginIdentifiableCommand, TabCompleter {
|
||||||
private final ToolAssist plugin;
|
private final ToolAssist plugin;
|
||||||
|
|
||||||
public Command_toolassist(ToolAssist plugin) {
|
public Command_toolassist(ToolAssist plugin) {
|
||||||
@ -56,7 +60,7 @@ public class Command_toolassist extends Command implements PluginIdentifiableCom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("tool")) {
|
if (args[0].equalsIgnoreCase("tools")) {
|
||||||
if (args.length != 4) return false;
|
if (args.length != 4) return false;
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("add")) {
|
if (args[1].equalsIgnoreCase("add")) {
|
||||||
@ -93,4 +97,42 @@ public class Command_toolassist extends Command implements PluginIdentifiableCom
|
|||||||
public @NotNull ToolAssist getPlugin() {
|
public @NotNull ToolAssist getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
switch (args.length) {
|
||||||
|
case 1 -> {
|
||||||
|
completions = List.of("tools", "plugin");
|
||||||
|
}
|
||||||
|
case 2 -> {
|
||||||
|
if (args[0].equalsIgnoreCase("tools")) {
|
||||||
|
completions = List.of("add", "remove");
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("plugin")) {
|
||||||
|
completions = List.of("permission", "radius", "sneak", "use_config");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 3 -> {
|
||||||
|
if (args[0].equalsIgnoreCase("tools")) {
|
||||||
|
if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
|
||||||
|
completions = Stream.of("pickaxe", "axe", "sword", "shears", "shovel", "hoe").sorted().toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("plugin")) {
|
||||||
|
if (args[1].equalsIgnoreCase("use_config") || args[1].equalsIgnoreCase("sneak")) {
|
||||||
|
completions = List.of("true", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions.stream().filter(p -> p.startsWith(args[args.length - 1])).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister() {
|
||||||
|
unregister(plugin.getServer().getCommandMap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,15 @@ public class MineListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void activate(BlockBreakEvent event) {
|
public void activate(BlockBreakEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack stack = player.getInventory().getItemInMainHand();
|
|
||||||
Block block = event.getBlock();
|
|
||||||
String permission = settings.permission();
|
String permission = settings.permission();
|
||||||
List<Block> blocks = identifier.populateAndRetrieve(block, stack);
|
|
||||||
|
|
||||||
if (!player.hasPermission(permission)) return;
|
if (!player.hasPermission(permission)) return;
|
||||||
|
|
||||||
if (!player.isSneaking() && settings.useSneak()) return;
|
if (!player.isSneaking() && settings.useSneak()) return;
|
||||||
|
|
||||||
|
ItemStack stack = player.getInventory().getItemInMainHand();
|
||||||
|
Block block = event.getBlock();
|
||||||
|
List<Block> blocks = identifier.populateAndRetrieve(block, stack);
|
||||||
|
|
||||||
blocks.forEach(Block::breakNaturally);
|
blocks.forEach(Block::breakNaturally);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user