Skip to content

Commit

Permalink
Removido método CrateManager#getDisplayItem()
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Feb 11, 2024
1 parent 90a6467 commit 62af0a2
Showing 1 changed file with 4 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ public void loadCrates() {

addCrate(new Crate("Menu", "Menu", CrateType.menu, new ItemStack(Material.AIR), new ArrayList<>(), null, 0, null, 0, 0, Collections.emptyList(), null));

List.of("All crate information has been loaded.", "Loading all the physical crate locations.")
.forEach(line -> this.plugin.debug(() -> line, Level.INFO));
List.of(
"All crate information has been loaded.",
"Loading all the physical crate locations."
).forEach(line -> this.plugin.debug(() -> line, Level.INFO));

FileConfiguration locations = FileManager.Files.LOCATIONS.getFile();
int loadedAmount = 0;
Expand Down Expand Up @@ -1045,56 +1047,6 @@ private ItemStack getKey(@NotNull FileConfiguration file) {
return new ItemBuilder().setMaterial(id).setName(name).setLore(lore).setGlow(glowing).build();
}

private ItemBuilder getDisplayItem(@NotNull FileConfiguration file, String prize) {
String path = "Crate.Prizes." + prize + ".";
ItemBuilder itemBuilder = new ItemBuilder();
String displayItem = file.getString(path + "DisplayItem");
if (displayItem == null) {
this.plugin.getLogger().warning("The display item for the prize " + prize + " is null. Please check your config.yml file.");
displayItem = "RED_TERRACOTTA";
}

try {
itemBuilder.setMaterial(displayItem)
.setAmount(file.getInt(path + "DisplayAmount", 1))
.setName(file.getString(path + "DisplayName"))
.setLore(file.getStringList(path + "Lore"))
.setGlow(file.getBoolean(path + "Glowing"))
.setUnbreakable(file.getBoolean(path + "Unbreakable"))
.hideItemFlags(file.getBoolean(path + "HideItemFlags"))
.addItemFlags(file.getStringList(path + "Flags"))
.addPatterns(file.getStringList(path + "Patterns"))
.setPlayerName(file.getString(path + "Player"))
.setCustomItem();

if (file.contains(path + "DisplayDamage") && file.getInt(path + "DisplayDamage") >= 1) {
itemBuilder.setDamage(file.getInt(path + "DisplayDamage"));
}

if (file.contains(path + "DisplayTrim.Pattern")) {
itemBuilder.setTrimPattern(Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(file.getString(path + "DisplayTrim.Pattern").toLowerCase())));
}

if (file.contains(path + "DisplayTrim.Material")) {
itemBuilder.setTrimMaterial(Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(file.getString(path + "DisplayTrim.Material").toLowerCase())));
}

if (file.contains(path + "DisplayEnchantments")) {
for (String enchantmentName : file.getStringList(path + "DisplayEnchantments")) {
Enchantment enchantment = MiscUtils.getEnchantment(enchantmentName.split(":")[0]);

if (enchantment != null) {
itemBuilder.addEnchantments(enchantment, Integer.parseInt(enchantmentName.split(":")[1]));
}
}
}

return itemBuilder;
} catch (Exception e) {
return new ItemBuilder().setMaterial(Material.RED_TERRACOTTA).setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor the reward: &c" + prize));
}
}

// Cleans the data file.
private void cleanDataFile() {
FileConfiguration data = FileManager.Files.DATA.getFile();
Expand Down

0 comments on commit 62af0a2

Please sign in to comment.