From 11f13af8cc8ef27ed523555c4c48e381419a0761 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 29 Jan 2017 01:48:53 +0100 Subject: [PATCH] Player data fixes --- .../lib/player/ChromaGamerBase.java | 31 ++++++++++++++++++- .../buttondevteam/lib/player/TBMCPlayer.java | 2 +- .../lib/player/TBMCPlayerBase.java | 17 ---------- .../lib/player/TBMCPlayerGetInfoEvent.java | 8 ++--- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java index 79037f7..2239694 100644 --- a/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java +++ b/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.function.Consumer; +import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import buttondevteam.lib.TBMCCoreAPI; @@ -56,7 +57,7 @@ public abstract class ChromaGamerBase implements AutoCloseable { return plugindata != null ? plugindata.getString("id") : null; } - protected static T getUser(String fname, Class cl) { + public static T getUser(String fname, Class cl) { try { T obj = cl.newInstance(); final File file = new File(TBMC_PLAYERS_DIR + getFolderForType(cl), fname + ".yml"); @@ -126,6 +127,17 @@ public abstract class ChromaGamerBase implements AutoCloseable { sync.accept(user.plugindata); } + /** + * Retunrs the ID for the T typed player object connected with this one or null if no connection found. + * + * @param cl + * The player class to get the ID from + * @return The ID or null if not found + */ + public String getConnectedID(Class cl) { + return plugindata.getString(getFolderForType(cl) + "_id"); + } + /** * Returns this player as a plugin player. This will return a new instance unless the player is online.
* Make sure to close both the returned and this object. A try-with-resources block or two can help.
@@ -146,4 +158,21 @@ public abstract class ChromaGamerBase implements AutoCloseable { public String getFolder() { return getFolderForType(getClass()); } + + /** + * Get player information. This method calls the {@link TBMCPlayerGetInfoEvent} to get all the player information across the TBMC plugins. + * + * @param target + * The {@link InfoTarget} to return the info for. + * @return The player information. + */ + public String getInfo(InfoTarget target) { + TBMCPlayerGetInfoEvent event = new TBMCPlayerGetInfoEvent(this, target); + Bukkit.getServer().getPluginManager().callEvent(event); + return event.getResult(); + } + + public enum InfoTarget { + MCHover, MCCommand, Discord + } } diff --git a/src/main/java/buttondevteam/lib/player/TBMCPlayer.java b/src/main/java/buttondevteam/lib/player/TBMCPlayer.java index badbe8e..617af5e 100644 --- a/src/main/java/buttondevteam/lib/player/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/player/TBMCPlayer.java @@ -1,6 +1,6 @@ package buttondevteam.lib.player; @PlayerClass(pluginname = "ButtonCore") -public class TBMCPlayer extends TBMCPlayerBase { +public final class TBMCPlayer extends TBMCPlayerBase { } diff --git a/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java b/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java index c24c1fd..954b3e0 100644 --- a/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java +++ b/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java @@ -189,21 +189,4 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase { else return null; } - - /** - * Get player information. This method calls the {@link TBMCPlayerGetInfoEvent} to get all the player information across the TBMC plugins. - * - * @param target - * The {@link InfoTarget} to return the info for. - * @return The player information. - */ - public String getInfo(InfoTarget target) { - TBMCPlayerGetInfoEvent event = new TBMCPlayerGetInfoEvent(this, target); - Bukkit.getServer().getPluginManager().callEvent(event); - return event.getResult(); - } - - public enum InfoTarget { - MCHover, MCCommand, Discord - } } diff --git a/src/main/java/buttondevteam/lib/player/TBMCPlayerGetInfoEvent.java b/src/main/java/buttondevteam/lib/player/TBMCPlayerGetInfoEvent.java index ba2bc74..6e310a0 100644 --- a/src/main/java/buttondevteam/lib/player/TBMCPlayerGetInfoEvent.java +++ b/src/main/java/buttondevteam/lib/player/TBMCPlayerGetInfoEvent.java @@ -7,7 +7,7 @@ import java.util.stream.Collectors; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import buttondevteam.lib.player.TBMCPlayerBase.InfoTarget; +import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; /** *

@@ -20,11 +20,11 @@ import buttondevteam.lib.player.TBMCPlayerBase.InfoTarget; public class TBMCPlayerGetInfoEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private TBMCPlayerBase player; + private ChromaGamerBase player; private List infolines; private InfoTarget target; - TBMCPlayerGetInfoEvent(TBMCPlayerBase player, InfoTarget target) { + TBMCPlayerGetInfoEvent(ChromaGamerBase player, InfoTarget target) { this.player = player; infolines = new ArrayList<>(); this.target = target; @@ -35,7 +35,7 @@ public class TBMCPlayerGetInfoEvent extends Event { * * @return A player object */ - public TBMCPlayerBase getPlayer() { + public ChromaGamerBase getPlayer() { return player; }