Quick and dirty fix and another fix
This commit is contained in:
parent
e13efa5e65
commit
5def9344e8
2 changed files with 47 additions and 10 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
package buttondevteam.lib.player;
|
||||||
|
|
||||||
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
public class ChannelPlayerData { //I just want this to work
|
||||||
|
private final PlayerData<String> data;
|
||||||
|
private final Channel def;
|
||||||
|
|
||||||
|
public ChannelPlayerData(String name, YamlConfiguration yaml, Channel def) {
|
||||||
|
data = new PlayerData<>(name, yaml, "");
|
||||||
|
this.def = def;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Channel get() {
|
||||||
|
String str = data.get();
|
||||||
|
if (str.isEmpty())
|
||||||
|
return def;
|
||||||
|
return Channel.getChannels().stream().filter(c -> str.equals(c.ID)).findAny().orElse(def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Channel value) {
|
||||||
|
data.set(value.toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -109,18 +109,16 @@ public abstract class ChromaGamerBase implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get from the given sender. May be null,.but shouldn't be.
|
* Get from the given sender. the object's type will depend on the sender's type. May be null, but shouldn't be.
|
||||||
*
|
*
|
||||||
* @param sender The sender to use
|
* @param sender The sender to use
|
||||||
* @param cl The type of the requested user object - subclasses of {@link TBMCPlayerBase} don't work, use {@link TBMCPlayer}
|
|
||||||
* @return A user as returned by a converter or null if none can supply it
|
* @return A user as returned by a converter or null if none can supply it
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public static ChromaGamerBase getFromSender(CommandSender sender) {
|
||||||
public static <T extends ChromaGamerBase> T getFromSender(CommandSender sender, Class<T> cl) {
|
|
||||||
for (val converter : senderConverters) {
|
for (val converter : senderConverters) {
|
||||||
val ocg = converter.apply(sender).filter(cg -> cl.isAssignableFrom(cg.getClass()));
|
val ocg = converter.apply(sender);
|
||||||
if (ocg.isPresent())
|
if (ocg.isPresent())
|
||||||
return (T) ocg.get();
|
return ocg.get();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -261,6 +259,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private final HashMap<String, EnumPlayerData> dataenummap = new HashMap<>();
|
private final HashMap<String, EnumPlayerData> dataenummap = new HashMap<>();
|
||||||
|
private ChannelPlayerData datachannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use from a data() method, which is in a method with the name of the key. For example, use flair() for the enclosing method of the outer data() to save to and load from "flair"
|
* Use from a data() method, which is in a method with the name of the key. For example, use flair() for the enclosing method of the outer data() to save to and load from "flair"
|
||||||
|
@ -290,6 +289,19 @@ public abstract class ChromaGamerBase implements AutoCloseable {
|
||||||
return dataenummap.get(mname);
|
return dataenummap.get(mname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channel
|
||||||
|
*
|
||||||
|
* @return A data object with methods to get and set
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected ChannelPlayerData dataChannel(Channel def) { //TODO: Make interface with fromString() method and require use of that for player data types
|
||||||
|
ThrowIfNoUser();
|
||||||
|
if (datachannel == null)
|
||||||
|
datachannel = new ChannelPlayerData("channel", plugindata, def);
|
||||||
|
return datachannel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get player information. This method calls the {@link TBMCPlayerGetInfoEvent} to get all the player information across the TBMC plugins.
|
* Get player information. This method calls the {@link TBMCPlayerGetInfoEvent} to get all the player information across the TBMC plugins.
|
||||||
*
|
*
|
||||||
|
@ -309,7 +321,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
|
||||||
|
|
||||||
//-----------------------------------------------------------------
|
//-----------------------------------------------------------------
|
||||||
|
|
||||||
public PlayerData<Channel> channel() {
|
public ChannelPlayerData channel() {
|
||||||
return data(Channel.GlobalChat);
|
return dataChannel(Channel.GlobalChat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue