!Small refactor

This commit is contained in:
Indyuce 2020-03-18 20:16:12 +01:00
parent 80bfe6faba
commit b2b5693676
2 changed files with 21 additions and 21 deletions

View File

@ -8,11 +8,12 @@ import net.Indyuce.mmocore.manager.data.YAMLPlayerDataManager;
public class YAMLDataProvider implements DataProvider {
private final YAMLPlayerDataManager playerManager;
private final YAMLGuildDataManager guildManager;
public YAMLDataProvider() {
playerManager = new YAMLPlayerDataManager();
guildManager = new YAMLGuildDataManager();
}
@Override
public PlayerDataManager getDataManager() {
return playerManager;

View File

@ -14,32 +14,32 @@ import net.Indyuce.mmocore.api.util.MMOSQL;
import net.Indyuce.mmocore.api.util.MMOSQL.Table;
public class MySQLOfflinePlayerData extends OfflinePlayerData {
int level;
long lastLogin;
PlayerClass profess;
List<UUID> friends;
private int level;
private long lastLogin;
private PlayerClass profess;
private List<UUID> friends;
public MySQLOfflinePlayerData(UUID uuid) {
super(uuid);
ResultSet result = MMOSQL.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';");
try {
if(!result.next()) {
if (!result.next()) {
level = 0;
lastLogin = 0;
profess = MMOCore.plugin.classManager.getDefaultClass();
friends = new ArrayList<UUID>();
}
else while(result.next()) {
level = result.getInt("level");
lastLogin = result.getLong("last_login");
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass()
: MMOCore.plugin.classManager.get(result.getString("class"));
if(!result.getString("friends").equalsIgnoreCase("null"))
MMOSQL.getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
else friends = new ArrayList<UUID>();
}
} else
while (result.next()) {
level = result.getInt("level");
lastLogin = result.getLong("last_login");
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
if (!result.getString("friends").equalsIgnoreCase("null"))
MMOSQL.getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
else
friends = new ArrayList<UUID>();
}
} catch (SQLException e) {
e.printStackTrace();
}
@ -48,8 +48,7 @@ public class MySQLOfflinePlayerData extends OfflinePlayerData {
@Override
public void removeFriend(UUID uuid) {
friends.remove(uuid);
new MMOSQL(Table.PLAYERDATA, uuid).updateData("friends",
friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
new MMOSQL(Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
}
@Override
@ -59,7 +58,7 @@ public class MySQLOfflinePlayerData extends OfflinePlayerData {
@Override
public PlayerClass getProfess() {
return profess;
return profess;
}
@Override