PlayerData ann + ConfigData def add

This commit is contained in:
Norbi Peti 2018-12-23 03:22:21 +01:00
parent a417d0ea3f
commit dbce36cd4e
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 7 additions and 3 deletions

View file

@ -12,7 +12,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />

View file

@ -30,8 +30,11 @@ public class ConfigData<T> { //TODO: Save after a while
@SuppressWarnings("unchecked")
public T get() {
Object val = config.get(path, def);
if (getter != null)
return getter.apply(val);
if (getter != null) {
T hmm = getter.apply(val);
if (hmm == null) hmm = def; //Set if the getter returned null
return hmm;
}
return (T) val;
}

View file

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
@ -203,6 +204,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
* @return The player as a {@link T} object or null if not having an account there
*/
@SuppressWarnings("unchecked")
@Nullable
public <T extends ChromaGamerBase> T getAs(Class<T> cl) { // TODO: Provide a way to use TBMCPlayerBase's loaded players
if (cl.getSimpleName().equals(getClass().getSimpleName()))
return (T) this;