2015-08-08 20:58:45 +00:00
|
|
|
|
package tk.sznp.thebuttonautoflair;
|
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.util.ArrayList;
|
2015-08-08 20:58:45 +00:00
|
|
|
|
import java.util.HashMap;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
import java.util.List;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
import java.util.UUID;
|
2015-08-08 20:58:45 +00:00
|
|
|
|
|
2015-12-19 12:42:04 +00:00
|
|
|
|
import org.bukkit.Bukkit;
|
2015-10-02 22:15:13 +00:00
|
|
|
|
import org.bukkit.Location;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2015-12-19 12:42:04 +00:00
|
|
|
|
import org.bukkit.entity.Player;
|
2015-10-02 22:15:13 +00:00
|
|
|
|
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public class MaybeOfflinePlayer {
|
2015-08-08 20:58:45 +00:00
|
|
|
|
public String PlayerName;
|
|
|
|
|
public String UserName;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public List<String> UserNames;
|
2015-12-19 12:42:04 +00:00
|
|
|
|
private String FlairTime;
|
|
|
|
|
private short FlairColor;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
public FlairStates FlairState;
|
|
|
|
|
public boolean RPMode = true;
|
|
|
|
|
public boolean PressedF;
|
|
|
|
|
public Location SavedLocation;
|
|
|
|
|
public boolean Working;
|
2015-12-30 12:31:59 +00:00
|
|
|
|
// public int Tables = 10;
|
|
|
|
|
public Channel CurrentChannel = Channel.GlobalChat;
|
|
|
|
|
public int FCount;
|
2015-12-31 19:19:52 +00:00
|
|
|
|
public boolean SendingLink = false;
|
2016-02-26 22:40:31 +00:00
|
|
|
|
public int FDeaths;
|
2015-08-31 19:21:20 +00:00
|
|
|
|
|
2015-10-17 00:06:32 +00:00
|
|
|
|
public UUID UUID;
|
|
|
|
|
|
|
|
|
|
public static HashMap<UUID, MaybeOfflinePlayer> AllPlayers = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public static MaybeOfflinePlayer AddPlayerIfNeeded(UUID uuid) {
|
|
|
|
|
if (!AllPlayers.containsKey(uuid)) {
|
2015-08-31 19:21:20 +00:00
|
|
|
|
MaybeOfflinePlayer player = new MaybeOfflinePlayer();
|
2015-10-17 00:06:32 +00:00
|
|
|
|
player.UUID = uuid;
|
2015-12-04 22:07:21 +00:00
|
|
|
|
player.FlairColor = 0;
|
|
|
|
|
player.FlairTime = "";
|
|
|
|
|
player.FlairState = FlairStates.NoComment;
|
|
|
|
|
player.UserNames = new ArrayList<>();
|
2015-10-17 00:06:32 +00:00
|
|
|
|
AllPlayers.put(uuid, player);
|
2015-08-31 19:21:20 +00:00
|
|
|
|
return player;
|
2015-08-08 20:58:45 +00:00
|
|
|
|
}
|
2015-10-17 00:06:32 +00:00
|
|
|
|
return AllPlayers.get(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Load(YamlConfiguration yc) {
|
|
|
|
|
ConfigurationSection cs = yc.getConfigurationSection("players");
|
|
|
|
|
for (String key : cs.getKeys(false)) {
|
|
|
|
|
ConfigurationSection cs2 = cs.getConfigurationSection(key);
|
|
|
|
|
MaybeOfflinePlayer mp = AddPlayerIfNeeded(java.util.UUID
|
|
|
|
|
.fromString(cs2.getString("uuid")));
|
|
|
|
|
mp.UserName = cs2.getString("username");
|
2015-12-04 22:07:21 +00:00
|
|
|
|
mp.FlairColor = (short) cs2.getInt("flaircolor");
|
|
|
|
|
mp.FlairTime = cs2.getString("flairtime");
|
|
|
|
|
String flairstate = cs2.getString("flairstate");
|
|
|
|
|
if (flairstate != null)
|
|
|
|
|
mp.FlairState = FlairStates.valueOf(flairstate);
|
|
|
|
|
else
|
|
|
|
|
mp.FlairState = FlairStates.NoComment;
|
2015-10-17 00:06:32 +00:00
|
|
|
|
mp.PlayerName = cs2.getString("playername");
|
2015-12-04 22:07:21 +00:00
|
|
|
|
mp.UserNames = cs2.getStringList("usernames");
|
2015-12-30 12:31:59 +00:00
|
|
|
|
mp.FCount = cs2.getInt("fcount");
|
2016-02-26 22:40:31 +00:00
|
|
|
|
mp.FDeaths = cs2.getInt("fdeaths");
|
2015-10-17 00:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Save(YamlConfiguration yc) {
|
2015-12-04 22:07:21 +00:00
|
|
|
|
ConfigurationSection cs = yc.createSection("players");
|
2015-10-17 00:06:32 +00:00
|
|
|
|
for (MaybeOfflinePlayer mp : MaybeOfflinePlayer.AllPlayers.values()) {
|
|
|
|
|
ConfigurationSection cs2 = cs.createSection(mp.UUID.toString());
|
|
|
|
|
cs2.set("playername", mp.PlayerName);
|
|
|
|
|
cs2.set("username", mp.UserName);
|
2015-12-04 22:07:21 +00:00
|
|
|
|
cs2.set("flaircolor", mp.FlairColor);
|
|
|
|
|
cs2.set("flairtime", mp.FlairTime);
|
|
|
|
|
cs2.set("flairstate", mp.FlairState.toString());
|
2015-10-17 00:06:32 +00:00
|
|
|
|
cs2.set("uuid", mp.UUID.toString());
|
2015-12-04 22:07:21 +00:00
|
|
|
|
cs2.set("usernames", mp.UserNames);
|
2015-12-30 12:31:59 +00:00
|
|
|
|
cs2.set("fcount", mp.FCount);
|
2016-02-26 22:40:31 +00:00
|
|
|
|
cs2.set("fdeaths", mp.FDeaths);
|
2015-10-17 00:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
|
|
|
|
|
public static MaybeOfflinePlayer GetFromName(String name) {
|
|
|
|
|
for (MaybeOfflinePlayer mp : AllPlayers.values())
|
|
|
|
|
if (mp.PlayerName.equalsIgnoreCase(name))
|
2015-10-17 00:06:32 +00:00
|
|
|
|
return mp;
|
|
|
|
|
return null;
|
2015-08-31 19:21:20 +00:00
|
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
|
|
|
|
|
public String GetFormattedFlair() {
|
|
|
|
|
if (FlairColor == 0x00)
|
|
|
|
|
return "";
|
|
|
|
|
if (FlairTime == null || FlairTime.length() == 0)
|
|
|
|
|
return String.format("<EFBFBD>%x(??s)<29>r", FlairColor);
|
|
|
|
|
return String.format("<EFBFBD>%x(%ss)<29>r", FlairColor, FlairTime);
|
|
|
|
|
}
|
2015-12-19 12:42:04 +00:00
|
|
|
|
|
|
|
|
|
public void SetFlairColor(int color) {
|
|
|
|
|
FlairColor = (short) color;
|
|
|
|
|
SetFlair2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetFlairTime(String time) {
|
|
|
|
|
FlairTime = time;
|
|
|
|
|
SetFlair2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetFlair(int color, String time) {
|
|
|
|
|
FlairColor = (short) color;
|
|
|
|
|
FlairTime = time;
|
|
|
|
|
SetFlair2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetFlair2() {
|
|
|
|
|
|
|
|
|
|
// Flairs from Command Block The Button - Teams
|
|
|
|
|
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
|
|
|
|
|
Player p = Bukkit.getPlayer(UUID);
|
2015-12-19 20:17:42 +00:00
|
|
|
|
p.setPlayerListName(String.format("%s%s", p.getName(),
|
2015-12-19 12:42:04 +00:00
|
|
|
|
GetFormattedFlair()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public short GetFlairColor() {
|
|
|
|
|
return FlairColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String GetFlairTime() {
|
|
|
|
|
return FlairTime;
|
|
|
|
|
}
|
2015-08-08 20:58:45 +00:00
|
|
|
|
}
|