Remade user data managing, added a test #30
4 changed files with 35 additions and 23 deletions
|
@ -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 extends ChromaGamerBase> T getUser(String fname, Class<T> cl) {
|
||||
public static <T extends ChromaGamerBase> T getUser(String fname, Class<T> 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 <T extends ChromaGamerBase> String getConnectedID(Class<T> 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.<br>
|
||||
* Make sure to close both the returned and this object. A try-with-resources block or two can help.<br>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package buttondevteam.lib.player;
|
||||
|
||||
@PlayerClass(pluginname = "ButtonCore")
|
||||
public class TBMCPlayer extends TBMCPlayerBase {
|
||||
public final class TBMCPlayer extends TBMCPlayerBase {
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -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<String> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue