9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 10:59:22 +00:00

Added amount option to /eagive

This commit is contained in:
Auxilor
2021-01-22 21:00:53 +00:00
parent e02241b740
commit e37612cff2
2 changed files with 121 additions and 36 deletions

View File

@@ -10,9 +10,11 @@ import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class CommandEagive extends AbstractCommand {
@@ -51,14 +53,25 @@ public class CommandEagive extends AbstractCommand {
return;
}
String itemName = args.get(1);
if (!itemName.contains(":")) {
String fullItemKey = args.get(1);
if (!fullItemKey.contains(":")) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String[] fullItemSplit = fullItemKey.split(":");
if (fullItemSplit.length == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
String itemNamespace = fullItemSplit[0];
String itemKey = fullItemSplit[1];
if (itemName.split(":")[0].equals("set")) {
ArmorSet set = ArmorSets.getByName(itemName.split(":")[1]);
List<ItemStack> items = new ArrayList<>();
int amount = 1;
if (itemKey.equalsIgnoreCase("set")) {
ArmorSet set = ArmorSets.getByName(itemKey);
if (set == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
@@ -73,36 +86,53 @@ public class CommandEagive extends AbstractCommand {
advanced = Boolean.parseBoolean(args.get(3));
}
if (args.size() >= 5) {
try {
amount = Integer.parseInt(args.get(4));
} catch (NumberFormatException e) {
amount = 1;
}
}
if (args.size() >= 3) {
ArmorSlot slot = ArmorSlot.getSlot(args.get(2));
if (slot == null) {
if (slot == null && !args.get(2).equalsIgnoreCase("full")) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
}
if (advanced) {
reciever.getInventory().addItem(set.getAdvancedItemStack(slot));
if (slot != null) {
items.add(set.getAdvancedItemStack(slot));
} else {
for (ArmorSlot slot2 : ArmorSlot.values()) {
items.add(set.getAdvancedItemStack(slot2));
}
}
} else {
reciever.getInventory().addItem(set.getItemStack(slot));
if (slot != null) {
items.add(set.getItemStack(slot));
} else {
for (ArmorSlot slot2 : ArmorSlot.values()) {
items.add(set.getItemStack(slot2));
}
}
}
} else {
for (ArmorSlot slot : ArmorSlot.values()) {
if (advanced) {
items.add(set.getAdvancedItemStack(slot));
} else {
items.add(set.getItemStack(slot));
}
}
return;
}
for (ArmorSlot slot : ArmorSlot.values()) {
if (advanced) {
reciever.getInventory().addItem(set.getAdvancedItemStack(slot));
} else {
reciever.getInventory().addItem(set.getItemStack(slot));
}
}
return;
}
if (itemName.split(":")[0].equals("crystal")) {
UpgradeCrystal crystal = UpgradeCrystal.getByName(itemName.split(":")[1]);
if (itemNamespace.equalsIgnoreCase("crystal")) {
UpgradeCrystal crystal = UpgradeCrystal.getByName(itemKey);
if (crystal == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
@@ -111,13 +141,19 @@ public class CommandEagive extends AbstractCommand {
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%item%", crystal.getItemStack().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
reciever.getInventory().addItem(crystal.getItemStack());
items.add(crystal.getItemStack());
return;
if (args.size() >= 3) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException e) {
amount = 1;
}
}
}
if (itemName.split(":")[0].equals("shard")) {
ArmorSet set = ArmorSets.getByName(itemName.split(":")[1]);
if (itemNamespace.equalsIgnoreCase("shard")) {
ArmorSet set = ArmorSets.getByName(itemKey);
if (set == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
return;
@@ -126,9 +162,21 @@ public class CommandEagive extends AbstractCommand {
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%item%", set.getAdvancementShardItem().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
reciever.getInventory().addItem(set.getAdvancementShardItem());
items.add(set.getAdvancementShardItem());
return;
if (args.size() >= 3) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException e) {
amount = 1;
}
}
}
for (ItemStack item : items) {
for (int i = 0; i < amount; i++) {
reciever.getInventory().addItem(item);
}
}
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));

View File

@@ -21,10 +21,29 @@ import java.util.stream.Collectors;
public class TabcompleterEagive extends AbstractTabCompleter {
/**
* The cached enchantment names.
* The cached names.
*/
private static final List<String> SET_NAMES = new ArrayList<>();
/**
* The cached slots.
*/
private static final List<String> SLOTS = new ArrayList<>();
/**
* The cached numbers.
*/
private static final List<String> NUMBERS = Arrays.asList(
"1",
"2",
"3",
"4",
"5",
"10",
"32",
"64"
);
/**
* Instantiate a new tab-completer for /eagive.
*/
@@ -42,6 +61,8 @@ public class TabcompleterEagive extends AbstractTabCompleter {
SET_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "set:" + armorSet.getName()).collect(Collectors.toList()));
SET_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "shard:" + armorSet.getName()).collect(Collectors.toList()));
SET_NAMES.addAll(UpgradeCrystal.values().stream().map(crystal -> "crystal:" + crystal.getTier()).collect(Collectors.toList()));
SLOTS.addAll(Arrays.stream(ArmorSlot.values()).map(slot -> slot.name().toLowerCase()).collect(Collectors.toList()));
SLOTS.add("full");
}
/**
@@ -73,18 +94,34 @@ public class TabcompleterEagive extends AbstractTabCompleter {
return completions;
}
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), Arrays.stream(ArmorSlot.values()).map(slot -> slot.name().toLowerCase()).collect(Collectors.toList()), completions);
if (args.get(1).startsWith("set:")) {
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), SLOTS, completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), Arrays.asList("true", "false"), completions);
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), Arrays.asList("true", "false"), completions);
Collections.sort(completions);
return completions;
Collections.sort(completions);
return completions;
}
if (args.size() == 5) {
StringUtil.copyPartialMatches(args.get(4), NUMBERS, completions);
Collections.sort(completions);
return completions;
}
} else {
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
Collections.sort(completions);
return completions;
}
}
return new ArrayList<>(0);