finished basics of Kit System (not tested)
Signed-off-by: Yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
9c638e9b3d
Commit
02d25dfcfa
@ -1,6 +1,7 @@
|
|||||||
package me.yaruma.fightsystem.kit;
|
package me.yaruma.fightsystem.kit;
|
||||||
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
public class Kit {
|
public class Kit {
|
||||||
|
|
||||||
@ -8,14 +9,14 @@ public class Kit {
|
|||||||
private int price;
|
private int price;
|
||||||
private boolean leaderAllowed;
|
private boolean leaderAllowed;
|
||||||
private boolean memberAllowed;
|
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.name = name;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
this.leaderAllowed = leaderAllowed;
|
this.leaderAllowed = leaderAllowed;
|
||||||
this.memberAllowed = memberAllowed;
|
this.memberAllowed = memberAllowed;
|
||||||
this.inventory = inventory;
|
this.playerInventory = playerInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -50,11 +51,11 @@ public class Kit {
|
|||||||
this.memberAllowed = memberAllowed;
|
this.memberAllowed = memberAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory getInventory() {
|
public PlayerInventory getInventory() {
|
||||||
return inventory;
|
return playerInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInventory(Inventory inventory) {
|
public void setPlayerInventory(Inventory inventory) {
|
||||||
this.inventory = inventory;
|
this.playerInventory = playerInventory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package me.yaruma.fightsystem.kit;
|
package me.yaruma.fightsystem.kit;
|
||||||
|
|
||||||
|
import de.warking.hunjy.CoinSystem.CoinSystem;
|
||||||
import me.yaruma.fightsystem.FightSystem;
|
import me.yaruma.fightsystem.FightSystem;
|
||||||
import me.yaruma.fightsystem.fight.Fight;
|
import me.yaruma.fightsystem.fight.Fight;
|
||||||
import me.yaruma.fightsystem.fight.FightPlayer;
|
import me.yaruma.fightsystem.fight.FightPlayer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -14,6 +18,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class KitManager {
|
public class KitManager {
|
||||||
|
|
||||||
|
public static final FightSystem instance = FightSystem.getPlugin();
|
||||||
public static final String PREFIX = "[KIT] ";
|
public static final String PREFIX = "[KIT] ";
|
||||||
private static final String kitsPath = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data";
|
private static final String kitsPath = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data";
|
||||||
|
|
||||||
@ -34,21 +39,25 @@ public class KitManager {
|
|||||||
yamlConfiguration.save(new File(kitsPath));
|
yamlConfiguration.save(new File(kitsPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBuy() {
|
public boolean canBuy(Player player, String kitName) {
|
||||||
return false; //wird spaeter gemacht
|
if(getKitByName(kitName).getPrice() <= CoinSystem.getCoinsManager(player).getCoins()) {
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buyKit() {
|
public void buyKit() {
|
||||||
//wird spaeter gemacht
|
//wird spaeter gemacht
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ownsKit() {
|
public boolean ownsKit(Player player) {
|
||||||
return false; //wird spaeter gemacht
|
return true; //wird spaeter gemacht
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadKitToPlayer(Kit kit, Player player) {
|
public void loadKitToPlayer(Kit kit, Player player) {
|
||||||
if(kit != null) {
|
if(kit != null) {
|
||||||
//ownsKit() methode
|
if(ownsKit(player)) {
|
||||||
|
|
||||||
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
|
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
|
||||||
if(fightPlayer != null) {
|
if(fightPlayer != null) {
|
||||||
if(fightPlayer.isLeader() && kit.isLeaderAllowed() || !fightPlayer.isLeader() && kit.isMemberAllowed()) {
|
if(fightPlayer.isLeader() && kit.isLeaderAllowed() || !fightPlayer.isLeader() && kit.isMemberAllowed()) {
|
||||||
@ -62,11 +71,38 @@ public class KitManager {
|
|||||||
player.sendMessage(PREFIX + "§cDu befindest dich in keinem Team!");
|
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!");
|
System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN OBWOHL ER IN KEINEM TEAM IST!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
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() {
|
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) {
|
public Kit getKitByName(String kitName) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren