Skip to content

Commit

Permalink
fix custom rarities, bump up version to 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-hydrogen committed Apr 21, 2022
1 parent 45ce71a commit 606052c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ilm9001</groupId>
<artifactId>cosmetics</artifactId>
<version>1.1.3</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>Cosmetics</name>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/ilm9001/cosmetics/rarity/Rarities.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ilm9001.cosmetics.util.Cosmetic;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.ArrayList;
Expand All @@ -14,21 +15,21 @@ public class Rarities {
private static final List<Rarity> rarities = new ArrayList<>();

public static void setRaritiesFromFile() {
List<Cosmetic> cosmeticsList = new ArrayList<>();
Cosmetics.refreshFiles();
FileConfiguration config = Cosmetics.getRarities();

for (String internalname : config.getConfigurationSection("Rarities").getKeys(false)) {
Component displayName;
TextColor color;
Map<String,Object> valuesmap = config.getConfigurationSection("Cosmetics."+internalname).getValues(false);;
Map<String,Object> valuesmap = config.getConfigurationSection("Rarities."+internalname).getValues(false);;
List<Number> colorList;
if(valuesmap.get("color") instanceof List && valuesmap.get("color") != null) {
colorList = (List<Number>) valuesmap.get("color");;
} else throw new IllegalArgumentException("Color list is not a list, or is null");

displayName = Component.text((String) valuesmap.get("display"));
color = TextColor.color(colorList.get(0).intValue(), colorList.get(1).intValue(), colorList.get(2).intValue());
displayName = Component.text((String) valuesmap.get("display"))
.decoration(TextDecoration.ITALIC,false)
.color(((String) valuesmap.get("display")).length() > 1 ? color : TextColor.color(255,255,255));

Rarity rarity = new Rarity(internalname, displayName, color);
rarities.add(rarity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CosmeticFactory() {
name = Component.text((String) valuesmap.get("name"));
modelID = (Integer) valuesmap.get("modelID");
type = CosmeticType.valueOf((String)valuesmap.get("type"));
Rarities.getRarities().stream().filter((r) -> !Objects.equals(r.getInternalRarityName(), valuesmap.get("rarity")))
Rarities.getRarities().stream().filter((r) -> Objects.equals(r.getInternalRarityName(), valuesmap.get("rarity")))
.findFirst().ifPresent(rarity::set);

if(valuesmap.get("material") != null) material = Material.matchMaterial(valuesmap.get("material").toString());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ilm9001/cosmetics/util/Cosmetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Cosmetic(String internalCosmeticName, Component cosmeticName, Integer mod
if(Util.isCosmetic(itemStack)) {
type = CosmeticType.getFromID(metaContainer.get(typekey, PersistentDataType.BYTE));
internalname = metaContainer.get(namekey,PersistentDataType.STRING);
Rarities.getRarities().stream().filter((r) -> !Objects.equals(r.getInternalRarityName(), metaContainer.get(raritykey, PersistentDataType.STRING)))
Rarities.getRarities().stream().filter((r) -> Objects.equals(r.getInternalRarityName(), metaContainer.get(raritykey, PersistentDataType.STRING)))
.findFirst().ifPresent(rarity::set);
} else {
return null;
Expand Down

0 comments on commit 606052c

Please sign in to comment.