1818
1919package me .cubecrafter .woolwars .kit ;
2020
21+ import com .cryptomorin .xseries .XPotion ;
2122import lombok .Getter ;
2223import me .cubecrafter .woolwars .WoolWars ;
2324import me .cubecrafter .woolwars .arena .team .Team ;
2930import org .bukkit .configuration .file .YamlConfiguration ;
3031import org .bukkit .inventory .ItemStack ;
3132import org .bukkit .inventory .PlayerInventory ;
33+ import org .bukkit .potion .PotionEffect ;
3234
35+ import java .util .ArrayList ;
3336import java .util .HashMap ;
37+ import java .util .List ;
3438import java .util .Map ;
3539
3640@ Getter
@@ -45,6 +49,7 @@ public class Kit {
4549
4650 private final Map <Integer , ItemStack > contents = new HashMap <>();
4751 private final ItemStack [] armor = new ItemStack [4 ];
52+ private final List <PotionEffect > effects = new ArrayList <>();
4853
4954 private final Ability ability ;
5055
@@ -66,6 +71,11 @@ public Kit(String id, YamlConfiguration config) {
6671 if (section == null ) continue ;
6772 armor [i ] = ItemBuilder .fromConfig (section ).setUnbreakable (true ).build ();
6873 }
74+
75+ for (String effect : config .getStringList ("effects" )) {
76+ String [] split = effect .split (":" );
77+ effects .add (XPotion .matchXPotion (split [0 ]).orElse (XPotion .SPEED ).buildPotionEffect (Integer .MAX_VALUE , Integer .parseInt (split [1 ]) - 1 ));
78+ }
6979 }
7080
7181 public void addToPlayer (WoolPlayer player , Team team ) {
@@ -75,6 +85,8 @@ public void addToPlayer(WoolPlayer player, Team team) {
7585 }
7686 player .getData ().setSelectedKit (id );
7787
88+ player .getPlayer ().getActivePotionEffects ().forEach (effect -> player .getPlayer ().removePotionEffect (effect .getType ()));
89+
7890 PlayerInventory inventory = player .getPlayer ().getInventory ();
7991 inventory .clear ();
8092 inventory .setArmorContents (null );
@@ -103,6 +115,8 @@ public void addToPlayer(WoolPlayer player, Team team) {
103115 }
104116 inventory .setItem (ability .getSlot (), ability .getItem ());
105117
118+ effects .forEach (effect -> player .getPlayer ().addPotionEffect (effect ));
119+
106120 player .send (Messages .KIT_SELECTED .asString ().replace ("{name}" , name ));
107121 }
108122
0 commit comments