mirror of
https://e.coding.net/circlecloud/PvPTitles.git
synced 2025-01-01 19:37:55 +00:00
feat: 随机值添加默认参数
This commit is contained in:
parent
13c94b14dc
commit
7ec451836b
@ -14,204 +14,204 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
public class DatabaseHandler {
|
public class DatabaseHandler {
|
||||||
private final PvPTitles pvpTitles;
|
private final PvPTitles pvpTitles;
|
||||||
private int Fame;
|
private int Fame;
|
||||||
private int Points;
|
private int Points;
|
||||||
private int defaultPoints;
|
private int defaultPoints;
|
||||||
private final Map<Integer, String> rankList;
|
private final Map<Integer, String> rankList;
|
||||||
private final Map<Integer, Integer> reqFame;
|
private final Map<Integer, Integer> reqFame;
|
||||||
private final Map<Integer, String> cashList;
|
private final Map<Integer, String> cashList;
|
||||||
public ChatColor PrefixColor;
|
public ChatColor PrefixColor;
|
||||||
|
|
||||||
private String tag;
|
private String tag;
|
||||||
private String ptag;
|
private String ptag;
|
||||||
|
|
||||||
public DatabaseHandler(final PvPTitles pvpTitles) {
|
public DatabaseHandler(final PvPTitles pvpTitles) {
|
||||||
this.rankList = new HashMap<>();
|
this.rankList = new HashMap<>();
|
||||||
this.reqFame = new HashMap<>();
|
this.reqFame = new HashMap<>();
|
||||||
this.cashList = new HashMap<>();
|
this.cashList = new HashMap<>();
|
||||||
this.pvpTitles = pvpTitles;
|
this.pvpTitles = pvpTitles;
|
||||||
this.SaveConfig();
|
this.SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FirstRun(final String playername) {
|
public void FirstRun(final String playername) {
|
||||||
final File file = new File((new StringBuilder())
|
final File file = new File((new StringBuilder())
|
||||||
.append(this.pvpTitles.getDataFolder())
|
.append(this.pvpTitles.getDataFolder())
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append("players")
|
.append("players")
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append(playername)
|
.append(playername)
|
||||||
.append(".yml")
|
.append(".yml")
|
||||||
.toString());
|
.toString());
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
this.pvpTitles.getDataFolder().mkdirs();
|
this.pvpTitles.getDataFolder().mkdirs();
|
||||||
|
|
||||||
final FileConfiguration config = new YamlConfiguration();
|
final FileConfiguration config = new YamlConfiguration();
|
||||||
config.set("Fame", 0);
|
config.set("Fame", 0);
|
||||||
config.set("Points", new Random().nextInt(defaultPoints));
|
config.set("Points", new Random().nextInt(defaultPoints));
|
||||||
try {
|
try {
|
||||||
config.save(file);
|
config.save(file);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return cashList
|
* @return cashList
|
||||||
*/
|
*/
|
||||||
public Map<Integer, String> getCashList() {
|
public Map<Integer, String> getCashList() {
|
||||||
return cashList;
|
return cashList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFame() {
|
public int getFame() {
|
||||||
return this.Fame;
|
return this.Fame;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPoints() {
|
public int getPoints() {
|
||||||
return Points;
|
return Points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPtag() {
|
public String getPtag() {
|
||||||
return ptag;
|
return ptag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return this.tag;
|
return this.tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadConfig() {
|
public void LoadConfig() {
|
||||||
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
final List<String> configList = config.getStringList("RankNames");
|
final List<String> configList = config.getStringList("RankNames");
|
||||||
defaultPoints = config.getInt("defaultPoints");
|
defaultPoints = config.getInt("defaultPoints", 50);
|
||||||
for (int i = 0; i < configList.size(); i++) {
|
for (int i = 0; i < configList.size(); i++) {
|
||||||
this.rankList.put(i, configList.get(i));
|
this.rankList.put(i, configList.get(i));
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final List<Integer> derp = (List<Integer>) config.getList("ReqFame");
|
final List<Integer> derp = (List<Integer>) config.getList("ReqFame");
|
||||||
for (int i = 0; i < derp.size(); i++) {
|
for (int i = 0; i < derp.size(); i++) {
|
||||||
this.reqFame.put(i, derp.get(i));
|
this.reqFame.put(i, derp.get(i));
|
||||||
}
|
}
|
||||||
this.GetPrefixColor(config.getString("PrefixColor"));
|
this.GetPrefixColor(config.getString("PrefixColor"));
|
||||||
final ConfigurationSection cash = config.getConfigurationSection("Cash");
|
final ConfigurationSection cash = config.getConfigurationSection("Cash");
|
||||||
for (final String key : cash.getKeys(false)) {
|
for (final String key : cash.getKeys(false)) {
|
||||||
try {
|
try {
|
||||||
final Integer num = Integer.valueOf(key);
|
final Integer num = Integer.valueOf(key);
|
||||||
cashList.put(num, cash.getString(key));
|
cashList.put(num, cash.getString(key));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
pvpTitles.getLogger().warning(key + "不是一个数字 已忽略!");
|
pvpTitles.getLogger().warning(key + "不是一个数字 已忽略!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag = config.getString("Tag");
|
tag = config.getString("Tag");
|
||||||
if (configList.size() != derp.size()) {
|
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.");
|
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 LoadPlayerData(final String playername) {
|
public void LoadPlayerData(final String playername) {
|
||||||
final File file = new File((new StringBuilder())
|
final File file = new File((new StringBuilder())
|
||||||
.append(this.pvpTitles.getDataFolder())
|
.append(this.pvpTitles.getDataFolder())
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append("players")
|
.append("players")
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append(playername)
|
.append(playername)
|
||||||
.append(".yml")
|
.append(".yml")
|
||||||
.toString());
|
.toString());
|
||||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
this.Fame = config.getInt("Fame");
|
this.Fame = config.getInt("Fame");
|
||||||
this.Points = config.getInt("Points");
|
this.Points = config.getInt("Points");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, String> RankList() {
|
public Map<Integer, String> RankList() {
|
||||||
return this.rankList;
|
return this.rankList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Integer> reqFame() {
|
public Map<Integer, Integer> reqFame() {
|
||||||
return this.reqFame;
|
return this.reqFame;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveConfig() {
|
public void SaveConfig() {
|
||||||
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
this.pvpTitles.getDataFolder().mkdirs();
|
this.pvpTitles.getDataFolder().mkdirs();
|
||||||
final FileConfiguration config = new YamlConfiguration();
|
final FileConfiguration config = new YamlConfiguration();
|
||||||
final String[] ranks = { "None",
|
final String[] ranks = { "None",
|
||||||
"Hero",
|
"Hero",
|
||||||
"Fierce Hero",
|
"Fierce Hero",
|
||||||
"Mighty Hero",
|
"Mighty Hero",
|
||||||
"Deadly Hero",
|
"Deadly Hero",
|
||||||
"Terrifying Hero",
|
"Terrifying Hero",
|
||||||
"Conquering Hero",
|
"Conquering Hero",
|
||||||
"Subjugating Hero",
|
"Subjugating Hero",
|
||||||
"Vanquishing Hero",
|
"Vanquishing Hero",
|
||||||
"Renowned Hero",
|
"Renowned Hero",
|
||||||
"Illustrious Hero",
|
"Illustrious Hero",
|
||||||
"Eminent Hero",
|
"Eminent Hero",
|
||||||
"King's Hero",
|
"King's Hero",
|
||||||
"Emperor's Hero",
|
"Emperor's Hero",
|
||||||
"Balthazar's Hero",
|
"Balthazar's Hero",
|
||||||
"Legendary Hero" };
|
"Legendary Hero" };
|
||||||
final Integer[] reqfame = { 0, 25, 75, 180, 360, 600, 1000, 1680, 2800, 4665, 7750, 12960, 21600, 36000, 60000, 100000 };
|
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("Tag", "Fame");
|
||||||
config.set("PrefixColor", "green");
|
config.set("PrefixColor", "green");
|
||||||
config.set("defaultPoints", 50);
|
config.set("defaultPoints", 50);
|
||||||
config.set("RankNames", Arrays.asList(ranks));
|
config.set("RankNames", Arrays.asList(ranks));
|
||||||
config.set("ReqFame", Arrays.asList(reqfame));
|
config.set("ReqFame", Arrays.asList(reqfame));
|
||||||
config.set("Cash.10", "give {player} 1 1");
|
config.set("Cash.10", "give {player} 1 1");
|
||||||
config.set("Cash.20", "give {player} 1 2");
|
config.set("Cash.20", "give {player} 1 2");
|
||||||
config.set("Cash.30", "give {player} 1 3");
|
config.set("Cash.30", "give {player} 1 3");
|
||||||
try {
|
try {
|
||||||
config.save(file);
|
config.save(file);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SavePlayerData(final String playername, final String path, final int fame) {
|
public void SavePlayerData(final String playername, final String path, final int fame) {
|
||||||
final File file = new File((new StringBuilder())
|
final File file = new File((new StringBuilder())
|
||||||
.append(this.pvpTitles.getDataFolder())
|
.append(this.pvpTitles.getDataFolder())
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append("players")
|
.append("players")
|
||||||
.append(File.separator)
|
.append(File.separator)
|
||||||
.append(playername)
|
.append(playername)
|
||||||
.append(".yml")
|
.append(".yml")
|
||||||
.toString());
|
.toString());
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
this.pvpTitles.getDataFolder().mkdir();
|
this.pvpTitles.getDataFolder().mkdir();
|
||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
config.set(path, fame);
|
config.set(path, fame);
|
||||||
try {
|
try {
|
||||||
config.save(file);
|
config.save(file);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SavePlayerFame(final String playername, final int fame) {
|
public void SavePlayerFame(final String playername, final int fame) {
|
||||||
SavePlayerData(playername, "Fame", fame);
|
SavePlayerData(playername, "Fame", fame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SavePlayerPoint(final String playername, final int fame) {
|
public void SavePlayerPoint(final String playername, final int fame) {
|
||||||
SavePlayerData(playername, "Points", fame);
|
SavePlayerData(playername, "Points", fame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoints(final int points) {
|
public void setPoints(final int points) {
|
||||||
Points = points;
|
Points = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetPrefixColor(final String color) {
|
private void GetPrefixColor(final String color) {
|
||||||
this.PrefixColor = ChatColor.valueOf(color.toUpperCase());
|
this.PrefixColor = ChatColor.valueOf(color.toUpperCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user