169 lines
4.8 KiB
Java
169 lines
4.8 KiB
Java
|
package com.gmail.mikeundead;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
import org.bukkit.ChatColor;
|
||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||
|
|
||
|
public class DatabaseHandler {
|
||
|
private final PvPTitles pvpTitles;
|
||
|
private int Fame;
|
||
|
private final Map<Integer, String> rankList;
|
||
|
private final Map<Integer, Integer> reqFame;
|
||
|
public ChatColor PrefixColor;
|
||
|
private String tag;
|
||
|
|
||
|
public DatabaseHandler(final PvPTitles pvpTitles) {
|
||
|
this.rankList = new HashMap<Integer, String>();
|
||
|
this.reqFame = new HashMap<Integer, Integer>();
|
||
|
this.pvpTitles = pvpTitles;
|
||
|
this.SaveConfig();
|
||
|
}
|
||
|
|
||
|
public void FirstRun(final String playername) {
|
||
|
final File file = new File((new StringBuilder())
|
||
|
.append(this.pvpTitles.getDataFolder())
|
||
|
.append(File.separator)
|
||
|
.append("players")
|
||
|
.append(File.separator)
|
||
|
.append(playername)
|
||
|
.append(".yml")
|
||
|
.toString());
|
||
|
|
||
|
if (!file.exists()) {
|
||
|
this.pvpTitles.getDataFolder().mkdirs();
|
||
|
|
||
|
final FileConfiguration config = new YamlConfiguration();
|
||
|
config.set("Fame", 0);
|
||
|
|
||
|
try {
|
||
|
config.save(file);
|
||
|
} catch (final IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public String getTag() {
|
||
|
return this.tag;
|
||
|
}
|
||
|
|
||
|
public void LoadConfig() {
|
||
|
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||
|
final List<String> configList = config.getStringList("RankNames");
|
||
|
for (int i = 0; i < configList.size(); i++) {
|
||
|
this.rankList.put(i, configList.get(i));
|
||
|
}
|
||
|
@SuppressWarnings("unchecked")
|
||
|
final List<Integer> derp = (List<Integer>) config.getList("ReqFame");
|
||
|
for (int i = 0; i < derp.size(); i++) {
|
||
|
this.reqFame.put(i, derp.get(i));
|
||
|
}
|
||
|
this.GetPrefixColor(config.getString("PrefixColor"));
|
||
|
tag = config.getString("Tag");
|
||
|
if (configList.size() != derp.size()) {
|
||
|
this.pvpTitles.log.info("WARNING - RankNames and ReqFame are not equal in their numbers.");
|
||
|
this.pvpTitles.log.info("WARNING - RankNames and ReqFame are not equal in their numbers.");
|
||
|
this.pvpTitles.log.info("WARNING - RankNames and ReqFame are not equal in their numbers.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void LoadPlayerFame(final String playername) {
|
||
|
final File file = new File((new StringBuilder())
|
||
|
.append(this.pvpTitles.getDataFolder())
|
||
|
.append(File.separator)
|
||
|
.append("players")
|
||
|
.append(File.separator)
|
||
|
.append(playername)
|
||
|
.append(".yml")
|
||
|
.toString());
|
||
|
|
||
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||
|
this.Fame = config.getInt("Fame");
|
||
|
}
|
||
|
|
||
|
public int PlayerFame() {
|
||
|
return this.Fame;
|
||
|
}
|
||
|
|
||
|
public Map<Integer, String> RankList() {
|
||
|
return this.rankList;
|
||
|
}
|
||
|
|
||
|
public Map<Integer, Integer> reqFame() {
|
||
|
return this.reqFame;
|
||
|
}
|
||
|
|
||
|
public void SaveConfig() {
|
||
|
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||
|
|
||
|
if (!file.exists()) {
|
||
|
this.pvpTitles.getDataFolder().mkdirs();
|
||
|
final FileConfiguration config = new YamlConfiguration();
|
||
|
final String[] ranks = { "None",
|
||
|
"Hero",
|
||
|
"Fierce Hero",
|
||
|
"Mighty Hero",
|
||
|
"Deadly Hero",
|
||
|
"Terrifying Hero",
|
||
|
"Conquering Hero",
|
||
|
"Subjugating Hero",
|
||
|
"Vanquishing Hero",
|
||
|
"Renowned Hero",
|
||
|
"Illustrious Hero",
|
||
|
"Eminent Hero",
|
||
|
"King's Hero",
|
||
|
"Emperor's Hero",
|
||
|
"Balthazar's Hero",
|
||
|
"Legendary Hero" };
|
||
|
final Integer[] reqfame = { 0, 25, 75, 180, 360, 600, 1000, 1680, 2800, 4665, 7750, 12960, 21600, 36000, 60000, 100000 };
|
||
|
config.set("Tag", "Fame");
|
||
|
config.set("PrefixColor", "green");
|
||
|
config.set("RankNames", Arrays.asList(ranks));
|
||
|
config.set("ReqFame", Arrays.asList(reqfame));
|
||
|
try {
|
||
|
config.save(file);
|
||
|
} catch (final IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void SavePlayerFame(final String playername, final int fame) {
|
||
|
final File file = new File((new StringBuilder())
|
||
|
.append(this.pvpTitles.getDataFolder())
|
||
|
.append(File.separator)
|
||
|
.append("players")
|
||
|
.append(File.separator)
|
||
|
.append(playername)
|
||
|
.append(".yml")
|
||
|
.toString());
|
||
|
if (!file.exists()) {
|
||
|
this.pvpTitles.getDataFolder().mkdir();
|
||
|
try {
|
||
|
file.createNewFile();
|
||
|
} catch (final Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||
|
config.set("Fame", fame);
|
||
|
try {
|
||
|
config.save(file);
|
||
|
} catch (final Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void GetPrefixColor(final String color) {
|
||
|
this.PrefixColor = ChatColor.valueOf(color.toUpperCase());
|
||
|
}
|
||
|
}
|