Fix getting user using abstract user classes (#101)

- The Discord plugin uses this to connect MC and DC accounts
- And it was a feataure of this plugin either way
This commit is contained in:
Norbi Peti 2023-03-12 23:26:47 +01:00
parent 6ec63b5ae7
commit 496af97e1c
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -25,6 +25,9 @@ import java.util.function.Supplier;
public abstract class ChromaGamerBase { public abstract class ChromaGamerBase {
private static final String TBMC_PLAYERS_DIR = "TBMC/players/"; private static final String TBMC_PLAYERS_DIR = "TBMC/players/";
private static final ArrayList<Function<CommandSender, ? extends Optional<? extends ChromaGamerBase>>> senderConverters = new ArrayList<>(); private static final ArrayList<Function<CommandSender, ? extends Optional<? extends ChromaGamerBase>>> senderConverters = new ArrayList<>();
/**
* Holds data per user class
*/
private static final HashMap<Class<? extends ChromaGamerBase>, StaticUserData<?>> staticDataMap = new HashMap<>(); private static final HashMap<Class<? extends ChromaGamerBase>, StaticUserData<?>> staticDataMap = new HashMap<>();
/** /**
@ -56,6 +59,7 @@ public abstract class ChromaGamerBase {
throw new RuntimeException("Class not registered as a user class! Use @UserClass or TBMCPlayerBase"); throw new RuntimeException("Class not registered as a user class! Use @UserClass or TBMCPlayerBase");
var sud = new StaticUserData<T>(folderName); var sud = new StaticUserData<T>(folderName);
sud.getConstructors().put(cl, constructor); sud.getConstructors().put(cl, constructor);
sud.getConstructors().put(userclass, constructor); // Alawys register abstract and prototype class (TBMCPlayerBase and TBMCPlayer)
staticDataMap.put(userclass, sud); staticDataMap.put(userclass, sud);
} }