SteamWar/FightSystem
Archiviert
13
1

Effekte in Kits verfügbar machen #76

Zusammengeführt
Lixfel hat 3 Commits von dev nach master 2019-12-22 17:17:20 +01:00 zusammengeführt
3 geänderte Dateien mit 74 neuen und 73 gelöschten Zeilen
Nur Änderungen aus Commit be6693e85a werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,22 +1,44 @@
package de.steamwar.fightsystem.kit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.Collection;
import java.util.Objects;
public class Kit {
private String name;
private boolean leaderAllowed;
private boolean memberAllowed;
private ItemStack[] inventory;
private ItemStack[] armor;
private final String name;
private final boolean leaderAllowed;
private final boolean memberAllowed;
private final ItemStack[] inventory;
private final ItemStack[] armor;
private final Collection<PotionEffect> effects;
Kit(String name, boolean leaderAllowed, boolean memberAllowed, ItemStack[] inventory, ItemStack[] armor) {
Kit(String name, Player player) {
this.name = name;
this.leaderAllowed = leaderAllowed;
this.memberAllowed = memberAllowed;
this.inventory = inventory;
this.armor = armor;
this.leaderAllowed = true;
this.memberAllowed = true;
this.inventory = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents();
this.effects = player.getActivePotionEffects();
}
Kit(ConfigurationSection kit){
name = kit.getName();
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[1]);
if(kit.isList("Armor"))
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[1]);
else
armor = null;
leaderAllowed = kit.getBoolean("LeaderAllowed");
memberAllowed = kit.getBoolean("MemberAllowed");
if(kit.isList("Effects"))
effects = (Collection<PotionEffect>) kit.getList("Effects");
else
effects = null;
}
public String getName() {
@ -31,18 +53,20 @@ public class Kit {
return memberAllowed;
}
ItemStack[] getInventory() {
return inventory;
}
ItemStack[] getArmor(){
return armor;
}
public void loadToPlayer(Player player) {
player.getInventory().setContents(inventory);
if(armor != null)
player.getInventory().setArmorContents(armor);
player.updateInventory();
player.addPotionEffects(effects);
}
void saveKit(ConfigurationSection section){
section.set("Items", inventory);
if(armor != null)
section.set("Armor", armor);
section.set("LeaderAllowed", leaderAllowed);
section.set("MemberAllowed", memberAllowed);
section.set("Effects", effects);
}
}

Datei anzeigen

@ -5,7 +5,6 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.IOException;
@ -14,7 +13,6 @@ import java.util.List;
import java.util.logging.Level;
public class KitManager {
private KitManager(){}
private static final String KITS_PATH = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data";
@ -24,60 +22,10 @@ public class KitManager {
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
public static void saveInventory(String kitName, Player player){
loadedKits.add(new Kit(kitName, true, true, player.getInventory().getContents(), player.getInventory().getArmorContents()));
loadedKits.add(new Kit(kitName, player));
saveAllKits();
}
private static Kit loadKitFromConfig(String name) {
String path = "Kits." + name;
if(kitData.contains(path)) {
List<ItemStack> items = (List<ItemStack>) kitData.getList(path + ".Items");
ItemStack[] armor = null;
if(kitData.isList(path + ".Armor"))
armor = kitData.getList(path + ".Armor").toArray(new ItemStack[1]);
boolean leaderAllowed = kitData.getBoolean(path + ".LeaderAllowed");
boolean memberAllowed = kitData.getBoolean(path + ".MemberAllowed");
return new Kit(name, leaderAllowed, memberAllowed, items.toArray(new ItemStack[1]), armor);
}
return null;
}
public static void loadAllKits() {
if(!new File(KITS_PATH).exists()) {
saveAllKits();
Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!");
FightSystem.shutdown(null);
return;
}
if(kitData.getConfigurationSection("Kits") != null) {
for(String key : kitData.getConfigurationSection("Kits").getKeys(false)) {
loadedKits.add(loadKitFromConfig(key));
}
}
}
private static void saveAllKits(){
YamlConfiguration yamlConfiguration = new YamlConfiguration();
for(Kit k : loadedKits){
String path = "Kits." + k.getName();
yamlConfiguration.set(path + ".Items", k.getInventory());
if(k.getArmor() != null)
yamlConfiguration.set(path + ".Armor", k.getArmor());
yamlConfiguration.set(path + ".LeaderAllowed", k.isLeaderAllowed());
yamlConfiguration.set(path + ".MemberAllowed", k.isMemberAllowed());
}
try {
yamlConfiguration.save(kits);
}catch(IOException e){
Bukkit.getLogger().log(Level.SEVERE, "Failed to save kits.data", e);
}
}
public static Kit getKitByName(String kitName) {
for(Kit kit : loadedKits) {
if(kit.getName().equalsIgnoreCase(kitName))
@ -99,4 +47,32 @@ public class KitManager {
}
return kits;
}
public static void loadAllKits() {
if(!new File(KITS_PATH).exists()) {
saveAllKits();
Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!");
FightSystem.shutdown(null);
return;
}
if(kitData.getConfigurationSection("Kits") != null) {
for(String key : kitData.getConfigurationSection("Kits").getKeys(false)) {
loadedKits.add(new Kit(kitData.getConfigurationSection("Kits." + key)));
}
}
}
private static void saveAllKits(){
YamlConfiguration yamlConfiguration = new YamlConfiguration();
for(Kit k : loadedKits)
k.saveKit(yamlConfiguration.createSection("Kits." + k.getName()));
try {
yamlConfiguration.save(kits);
}catch(IOException e){
Bukkit.getLogger().log(Level.SEVERE, "Failed to save kits.data", e);
}
}
}

Datei anzeigen

@ -1,8 +1,9 @@
name: FightSystem
version: 1.0
author: [Yaruma3341, Lixfel]
version: "1.0"
authors: [Yaruma3341, Lixfel]
main: de.steamwar.fightsystem.FightSystem
depend: [SpigotCore, WorldEdit, ProtocolLib]
api-version: "1.13"
commands:
ak: