TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java
Telesphoreo 941bbc8da3 OPs can now have persistent tags (#108)
* new high end piece of software

- refactor all the shit to isEnabled
- idk debug
- gotta keep the messages consistent
- worldedit 🅱️ roke
- lockup description
- add /nh as an alias for namehistory
- yo /setl actually checks for w/e now cool
- gtfo and unban now are less bugs
- /whitelist is no longer written in tfm43 code and in beta
- l a m b a d a in help
- enable the bridges
- i worked on a converter for the login messages but then seth already made it work so fuck me i wasted an hour of my life

* whitelist

* i enabled them for testing

* OPs can now have persistent tags!

* Summary (required)
2018-07-30 00:23:01 -07:00

84 lines
2.0 KiB
Java

package me.totalfreedom.totalfreedommod.player;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import net.pravian.aero.base.ConfigLoadable;
import net.pravian.aero.base.ConfigSavable;
import net.pravian.aero.base.Validatable;
import org.apache.commons.lang3.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
{
@Getter
@Setter
private String username;
@Getter
@Setter
private long firstJoinUnix;
@Getter
@Setter
private long lastJoinUnix;
private final List<String> ips = Lists.newArrayList();
public PlayerData(Player player)
{
this(player.getName());
}
public PlayerData(String username)
{
this.username = username;
}
@Override
public void loadFrom(ConfigurationSection cs)
{
this.username = cs.getString("username", username);
this.ips.clear();
this.ips.addAll(cs.getStringList("ips"));
this.firstJoinUnix = cs.getLong("first_join", 0);
this.lastJoinUnix = cs.getLong("last_join", 0);
}
@Override
public void saveTo(ConfigurationSection cs)
{
Validate.isTrue(isValid(), "Could not save player entry: " + username + ". Entry not valid!");
cs.set("username", username);
cs.set("ips", ips);
cs.set("first_join", firstJoinUnix);
cs.set("last_join", lastJoinUnix);
}
public List<String> getIps()
{
return Collections.unmodifiableList(ips);
}
// IP utils
public boolean addIp(String ip)
{
return ips.contains(ip) ? false : ips.add(ip);
}
public boolean removeIp(String ip)
{
return ips.remove(ip);
}
@Override
public boolean isValid()
{
return username != null
&& firstJoinUnix != 0
&& lastJoinUnix != 0
&& !ips.isEmpty();
}
}