From fcde18f0c81458a1cb00001f8883eeb1abc77875 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 28 Aug 2022 19:03:12 +0200 Subject: [PATCH] Add item giver --- src/de/steamwar/misslewars/MissileWars.java | 4 ++++ .../misslewars/commands/CommandItems.java | 24 +++++++++++++++++++ .../misslewars/items/SpecialItem.java | 9 +++++++ 3 files changed, 37 insertions(+) create mode 100644 src/de/steamwar/misslewars/commands/CommandItems.java diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index e179d89..34d97db 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -21,6 +21,7 @@ package de.steamwar.misslewars; import de.steamwar.misslewars.commands.CommandAcceptDecline; import de.steamwar.misslewars.commands.CommandInvite; +import de.steamwar.misslewars.commands.CommandItems; import de.steamwar.misslewars.commands.CommandSpectate; import de.steamwar.misslewars.countdowns.EndCountdown; import de.steamwar.misslewars.countdowns.ItemCountdown; @@ -93,6 +94,9 @@ public class MissileWars extends JavaPlugin { StateDependent.setupState(fightState); Bukkit.getScheduler().runTaskTimer(this, new FightInfoPacketSender(), 20, 20); + if(Config.test()) { + new CommandItems(); + } } public static void waiting() { diff --git a/src/de/steamwar/misslewars/commands/CommandItems.java b/src/de/steamwar/misslewars/commands/CommandItems.java new file mode 100644 index 0000000..86629b0 --- /dev/null +++ b/src/de/steamwar/misslewars/commands/CommandItems.java @@ -0,0 +1,24 @@ +package de.steamwar.misslewars.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.misslewars.items.SpecialItem; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.stream.Collectors; + +public class CommandItems extends SWCommand { + public CommandItems() { + super("give"); + } + + public void genericCommand(Player player, String[] args) { + SWListInv inv = new SWListInv<>(player, "Misslewars Items", SpecialItem.getAllItems().stream().map(item -> new SWListInv.SWListEntry<>(new SWItem(item.getType(), item.getItemMeta().getDisplayName()), item)).collect(Collectors.toList()), (clickType, itemStack) -> { + player.closeInventory(); + player.getInventory().addItem(itemStack); + }); + inv.open(); + } +} diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index 5144bcc..2cc7cd7 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -117,4 +117,13 @@ public abstract class SpecialItem { lastItemWasSupportItem = false; return missileItems.get(random.nextInt(missileItems.size())).getItem(); } + + public static List getAllItems() { + List items = new ArrayList<>(); + for (SpecialItem specialItem : supportItems) + items.add(specialItem.getItem()); + for (SpecialItem specialItem : missileItems) + items.add(specialItem.getItem()); + return items; + } }