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 2c0a9bf07..ec530e4b8 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,4 +1,76 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; -public class BackpackCommand { +import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; +import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.api.Slimefun; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.List; + +class BackpackCommand extends SubCommand { + + BackpackCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { + super(plugin, cmd); + } + + @Override + public String getName() { + return "backpack"; + } + + @Override + public boolean isHidden() { + return false; + } + + @Override + public void onExecute(CommandSender sender, String[] args) { + if (!(sender instanceof Player) || !(sender.hasPermission("slimefun.command.backpack"))) { + SlimefunPlugin.getLocal().sendMessage(sender, "messages.no-permission", true); + return; + } + if (args.length != 3) { + SlimefunPlugin.getLocal().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack ")); + return; + } + + Player p = (Player) sender; + String ownerName = args[1]; + int id = Integer.parseInt(args[2]); + OfflinePlayer owner = Bukkit.getPlayer(ownerName); + + if (owner == null) { + owner = Bukkit.getOfflinePlayer(ownerName); + if (!owner.hasPlayedBefore()) { + SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.player-never-joined"); + return; + } + } + + PlayerProfile.get(owner, profile -> { + if (!profile.getBackpack(id).isPresent()) { + SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.backpack-does-not-exist"); + return; + } + PlayerBackpack bp = profile.getBackpack(id).get(); + //No point switching for size, would still miss soulbound + ItemStack item = SlimefunItems.BACKPACK_MEDIUM; + ItemMeta meta = item.getItemMeta(); + List lore = meta.getLore(); + lore.set(2, ChatColor.GRAY + "ID: " + profile.getUUID().toString() + "#" + id); + meta.setLore(lore); + item.setItemMeta(meta); + Slimefun.runSync(() -> p.getInventory().addItem(item)); + }); + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java index 9e7c5894b..6f12ecdd6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java @@ -25,5 +25,6 @@ public final class Commands { commands.add(new OpenGuideCommand(plugin, cmd)); commands.add(new SearchCommand(plugin, cmd)); commands.add(new DebugFishCommand(plugin, cmd)); + commands.add(new BackpackCommand(plugin,cmd)); } } diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index f40ebdecb..f9341eb3d 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -2,6 +2,7 @@ commands: help: Displays this help screen cheat: Allows you to cheat Items give: Give somebody some Slimefun Items + backpack: Retrieve an existing backpack guide: Gives yourself a Slimefun Guide timings: Lag-Info about your Server teleporter: See other Player's Waypoints @@ -42,6 +43,10 @@ guide: cheat: no-multiblocks: '&4You cannot cheat in Multiblocks, you have to build them!' + + backpack: + player-never-joined: '&4No player with that name has ever joined the server!' + backpack-does-not-exist: '&4That backpack does not exist!' pages: previous: 'Previous page' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2eb5955dc..b70199053 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -37,6 +37,9 @@ permissions: slimefun.command.versions: description: Allows you to do /sf versions default: op + slimefun.command.backpack: + description: Allows you to do /sf backpack + default: op slimefun.command.guide: description: Allows you to obtain the Slimefun guide book default: true