Skip to content

Commit

Permalink
feat(cosmetic): Now properly saves owned & current cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuvlyy committed Oct 31, 2024
1 parent 2d04a93 commit c1b48e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class Constants
public static final String PLAYER_DATA_PREFIX =
fr.hashtek.tekore.common.constants.Constants.GAME_PREFIX_KEY + "breakffa:";

public static final String COSMETIC_KEY = "cosmetics";

}
16 changes: 16 additions & 0 deletions src/main/java/fr/hashtek/spigot/breakffa/cosmetics/Cosmetic.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package fr.hashtek.spigot.breakffa.cosmetics;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonValue;
import org.bukkit.Material;
import org.bukkit.entity.Player;

/**
* @param <T> Cosmetic type
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public class Cosmetic
<T extends AbstractCosmetic>
{
Expand Down Expand Up @@ -178,6 +182,7 @@ protected boolean buyConditions(Player player)
/**
* @return Raw name (the one stored in the database)
*/
@JsonValue
public String getRawName()
{
return this.rawName;
Expand Down Expand Up @@ -239,4 +244,15 @@ public CosmeticRarity getRarity()
return this.rarity;
}

/**
* @param rawName Cosmetic's raw name
* @return Cosmetic
* @apiNote Solely used for Redis access.
*/
@JsonCreator
public static Cosmetic getFromRawName(String rawName)
{
return CosmeticManager.COSMETIC_REGISTRY.get(rawName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface CurrentCosmeticGetter
}


private static final Map<String, Cosmetic<? extends AbstractCosmetic>> COSMETIC_REGISTRY =
public static final Map<String, Cosmetic<? extends AbstractCosmetic>> COSMETIC_REGISTRY =
getCosmetics().stream().collect(Collectors.toMap(Cosmetic::getRawName, cosmetic -> cosmetic));

private final Set<Cosmetic<? extends AbstractCosmetic>> ownedCosmetics;
Expand Down

0 comments on commit c1b48e7

Please sign in to comment.