2016-04-25 20:03:39 +00:00
|
|
|
package io.github.norbipeti.thebuttonmc;
|
2015-08-08 20:58:45 +00:00
|
|
|
|
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;
|
2016-04-24 17:46:41 +00:00
|
|
|
private short FlairTime;
|
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;
|
2016-02-26 23:32:33 +00:00
|
|
|
public boolean RainbowPresserColorMode = false;
|
2016-04-21 19:46:28 +00:00
|
|
|
public String OtherColorMode = "";
|
2016-04-24 15:29:08 +00:00
|
|
|
public boolean ChatOnly = false;
|
2016-04-24 17:46:41 +00:00
|
|
|
public boolean FlairCheater = false;
|
2016-05-13 10:27:50 +00:00
|
|
|
public int LoginWarningCount = 0;
|
2016-04-24 17:46:41 +00:00
|
|
|
public static final short FlairTimeNonPresser = -1;
|
|
|
|
public static final short FlairTimeCantPress = -2;
|
|
|
|
public static final short FlairTimeNone = -3;
|
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;
|
2016-04-25 20:14:14 +00:00
|
|
|
player.FlairTime = FlairTimeNone;
|
2015-12-04 22:07:21 +00:00
|
|
|
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");
|
2016-04-24 17:46:41 +00:00
|
|
|
String tmp = cs2.getString("flairtime");
|
|
|
|
if (tmp.equals("--"))
|
|
|
|
mp.FlairTime = FlairTimeNonPresser;
|
2016-04-24 18:12:48 +00:00
|
|
|
else if (tmp.equals("??"))
|
|
|
|
mp.FlairTime = FlairTimeCantPress;
|
2016-04-24 17:46:41 +00:00
|
|
|
else if (tmp.length() > 0)
|
|
|
|
mp.FlairTime = Short.parseShort(tmp);
|
2015-12-04 22:07:21 +00:00
|
|
|
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");
|
2016-04-24 17:46:41 +00:00
|
|
|
mp.FlairCheater = cs2.getBoolean("flaircheater");
|
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("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);
|
2016-04-24 17:46:41 +00:00
|
|
|
cs2.set("flaircheater", mp.FlairCheater);
|
2015-10-17 00:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
|
|
|
public static MaybeOfflinePlayer GetFromName(String name) {
|
2016-04-24 18:12:48 +00:00
|
|
|
Player p = Bukkit.getPlayer(name);
|
|
|
|
if (p != null)
|
|
|
|
return AllPlayers.get(p.getUniqueId());
|
|
|
|
else
|
|
|
|
return null;
|
2015-08-31 19:21:20 +00:00
|
|
|
}
|
2015-12-04 22:07:21 +00:00
|
|
|
|
|
|
|
public String GetFormattedFlair() {
|
2016-04-24 17:46:41 +00:00
|
|
|
if (FlairTime == FlairTimeCantPress)
|
2016-05-05 19:55:21 +00:00
|
|
|
return String.format("§r(--s)§r");
|
2016-04-24 17:46:41 +00:00
|
|
|
if (FlairTime == FlairTimeNonPresser)
|
2016-05-05 19:55:21 +00:00
|
|
|
return String.format("§7(--s)§r");
|
2016-04-24 17:46:41 +00:00
|
|
|
if (FlairTime == FlairTimeNone)
|
2015-12-04 22:07:21 +00:00
|
|
|
return "";
|
2016-05-05 19:55:21 +00:00
|
|
|
return String.format("§%x(%ss)§r", GetFlairColor(), FlairTime);
|
2015-12-04 22:07:21 +00:00
|
|
|
}
|
2015-12-19 12:42:04 +00:00
|
|
|
|
2016-04-24 17:46:41 +00:00
|
|
|
public void SetFlair(short time) {
|
2015-12-19 12:42:04 +00:00
|
|
|
FlairTime = time;
|
2016-04-24 17:46:41 +00:00
|
|
|
FlairUpdate();
|
2015-12-19 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 17:46:41 +00:00
|
|
|
public void SetFlair(short time, boolean cheater) {
|
2015-12-19 12:42:04 +00:00
|
|
|
FlairTime = time;
|
2016-04-24 17:46:41 +00:00
|
|
|
FlairCheater = cheater;
|
|
|
|
FlairUpdate();
|
2015-12-19 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 17:46:41 +00:00
|
|
|
public void FlairUpdate() {
|
2015-12-19 12:42:04 +00:00
|
|
|
|
|
|
|
// 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() {
|
2016-04-24 17:46:41 +00:00
|
|
|
if (FlairCheater)
|
|
|
|
return 0x5;
|
|
|
|
if (FlairTime == -1)
|
|
|
|
return 0x7;
|
|
|
|
else if (FlairTime == -2)
|
|
|
|
return 0xf;
|
|
|
|
else if (FlairTime <= 60 && FlairTime >= 52)
|
|
|
|
return 0x5;
|
|
|
|
else if (FlairTime <= 51 && FlairTime >= 42)
|
|
|
|
return 0x9;
|
|
|
|
else if (FlairTime <= 41 && FlairTime >= 32)
|
|
|
|
return 0xa;
|
|
|
|
else if (FlairTime <= 31 && FlairTime >= 22)
|
|
|
|
return 0xe;
|
|
|
|
else if (FlairTime <= 21 && FlairTime >= 11)
|
|
|
|
return 0x6;
|
|
|
|
else if (FlairTime <= 11 && FlairTime >= 0)
|
|
|
|
return 0xc;
|
|
|
|
return 0xf;
|
2015-12-19 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 17:46:41 +00:00
|
|
|
public short GetFlairTime() {
|
2015-12-19 12:42:04 +00:00
|
|
|
return FlairTime;
|
|
|
|
}
|
2016-04-24 15:29:08 +00:00
|
|
|
|
|
|
|
public static MaybeOfflinePlayer GetFromPlayer(Player p) {
|
|
|
|
return MaybeOfflinePlayer.AllPlayers.get(p.getUniqueId());
|
|
|
|
}
|
2015-08-08 20:58:45 +00:00
|
|
|
}
|