Skip to content

Commit cd4d88a

Browse files
feat(): added stash, and fixed slight visual bug with bows
1 parent 8fb1e39 commit cd4d88a

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package net.swofty.type.skyblockgeneric.commands;
2+
3+
import net.minestom.server.command.builder.arguments.ArgumentEnum;
4+
import net.minestom.server.command.builder.arguments.ArgumentType;
5+
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
6+
import net.swofty.commons.item.ItemType;
7+
import net.swofty.type.generic.command.CommandParameters;
8+
import net.swofty.type.generic.command.HypixelCommand;
9+
import net.swofty.type.generic.user.categories.Rank;
10+
import net.swofty.type.skyblockgeneric.data.datapoints.DatapointStash;
11+
import net.swofty.type.skyblockgeneric.item.SkyBlockItem;
12+
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
13+
14+
@CommandParameters(aliases = "addtostash",
15+
description = "Force add an item to your stash",
16+
usage = "/addtostash <item> [amount]",
17+
permission = Rank.ADMIN,
18+
allowsConsole = false)
19+
public class AddToStashCommand extends HypixelCommand {
20+
@Override
21+
public void registerUsage(MinestomCommand command) {
22+
ArgumentEnum<ItemType> itemArgument = ArgumentType.Enum("item", ItemType.class);
23+
ArgumentInteger amountArgument = ArgumentType.Integer("amount");
24+
25+
// Single item syntax
26+
command.addSyntax((sender, context) -> {
27+
if (!permissionCheck(sender)) return;
28+
29+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
30+
ItemType itemType = context.get(itemArgument);
31+
32+
addItemToStash(player, itemType, 1);
33+
}, itemArgument);
34+
35+
// With amount syntax
36+
command.addSyntax((sender, context) -> {
37+
if (!permissionCheck(sender)) return;
38+
39+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
40+
ItemType itemType = context.get(itemArgument);
41+
int amount = context.get(amountArgument);
42+
43+
addItemToStash(player, itemType, amount);
44+
}, itemArgument, amountArgument);
45+
}
46+
47+
private void addItemToStash(SkyBlockPlayer player, ItemType itemType, int amount) {
48+
DatapointStash.PlayerStash stash = player.getStash();
49+
SkyBlockItem item = new SkyBlockItem(itemType);
50+
51+
// Check if stackable (maxStackSize > 1 means material stash)
52+
if (item.getMaterial().maxStackSize() > 1) {
53+
stash.addToMaterialStash(itemType, amount);
54+
player.sendMessage("§aAdded §e" + amount + "x " + itemType.getDisplayName() + " §ato your material stash.");
55+
} else {
56+
// Non-stackable items go to item stash
57+
int added = 0;
58+
for (int i = 0; i < amount; i++) {
59+
if (stash.addToItemStash(new SkyBlockItem(itemType))) {
60+
added++;
61+
} else {
62+
break;
63+
}
64+
}
65+
if (added > 0) {
66+
player.sendMessage("§aAdded §e" + added + "x " + itemType.getDisplayName() + " §ato your item stash.");
67+
}
68+
if (added < amount) {
69+
player.sendMessage("§cCouldn't add " + (amount - added) + " items - item stash is at limit (720).");
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)