diff --git a/eco-api/src/main/java/com/willfp/eco/core/command/impl/PluginCommand.java b/eco-api/src/main/java/com/willfp/eco/core/command/impl/PluginCommand.java index 791febfa..858c5380 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/command/impl/PluginCommand.java +++ b/eco-api/src/main/java/com/willfp/eco/core/command/impl/PluginCommand.java @@ -20,14 +20,16 @@ public abstract class PluginCommand extends HandledCommand implements CommandExe *

* The name cannot be the same as an existing command as this will conflict. * + * @param plugin The plugin. * @param name The name used in execution. * @param permission The permission required to execute the command. * @param playersOnly If only players should be able to execute this command. */ - protected PluginCommand(@NotNull final String name, + protected PluginCommand(@NotNull final EcoPlugin plugin, + @NotNull final String name, @NotNull final String permission, final boolean playersOnly) { - super(name, permission, playersOnly); + super(plugin, name, permission, playersOnly); } /** diff --git a/eco-api/src/main/java/com/willfp/eco/core/command/impl/Subcommand.java b/eco-api/src/main/java/com/willfp/eco/core/command/impl/Subcommand.java index e48e3cc3..8892ea50 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/command/impl/Subcommand.java +++ b/eco-api/src/main/java/com/willfp/eco/core/command/impl/Subcommand.java @@ -1,5 +1,6 @@ package com.willfp.eco.core.command.impl; +import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.CommandBase; import com.willfp.eco.internal.commands.HandledCommand; import org.jetbrains.annotations.NotNull; @@ -8,24 +9,28 @@ public abstract class Subcommand extends HandledCommand { /** * Create subcommand. * + * @param plugin The plugin. * @param name The subcommand name. * @param permission The subcommand permission. * @param playersOnly If the subcommand only works on players. */ - protected Subcommand(@NotNull final String name, + protected Subcommand(@NotNull final EcoPlugin plugin, + @NotNull final String name, @NotNull final String permission, final boolean playersOnly) { - super(name, permission, playersOnly); + super(plugin, name, permission, playersOnly); } /** * Create subcommand. * + * @param plugin The plugin. * @param name The name of the subcommand. * @param parent The parent command. */ - protected Subcommand(@NotNull final String name, + protected Subcommand(@NotNull final EcoPlugin plugin, + @NotNull final String name, @NotNull final CommandBase parent) { - super(name, parent.getPermission(), parent.isPlayersOnly()); + super(plugin, name, parent.getPermission(), parent.isPlayersOnly()); } } diff --git a/eco-api/src/main/java/com/willfp/eco/internal/commands/HandledCommand.java b/eco-api/src/main/java/com/willfp/eco/internal/commands/HandledCommand.java index 60de622d..bc97aded 100644 --- a/eco-api/src/main/java/com/willfp/eco/internal/commands/HandledCommand.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/commands/HandledCommand.java @@ -1,9 +1,11 @@ package com.willfp.eco.internal.commands; +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.PluginDependent; import com.willfp.eco.core.command.CommandBase; import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.TabCompleteHandler; -import com.willfp.eco.core.command.util.CommandUtils; +import com.willfp.eco.internal.commands.util.CommandUtils; import lombok.AccessLevel; import lombok.Getter; import org.bukkit.command.CommandSender; @@ -16,7 +18,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -public abstract class HandledCommand implements CommandBase { +public abstract class HandledCommand extends PluginDependent implements CommandBase { /** * The name of the command. */ @@ -50,13 +52,16 @@ public abstract class HandledCommand implements CommandBase { *

* The name cannot be the same as an existing command as this will conflict. * + * @param plugin Instance of a plugin. * @param name The name used in execution. * @param permission The permission required to execute the command. * @param playersOnly If only players should be able to execute this command. */ - protected HandledCommand(@NotNull final String name, + protected HandledCommand(@NotNull final EcoPlugin plugin, + @NotNull final String name, @NotNull final String permission, final boolean playersOnly) { + super(plugin); this.name = name; this.permission = permission; this.playersOnly = playersOnly; @@ -84,14 +89,14 @@ public abstract class HandledCommand implements CommandBase { */ protected final void handle(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (!CommandUtils.canExecute(sender, this)) { + if (!CommandUtils.canExecute(sender, this, this.getPlugin())) { return; } if (args.length > 0) { for (CommandBase subcommand : this.getSubcommands()) { if (subcommand.getName().equalsIgnoreCase(args[0])) { - if (!CommandUtils.canExecute(sender, subcommand)) { + if (!CommandUtils.canExecute(sender, subcommand, this.getPlugin())) { return; } diff --git a/eco-api/src/main/java/com/willfp/eco/core/command/util/CommandUtils.java b/eco-api/src/main/java/com/willfp/eco/internal/commands/util/CommandUtils.java similarity index 57% rename from eco-api/src/main/java/com/willfp/eco/core/command/util/CommandUtils.java rename to eco-api/src/main/java/com/willfp/eco/internal/commands/util/CommandUtils.java index 64f7f86d..50dc8e8d 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/command/util/CommandUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/commands/util/CommandUtils.java @@ -1,7 +1,7 @@ -package com.willfp.eco.core.command.util; +package com.willfp.eco.internal.commands.util; +import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.CommandBase; -import com.willfp.eco.internal.Internals; import lombok.experimental.UtilityClass; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -9,22 +9,16 @@ import org.jetbrains.annotations.NotNull; @UtilityClass public class CommandUtils { - /** - * Check if the sender can execute a command. - * - * @param sender The sender. - * @param command The command. - * @return If possible. Sends messages. - */ public boolean canExecute(@NotNull final CommandSender sender, - @NotNull final CommandBase command) { + @NotNull final CommandBase command, + @NotNull final EcoPlugin plugin) { if (command.isPlayersOnly() && !(sender instanceof Player)) { - sender.sendMessage(Internals.getInstance().getPlugin().getLangYml().getMessage("not-player")); + sender.sendMessage(plugin.getLangYml().getMessage("not-player")); return false; } if (!sender.hasPermission(command.getPermission()) && sender instanceof Player) { - sender.sendMessage(Internals.getInstance().getPlugin().getLangYml().getNoPermission()); + sender.sendMessage(plugin.getLangYml().getNoPermission()); return false; } diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 39a10e0f..7d1dc50a 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -1 +1 @@ -multiple-in-craft: '&l&c! &fThis recipe requires &a%amount%&f of this item.' +multiple-in-craft: '&l&c! &fThis recipe requires &a%amount%&f of this item.' \ No newline at end of file