mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-12 13:53:54 +00:00
1.16 Update (#219)
This commit is contained in:
@ -9,7 +9,6 @@ import me.totalfreedom.totalfreedommod.caging.CageData;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.freeze.FreezeData;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Arrow;
|
||||
@ -79,7 +78,7 @@ public class FPlayer
|
||||
|
||||
public FPlayer(TotalFreedomMod plugin, Player player)
|
||||
{
|
||||
this(plugin, player.getName(), Ips.getIp(player));
|
||||
this(plugin, player.getName(), FUtil.getIp(player));
|
||||
}
|
||||
|
||||
private FPlayer(TotalFreedomMod plugin, String name, String ip)
|
||||
@ -100,7 +99,7 @@ public class FPlayer
|
||||
{
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (Ips.getIp(onlinePlayer).equals(ip))
|
||||
if (FUtil.getIp(onlinePlayer).equals(ip))
|
||||
{
|
||||
player = onlinePlayer;
|
||||
break;
|
||||
|
@ -1,59 +1,114 @@
|
||||
package me.totalfreedom.totalfreedommod.player;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
public class PlayerData
|
||||
{
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String username;
|
||||
@Getter
|
||||
@Setter
|
||||
private long firstJoinUnix;
|
||||
@Getter
|
||||
@Setter
|
||||
private long lastJoinUnix;
|
||||
private String name;
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
private final List<String> notes = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
private String tag = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private String discordID = null;
|
||||
private final List<String> backupCodes = Lists.newArrayList();
|
||||
@Setter
|
||||
private boolean donator = false;
|
||||
@Setter
|
||||
private Boolean masterBuilder = false;
|
||||
@Setter
|
||||
private Boolean verification = false;
|
||||
@Getter
|
||||
@Setter
|
||||
private String rideMode = "ask";
|
||||
@Getter
|
||||
@Setter
|
||||
private int coins;
|
||||
private List<String> items = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
private int totalVotes;
|
||||
|
||||
public PlayerData(ResultSet resultSet)
|
||||
{
|
||||
try
|
||||
{
|
||||
name = resultSet.getString("username");
|
||||
ips.clear();
|
||||
ips.addAll(FUtil.stringToList(resultSet.getString("ips")));
|
||||
notes.clear();
|
||||
notes.addAll(FUtil.stringToList(resultSet.getString("notes")));
|
||||
tag = resultSet.getString("tag");
|
||||
discordID = resultSet.getString("discord_id");
|
||||
backupCodes.clear();
|
||||
backupCodes.addAll(FUtil.stringToList(resultSet.getString("backup_codes")));
|
||||
masterBuilder = resultSet.getBoolean("master_builder");
|
||||
verification = resultSet.getBoolean("verification");
|
||||
rideMode = resultSet.getString("ride_mode");
|
||||
coins = resultSet.getInt("coins");
|
||||
items.clear();
|
||||
items.addAll(FUtil.stringToList(resultSet.getString("items")));
|
||||
totalVotes = resultSet.getInt("total_votes");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to load player: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Force verification for Master Builders
|
||||
if (masterBuilder && !verification)
|
||||
{
|
||||
verification = true;
|
||||
TotalFreedomMod.plugin().pl.save(this);
|
||||
}
|
||||
else if (!masterBuilder && discordID == null && verification)
|
||||
{
|
||||
this.verification = false;
|
||||
TotalFreedomMod.plugin().pl.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder output = new StringBuilder();
|
||||
|
||||
output.append("Player: ").append(name).append("\n")
|
||||
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
|
||||
.append("- Discord ID: ").append(discordID).append("\n")
|
||||
.append("- Master Builder: ").append(masterBuilder).append("\n")
|
||||
.append("- Has Verification: ").append(verification).append("\n")
|
||||
.append("- Coins: ").append(coins).append("\n")
|
||||
.append("- Total Votes: ").append(totalVotes).append("\n")
|
||||
.append("- Tag: ").append(tag).append("\n")
|
||||
.append("- Ride Mode: ").append(rideMode)
|
||||
.append("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n");
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
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);
|
||||
this.name = player.getName();
|
||||
}
|
||||
|
||||
public List<String> getIps()
|
||||
@ -61,23 +116,127 @@ public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
return Collections.unmodifiableList(ips);
|
||||
}
|
||||
|
||||
// IP utils
|
||||
public boolean addIp(String ip)
|
||||
{
|
||||
return ips.contains(ip) ? false : ips.add(ip);
|
||||
return !ips.contains(ip) && ips.add(ip);
|
||||
}
|
||||
|
||||
public boolean removeIp(String ip)
|
||||
public void removeIp(String ip)
|
||||
{
|
||||
return ips.remove(ip);
|
||||
ips.remove(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
public void clearIps()
|
||||
{
|
||||
return username != null
|
||||
&& firstJoinUnix != 0
|
||||
&& lastJoinUnix != 0
|
||||
&& !ips.isEmpty();
|
||||
ips.clear();
|
||||
}
|
||||
|
||||
public void addIps(List<String> ips)
|
||||
{
|
||||
ips.addAll(ips);
|
||||
}
|
||||
|
||||
public List<String> getNotes()
|
||||
{
|
||||
return Collections.unmodifiableList(notes);
|
||||
}
|
||||
|
||||
public void clearNotes()
|
||||
{
|
||||
notes.clear();
|
||||
}
|
||||
|
||||
public List<String> getBackupCodes()
|
||||
{
|
||||
return Collections.unmodifiableList(backupCodes);
|
||||
}
|
||||
|
||||
public void setBackupCodes(List<String> codes)
|
||||
{
|
||||
backupCodes.clear();
|
||||
backupCodes.addAll(codes);
|
||||
}
|
||||
|
||||
public void removeBackupCode(String code)
|
||||
{
|
||||
backupCodes.remove(code);
|
||||
}
|
||||
|
||||
public void addNote(String note)
|
||||
{
|
||||
notes.add(note);
|
||||
}
|
||||
|
||||
public boolean removeNote(int id) throws IndexOutOfBoundsException
|
||||
{
|
||||
try
|
||||
{
|
||||
notes.remove(id);
|
||||
}
|
||||
catch (IndexOutOfBoundsException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void giveItem(ShopItem item)
|
||||
{
|
||||
items.add(item.getDataName());
|
||||
}
|
||||
|
||||
public List<String> getItems()
|
||||
{
|
||||
return Collections.unmodifiableList(items);
|
||||
}
|
||||
|
||||
public boolean hasItem(ShopItem item)
|
||||
{
|
||||
if (items.contains(item.getDataName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeItem(ShopItem item)
|
||||
{
|
||||
items.remove(item.getDataName());
|
||||
}
|
||||
|
||||
public boolean hasVerification()
|
||||
{
|
||||
return verification;
|
||||
}
|
||||
|
||||
public boolean isDonator()
|
||||
{
|
||||
return donator;
|
||||
}
|
||||
|
||||
public boolean isMasterBuilder()
|
||||
{
|
||||
return masterBuilder;
|
||||
}
|
||||
|
||||
public Map<String, Object> toSQLStorable()
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>()
|
||||
{{
|
||||
put("username", name);
|
||||
put("ips", FUtil.listToString(ips));
|
||||
put("notes", FUtil.listToString(notes));
|
||||
put("tag", tag);
|
||||
put("discord_id", discordID);
|
||||
put("backup_codes", FUtil.listToString(backupCodes));
|
||||
put("donator", masterBuilder);
|
||||
put("master_builder", masterBuilder);
|
||||
put("verification", verification);
|
||||
put("ride_mode", rideMode);
|
||||
put("coins", coins);
|
||||
put("items", FUtil.listToString(items));
|
||||
put("total_votes", totalVotes);
|
||||
}};
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,41 @@
|
||||
package me.totalfreedom.totalfreedommod.player;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerList extends FreedomService
|
||||
{
|
||||
|
||||
public static final long AUTO_PURGE_TICKS = 20L * 60L * 5L;
|
||||
//
|
||||
@Getter
|
||||
public final Map<String, FPlayer> playerMap = Maps.newHashMap(); // ip,dataMap
|
||||
@Getter
|
||||
public final Map<String, PlayerData> dataMap = Maps.newHashMap(); // ip,dataMap
|
||||
@Getter
|
||||
private final File configFolder;
|
||||
|
||||
public PlayerList(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.configFolder = new File(plugin.getDataFolder(), "players");
|
||||
}
|
||||
@Getter
|
||||
public final Map<String, PlayerData> dataMap = Maps.newHashMap(); // username, data
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
public void onStart()
|
||||
{
|
||||
playerMap.clear();
|
||||
dataMap.clear();
|
||||
|
||||
// Preload online players
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
getPlayer(player);
|
||||
}
|
||||
loadMasterBuilders();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
public void onStop()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
for (PlayerData data : dataMap.values())
|
||||
{
|
||||
YamlConfig config = getConfig(data);
|
||||
data.saveTo(config);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
public FPlayer getPlayerSync(Player player)
|
||||
@ -74,11 +46,34 @@ public class PlayerList extends FreedomService
|
||||
}
|
||||
}
|
||||
|
||||
public void loadMasterBuilders()
|
||||
{
|
||||
ResultSet resultSet = plugin.sql.getMasterBuilders();
|
||||
|
||||
if (resultSet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
PlayerData playerData = load(resultSet);
|
||||
dataMap.put(playerData.getName(), playerData);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to parse master builders: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String getIp(OfflinePlayer player)
|
||||
{
|
||||
if (player.isOnline())
|
||||
{
|
||||
return Ips.getIp(player.getPlayer());
|
||||
return FUtil.getIp(player.getPlayer());
|
||||
}
|
||||
|
||||
final PlayerData entry = getData(player.getName());
|
||||
@ -86,137 +81,244 @@ public class PlayerList extends FreedomService
|
||||
return (entry == null ? null : entry.getIps().iterator().next());
|
||||
}
|
||||
|
||||
public List<String> getMasterBuilderNames()
|
||||
{
|
||||
List<String> masterBuilders = new ArrayList<>();
|
||||
for (PlayerData playerData : plugin.pl.dataMap.values())
|
||||
{
|
||||
if (playerData.isMasterBuilder())
|
||||
{
|
||||
masterBuilders.add(playerData.getName());
|
||||
}
|
||||
}
|
||||
return masterBuilders;
|
||||
}
|
||||
|
||||
public boolean canManageMasterBuilders(String name)
|
||||
{
|
||||
PlayerData data = getData(name);
|
||||
|
||||
if ((!ConfigEntry.HOST_SENDER_NAMES.getStringList().contains(name.toLowerCase()) && data != null && !ConfigEntry.SERVER_OWNERS.getStringList().contains(data.getName()))
|
||||
&& !ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(data.getName())
|
||||
&& !isTelnetMasterBuilder(data)
|
||||
&& !ConfigEntry.HOST_SENDER_NAMES.getStringList().contains(name.toLowerCase()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTelnetMasterBuilder(PlayerData playerData)
|
||||
{
|
||||
Admin admin = plugin.al.getEntryByName(playerData.getName());
|
||||
if (admin != null && admin.getRank().isAtLeast(Rank.TELNET_ADMIN) && playerData.isMasterBuilder())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// May not return null
|
||||
public FPlayer getPlayer(Player player)
|
||||
{
|
||||
FPlayer tPlayer = playerMap.get(Ips.getIp(player));
|
||||
FPlayer tPlayer = playerMap.get(FUtil.getIp(player));
|
||||
if (tPlayer != null)
|
||||
{
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
tPlayer = new FPlayer(plugin, player);
|
||||
playerMap.put(Ips.getIp(player), tPlayer);
|
||||
playerMap.put(FUtil.getIp(player), tPlayer);
|
||||
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
// May not return null
|
||||
public PlayerData getData(Player player)
|
||||
public PlayerData loadByName(String name)
|
||||
{
|
||||
// Check already loaded
|
||||
PlayerData data = dataMap.get(Ips.getIp(player));
|
||||
if (data != null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
// Load data
|
||||
data = getData(player.getName());
|
||||
|
||||
// Create data if nonexistent
|
||||
if (data == null)
|
||||
{
|
||||
FLog.info("Creating new player data entry for " + player.getName());
|
||||
|
||||
// Create new player
|
||||
final long unix = FUtil.getUnixTime();
|
||||
data = new PlayerData(player);
|
||||
data.setFirstJoinUnix(unix);
|
||||
data.setLastJoinUnix(unix);
|
||||
data.addIp(Ips.getIp(player));
|
||||
|
||||
// Store player
|
||||
dataMap.put(player.getName().toLowerCase(), data);
|
||||
|
||||
// Save player
|
||||
YamlConfig config = getConfig(data);
|
||||
data.saveTo(config);
|
||||
config.save();
|
||||
}
|
||||
|
||||
return data;
|
||||
return load(plugin.sql.getPlayerByName(name));
|
||||
}
|
||||
|
||||
// May return null
|
||||
public PlayerData getData(String username)
|
||||
public PlayerData loadByIp(String ip)
|
||||
{
|
||||
username = username.toLowerCase();
|
||||
return load(plugin.sql.getPlayerByIp(ip));
|
||||
}
|
||||
|
||||
// Check if the player is a known player
|
||||
final File configFile = getConfigFile(username);
|
||||
if (!configFile.exists())
|
||||
public PlayerData load(ResultSet resultSet)
|
||||
{
|
||||
if (resultSet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new PlayerData(resultSet);
|
||||
}
|
||||
|
||||
// Create and load entry
|
||||
final PlayerData data = new PlayerData(username);
|
||||
data.loadFrom(getConfig(data));
|
||||
public Boolean isPlayerImpostor(Player player)
|
||||
{
|
||||
PlayerData playerData = getData(player);
|
||||
return !plugin.al.isAdmin(player)
|
||||
&& (playerData.hasVerification())
|
||||
&& !playerData.getIps().contains(FUtil.getIp(player));
|
||||
}
|
||||
|
||||
if (!data.isValid())
|
||||
public boolean isImposter(Player player)
|
||||
{
|
||||
return isPlayerImpostor(player) || plugin.al.isAdminImpostor(player);
|
||||
}
|
||||
|
||||
public void verify(Player player, String backupCode)
|
||||
{
|
||||
PlayerData playerData = getData(player);
|
||||
if (backupCode != null)
|
||||
{
|
||||
FLog.warning("Could not load player data entry: " + username + ". Entry is not valid!");
|
||||
configFile.delete();
|
||||
return null;
|
||||
playerData.removeBackupCode(backupCode);
|
||||
}
|
||||
playerData.addIp(FUtil.getIp(player));
|
||||
save(playerData);
|
||||
|
||||
// Only store data if the player is online
|
||||
for (String ip : data.getIps())
|
||||
if (plugin.al.isAdminImpostor(player))
|
||||
{
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
Admin admin = null;
|
||||
for (Admin loopAdmin : plugin.al.getAllAdmins())
|
||||
{
|
||||
if (Ips.getIp(onlinePlayer).equals(ip))
|
||||
if (loopAdmin.getName().equalsIgnoreCase(player.getName()))
|
||||
{
|
||||
dataMap.put(ip, data);
|
||||
return data;
|
||||
admin = loopAdmin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
admin.setLastLogin(new Date());
|
||||
admin.addIp(FUtil.getIp(player));
|
||||
plugin.al.updateTables();
|
||||
plugin.al.save(admin);
|
||||
}
|
||||
|
||||
plugin.rm.updateDisplay(player);
|
||||
}
|
||||
|
||||
public void syncIps(Admin admin)
|
||||
{
|
||||
PlayerData playerData = getData(admin.getName());
|
||||
playerData.clearIps();
|
||||
playerData.addIps(admin.getIps());
|
||||
plugin.pl.save(playerData);
|
||||
}
|
||||
public void syncIps(PlayerData playerData)
|
||||
{
|
||||
Admin admin = plugin.al.getEntryByName(playerData.getName());
|
||||
|
||||
if (admin != null && admin.isActive())
|
||||
{
|
||||
admin.clearIPs();
|
||||
admin.addIps(playerData.getIps());
|
||||
plugin.al.updateTables();
|
||||
plugin.al.save(admin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void save(PlayerData player)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultSet currentSave = plugin.sql.getPlayerByName(player.getName());
|
||||
for (Map.Entry<String, Object> entry : player.toSQLStorable().entrySet())
|
||||
{
|
||||
Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue());
|
||||
if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null)
|
||||
{
|
||||
plugin.sql.setPlayerValue(player, entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final String ip = Ips.getIp(player);
|
||||
playerMap.remove(ip);
|
||||
dataMap.remove(ip);
|
||||
}
|
||||
|
||||
public Collection<FPlayer> getLoadedPlayers()
|
||||
{
|
||||
return playerMap.values();
|
||||
}
|
||||
|
||||
public Collection<PlayerData> getLoadedData()
|
||||
{
|
||||
return dataMap.values();
|
||||
}
|
||||
|
||||
public int purgeAllData()
|
||||
{
|
||||
int deleted = 0;
|
||||
for (File file : getConfigFolder().listFiles())
|
||||
catch (SQLException e)
|
||||
{
|
||||
deleted += file.delete() ? 1 : 0;
|
||||
FLog.severe("Failed to save player: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerData getData(Player player)
|
||||
{
|
||||
// Check for existing data
|
||||
PlayerData playerData = dataMap.get(player.getName());
|
||||
if (playerData != null)
|
||||
{
|
||||
return playerData;
|
||||
}
|
||||
|
||||
dataMap.clear();
|
||||
return deleted;
|
||||
// Load data
|
||||
playerData = loadByName(player.getName());
|
||||
|
||||
if (playerData == null)
|
||||
{
|
||||
playerData = loadByIp(FUtil.getIp(player));
|
||||
if (playerData != null)
|
||||
{
|
||||
plugin.sql.updatePlayerName(playerData.getName(),player.getName());
|
||||
playerData.setName(player.getName());
|
||||
dataMap.put(player.getName(), playerData);
|
||||
return playerData;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataMap.put(player.getName(), playerData);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
// Create new data if nonexistent
|
||||
if (playerData == null)
|
||||
{
|
||||
FLog.info("Creating new player verification entry for " + player.getName());
|
||||
|
||||
// Create new player
|
||||
playerData = new PlayerData(player);
|
||||
playerData.addIp(FUtil.getIp(player));
|
||||
|
||||
// Store player
|
||||
dataMap.put(player.getName(), playerData);
|
||||
|
||||
// Save player
|
||||
plugin.sql.addPlayer(playerData);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected File getConfigFile(String name)
|
||||
public PlayerData getData(String username)
|
||||
{
|
||||
return new File(getConfigFolder(), name + ".yml");
|
||||
// Check for existing data
|
||||
PlayerData playerData = dataMap.get(username);
|
||||
if (playerData != null)
|
||||
{
|
||||
return playerData;
|
||||
}
|
||||
|
||||
playerData = loadByName(username);
|
||||
|
||||
if (playerData != null)
|
||||
{
|
||||
dataMap.put(username, playerData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
protected YamlConfig getConfig(PlayerData data)
|
||||
public PlayerData getDataByIp(String ip)
|
||||
{
|
||||
final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getUsername().toLowerCase()), false);
|
||||
config.load();
|
||||
return config;
|
||||
PlayerData player = loadByIp(ip);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
dataMap.put(player.getName(), player);
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user