Skip to content

Commit

Permalink
Fixed issue with armor not being added to kit contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckerr committed Sep 1, 2021
1 parent c8fa09e commit 2a43038
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 27 deletions.
33 changes: 30 additions & 3 deletions core/src/main/java/wtf/nucker/kitpvpplus/managers/KitManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import wtf.nucker.kitpvpplus.exceptions.KitAlreadyExistException;
import wtf.nucker.kitpvpplus.exceptions.KitNotExistException;
import wtf.nucker.kitpvpplus.objects.Kit;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static void setup() {
config = configInstance.getConfig();
}

public Kit createKit(String id) {
public void createKit(String id) {
String nameId = id;
id = id.toLowerCase();
if (KitManager.getConfig().contains(id)) throw new KitAlreadyExistException("This kit already exists");
Expand All @@ -66,7 +67,6 @@ public Kit createKit(String id) {
kit.setCooldown(0);

kitCache.add(kit);
return kit;
}

public void deleteKit(String id) {
Expand Down Expand Up @@ -201,11 +201,23 @@ public ClockUtils.CountingRunnable setCooldownRunnable(ClockUtils.CountingRunnab
public void setInventory(Inventory inv) {
section.set("inventory", null);
for (int i = 0; i < inv.getContents().length; i++) {
ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory." + i, inv.getItem(i));
ItemUtils.deserialize(KitManager.getConfig(), configId + ".inventory." + i, inv.getItem(i));
}
KitManager.getConfigInstance().save();
}

@Override
public void setInventory(PlayerInventory inv) {
this.setInventory((Inventory) inv);

ItemUtils.deserialize(KitManager.getConfig(), configId + ".inventory-armor.helmet", inv.getHelmet());
ItemUtils.deserialize(KitManager.getConfig(), configId + ".inventory-armor.chestplate", inv.getChestplate());
ItemUtils.deserialize(KitManager.getConfig(), configId + ".inventory-armor.leggings", inv.getLeggings());
ItemUtils.deserialize(KitManager.getConfig(), configId + ".inventory-armor.boots", inv.getBoots());

KitManager.getConfigInstance().save();
}

@Override
public void fillInventory(Player player) {
player.getInventory().clear();
Expand All @@ -214,6 +226,21 @@ public void fillInventory(Player player) {
int index = Integer.parseInt(key);
inv.setItem(index, ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory." + key));
}

if(section.contains("inventory-armor")) {
if(section.contains("inventory-armor.helmet")) {
player.getInventory().setHelmet(ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory-armor.helmet"));
}
if(section.contains("inventory-armor.chestplate")) {
player.getInventory().setChestplate(ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory-armor.chestplate"));
}
if(section.contains("inventory-armor.leggings")) {
player.getInventory().setLeggings(ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory-armor.leggings"));
}
if(section.contains("inventory-armor.boots")) {
player.getInventory().setBoots(ItemUtils.serialize(KitManager.getConfig(), configId + ".inventory-armor.boots"));
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public LeaderBoardManager() {
this.getBalLeaderboard().sort();
this.getKsLeaderboard().sort();
this.getLevelLeaderboard().sort();
}); }
});
}

private void registerLeaderboards() {
DataManager manager = KitPvPPlus.getInstance().getDataManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public class PlayerBank {

private final OfflinePlayer player;
private static StorageType.BankStorageType storageType;
private FlatFile playerData;

public PlayerBank(OfflinePlayer player) {
this.player = player;
this.playerData = new FlatFile(player);
}

public double getBal() {
Expand Down
44 changes: 24 additions & 20 deletions core/src/main/java/wtf/nucker/kitpvpplus/objects/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import wtf.nucker.kitpvpplus.utils.ClockUtils;

import java.util.List;
Expand All @@ -14,43 +15,46 @@
*/
public interface Kit {

public String getId();
String getId();

public String getDisplayname();
String getDisplayname();

public Material getIcon();
Material getIcon();

public List<String> getLore();
List<String> getLore();

public int getPrice();
int getPrice();

public String getPermission();
String getPermission();

public String setDisplayname(String newName);
String setDisplayname(String newName);

public Material setIcon(Material material);
Material setIcon(Material material);

public List<String> addToLore(String item);
List<String> addToLore(String item);

public List<String> removeFromLore(String item);
List<String> removeFromLore(String item);

public List<String> setLore(List<String> newLore);
List<String> setLore(List<String> newLore);

public int setPrice(int newPrice);
int setPrice(int newPrice);

public String setPermission(String newPerm);
String setPermission(String newPerm);

public boolean isFree();
boolean isFree();

public int getCooldown();
int getCooldown();

public int setCooldown(int cooldown);
int setCooldown(int cooldown);

public ClockUtils.CountingRunnable getCooldownRunnable();
ClockUtils.CountingRunnable getCooldownRunnable();

public ClockUtils.CountingRunnable setCooldownRunnable(ClockUtils.CountingRunnable runnable);
ClockUtils.CountingRunnable setCooldownRunnable(ClockUtils.CountingRunnable runnable);

public void setInventory(Inventory inv);
void setInventory(Inventory inv);

void setInventory(PlayerInventory inv);

void fillInventory(Player player);

public void fillInventory(Player player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static ItemStack buildItem(String name, Material material, int amount, St
return res;
}

public static void serialize(YamlConfiguration config, String path, ItemStack item) {
public static void deserialize(YamlConfiguration config, String path, ItemStack item) {
if (item == null || item.getType().equals(XMaterial.AIR.parseMaterial())) return;
config.set(path + ".type", item.getType().name());
config.set(path + ".amount", item.getAmount());
Expand Down Expand Up @@ -76,6 +76,7 @@ public static void serialize(YamlConfiguration config, String path, ItemStack it
}

public static ItemStack serialize(YamlConfiguration config, String path) {
Logger.debug(path);
ItemStack item = new ItemStack(Material.valueOf(config.getString(path + ".type")), config.getInt(path + ".amount"), Short.parseShort(String.valueOf(config.getInt(path + ".durability"))));
if (config.contains(path + ".enchantments")) {
for (String key : config.getConfigurationSection(path + ".enchantments").getKeys(false)) {
Expand Down

0 comments on commit 2a43038

Please sign in to comment.