diff --git a/src/main/java/buttondevteam/lib/TBMCPlayer.java b/src/main/java/buttondevteam/lib/TBMCPlayer.java index 5deb51f..a6e6118 100644 --- a/src/main/java/buttondevteam/lib/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/TBMCPlayer.java @@ -101,7 +101,8 @@ public class TBMCPlayer implements AutoCloseable { String mname = st.getMethodName(); if (!mname.startsWith("get")) throw new UnsupportedOperationException("Can only use getEnumData from a getXYZ method"); - final String retstr = (String) getLoadedPlayers().get(uuid).data.get(mname.substring("get".length()).toLowerCase()); + final String retstr = (String) getLoadedPlayers().get(uuid).data + .get(mname.substring("get".length()).toLowerCase()); if (retstr != null) return Enum.valueOf(cl, retstr); else @@ -444,4 +445,21 @@ public class TBMCPlayer implements AutoCloseable { public static HashMap getLoadedPlayers() { return LoadedPlayers; } + + /** + * 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/TBMCPlayerGetInfoEvent.java b/src/main/java/buttondevteam/lib/TBMCPlayerGetInfoEvent.java new file mode 100644 index 0000000..6dac56d --- /dev/null +++ b/src/main/java/buttondevteam/lib/TBMCPlayerGetInfoEvent.java @@ -0,0 +1,73 @@ +package buttondevteam.lib; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import buttondevteam.lib.TBMCPlayer.InfoTarget; + +/** + *

+ * This event gets called when player information is requested. It can be used to give more per-plugin information about a player. + *

+ * + * @author Norbi + * + */ +public class TBMCPlayerGetInfoEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + private TBMCPlayer player; + private List infolines; + private TBMCPlayer.InfoTarget target; + + TBMCPlayerGetInfoEvent(TBMCPlayer player, TBMCPlayer.InfoTarget target) { + this.player = player; + infolines = new ArrayList<>(); + this.target = target; + } + + /** + * Get the {@link TBMCPlayer} object + * + * @return A player object + */ + public TBMCPlayer getPlayer() { + return player; + } + + /** + * Add a line to the information text. The line should be in the format of key: value . + * + * @param infoline + * The line to add + */ + public void addInfo(String infoline) { + infolines.add(infoline); + } + + /** + * Get the {@link InfoTarget} we want the information for. Use this to format the returned string. + * + * @return The target of the information. + */ + public TBMCPlayer.InfoTarget getTarget() { + return target; + } + + String getResult() { + return infolines.stream().collect(Collectors.joining("\n")); + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +}