mirror of
https://e.coding.net/circlecloud/PvPTitles.git
synced 2024-12-21 15:28:46 +00:00
修复点数扣除问题...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
516bfaa7d9
commit
d08fe68b08
@ -41,9 +41,8 @@ public class CashCommand implements CommandExecutor {
|
||||
sender.sendMessage("§c不存在当前的物品!");
|
||||
return true;
|
||||
}
|
||||
databaseHandler.setPoints(point - num);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), databaseHandler.getCashList().get(num).replace("{player}", player.getName()));
|
||||
databaseHandler.SaveConfig();
|
||||
databaseHandler.SavePlayerPoint(sender.getName(), point - num);
|
||||
sender.sendMessage("§a兑换成功!");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "不正确的参数!");
|
||||
|
@ -14,204 +14,204 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class DatabaseHandler {
|
||||
private final PvPTitles pvpTitles;
|
||||
private int Fame;
|
||||
private int Points;
|
||||
private int defaultPoints;
|
||||
private final Map<Integer, String> rankList;
|
||||
private final Map<Integer, Integer> reqFame;
|
||||
private final Map<Integer, String> cashList;
|
||||
public ChatColor PrefixColor;
|
||||
private final PvPTitles pvpTitles;
|
||||
private int Fame;
|
||||
private int Points;
|
||||
private int defaultPoints;
|
||||
private final Map<Integer, String> rankList;
|
||||
private final Map<Integer, Integer> reqFame;
|
||||
private final Map<Integer, String> cashList;
|
||||
public ChatColor PrefixColor;
|
||||
|
||||
private String tag;
|
||||
private String ptag;
|
||||
private String tag;
|
||||
private String ptag;
|
||||
|
||||
public DatabaseHandler(final PvPTitles pvpTitles) {
|
||||
this.rankList = new HashMap<>();
|
||||
this.reqFame = new HashMap<>();
|
||||
this.cashList = new HashMap<>();
|
||||
this.pvpTitles = pvpTitles;
|
||||
this.SaveConfig();
|
||||
}
|
||||
public DatabaseHandler(final PvPTitles pvpTitles) {
|
||||
this.rankList = new HashMap<>();
|
||||
this.reqFame = new HashMap<>();
|
||||
this.cashList = new HashMap<>();
|
||||
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());
|
||||
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();
|
||||
if (!file.exists()) {
|
||||
this.pvpTitles.getDataFolder().mkdirs();
|
||||
|
||||
final FileConfiguration config = new YamlConfiguration();
|
||||
config.set("Fame", 0);
|
||||
config.set("Points", new Random().nextInt(25) + 25);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
final FileConfiguration config = new YamlConfiguration();
|
||||
config.set("Fame", 0);
|
||||
config.set("Points", new Random().nextInt(defaultPoints));
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return cashList
|
||||
*/
|
||||
public Map<Integer, String> getCashList() {
|
||||
return cashList;
|
||||
}
|
||||
/**
|
||||
* @return cashList
|
||||
*/
|
||||
public Map<Integer, String> getCashList() {
|
||||
return cashList;
|
||||
}
|
||||
|
||||
public int getFame() {
|
||||
return this.Fame;
|
||||
}
|
||||
public int getFame() {
|
||||
return this.Fame;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return Points;
|
||||
}
|
||||
public int getPoints() {
|
||||
return Points;
|
||||
}
|
||||
|
||||
public String getPtag() {
|
||||
return ptag;
|
||||
}
|
||||
public String getPtag() {
|
||||
return ptag;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
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");
|
||||
defaultPoints = config.getInt("defaultPoints");
|
||||
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"));
|
||||
final ConfigurationSection cash = config.getConfigurationSection("Cash");
|
||||
for (final String key : cash.getKeys(false)) {
|
||||
try {
|
||||
final Integer num = Integer.valueOf(key);
|
||||
cashList.put(num, cash.getString(key));
|
||||
} catch (final Exception e) {
|
||||
pvpTitles.getLogger().warning(key + "不是一个数字 已忽略!");
|
||||
}
|
||||
}
|
||||
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 LoadConfig() {
|
||||
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
final List<String> configList = config.getStringList("RankNames");
|
||||
defaultPoints = config.getInt("defaultPoints");
|
||||
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"));
|
||||
final ConfigurationSection cash = config.getConfigurationSection("Cash");
|
||||
for (final String key : cash.getKeys(false)) {
|
||||
try {
|
||||
final Integer num = Integer.valueOf(key);
|
||||
cashList.put(num, cash.getString(key));
|
||||
} catch (final Exception e) {
|
||||
pvpTitles.getLogger().warning(key + "不是一个数字 已忽略!");
|
||||
}
|
||||
}
|
||||
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 LoadPlayerData(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");
|
||||
this.Points = config.getInt("Points");
|
||||
}
|
||||
public void LoadPlayerData(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");
|
||||
this.Points = config.getInt("Points");
|
||||
}
|
||||
|
||||
public Map<Integer, String> RankList() {
|
||||
return this.rankList;
|
||||
}
|
||||
public Map<Integer, String> RankList() {
|
||||
return this.rankList;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> reqFame() {
|
||||
return this.reqFame;
|
||||
}
|
||||
public Map<Integer, Integer> reqFame() {
|
||||
return this.reqFame;
|
||||
}
|
||||
|
||||
public void SaveConfig() {
|
||||
final File file = new File(this.pvpTitles.getDataFolder(), "config.yml");
|
||||
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("defaultPoints", 50);
|
||||
config.set("RankNames", Arrays.asList(ranks));
|
||||
config.set("ReqFame", Arrays.asList(reqfame));
|
||||
config.set("Cash.10", "give {player} 1 1");
|
||||
config.set("Cash.20", "give {player} 1 2");
|
||||
config.set("Cash.30", "give {player} 1 3");
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
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("defaultPoints", 50);
|
||||
config.set("RankNames", Arrays.asList(ranks));
|
||||
config.set("ReqFame", Arrays.asList(reqfame));
|
||||
config.set("Cash.10", "give {player} 1 1");
|
||||
config.set("Cash.20", "give {player} 1 2");
|
||||
config.set("Cash.30", "give {player} 1 3");
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SavePlayerData(final String playername, final String path, 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(path, fame);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void SavePlayerData(final String playername, final String path, 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(path, fame);
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void SavePlayerFame(final String playername, final int fame) {
|
||||
SavePlayerData(playername, "Fame", fame);
|
||||
}
|
||||
public void SavePlayerFame(final String playername, final int fame) {
|
||||
SavePlayerData(playername, "Fame", fame);
|
||||
}
|
||||
|
||||
public void SavePlayerPoint(final String playername, final int fame) {
|
||||
SavePlayerData(playername, "Points", fame);
|
||||
}
|
||||
public void SavePlayerPoint(final String playername, final int fame) {
|
||||
SavePlayerData(playername, "Points", fame);
|
||||
}
|
||||
|
||||
public void setPoints(final int points) {
|
||||
Points = points;
|
||||
}
|
||||
public void setPoints(final int points) {
|
||||
Points = points;
|
||||
}
|
||||
|
||||
private void GetPrefixColor(final String color) {
|
||||
this.PrefixColor = ChatColor.valueOf(color.toUpperCase());
|
||||
}
|
||||
private void GetPrefixColor(final String color) {
|
||||
this.PrefixColor = ChatColor.valueOf(color.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
@ -87,14 +87,14 @@ public class HandlePlayerPrefix implements Listener {
|
||||
fame++;
|
||||
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得一点 " + tag + ".");
|
||||
this.databaseHandler.LoadPlayerData(player.getName());
|
||||
if (killedpoint < 1) {
|
||||
if (killedpoint == 1) {
|
||||
player.sendMessage(ChatColor.RED + killed + " 已经是穷光蛋了 无法获得任何点数.");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得了点数1点(可兑换物品).");
|
||||
this.databaseHandler.SavePlayerPoint(player.getName(), databaseHandler.getPoints() + 1);
|
||||
this.databaseHandler.SavePlayerPoint(killed, killedpoint - 1);
|
||||
}
|
||||
this.databaseHandler.SavePlayerFame(player.getName(), fame);
|
||||
|
||||
final String newRank = this.ranks.GetRank(fame);
|
||||
|
||||
if (!currentRank.equalsIgnoreCase(newRank)) {
|
||||
|
Loading…
Reference in New Issue
Block a user