hugo4715
6/17/2016 - 2:01 PM

KitSelecotrGui.java

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import fr.hugo4715.crackedskywars.SkyWars;
import fr.hugo4715.crackedskywars.data.PlayerData;
import fr.hugo4715.crackedskywars.kit.internal.Kit;
import fr.hugo4715.crackedskywars.util.EnchantGlow;
import net.md_5.bungee.api.ChatColor;

public class KitSelectorGui extends AbstractGui {
	PlayerData data;
	public KitSelectorGui(Player player) {
		super(SkyWars.get(), player, ChatColor.GREEN + "Kits", 2*9, 10);
		data = SkyWars.get().getPlayerData(player);
	}
	
	@Override
	public void update() {
		if(data == null || data.getKits() == null)return;
		
		for(final AtomicInteger i = new AtomicInteger(0); i.get() < inv.getSize();i.incrementAndGet()){
			if(i.get() < data.getKits().length){
				Validate.notNull(data.getKits());
				ItemStack s = data.getKits()[i.get()].getIcon();
				if(data.getSelectedKit().equals(data.getKits()[i.get()].getClass().getSimpleName()))EnchantGlow.addGlow(s);
				
				inv.setItem(i.get(), s);
				buttons.put(i.get(), new ButtonClickListener() {
					
					@Override
					void onClick(int slot) {
						System.out.println(slot);
						Kit k = data.getKits()[slot];
						
						if(k.isBought()){
							data.setSelectedKit(k.getClass().getSimpleName());
							player.sendMessage(ChatColor.GREEN + "Vous avez maintenant le kit " + k.getClass().getSimpleName().substring("Kit".length()));
							stop();
						}else{
							player.sendMessage(ChatColor.RED + "Ce kit n'est pas debloqué!");
							stop();
						}						
					}
				});
			}
		}
	}

}