|
@@ -2,7 +2,6 @@ package com.gmail.nossr50.database;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedWriter;
|
|
import java.io.BufferedWriter;
|
|
-import java.io.Closeable;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileReader;
|
|
import java.io.FileReader;
|
|
import java.io.FileWriter;
|
|
import java.io.FileWriter;
|
|
@@ -10,6 +9,7 @@ import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
|
+import java.util.EnumMap;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -98,8 +98,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -164,8 +178,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -203,8 +231,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -294,8 +336,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -311,7 +367,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
public Map<SkillType, Integer> readRank(String playerName) {
|
|
public Map<SkillType, Integer> readRank(String playerName) {
|
|
updateLeaderboards();
|
|
updateLeaderboards();
|
|
|
|
|
|
- Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
|
|
|
|
|
|
+ Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class);
|
|
|
|
|
|
for (SkillType skill : SkillType.NON_CHILD_SKILLS) {
|
|
for (SkillType skill : SkillType.NON_CHILD_SKILLS) {
|
|
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
|
|
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
|
|
@@ -381,18 +437,25 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Deprecated
|
|
@Deprecated
|
|
public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
|
|
public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
|
|
- return loadPlayerProfile(playerName, "", create);
|
|
|
|
|
|
+ return loadPlayerProfile(playerName, "", false);
|
|
}
|
|
}
|
|
|
|
|
|
- public PlayerProfile loadPlayerProfile(UUID uuid, boolean create) {
|
|
|
|
- return loadPlayerProfile("", uuid.toString(), create);
|
|
|
|
|
|
+ public PlayerProfile loadPlayerProfile(UUID uuid) {
|
|
|
|
+ return loadPlayerProfile("", uuid.toString(), false);
|
|
}
|
|
}
|
|
|
|
|
|
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean create) {
|
|
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean create) {
|
|
@@ -448,7 +511,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
in.close();
|
|
in.close();
|
|
}
|
|
}
|
|
catch (IOException e) {
|
|
catch (IOException e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ // Ignore
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -491,7 +554,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -532,8 +602,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -573,8 +657,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -601,7 +699,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return users;
|
|
return users;
|
|
@@ -671,7 +776,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -897,8 +1009,22 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
- tryClose(in);
|
|
|
|
- tryClose(out);
|
|
|
|
|
|
+ if (in != null) {
|
|
|
|
+ try {
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (out != null) {
|
|
|
|
+ try {
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ // Ignore
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -923,18 +1049,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void tryClose(Closeable c) {
|
|
|
|
- if (c == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- c.close();
|
|
|
|
- }
|
|
|
|
- catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
|
|
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
|
|
if (statsList == null) {
|
|
if (statsList == null) {
|
|
return null;
|
|
return null;
|
|
@@ -967,8 +1081,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
private PlayerProfile loadFromLine(String[] character) {
|
|
private PlayerProfile loadFromLine(String[] character) {
|
|
Map<SkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
|
Map<SkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
|
- Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
|
|
|
|
- Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
|
|
|
|
|
|
+ Map<SkillType, Float> skillsXp = new EnumMap<SkillType, Float>(SkillType.class); // Skill & XP
|
|
|
|
+ Map<AbilityType, Integer> skillsDATS = new EnumMap<AbilityType, Integer>(AbilityType.class); // Ability & Cooldown
|
|
MobHealthbarType mobHealthbarType;
|
|
MobHealthbarType mobHealthbarType;
|
|
|
|
|
|
// TODO on updates, put new values in a try{} ?
|
|
// TODO on updates, put new values in a try{} ?
|
|
@@ -1019,7 +1133,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
private Map<SkillType, Integer> getSkillMapFromLine(String[] character) {
|
|
private Map<SkillType, Integer> getSkillMapFromLine(String[] character) {
|
|
- Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
|
|
|
|
|
|
+ Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class); // Skill & Level
|
|
|
|
|
|
skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
|
|
skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
|
|
skills.put(SkillType.MINING, Integer.valueOf(character[1]));
|
|
skills.put(SkillType.MINING, Integer.valueOf(character[1]));
|
|
@@ -1041,4 +1155,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|
public DatabaseType getDatabaseType() {
|
|
public DatabaseType getDatabaseType() {
|
|
return DatabaseType.FLATFILE;
|
|
return DatabaseType.FLATFILE;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDisable() { }
|
|
}
|
|
}
|