TFM-4.3-Reloaded/src/main/java/me/StevenLawson/TotalFreedomMod/player/Player.java

145 lines
3.2 KiB
Java
Raw Normal View History

2022-03-20 12:35:43 +00:00
package me.StevenLawson.TotalFreedomMod.player;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
2022-03-20 12:35:43 +00:00
import com.google.common.collect.ImmutableList;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.configuration.ConfigurationSection;
2022-03-20 12:35:43 +00:00
public class Player
{
private final UUID uuid;
private String firstJoinName;
private String lastJoinName;
private long firstJoinUnix;
private long lastJoinUnix;
private final List<String> ips;
2022-03-20 12:35:43 +00:00
protected Player(UUID uuid, ConfigurationSection section)
{
this(uuid);
this.firstJoinName = section.getString("firstjoinname");
this.lastJoinName = section.getString("lastjoinname");
this.firstJoinUnix = section.getLong("firstjoinunix");
this.lastJoinUnix = section.getLong("lastjoinunix");
this.ips.addAll(section.getStringList("ips"));
}
2022-03-20 12:35:43 +00:00
protected Player(UUID uuid, String firstJoinName, String lastJoinName, long firstJoinUnix, long lastJoinUnix, List<String> ips)
{
this(uuid);
this.firstJoinName = firstJoinName;
this.lastJoinName = lastJoinName;
this.firstJoinUnix = firstJoinUnix;
this.lastJoinUnix = lastJoinUnix;
this.ips.addAll(ips);
}
2022-03-20 12:35:43 +00:00
protected Player(UUID uuid)
{
if (uuid == null)
{
throw new IllegalArgumentException("UUID can not be null!");
}
this.uuid = uuid;
this.ips = new ArrayList<String>();
}
// Getters / Setters below
public UUID getUniqueId()
{
return uuid;
}
public List<String> getFuzziedIps() {
final ArrayList<String> fuzziedIps = new ArrayList<>();
for (String ip : ips)
{
fuzziedIps.add(Utilities.getFuzzyIp(ip));
}
return ImmutableList.copyOf(fuzziedIps);
}
public List<String> getIps()
{
return Collections.unmodifiableList(ips);
}
public String getFirstLoginName()
{
return firstJoinName;
}
public void setFirstLoginName(String firstJoinName)
{
this.firstJoinName = firstJoinName;
}
public String getLastLoginName()
{
return lastJoinName;
}
public void setLastLoginName(String lastJoinName)
{
this.lastJoinName = lastJoinName;
}
public long getFirstLoginUnix()
{
return firstJoinUnix;
}
public void setFirstLoginUnix(long firstJoinUnix)
{
this.firstJoinUnix = firstJoinUnix;
}
public long getLastLoginUnix()
{
return lastJoinUnix;
}
public void setLastLoginUnix(long lastJoinUnix)
{
this.lastJoinUnix = lastJoinUnix;
}
public boolean addIp(String ip)
{
if (!ips.contains(ip))
{
ips.add(ip);
return true;
}
return false;
}
public final boolean isComplete()
{
return firstJoinName != null
&& lastJoinName != null
&& firstJoinUnix != 0
&& lastJoinUnix != 0
&& !ips.isEmpty();
}
public void save()
{
2022-03-20 12:35:43 +00:00
PlayerList.save(this);
}
}