From 990bddf300e916f5dd0bfb9c48fbccb0a6f37960 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Fri, 14 Jun 2019 17:21:40 +0200 Subject: [PATCH] Inviting and removing via GUI --- src/me/yaruma/fightsystem/commands/GUI.java | 25 +++++++++++++++++++ .../yaruma/fightsystem/fight/FightTeam.java | 2 ++ .../listener/PlayerInteractListener.java | 10 +++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/me/yaruma/fightsystem/commands/GUI.java b/src/me/yaruma/fightsystem/commands/GUI.java index bd7f28c..d124a5e 100644 --- a/src/me/yaruma/fightsystem/commands/GUI.java +++ b/src/me/yaruma/fightsystem/commands/GUI.java @@ -13,12 +13,14 @@ import me.yaruma.fightsystem.fight.FightTeam; import me.yaruma.fightsystem.kit.Kit; import me.yaruma.fightsystem.kit.KitManager; import me.yaruma.fightsystem.utils.Config; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class GUI { @@ -44,6 +46,29 @@ public class GUI { inv.open(); } + public static void chooseInvitation(Player p){ + List> players = SWListInv.createPlayerList(p); + players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getValue())) != null); + SWListInv inv = new SWListInv<>(p, "Spieler einladen", (ClickType click, UUID player) -> { + p.performCommand("invite " + WarkingUser.get(player).getUserName()); + p.closeInventory(); + }, players); + inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + inv.open(); + } + + public static void chooseRemove(Player p){ + List> players = SWListInv.createPlayerList(p); + FightTeam team = Fight.getPlayerTeam(p); + players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getValue())))); + SWListInv inv = new SWListInv<>(p, "Spieler rauswerfen", (ClickType click, UUID player) -> { + p.performCommand("ak remove " + WarkingUser.get(player).getUserName()); + p.closeInventory(); + }, players); + inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + inv.open(); + } + public static void kitSelection(Player p){ FightPlayer fightPlayer = Fight.getFightPlayer(p); List> iconList = new ArrayList<>(); diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index 47e04f5..2fcfe40 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -142,6 +142,8 @@ public class FightTeam { this.leader = leader; leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); Inventory inventory = leader.getPlayer().getInventory(); + inventory.setItem(0, new ItemBuilder(Material.PAPER).removeAllAtributs().setDisplayName("§eSpieler einladen").build()); + inventory.setItem(2, new ItemBuilder(Material.FIREWORK_CHARGE).removeAllAtributs().setDisplayName("§cSpieler rauswerfen").build()); inventory.setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); inventory.setItem(5, new ItemBuilder(Material.INK_SACK, (short) 1).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§4Abbrechen").build()); inventory.setItem(7, new ItemBuilder(Material.CAULDRON_ITEM).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); diff --git a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java index 3c4277c..70be055 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java @@ -15,12 +15,10 @@ import org.bukkit.inventory.meta.ItemMeta; public class PlayerInteractListener implements Listener { - private final FightSystem instance = FightSystem.getPlugin(); - @EventHandler public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if(instance.getFightState() == FightState.SETUP && + if(FightSystem.getFightState() == FightState.SETUP && event.getItem() != null && Fight.getPlayerTeam(player) != null) { ItemMeta itemMeta = event.getItem().getItemMeta(); @@ -37,6 +35,12 @@ public class PlayerInteractListener implements Listener { } switch (displayName) { + case "§cSpieler rauswerfen": + GUI.chooseRemove(player); + break; + case "§eSpieler einladen": + GUI.chooseInvitation(player); + break; case "§cNicht bereit": fightTeam.setReady(true); break;