|
| 1 | +package net.swofty.type.skyblockgeneric.commands; |
| 2 | + |
| 3 | +import net.minestom.server.command.builder.arguments.ArgumentWord; |
| 4 | +import net.swofty.commons.item.ItemType; |
| 5 | +import net.swofty.type.generic.command.CommandParameters; |
| 6 | +import net.swofty.type.generic.command.HypixelCommand; |
| 7 | +import net.swofty.type.generic.user.categories.Rank; |
| 8 | +import net.swofty.type.skyblockgeneric.data.datapoints.DatapointStash; |
| 9 | +import net.swofty.type.skyblockgeneric.item.SkyBlockItem; |
| 10 | +import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; |
| 11 | + |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +@CommandParameters(aliases = "pickupstash", |
| 16 | + description = "Pickup items from your stash", |
| 17 | + usage = "/pickupstash [item|material]", |
| 18 | + permission = Rank.DEFAULT, |
| 19 | + allowsConsole = false) |
| 20 | +public class PickupStashCommand extends HypixelCommand { |
| 21 | + @Override |
| 22 | + public void registerUsage(MinestomCommand command) { |
| 23 | + ArgumentWord typeArg = new ArgumentWord("type").from("item", "material"); |
| 24 | + |
| 25 | + // No args - pick up from both stashes |
| 26 | + command.addSyntax((sender, context) -> { |
| 27 | + if (!permissionCheck(sender)) return; |
| 28 | + |
| 29 | + SkyBlockPlayer player = (SkyBlockPlayer) sender; |
| 30 | + pickupFromItemStash(player); |
| 31 | + pickupFromMaterialStash(player); |
| 32 | + }); |
| 33 | + |
| 34 | + // With type argument |
| 35 | + command.addSyntax((sender, context) -> { |
| 36 | + if (!permissionCheck(sender)) return; |
| 37 | + |
| 38 | + SkyBlockPlayer player = (SkyBlockPlayer) sender; |
| 39 | + String type = context.get(typeArg); |
| 40 | + |
| 41 | + if (type.equalsIgnoreCase("material")) { |
| 42 | + pickupFromMaterialStash(player); |
| 43 | + } else { |
| 44 | + pickupFromItemStash(player); |
| 45 | + } |
| 46 | + }, typeArg); |
| 47 | + } |
| 48 | + |
| 49 | + private void pickupFromItemStash(SkyBlockPlayer player) { |
| 50 | + DatapointStash.PlayerStash stash = player.getStash(); |
| 51 | + |
| 52 | + if (stash.getItemStashCount() == 0) { |
| 53 | + player.sendMessage("§cYour item stash is already empty!"); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + int pickedUp = 0; |
| 58 | + while (player.hasEmptySlots(1) && stash.getItemStashCount() > 0) { |
| 59 | + SkyBlockItem removed = stash.removeFromItemStash(0); |
| 60 | + if (removed != null) { |
| 61 | + player.addAndUpdateItem(removed); |
| 62 | + player.sendMessage("§aFrom stash: §f" + removed.getDisplayName()); |
| 63 | + pickedUp++; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (pickedUp == 0) { |
| 68 | + player.sendMessage("§cCouldn't unstash your item stash! Your inventory is full!"); |
| 69 | + } else if (stash.getItemStashCount() == 0) { |
| 70 | + player.sendMessage("§aYou picked up all items from your item stash!"); |
| 71 | + } else { |
| 72 | + player.sendMessage("§eYou still have §c" + stash.getItemStashCount() + " §eitems in there!"); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + private void pickupFromMaterialStash(SkyBlockPlayer player) { |
| 77 | + DatapointStash.PlayerStash stash = player.getStash(); |
| 78 | + |
| 79 | + if (stash.getMaterialStashCount() == 0) { |
| 80 | + player.sendMessage("§cYour material stash is already empty!"); |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + int pickedUp = 0; |
| 85 | + List<ItemType> types = new ArrayList<>(stash.getMaterialStash().keySet()); |
| 86 | + |
| 87 | + for (ItemType type : types) { |
| 88 | + int amount = stash.getMaterialStash().getOrDefault(type, 0); |
| 89 | + int maxStackSize = type.material.maxStackSize(); |
| 90 | + |
| 91 | + while (amount > 0 && player.hasEmptySlots(1)) { |
| 92 | + int toPickup = Math.min(amount, maxStackSize); |
| 93 | + int removed = stash.removeFromMaterialStash(type, toPickup); |
| 94 | + if (removed > 0) { |
| 95 | + SkyBlockItem newItem = new SkyBlockItem(type); |
| 96 | + newItem.setAmount(removed); |
| 97 | + player.addAndUpdateItem(newItem); |
| 98 | + player.sendMessage("§aFrom stash: §f" + type.getDisplayName() + " §7x" + removed); |
| 99 | + pickedUp += removed; |
| 100 | + amount -= removed; |
| 101 | + } else { |
| 102 | + break; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + if (!player.hasEmptySlots(1)) break; |
| 107 | + } |
| 108 | + |
| 109 | + if (pickedUp == 0) { |
| 110 | + player.sendMessage("§cCouldn't unstash your material stash! Your inventory is full!"); |
| 111 | + } else if (stash.getMaterialStashCount() == 0) { |
| 112 | + player.sendMessage("§aYou picked up all items from your material stash!"); |
| 113 | + } else { |
| 114 | + player.sendMessage("§eYou still have §c" + stash.getMaterialStashCount() + |
| 115 | + " §ematerials totalling §c" + stash.getMaterialTypeCount() + |
| 116 | + " §etypes of materials in there!"); |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments