From 1c7df17d9d5a4c0d98efc73130ad54be0cf1e266 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 15 Jun 2017 22:09:29 +0200 Subject: [PATCH] Added getTypeForFolder --- .../lib/player/ChromaGamerBase.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java index d22d120..5d7b1b1 100644 --- a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java +++ b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java @@ -7,13 +7,16 @@ import java.util.function.Consumer; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; + +import com.google.common.collect.HashBiMap; + import buttondevteam.lib.TBMCCoreAPI; @ChromaGamerEnforcer public abstract class ChromaGamerBase implements AutoCloseable { public static final String TBMC_PLAYERS_DIR = "TBMC/players/"; - private static final HashMap, String> playerTypes = new HashMap<>(); + private static final HashBiMap, String> playerTypes = HashBiMap.create(); /** * Used for connecting with every type of user ({@link #connectWith(ChromaGamerBase)}) @@ -32,7 +35,7 @@ public abstract class ChromaGamerBase implements AutoCloseable { * Returns the folder name for the given player class. * * @param cl - * The class to get the folder from (like {@link TBMCPlayerBase} or one of it's subclasses + * The class to get the folder from (like {@link TBMCPlayerBase} or one of it's subclasses) * @return The folder name for the given type * @throws RuntimeException * If the class doesn't have the {@link UserClass} annotation. @@ -45,6 +48,17 @@ public abstract class ChromaGamerBase implements AutoCloseable { throw new RuntimeException("Class not registered as a user class! Use @UserClass or @AbstractUserClass"); } + /** + * Returns the player class for the given folder name. + * + * @param foldername + * The folder to get the class from (like "minecraft") + * @return The type for the given folder name or null if not found + */ + public static Class getTypeForFolder(String foldername) { + return playerTypes.inverse().get(foldername); + } + /** * This method returns the filename for this player data. For example, for Minecraft-related data, MC UUIDs, for Discord data, use Discord IDs, etc.
* Does not include .yml