Quick and dirty fix and another fix

This commit is contained in:
Norbi Peti 2018-10-25 23:50:17 +02:00
parent e13efa5e65
commit 5def9344e8
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 47 additions and 10 deletions

View file

@ -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());
}
}

View file

@ -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 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
*/
@SuppressWarnings("unchecked")
public static <T extends ChromaGamerBase> T getFromSender(CommandSender sender, Class<T> cl) {
public static ChromaGamerBase getFromSender(CommandSender sender) {
for (val converter : senderConverters) {
val ocg = converter.apply(sender).filter(cg -> cl.isAssignableFrom(cg.getClass()));
val ocg = converter.apply(sender);
if (ocg.isPresent())
return (T) ocg.get();
return ocg.get();
}
return null;
}
@ -261,6 +259,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
@SuppressWarnings("rawtypes")
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"
@ -290,6 +289,19 @@ public abstract class ChromaGamerBase implements AutoCloseable {
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.
*
@ -309,7 +321,7 @@ public abstract class ChromaGamerBase implements AutoCloseable {
//-----------------------------------------------------------------
public PlayerData<Channel> channel() {
return data(Channel.GlobalChat);
public ChannelPlayerData channel() {
return dataChannel(Channel.GlobalChat);
}
}