diff --git a/src/main/java/com/alttd/easter/commands/Command.java b/src/main/java/com/alttd/easter/commands/Command.java
index 3ee0701..dac52a9 100644
--- a/src/main/java/com/alttd/easter/commands/Command.java
+++ b/src/main/java/com/alttd/easter/commands/Command.java
@@ -3,6 +3,7 @@ package com.alttd.easter.commands;
import com.alttd.easter.Easter;
import com.alttd.easter.commands.subcommands.Reload;
import com.alttd.easter.commands.subcommands.SetPrize;
+import com.alttd.easter.commands.subcommands.SpawnEggs;
import com.alttd.easter.config.Messages;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -33,11 +34,11 @@ public class Command implements CommandExecutor, TabExecutor {
}
command.setExecutor(this);
command.setTabCompleter(this);
- command.setAliases(List.of("pu"));
subCommands = List.of(
new Reload(easter),
- new SetPrize()
+ new SetPrize(),
+ new SpawnEggs()
);
}
diff --git a/src/main/java/com/alttd/easter/commands/subcommands/SpawnEggs.java b/src/main/java/com/alttd/easter/commands/subcommands/SpawnEggs.java
new file mode 100644
index 0000000..e931ea8
--- /dev/null
+++ b/src/main/java/com/alttd/easter/commands/subcommands/SpawnEggs.java
@@ -0,0 +1,110 @@
+package com.alttd.easter.commands.subcommands;
+
+import com.alttd.easter.commands.SubCommand;
+import com.alttd.easter.config.Messages;
+import com.alttd.easter.egg.EggType;
+import com.alttd.easter.util.ItemUtils;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SpawnEggs extends SubCommand {
+
+ @Override
+ public boolean onCommand(CommandSender commandSender, String[] args) {
+ if (!(commandSender instanceof Player player)) {
+ commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
+ return true;
+ }
+
+ int amount = 1;
+ if (args.length >= 2) {
+ try {
+ amount = Math.max(1, Integer.parseInt(args[1]));
+ } catch (NumberFormatException ignored) {
+ // keep default
+ }
+ }
+
+ // Optional: allow spawning a single type via argument
+ if (args.length >= 2) {
+ EggType specific = parseEggType(args[1]);
+ if (specific != null) {
+ giveEgg(player, specific, amount);
+ player.sendRichMessage("Spawned " + amount + " of " + ItemUtils.prettify(specific.name()) + " egg(s).");
+ return true;
+ }
+ }
+ if (args.length >= 3) {
+ EggType specific = parseEggType(args[2]);
+ if (specific != null) {
+ giveEgg(player, specific, amount);
+ player.sendRichMessage("Spawned " + amount + " of " + ItemUtils.prettify(specific.name()) + " egg(s).");
+ return true;
+ }
+ }
+
+ for (EggType type : EggType.values()) {
+ giveEgg(player, type, amount);
+ }
+ player.sendRichMessage("Spawned " + amount + " of every easter egg in your inventory for debugging.");
+ return true;
+ }
+
+ private void giveEgg(Player player, EggType type, int amount) {
+ ItemStack item = ItemUtils.createEggItem(type);
+ item.setAmount(Math.max(1, Math.min(64, amount)));
+ var left = player.getInventory().addItem(item);
+ if (!left.isEmpty()) {
+ // drop leftovers at the player's location
+ left.values().forEach(stack -> player.getWorld().dropItemNaturally(player.getLocation(), stack));
+ }
+ }
+
+ private EggType parseEggType(String arg) {
+ String key = arg.trim().toUpperCase().replace('-', '_').replace(' ', '_');
+ // try direct enum name
+ try {
+ return EggType.valueOf(key);
+ } catch (IllegalArgumentException ignored) {
+ }
+ // try match by pretty color words contained
+ for (EggType type : EggType.values()) {
+ if (ItemUtils.prettify(type.name()).replace(" ", "").equalsIgnoreCase(arg.replace(" ", ""))) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return "spawneggs";
+ }
+
+ @Override
+ public List getTabComplete(CommandSender commandSender, String[] args) {
+ List res = new ArrayList<>();
+ if (args.length == 2) {
+ // amount suggestions
+ res.addAll(List.of("1", "4", "16", "64"));
+ // also allow type in 2nd arg for convenience
+ for (EggType type : EggType.values()) {
+ res.add(type.name().toLowerCase());
+ }
+ } else if (args.length == 3) {
+ for (EggType type : EggType.values()) {
+ res.add(type.name().toLowerCase());
+ }
+ }
+ return res;
+ }
+
+ @Override
+ public String getHelpMessage() {
+ return Messages.HELP.SPAWN_EGGS;
+ }
+}
diff --git a/src/main/java/com/alttd/easter/config/Messages.java b/src/main/java/com/alttd/easter/config/Messages.java
index 35c1b89..9d1f819 100644
--- a/src/main/java/com/alttd/easter/config/Messages.java
+++ b/src/main/java/com/alttd/easter/config/Messages.java
@@ -26,6 +26,7 @@ public class Messages extends AbstractConfig {
public static String HELP_MESSAGE = "Show this menu: /pu help";
public static String RELOAD = "Reload the configs for Easter: /pu reload";
public static String SET_PRIZE = "Add the item in your hand as a prize: /pu setprize";
+ public static String SPAWN_EGGS = "Give yourself debug eggs: /pu spawneggs [amount|type] [type]";
@SuppressWarnings("unused")
private static void load() {
@@ -33,6 +34,7 @@ public class Messages extends AbstractConfig {
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
RELOAD = config.getString(prefix, "reload", RELOAD);
SET_PRIZE = config.getString(prefix, "set-prize", SET_PRIZE);
+ SPAWN_EGGS = config.getString(prefix, "spawn-eggs", SPAWN_EGGS);
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 86eba80..30c7c32 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -17,3 +17,6 @@ permissions:
easter.setprize:
description: Set the held item as a prize
default: op
+ easter.spawneggs:
+ description: Give yourself debug eggs
+ default: op