From e4225d7aecfb5a63eff882cf3734a610f0a1d5ea Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 19 May 2021 17:36:10 +0200 Subject: [PATCH] Fixed a permissions issue with `/sf charge` --- CHANGELOG.md | 1 + .../core/commands/subcommands/BackpackCommand.java | 14 ++++++++++++++ .../core/commands/subcommands/ChargeCommand.java | 6 +++++- .../core/commands/subcommands/CheatCommand.java | 3 +++ .../commands/subcommands/DebugFishCommand.java | 3 +++ .../core/commands/subcommands/GiveCommand.java | 3 +++ .../core/commands/subcommands/GuideCommand.java | 3 +++ .../core/commands/subcommands/HelpCommand.java | 3 +++ .../commands/subcommands/OpenGuideCommand.java | 1 + .../core/commands/subcommands/ResearchCommand.java | 10 +++++++++- .../core/commands/subcommands/SearchCommand.java | 3 +++ .../commands/subcommands/SlimefunSubCommands.java | 5 ++++- .../core/commands/subcommands/StatsCommand.java | 3 +++ .../commands/subcommands/TeleporterCommand.java | 3 +++ .../core/commands/subcommands/TimingsCommand.java | 1 + .../core/commands/subcommands/VersionsCommand.java | 2 ++ 16 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fcef9cf..f3f0d8e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * Fixed #3064 * Fixed #2964 * Fixed #2979 +* Fixed a permissions issue with `/sf charge` ## Release Candidate 23 (19 May 2021) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#23 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index cdc65a340..d1914e667 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -11,10 +13,22 @@ import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.RestoredBackpack; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; +/** + * This command that allows for backpack retrieval in the event they are lost. + * The command accepts a name and id, if those match up it spawns a Medium Backpack + * with the correct lore set in the sender's inventory. + * + * @author Sfiguz7 + * + * @see RestoredBackpack + * + */ class BackpackCommand extends SubCommand { + @ParametersAreNonnullByDefault BackpackCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "backpack", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java index 8d3a64f09..c06d5fbd1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -19,6 +21,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; */ class ChargeCommand extends SubCommand { + @ParametersAreNonnullByDefault ChargeCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "charge", false); } @@ -31,10 +34,11 @@ class ChargeCommand extends SubCommand { @Override public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player) { - if (sender.hasPermission("slimefun.charge.command")) { + if (sender.hasPermission("slimefun.command.charge")) { Player p = (Player) sender; ItemStack item = p.getInventory().getItemInMainHand(); SlimefunItem slimefunItem = SlimefunItem.getByItem(item); + if (slimefunItem instanceof Rechargeable) { Rechargeable rechargeableItem = (Rechargeable) slimefunItem; rechargeableItem.setItemCharge(item, rechargeableItem.getMaxItemCharge(item)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java index 3a4e18aca..659023daa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,6 +12,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class CheatCommand extends SubCommand { + @ParametersAreNonnullByDefault CheatCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "cheat", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java index 1900a471d..619b6d2ec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,6 +12,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class DebugFishCommand extends SubCommand { + @ParametersAreNonnullByDefault DebugFishCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "debug_fish", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index dc3e4f00d..f0efe22d0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -16,12 +16,15 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; +import javax.annotation.ParametersAreNonnullByDefault; + class GiveCommand extends SubCommand { private static final String PLACEHOLDER_PLAYER = "%player%"; private static final String PLACEHOLDER_ITEM = "%item%"; private static final String PLACEHOLDER_AMOUNT = "%amount%"; + @ParametersAreNonnullByDefault GiveCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "give", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java index c0f6a1949..94b49f630 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -11,6 +13,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class GuideCommand extends SubCommand { + @ParametersAreNonnullByDefault GuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "guide", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java index 43e43feb3..6ff08892f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; @@ -8,6 +10,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class HelpCommand extends SubCommand { + @ParametersAreNonnullByDefault HelpCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "help", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java index 8947d989f..7e4b88d7b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java @@ -13,6 +13,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class OpenGuideCommand extends SubCommand { + @ParametersAreNonnullByDefault OpenGuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "open_guide", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java index 9c3d29889..59dbd7dd4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java @@ -3,6 +3,9 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import java.util.Optional; import java.util.function.UnaryOperator; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,6 +21,7 @@ class ResearchCommand extends SubCommand { private static final String PLACEHOLDER_PLAYER = "%player%"; private static final String PLACEHOLDER_RESEARCH = "%research%"; + @ParametersAreNonnullByDefault ResearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "research", false); } @@ -57,6 +61,7 @@ class ResearchCommand extends SubCommand { } } + @ParametersAreNonnullByDefault private void giveResearch(CommandSender sender, Player p, String input) { Optional research = getResearchFromString(input); @@ -70,6 +75,7 @@ class ResearchCommand extends SubCommand { } } + @ParametersAreNonnullByDefault private void researchAll(CommandSender sender, PlayerProfile profile, Player p) { for (Research res : SlimefunPlugin.getRegistry().getResearches()) { if (!profile.hasUnlocked(res)) { @@ -80,6 +86,7 @@ class ResearchCommand extends SubCommand { } } + @ParametersAreNonnullByDefault private void reset(PlayerProfile profile, Player p) { for (Research research : SlimefunPlugin.getRegistry().getResearches()) { profile.setResearched(research, false); @@ -88,7 +95,8 @@ class ResearchCommand extends SubCommand { SlimefunPlugin.getLocalization().sendMessage(p, "commands.research.reset", true, msg -> msg.replace(PLACEHOLDER_PLAYER, p.getName())); } - private Optional getResearchFromString(String input) { + @Nonnull + private Optional getResearchFromString(@Nonnull String input) { if (!input.contains(":")) { return Optional.empty(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java index c52927221..56a4faaa1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java @@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import java.util.Arrays; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -14,6 +16,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class SearchCommand extends SubCommand { + @ParametersAreNonnullByDefault SearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "search", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java index 10378c3ff..488750f99 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java @@ -4,6 +4,8 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import javax.annotation.Nonnull; + import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -20,7 +22,8 @@ public final class SlimefunSubCommands { private SlimefunSubCommands() {} - public static Collection getAllCommands(SlimefunCommand cmd) { + @Nonnull + public static Collection getAllCommands(@Nonnull SlimefunCommand cmd) { SlimefunPlugin plugin = cmd.getPlugin(); List commands = new LinkedList<>(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java index 1bb18b3e6..a6e3651fb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java @@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import java.util.Optional; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -14,6 +16,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class StatsCommand extends SubCommand { + @ParametersAreNonnullByDefault StatsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "stats", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java index 2d7d56ba5..fbd31fe07 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.block.BlockFace; @@ -12,6 +14,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class TeleporterCommand extends SubCommand { + @ParametersAreNonnullByDefault TeleporterCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "teleporter", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java index 3673f48a6..849abbef4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java @@ -24,6 +24,7 @@ class TimingsCommand extends SubCommand { private static final String FLAG_PREFIX = "--"; private final Set flags = new HashSet<>(Arrays.asList("verbose")); + @ParametersAreNonnullByDefault TimingsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "timings", false); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index 63d9f13e9..7c69fbaae 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import java.util.Collection; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -29,6 +30,7 @@ import net.md_5.bungee.api.chat.hover.content.Text; */ class VersionsCommand extends SubCommand { + @ParametersAreNonnullByDefault VersionsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { super(plugin, cmd, "versions", false); }