From e021fb9ce35eb7ede4cf3ebf65991e9c24af3813 Mon Sep 17 00:00:00 2001 From: Sfiguz7 Date: Mon, 11 May 2020 01:25:59 +0200 Subject: [PATCH] Tweaked, requested changes added --- .../commands/subcommands/BackpackCommand.java | 44 +++++++------------ .../core/commands/subcommands/Commands.java | 5 ++- .../items/tools/HiddenBackpack.java | 14 ++++++ .../setup/SlimefunItemSetup.java | 3 ++ .../Slimefun/Lists/SlimefunItems.java | 2 + src/main/resources/languages/messages_en.yml | 2 + 6 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HiddenBackpack.java 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 ec530e4b8..ae44bc97d 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,21 +1,16 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; -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 io.github.thebusybiscuit.slimefun4.utils.PatternUtils; 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 { @@ -40,21 +35,21 @@ class BackpackCommand extends SubCommand { return; } if (args.length != 3) { - SlimefunPlugin.getLocal().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack ")); + 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; - } + final Player p = (Player) sender; + final String ownerName = args[1]; + if (!PatternUtils.NUMERIC.matcher(args[2]).matches()){ + SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.invalid-id"); + return; + } + final int id = Integer.parseInt(args[2]); + final OfflinePlayer owner = Bukkit.getOfflinePlayer(ownerName); + if (!owner.hasPlayedBefore()) { + SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.player-never-joined"); + return; } PlayerProfile.get(owner, profile -> { @@ -62,15 +57,10 @@ class BackpackCommand extends SubCommand { 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)); + Slimefun.runSync(() -> { + p.getInventory().addItem(SlimefunItems.RESTORED_BACKPACK); + SlimefunPlugin.getLocal().sendMessage(sender, "guide.backpack.restored-backpack-given"); + }); }); } } 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 6f12ecdd6..e11282560 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 @@ -8,7 +8,8 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin; public final class Commands { - private Commands() {} + private Commands() { + } public static void addCommands(SlimefunCommand cmd, Collection commands) { SlimefunPlugin plugin = cmd.getPlugin(); @@ -25,6 +26,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)); + commands.add(new BackpackCommand(plugin, cmd)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HiddenBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HiddenBackpack.java new file mode 100644 index 000000000..dde56143f --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/HiddenBackpack.java @@ -0,0 +1,14 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.tools; + +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import org.bukkit.inventory.ItemStack; + +public class HiddenBackpack extends SlimefunBackpack { + + public HiddenBackpack(Category category, SlimefunItemStack item) { + super(1, category, item, RecipeType.NULL, new ItemStack[9]); + this.hidden = true; + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 2d663c822..11bc3c042 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup; import java.util.ArrayList; import java.util.List; +import io.github.thebusybiscuit.slimefun4.implementation.items.tools.HiddenBackpack; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Effect; @@ -1202,6 +1203,8 @@ public final class SlimefunItemSetup { new ItemStack[] {SlimefunItems.GOLD_24K, null, SlimefunItems.GOLD_24K, new ItemStack(Material.LEATHER), SlimefunItems.GILDED_BACKPACK, new ItemStack(Material.LEATHER), SlimefunItems.GOLD_24K, null, SlimefunItems.GOLD_24K}) .register(plugin); + new HiddenBackpack(categories.usefulItems, (SlimefunItemStack) SlimefunItems.RESTORED_BACKPACK).register(plugin); + new SlimefunItem(categories.technicalComponents, (SlimefunItemStack) SlimefunItems.MAGNET, RecipeType.SMELTERY, new ItemStack[] {SlimefunItems.NICKEL_INGOT, SlimefunItems.ALUMINUM_DUST, SlimefunItems.IRON_DUST, SlimefunItems.COBALT_INGOT, null, null, null, null, null}) .register(plugin); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java index 5c3ba2d14..edb52f5fe 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/SlimefunItems.java @@ -72,6 +72,8 @@ public final class SlimefunItems { public static final ItemStack RADIANT_BACKPACK = new SlimefunItemStack("RADIANT_BACKPACK", "40cb1e67b512ab2d4bf3d7ace0eaaf61c32cd4681ddc3987ceb326706a33fa", "&eRadiant Backpack", "", "&7Size: &e54 (Double chest)", "&7ID: ", "", "&7&eRight Click&7 to open"); public static final SlimefunItemStack BOUND_BACKPACK = new SlimefunItemStack("BOUND_BACKPACK", "2a3b34862b9afb63cf8d5779966d3fba70af82b04e83f3eaf6449aeba", "&cSoulbound Backpack", "", "&7Size: &e36", "&7ID: ", "", "&7&eRight Click&7 to open"); public static final SlimefunItemStack COOLER = new SlimefunItemStack("COOLER", "d4c1572584eb5de229de9f5a4f779d0aacbaffd33bcb33eb4536a6a2bc6a1", "&bCooler", "&rAllows you to store Juices/Smoothies", "&rand automatically consumes them when you are hungry", "&rand you have this in your Inventory", "", "&7Size: &e27", "&7ID: ", "", "&7&eRight Click&7 to open"); + public static final ItemStack RESTORED_BACKPACK = new SlimefunItemStack("RESTORED_BACKPACK", "40cb1e67b512ab2d4bf3d7ace0eaaf61c32cd4681ddc3987ceb326706a33fa", "&eRestored Backpack", "", "&7Retrieve your lost items", "", "&7&eRight Click&7 to open"); + /* Jetpacks */ public static final SlimefunItemStack DURALUMIN_JETPACK = new SlimefunItemStack("DURALUMIN_JETPACK", Material.LEATHER_CHESTPLATE, Color.SILVER, "&9Electric Jetpack &7- &eI", "", "&8\u21E8 &7Material: &bDuralumin", "&c&o&8\u21E8 &e\u26A1 &70 / 20 J", "&8\u21E8 &7Thrust: &c0.35", "", "&7Hold &eShift&7 to use"); diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index f9341eb3d..c2e64a3bc 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -45,8 +45,10 @@ guide: no-multiblocks: '&4You cannot cheat in Multiblocks, you have to build them!' backpack: + invalid-id: '&4The id must be a non-negative integer!' player-never-joined: '&4No player with that name has ever joined the server!' backpack-does-not-exist: '&4That backpack does not exist!' + restored-backpack-given: 'Backpack restored successfully! Added to your inventory!' pages: previous: 'Previous page'