started coding Kit System
Signed-off-by: Yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
c76cac319e
Commit
9c638e9b3d
@ -71,10 +71,13 @@ public class FightSystem extends JavaPlugin {
|
||||
private final File kits = new File("plugins/" + this.getName(), "kits.data");
|
||||
private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits);
|
||||
|
||||
private void saveKitData() {
|
||||
public void saveKitData() {
|
||||
try { getKitData.save(kits); } catch (Exception ignored) { }
|
||||
}
|
||||
|
||||
public FileConfiguration getKitData() {
|
||||
return getKitData;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
@ -163,6 +166,8 @@ public class FightSystem extends JavaPlugin {
|
||||
|
||||
loadConfig();
|
||||
|
||||
getKitManager().loadAllKits();
|
||||
|
||||
init();
|
||||
|
||||
fightState = FightState.SETUP;
|
||||
@ -204,6 +209,7 @@ public class FightSystem extends JavaPlugin {
|
||||
if(!new File("plugins/" + this.getName() + "/config.yml").exists()) {
|
||||
saveDefaultConfig();
|
||||
System.out.println(PREFIX + "config.yml erstellt und geladen!");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
if(!new File("plugins/" + this.getName() + "/kits.data").exists()) {
|
||||
saveKitData();
|
||||
|
@ -114,7 +114,7 @@ public class AkCommand implements CommandExecutor {
|
||||
}
|
||||
} else if(args[0].equalsIgnoreCase("kit")) {
|
||||
if(FightSystem.getPlugin().getFightState() == FightState.SETUP) {
|
||||
FightSystem.getPlugin().getKitManager().loadInventoryToPlayer("plugins/" + FightSystem.getPlugin().getName() + "/kits.data", player);
|
||||
//Kit
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
60
src/me/yaruma/fightsystem/kit/Kit.java
Normale Datei
60
src/me/yaruma/fightsystem/kit/Kit.java
Normale Datei
@ -0,0 +1,60 @@
|
||||
package me.yaruma.fightsystem.kit;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class Kit {
|
||||
|
||||
private String name;
|
||||
private int price;
|
||||
private boolean leaderAllowed;
|
||||
private boolean memberAllowed;
|
||||
private Inventory inventory;
|
||||
|
||||
public Kit(String name, int price, boolean leaderAllowed, boolean memberAllowed, Inventory inventory) {
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
this.leaderAllowed = leaderAllowed;
|
||||
this.memberAllowed = memberAllowed;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public boolean isLeaderAllowed() {
|
||||
return leaderAllowed;
|
||||
}
|
||||
|
||||
public void setLeaderAllowed(boolean leaderAllowed) {
|
||||
this.leaderAllowed = leaderAllowed;
|
||||
}
|
||||
|
||||
public boolean isMemberAllowed() {
|
||||
return memberAllowed;
|
||||
}
|
||||
|
||||
public void setMemberAllowed(boolean memberAllowed) {
|
||||
this.memberAllowed = memberAllowed;
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
}
|
@ -1,29 +1,87 @@
|
||||
package me.yaruma.fightsystem.kit;
|
||||
|
||||
import me.yaruma.fightsystem.FightSystem;
|
||||
import me.yaruma.fightsystem.fight.Fight;
|
||||
import me.yaruma.fightsystem.fight.FightPlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KitManager {
|
||||
|
||||
public void loadInventoryToPlayer(String path, Player player) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new File(path));
|
||||
ItemStack[] content = ((List<ItemStack>) yamlConfiguration.get("inventory.armor")).toArray(new ItemStack[0]);
|
||||
public static final String PREFIX = "[KIT] ";
|
||||
private static final String kitsPath = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data";
|
||||
|
||||
private static ArrayList<Kit> loadedKits = new ArrayList<>();
|
||||
|
||||
private void loadInventoryToPlayer(String kitName, Player player) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new File(kitsPath));
|
||||
ItemStack[] content = ((List<ItemStack>) yamlConfiguration.get("Kits." + kitName + ".Armor")).toArray(new ItemStack[0]);
|
||||
player.getInventory().setArmorContents(content);
|
||||
content = ((List<ItemStack>) yamlConfiguration.get("inventory.content")).toArray(new ItemStack[0]);
|
||||
content = ((List<ItemStack>) yamlConfiguration.get("Kits." + kitName + ".Items")).toArray(new ItemStack[0]);
|
||||
player.getInventory().setContents(content);
|
||||
}
|
||||
|
||||
public void saveInventory(String path, Player player) throws IOException {
|
||||
private void saveInventory(String kitName, Player player) throws IOException {
|
||||
YamlConfiguration yamlConfiguration = new YamlConfiguration();
|
||||
yamlConfiguration.set("inventory.armor", player.getInventory().getArmorContents());
|
||||
yamlConfiguration.set("inventory.contents", player.getInventory().getContents());
|
||||
yamlConfiguration.save(new File(path));
|
||||
yamlConfiguration.set("Kits." + kitName + ".Armor", player.getInventory().getArmorContents());
|
||||
yamlConfiguration.set("Kits." + kitName + ".Items", player.getInventory().getContents());
|
||||
yamlConfiguration.save(new File(kitsPath));
|
||||
}
|
||||
|
||||
|
||||
public boolean canBuy() {
|
||||
return false; //wird spaeter gemacht
|
||||
}
|
||||
|
||||
public void buyKit() {
|
||||
//wird spaeter gemacht
|
||||
}
|
||||
|
||||
public boolean ownsKit() {
|
||||
return false; //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!");
|
||||
} 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 befindest dich in keinem Team!");
|
||||
System.out.println(PREFIX + "§4Warning: EIN SPIELER WOLLTE EIN KIT AUSWAEHLEN OBWOHL ER IN KEINEM TEAM IST!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAllKits() {
|
||||
//Lade alle Kits aus der Config
|
||||
}
|
||||
|
||||
public Kit getKitByName(String kitName) {
|
||||
for(Kit kit : loadedKits) {
|
||||
if(kit.getName().equalsIgnoreCase(kitName))
|
||||
return kit;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getKitsPath() {
|
||||
return kitsPath;
|
||||
}
|
||||
|
||||
public static ArrayList<Kit> getLoadedKits() {
|
||||
return loadedKits;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren