forked from Upstream/mmocore
!Small refactor
This commit is contained in:
parent
80bfe6faba
commit
b2b5693676
@ -8,11 +8,12 @@ import net.Indyuce.mmocore.manager.data.YAMLPlayerDataManager;
|
|||||||
public class YAMLDataProvider implements DataProvider {
|
public class YAMLDataProvider implements DataProvider {
|
||||||
private final YAMLPlayerDataManager playerManager;
|
private final YAMLPlayerDataManager playerManager;
|
||||||
private final YAMLGuildDataManager guildManager;
|
private final YAMLGuildDataManager guildManager;
|
||||||
|
|
||||||
public YAMLDataProvider() {
|
public YAMLDataProvider() {
|
||||||
playerManager = new YAMLPlayerDataManager();
|
playerManager = new YAMLPlayerDataManager();
|
||||||
guildManager = new YAMLGuildDataManager();
|
guildManager = new YAMLGuildDataManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerDataManager getDataManager() {
|
public PlayerDataManager getDataManager() {
|
||||||
return playerManager;
|
return playerManager;
|
||||||
|
@ -14,32 +14,32 @@ import net.Indyuce.mmocore.api.util.MMOSQL;
|
|||||||
import net.Indyuce.mmocore.api.util.MMOSQL.Table;
|
import net.Indyuce.mmocore.api.util.MMOSQL.Table;
|
||||||
|
|
||||||
public class MySQLOfflinePlayerData extends OfflinePlayerData {
|
public class MySQLOfflinePlayerData extends OfflinePlayerData {
|
||||||
int level;
|
private int level;
|
||||||
long lastLogin;
|
private long lastLogin;
|
||||||
PlayerClass profess;
|
private PlayerClass profess;
|
||||||
List<UUID> friends;
|
private List<UUID> friends;
|
||||||
|
|
||||||
public MySQLOfflinePlayerData(UUID uuid) {
|
public MySQLOfflinePlayerData(UUID uuid) {
|
||||||
super(uuid);
|
super(uuid);
|
||||||
|
|
||||||
ResultSet result = MMOSQL.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';");
|
ResultSet result = MMOSQL.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!result.next()) {
|
if (!result.next()) {
|
||||||
level = 0;
|
level = 0;
|
||||||
lastLogin = 0;
|
lastLogin = 0;
|
||||||
profess = MMOCore.plugin.classManager.getDefaultClass();
|
profess = MMOCore.plugin.classManager.getDefaultClass();
|
||||||
friends = new ArrayList<UUID>();
|
friends = new ArrayList<UUID>();
|
||||||
}
|
} else
|
||||||
else while(result.next()) {
|
while (result.next()) {
|
||||||
level = result.getInt("level");
|
level = result.getInt("level");
|
||||||
lastLogin = result.getLong("last_login");
|
lastLogin = result.getLong("last_login");
|
||||||
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass()
|
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
|
||||||
: MMOCore.plugin.classManager.get(result.getString("class"));
|
if (!result.getString("friends").equalsIgnoreCase("null"))
|
||||||
if(!result.getString("friends").equalsIgnoreCase("null"))
|
MMOSQL.getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
||||||
MMOSQL.getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
else
|
||||||
else friends = new ArrayList<UUID>();
|
friends = new ArrayList<UUID>();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -48,8 +48,7 @@ public class MySQLOfflinePlayerData extends OfflinePlayerData {
|
|||||||
@Override
|
@Override
|
||||||
public void removeFriend(UUID uuid) {
|
public void removeFriend(UUID uuid) {
|
||||||
friends.remove(uuid);
|
friends.remove(uuid);
|
||||||
new MMOSQL(Table.PLAYERDATA, uuid).updateData("friends",
|
new MMOSQL(Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
|
||||||
friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +58,7 @@ public class MySQLOfflinePlayerData extends OfflinePlayerData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlayerClass getProfess() {
|
public PlayerClass getProfess() {
|
||||||
return profess;
|
return profess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user