From 0fc18aca2b25c22ac58d2de5d183e38bf21d8b31 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Mon, 23 Oct 2023 21:50:11 +0200 Subject: [PATCH] Add ShortcutCommand --- .../Bukkit/Command/ShortcutCommand.java | 59 +++++++++++++++++++ .../Bukkit/Listener/ItemShortcut.java | 2 +- .../Minepacks/Bukkit/Minepacks.java | 2 + pom.xml | 2 +- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/ShortcutCommand.java diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/ShortcutCommand.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/ShortcutCommand.java new file mode 100644 index 0000000..aa3963a --- /dev/null +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/ShortcutCommand.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023 GeorgH93 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package at.pcgamingfreaks.Minepacks.Bukkit.Command; + +import at.pcgamingfreaks.Command.HelpData; +import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand; +import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemShortcut; +import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; +import at.pcgamingfreaks.Minepacks.Bukkit.Permissions; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ShortcutCommand extends MinepacksCommand +{ + private final ItemShortcut itemShortcut; + + public ShortcutCommand(Minepacks plugin, final @NotNull ItemShortcut itemShortcut) + { + super(plugin, "shortcut", plugin.getLanguage().getTranslated("Commands.Description.Shortcut"), Permissions.USE, true, plugin.getLanguage().getCommandAliases("Shortcut")); + this.itemShortcut = itemShortcut; + } + + @Override + public void execute(@NotNull CommandSender sender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args) + { + itemShortcut.addItem((Player) sender); + } + + @Override + public List tabComplete(@NotNull CommandSender sender, @NotNull String mainCommandAlias, @NotNull String alias, @NotNull String[] args) + { + return null; + } + @Override + public @Nullable List getHelp(@NotNull CommandSender requester) + { + return null; + } +} diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index a9401d2..a7e0d86 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -91,7 +91,7 @@ public boolean isItemShortcut(final @Nullable ItemStack stack) return itemDisplayName != null && itemNameNoReset.equals(itemDisplayName.replace(ChatColor.RESET.toString(), "")); } - private void addItem(Player player) + public void addItem(Player player) { if(player.hasPermission(Permissions.USE)) { diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java index f325707..500c6b4 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java @@ -27,6 +27,7 @@ import at.pcgamingfreaks.Minepacks.Bukkit.API.*; import at.pcgamingfreaks.Minepacks.Bukkit.Command.CommandManager; import at.pcgamingfreaks.Minepacks.Bukkit.Command.InventoryClearCommand; +import at.pcgamingfreaks.Minepacks.Bukkit.Command.ShortcutCommand; import at.pcgamingfreaks.Minepacks.Bukkit.Database.Config; import at.pcgamingfreaks.Minepacks.Bukkit.Database.Database; import at.pcgamingfreaks.Minepacks.Bukkit.Database.Language; @@ -220,6 +221,7 @@ private void load() { shortcut = new ItemShortcut(this); pluginManager.registerEvents(shortcut, this); + commandManager.registerSubCommand(new ShortcutCommand(this, shortcut)); } else shortcut = null; if(config.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this); diff --git a/pom.xml b/pom.xml index 9c897ae..f479670 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom - 2.4.23 + 2.4.24-SNAPSHOT UTF-8 UTF-8