SteamWar/FightSystem
Archiviert
13
1

started coding Kit System

Signed-off-by: Yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-03-26 22:59:47 +01:00
Ursprung c76cac319e
Commit 9c638e9b3d
4 geänderte Dateien mit 134 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -71,10 +71,13 @@ public class FightSystem extends JavaPlugin {
private final File kits = new File("plugins/" + this.getName(), "kits.data"); private final File kits = new File("plugins/" + this.getName(), "kits.data");
private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits); private final FileConfiguration getKitData = YamlConfiguration.loadConfiguration(kits);
private void saveKitData() { public void saveKitData() {
try { getKitData.save(kits); } catch (Exception ignored) { } try { getKitData.save(kits); } catch (Exception ignored) { }
} }
public FileConfiguration getKitData() {
return getKitData;
}
public void onEnable() { public void onEnable() {
@ -163,6 +166,8 @@ public class FightSystem extends JavaPlugin {
loadConfig(); loadConfig();
getKitManager().loadAllKits();
init(); init();
fightState = FightState.SETUP; fightState = FightState.SETUP;
@ -204,6 +209,7 @@ public class FightSystem extends JavaPlugin {
if(!new File("plugins/" + this.getName() + "/config.yml").exists()) { if(!new File("plugins/" + this.getName() + "/config.yml").exists()) {
saveDefaultConfig(); saveDefaultConfig();
System.out.println(PREFIX + "config.yml erstellt und geladen!"); System.out.println(PREFIX + "config.yml erstellt und geladen!");
Bukkit.shutdown();
} }
if(!new File("plugins/" + this.getName() + "/kits.data").exists()) { if(!new File("plugins/" + this.getName() + "/kits.data").exists()) {
saveKitData(); saveKitData();

Datei anzeigen

@ -114,7 +114,7 @@ public class AkCommand implements CommandExecutor {
} }
} else if(args[0].equalsIgnoreCase("kit")) { } else if(args[0].equalsIgnoreCase("kit")) {
if(FightSystem.getPlugin().getFightState() == FightState.SETUP) { if(FightSystem.getPlugin().getFightState() == FightState.SETUP) {
FightSystem.getPlugin().getKitManager().loadInventoryToPlayer("plugins/" + FightSystem.getPlugin().getName() + "/kits.data", player); //Kit
} }
} }
}else{ }else{

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -1,29 +1,87 @@
package me.yaruma.fightsystem.kit; 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.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class KitManager { public class KitManager {
public void loadInventoryToPlayer(String path, Player player) { public static final String PREFIX = "[KIT] ";
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new File(path)); private static final String kitsPath = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data";
ItemStack[] content = ((List<ItemStack>) yamlConfiguration.get("inventory.armor")).toArray(new ItemStack[0]);
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); 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); 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 yamlConfiguration = new YamlConfiguration();
yamlConfiguration.set("inventory.armor", player.getInventory().getArmorContents()); yamlConfiguration.set("Kits." + kitName + ".Armor", player.getInventory().getArmorContents());
yamlConfiguration.set("inventory.contents", player.getInventory().getContents()); yamlConfiguration.set("Kits." + kitName + ".Items", player.getInventory().getContents());
yamlConfiguration.save(new File(path)); 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;
}
} }