|
| 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.minestom.server.instance.SharedInstance; |
| 7 | +import net.swofty.type.generic.command.CommandParameters; |
| 8 | +import net.swofty.type.generic.command.HypixelCommand; |
| 9 | +import net.swofty.type.skyblockgeneric.tree.SkyBlockTree; |
| 10 | +import net.swofty.type.skyblockgeneric.tree.TreeConfig; |
| 11 | +import net.swofty.type.skyblockgeneric.tree.TreeType; |
| 12 | +import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; |
| 13 | +import net.swofty.type.generic.user.categories.Rank; |
| 14 | + |
| 15 | +@CommandParameters( |
| 16 | + aliases = "tree", |
| 17 | + description = "Generates a tree at your location", |
| 18 | + usage = "/generatetree <type> [minHeight maxHeight] [minWidth maxWidth]", |
| 19 | + permission = Rank.ADMIN, |
| 20 | + allowsConsole = false |
| 21 | +) |
| 22 | +public class GenerateTreeCommand extends HypixelCommand { |
| 23 | + @Override |
| 24 | + public void registerUsage(MinestomCommand command) { |
| 25 | + ArgumentEnum<TreeType> treeTypeArg = ArgumentType.Enum("type", TreeType.class); |
| 26 | + ArgumentInteger minHeightArg = ArgumentType.Integer("minHeight"); |
| 27 | + ArgumentInteger maxHeightArg = ArgumentType.Integer("maxHeight"); |
| 28 | + ArgumentInteger minWidthArg = ArgumentType.Integer("minWidth"); |
| 29 | + ArgumentInteger maxWidthArg = ArgumentType.Integer("maxWidth"); |
| 30 | + |
| 31 | + // Just type - use defaults |
| 32 | + command.addSyntax((sender, context) -> { |
| 33 | + if (!permissionCheck(sender)) return; |
| 34 | + |
| 35 | + SkyBlockPlayer player = (SkyBlockPlayer) sender; |
| 36 | + TreeType type = context.get(treeTypeArg); |
| 37 | + |
| 38 | + generateTree(player, type, type.getDefaultConfig()); |
| 39 | + }, treeTypeArg); |
| 40 | + |
| 41 | + // Type + height |
| 42 | + command.addSyntax((sender, context) -> { |
| 43 | + if (!permissionCheck(sender)) return; |
| 44 | + |
| 45 | + SkyBlockPlayer player = (SkyBlockPlayer) sender; |
| 46 | + TreeType type = context.get(treeTypeArg); |
| 47 | + int minHeight = context.get(minHeightArg); |
| 48 | + int maxHeight = context.get(maxHeightArg); |
| 49 | + |
| 50 | + if (minHeight > maxHeight) { |
| 51 | + player.sendMessage("§cMinimum height cannot be greater than maximum height!"); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + if (minHeight < 2 || maxHeight > 50) { |
| 56 | + player.sendMessage("§cHeight must be between 2 and 50!"); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + TreeConfig customConfig = type.getDefaultConfig() |
| 61 | + .withMinHeight(minHeight) |
| 62 | + .withMaxHeight(maxHeight); |
| 63 | + |
| 64 | + generateTree(player, type, customConfig); |
| 65 | + }, treeTypeArg, minHeightArg, maxHeightArg); |
| 66 | + |
| 67 | + // Type + height + width |
| 68 | + command.addSyntax((sender, context) -> { |
| 69 | + if (!permissionCheck(sender)) return; |
| 70 | + |
| 71 | + SkyBlockPlayer player = (SkyBlockPlayer) sender; |
| 72 | + TreeType type = context.get(treeTypeArg); |
| 73 | + int minHeight = context.get(minHeightArg); |
| 74 | + int maxHeight = context.get(maxHeightArg); |
| 75 | + int minWidth = context.get(minWidthArg); |
| 76 | + int maxWidth = context.get(maxWidthArg); |
| 77 | + |
| 78 | + if (minHeight > maxHeight) { |
| 79 | + player.sendMessage("§cMinimum height cannot be greater than maximum height!"); |
| 80 | + return; |
| 81 | + } |
| 82 | + |
| 83 | + if (minWidth > maxWidth) { |
| 84 | + player.sendMessage("§cMinimum width cannot be greater than maximum width!"); |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + if (minHeight < 2 || maxHeight > 50) { |
| 89 | + player.sendMessage("§cHeight must be between 2 and 50!"); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + if (minWidth < 1 || maxWidth > 20) { |
| 94 | + player.sendMessage("§cWidth must be between 1 and 20!"); |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + TreeConfig customConfig = type.getDefaultConfig() |
| 99 | + .withMinHeight(minHeight) |
| 100 | + .withMaxHeight(maxHeight) |
| 101 | + .withMinWidth(minWidth) |
| 102 | + .withMaxWidth(maxWidth); |
| 103 | + |
| 104 | + generateTree(player, type, customConfig); |
| 105 | + }, treeTypeArg, minHeightArg, maxHeightArg, minWidthArg, maxWidthArg); |
| 106 | + } |
| 107 | + |
| 108 | + private void generateTree(SkyBlockPlayer player, TreeType type, TreeConfig config) { |
| 109 | + SkyBlockTree tree = new SkyBlockTree( |
| 110 | + 0, |
| 111 | + player.getPosition().blockX(), |
| 112 | + player.getPosition().blockY(), |
| 113 | + player.getPosition().blockZ(), |
| 114 | + type, |
| 115 | + config |
| 116 | + ); |
| 117 | + |
| 118 | + tree.build((SharedInstance) player.getInstance()); |
| 119 | + |
| 120 | + player.sendMessage("§aGenerated " + type.name().toLowerCase().replace("_", " ") + |
| 121 | + " tree! Height: " + config.minHeight() + "-" + config.maxHeight() + |
| 122 | + ", Width: " + config.minWidth() + "-" + config.maxWidth()); |
| 123 | + } |
| 124 | +} |
0 commit comments