Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ public MinionGiveCommand(
@Execute(name = "give")
@Permission("eternalminions.command.give")
public Notice give(@Context Player player) {
return this.give(player, this.behaviors.defaultBehavior());
return this.give(player, this.behaviors.defaultBehavior(), 1);
}

@Execute(name = "give")
@Permission("eternalminions.command.give")
public Notice give(@Context Player player, @Arg("type") String type) {
return this.give(player, type, 1);
}

@Execute(name = "give")
@Permission("eternalminions.command.give")
public Notice give(@Context Player player, @Arg("type") String type, @Arg("amount") int amount) {
MinionBehavior behavior = this.behaviors.find(type).orElse(null);
if (behavior == null) {
return this.messages.minionTypeUnknown;
}
return this.give(player, behavior);
return this.give(player, behavior, amount);
}

private Notice give(Player player, MinionBehavior behavior) {
player.getInventory().addItem(this.items.create(behavior));
private Notice give(Player player, MinionBehavior behavior, int amount) {
player.getInventory().addItem(this.items.create(behavior, amount));
return this.messages.minionItemReceived;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public final class MinionItemFactory {

private static final int MAX_AMOUNT = 576;

private final MinionBehaviorRegistry behaviors;
private final MinionAppearanceItems appearance;
private final MiniMessage miniMessage;
Expand Down Expand Up @@ -58,6 +60,12 @@ public MinionItemFactory(
this.upgradesKey = new NamespacedKey(plugin, "minion_upgrades");
}

public ItemStack create(MinionBehavior behavior, int amount) {
ItemStack item = this.create(behavior);
item.setAmount(Math.max(1, Math.min(amount, MAX_AMOUNT)));
return item;
}

public ItemStack create(MinionBehavior behavior) {
ItemStack item = this.appearance.head(behavior.config());
ItemMeta meta = item.getItemMeta();
Expand Down