diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java index 5f48cf7..e970307 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java @@ -1,18 +1,23 @@ package com.gmail.St3venAU.plugins.ArmorStandTools; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.PluginCommandYamlParser; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + class Config { private static Main plugin; @@ -37,6 +42,7 @@ class Config { static boolean requireCreative = false; static int defaultASCmdCooldownTicks = 0; static boolean ignoreWGForASCmdExecution = false; + static List commandsBlocked = new ArrayList(); static String invReturned, asDropped, asVisible, isTrue, isFalse, @@ -51,7 +57,7 @@ class Config { assignedCmdToAS, assignCmdError, ascmdHelp, viewCmd, removeCmd, assignConsole, assignPlayer, executeCmdError, cmdOnCooldown, cooldownRemovedFrom, isAnInvalidCooldown, - cooldownSetTo, ticksFor, setCooldown, removeCooldown; + cooldownSetTo, ticksFor, setCooldown, removeCooldown, commandBlocked; static void reload(Main main) { plugin = main; @@ -122,6 +128,7 @@ class Config { ticksFor = languageConfig.getString("ticksFor"); setCooldown = languageConfig.getString("setCooldown"); ticksFor = languageConfig.getString("ticksFor"); + commandBlocked = languageConfig.getString("commandBlocked"); } private static void reloadMainConfig() { @@ -150,6 +157,20 @@ class Config { debug = config.getBoolean("debug", false); plugin.carryingArmorStand.clear(); + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { + for (String blocked : config.getStringList("commandBlocked")) { + for (Plugin plugin : plugin.getServer().getPluginManager().getPlugins()) { + command: for (Command command : PluginCommandYamlParser.parse(plugin)) { + if (command.getAliases().contains(blocked)) { + commandsBlocked.addAll(command.getAliases()); + break command; + } + } + } + + commandsBlocked.add(blocked); + }}); + for(ArmorStandTool tool : ArmorStandTool.values()) { tool.setEnabled(config); } diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index 664a9cf..c658d08 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -52,6 +52,23 @@ public class MainListener implements Listener { this.plugin = main; } + @EventHandler(ignoreCancelled = true) + public void onCommandProcess(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + if (!plugin.carryingArmorStand.containsKey(player.getUniqueId())) + return; + + String command = event.getMessage().split(" ")[0].toLowerCase(); + for (String block : Config.commandsBlocked) { + if (!command.contains(block)) + continue; + + player.sendMessage(ChatColor.RED + Config.commandBlocked); + event.setCancelled(true); + return; + } + } + @EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { if(event.getRightClicked() instanceof ArmorStand) { diff --git a/src/config.yml b/src/config.yml index cc8cfbb..082c9a8 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,7 +4,7 @@ # # Main Config # -# File generated by: v3.4.0 +# File generated by: v3.5.0 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # @@ -20,6 +20,7 @@ # - Player head tool: Set's an armor stand's head to the head of a specified player. # - Support for WorldGuard regions. # - User customizable language config. +# - Block commands while player are using AST. # # Commands: # /astools Give yourself all of the armor stand tools (Note: Clears your inventory) @@ -35,6 +36,7 @@ # # Permissions: # astools.command Permission for the /astools command +# astools.bypass Permission for the bypass blocked commands # astools.reload Permission to reload the plugin with /astools reload # astools.use Permission for using any of the tools (except the ones below that have their own separate permissions) # astools.clone Permission to use the clone tool (Clones an armor stand without requiring the materials) @@ -107,4 +109,7 @@ enableTool: gui_slots: true gui_pHead: true gui_invul: true - gui_move: true \ No newline at end of file + gui_move: true +commandBlocked: +- ehat +- hat diff --git a/src/language.yml b/src/language.yml index ba85d53..5967851 100644 --- a/src/language.yml +++ b/src/language.yml @@ -4,7 +4,7 @@ # # Language Config # -# File generated by: v3.4.0 +# File generated by: v3.5.0 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # @@ -89,6 +89,8 @@ cooldownSetTo: 'Cooldown set to' ticksFor: 'ticks for' setCooldown: 'Set the cooldown for the command' removeCooldown: 'Remove the cooldown for the command' +# New since v3.4.0 +commandBlocked: 'You cannot use this command while you are using AST' # ############################# # Tool names & descriptions # @@ -254,4 +256,4 @@ tool: lore: gui_invul: name: 'Toggle Invulnerability' - lore: \ No newline at end of file + lore: diff --git a/src/plugin.yml b/src/plugin.yml index feb162b..1f4fe1c 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,7 @@ main: com.gmail.St3venAU.plugins.ArmorStandTools.Main name: ArmorStandTools -version: 3.4.0 -api-version: 1.13 +version: 3.5.0 +api-version: 1.14 author: St3venAU description: Armor stand manipulation tools softdepend: [WorldGuard, PlotSquared] @@ -12,4 +12,4 @@ commands: usage: Usage /astools or /astools reload ascmd: description: View/Remove/Assign the command assigned to the nearest armor stand - usage: Usage /ascmd view, /ascmd remove, /ascmd assign \ No newline at end of file + usage: Usage /ascmd view, /ascmd remove, /ascmd assign