2014-04-11 15:24:44 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
|
|
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
2014-04-15 13:43:07 +00:00
|
|
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
2014-04-11 15:24:44 +00:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public class TFM_Player
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
private final UUID uuid;
|
|
|
|
private String firstJoinName;
|
|
|
|
private String lastJoinName;
|
2014-06-29 10:09:03 +00:00
|
|
|
private long firstLoginUnix;
|
|
|
|
private long lastLoginUnix;
|
2014-04-11 15:24:44 +00:00
|
|
|
private final List<String> ips;
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
protected TFM_Player(UUID uuid, ConfigurationSection section)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
this(uuid);
|
|
|
|
|
|
|
|
this.firstJoinName = section.getString("firstjoinname");
|
|
|
|
this.lastJoinName = section.getString("lastjoinname");
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
this.firstLoginUnix = section.getLong("firstjoinunix");
|
|
|
|
this.lastLoginUnix = section.getLong("lastjoinunix");
|
2014-04-11 15:24:44 +00:00
|
|
|
|
|
|
|
this.ips.addAll(section.getStringList("ips"));
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
protected TFM_Player(UUID uuid, String firstJoinName, String lastJoinName, long firstJoinUnix, long lastJoinUnix, List<String> ips)
|
|
|
|
{
|
|
|
|
this(uuid);
|
|
|
|
|
|
|
|
this.firstJoinName = firstJoinName;
|
|
|
|
this.lastJoinName = lastJoinName;
|
|
|
|
|
|
|
|
this.firstLoginUnix = firstJoinUnix;
|
|
|
|
this.lastLoginUnix = lastJoinUnix;
|
|
|
|
|
|
|
|
this.ips.addAll(ips);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected TFM_Player(UUID uuid)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-06-29 14:39:25 +00:00
|
|
|
if (uuid == null)
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("UUID can not be null!");
|
|
|
|
}
|
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
this.uuid = uuid;
|
|
|
|
this.ips = new ArrayList<String>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getters / Setters below
|
|
|
|
public UUID getUniqueId()
|
|
|
|
{
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getIps()
|
|
|
|
{
|
|
|
|
return Collections.unmodifiableList(ips);
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public String getFirstLoginName()
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
return firstJoinName;
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public void setFirstLoginName(String firstJoinName)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
this.firstJoinName = firstJoinName;
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public String getLastLoginName()
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
return lastJoinName;
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public void setLastLoginName(String lastJoinName)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
this.lastJoinName = lastJoinName;
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public long getFirstLoginUnix()
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-06-29 10:09:03 +00:00
|
|
|
return firstLoginUnix;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public void setFirstLoginUnix(long firstJoinUnix)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-06-29 10:09:03 +00:00
|
|
|
this.firstLoginUnix = firstJoinUnix;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public long getLastLoginUnix()
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-06-29 10:09:03 +00:00
|
|
|
return lastLoginUnix;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 10:09:03 +00:00
|
|
|
public void setLastLoginUnix(long lastJoinUnix)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-06-29 10:09:03 +00:00
|
|
|
this.lastLoginUnix = lastJoinUnix;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean addIp(String ip)
|
|
|
|
{
|
|
|
|
if (!ips.contains(ip))
|
|
|
|
{
|
|
|
|
ips.add(ip);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isComplete()
|
|
|
|
{
|
|
|
|
return firstJoinName != null
|
|
|
|
&& lastJoinName != null
|
2014-06-29 10:09:03 +00:00
|
|
|
&& firstLoginUnix != 0
|
|
|
|
&& lastLoginUnix != 0
|
2014-04-11 15:24:44 +00:00
|
|
|
&& !ips.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save()
|
|
|
|
{
|
|
|
|
if (!isComplete())
|
|
|
|
{
|
|
|
|
throw new IllegalStateException("Entry is not complete");
|
|
|
|
}
|
|
|
|
|
2014-05-19 17:32:25 +00:00
|
|
|
final TFM_Config config = TFM_PlayerList.getConfig();
|
2014-04-11 15:24:44 +00:00
|
|
|
final ConfigurationSection section;
|
|
|
|
|
|
|
|
if (config.isConfigurationSection(uuid.toString()))
|
|
|
|
{
|
|
|
|
section = config.getConfigurationSection(uuid.toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
section = config.createSection(uuid.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
section.set("firstjoinname", firstJoinName);
|
|
|
|
section.set("lastjoinname", lastJoinName);
|
2014-06-29 10:09:03 +00:00
|
|
|
section.set("firstjoinunix", firstLoginUnix);
|
|
|
|
section.set("lastjoinunix", lastLoginUnix);
|
2014-04-11 15:24:44 +00:00
|
|
|
section.set("ips", ips);
|
|
|
|
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
}
|