diff --git a/src/me/yaruma/fightsystem/kit/Kit.java b/src/me/yaruma/fightsystem/kit/Kit.java index 7a24b26..ec849ad 100644 --- a/src/me/yaruma/fightsystem/kit/Kit.java +++ b/src/me/yaruma/fightsystem/kit/Kit.java @@ -1,6 +1,7 @@ package me.yaruma.fightsystem.kit; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.PlayerInventory; public class Kit { @@ -8,14 +9,14 @@ public class Kit { private int price; private boolean leaderAllowed; private boolean memberAllowed; - private Inventory inventory; + private PlayerInventory playerInventory; - public Kit(String name, int price, boolean leaderAllowed, boolean memberAllowed, Inventory inventory) { + public Kit(String name, int price, boolean leaderAllowed, boolean memberAllowed, PlayerInventory playerInventory) { this.name = name; this.price = price; this.leaderAllowed = leaderAllowed; this.memberAllowed = memberAllowed; - this.inventory = inventory; + this.playerInventory = playerInventory; } public String getName() { @@ -50,11 +51,11 @@ public class Kit { this.memberAllowed = memberAllowed; } - public Inventory getInventory() { - return inventory; + public PlayerInventory getInventory() { + return playerInventory; } - public void setInventory(Inventory inventory) { - this.inventory = inventory; + public void setPlayerInventory(Inventory inventory) { + this.playerInventory = playerInventory; } } diff --git a/src/me/yaruma/fightsystem/kit/KitManager.java b/src/me/yaruma/fightsystem/kit/KitManager.java index 59cdc1c..08e5c2b 100644 --- a/src/me/yaruma/fightsystem/kit/KitManager.java +++ b/src/me/yaruma/fightsystem/kit/KitManager.java @@ -1,11 +1,15 @@ package me.yaruma.fightsystem.kit; +import de.warking.hunjy.CoinSystem.CoinSystem; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.fight.Fight; import me.yaruma.fightsystem.fight.FightPlayer; +import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import java.io.File; import java.io.IOException; @@ -14,6 +18,7 @@ import java.util.List; public class KitManager { + public static final FightSystem instance = FightSystem.getPlugin(); public static final String PREFIX = "[KIT] "; private static final String kitsPath = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data"; @@ -34,39 +39,70 @@ public class KitManager { yamlConfiguration.save(new File(kitsPath)); } - public boolean canBuy() { - return false; //wird spaeter gemacht + public boolean canBuy(Player player, String kitName) { + if(getKitByName(kitName).getPrice() <= CoinSystem.getCoinsManager(player).getCoins()) { + return true; + } else + return false; } public void buyKit() { //wird spaeter gemacht } - public boolean ownsKit() { - return false; //wird spaeter gemacht + public boolean ownsKit(Player player) { + return true; //wird spaeter gemacht } public void loadKitToPlayer(Kit kit, Player player) { if(kit != null) { - //ownsKit() methode - FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); - if(fightPlayer != null) { - if(fightPlayer.isLeader() && kit.isLeaderAllowed() || !fightPlayer.isLeader() && kit.isMemberAllowed()) { - loadInventoryToPlayer(kit.getName(), player); - player.sendMessage(PREFIX + "§6" + kit.getName() + " §ageladen!"); + if(ownsKit(player)) { + + FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); + if(fightPlayer != null) { + if(fightPlayer.isLeader() && kit.isLeaderAllowed() || !fightPlayer.isLeader() && kit.isMemberAllowed()) { + loadInventoryToPlayer(kit.getName(), player); + player.sendMessage(PREFIX + "§6" + kit.getName() + " §ageladen!"); + } else { + player.sendMessage(PREFIX + "§cDu darfst dieses Kit nicht verwenden!"); + System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN WELCHES FUER IHN NICHT ZUGAENGLICH IST!"); + } } else { - player.sendMessage(PREFIX + "§cDu darfst dieses Kit nicht verwenden!"); - System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN WELCHES FUER IHN NICHT ZUGAENGLICH IST!"); + player.sendMessage(PREFIX + "§cDu befindest dich in keinem Team!"); + System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN OBWOHL ER IN KEINEM TEAM IST!"); } + } else { - player.sendMessage(PREFIX + "§cDu befindest dich in keinem Team!"); - System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN OBWOHL ER IN KEINEM TEAM IST!"); + player.sendMessage(PREFIX + "§cDu besitzt dieses Kit nicht!"); + System.out.println("§4Warning: JEMAND HAT VERSUCHT EIN KIT ZU LADEN WELCHES ER NICHT BESITZT!"); } } } + public Kit loadKitFromConfig(String name) { + if(instance.getKitData().contains("Kit." + name)) { + ItemStack[] armor = (ItemStack[]) instance.getKitData().get("Kit." + name + ".Armor"); + ItemStack[] items = (ItemStack[]) instance.getKitData().get("Kit." + name + ".Items"); + + PlayerInventory playerInventory = (PlayerInventory) Bukkit.createInventory(null, InventoryType.PLAYER); + playerInventory.setArmorContents(armor); + playerInventory.setContents(items); + + int price = instance.getKitData().getInt("Kits." + name + ".Price"); + boolean leaderAllowed = instance.getKitData().getBoolean("Kits." + name + ".LeaderAllowed"); + boolean memberAllowed = instance.getKitData().getBoolean("Kits." + name + ".MemberAllowed"); + + Kit kit = new Kit(name, price, leaderAllowed, memberAllowed, playerInventory); + return kit; + } else + System.out.println("§4Warning: ES WURDE VERSUCHT EIN KIT ZU LADEN DAS NICHT EXISTIERT!"); + return null; + } + public void loadAllKits() { - //Lade alle Kits aus der Config + for(String key : instance.getKitData().getConfigurationSection("Kits").getKeys(false)) { + loadedKits.add(loadKitFromConfig(key)); + } } public Kit getKitByName(String kitName) {