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不存在当前的物品!");
|
sender.sendMessage("§c不存在当前的物品!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
databaseHandler.setPoints(point - num);
|
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), databaseHandler.getCashList().get(num).replace("{player}", player.getName()));
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), databaseHandler.getCashList().get(num).replace("{player}", player.getName()));
|
||||||
databaseHandler.SaveConfig();
|
databaseHandler.SavePlayerPoint(sender.getName(), point - num);
|
||||||
sender.sendMessage("§a兑换成功!");
|
sender.sendMessage("§a兑换成功!");
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + "不正确的参数!");
|
player.sendMessage(ChatColor.RED + "不正确的参数!");
|
||||||
|
@ -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(25) + 25);
|
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");
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,14 @@ public class HandlePlayerPrefix implements Listener {
|
|||||||
fame++;
|
fame++;
|
||||||
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得一点 " + tag + ".");
|
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得一点 " + tag + ".");
|
||||||
this.databaseHandler.LoadPlayerData(player.getName());
|
this.databaseHandler.LoadPlayerData(player.getName());
|
||||||
if (killedpoint < 1) {
|
if (killedpoint == 1) {
|
||||||
player.sendMessage(ChatColor.RED + killed + " 已经是穷光蛋了 无法获得任何点数.");
|
player.sendMessage(ChatColor.RED + killed + " 已经是穷光蛋了 无法获得任何点数.");
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得了点数1点(可兑换物品).");
|
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得了点数1点(可兑换物品).");
|
||||||
this.databaseHandler.SavePlayerPoint(player.getName(), databaseHandler.getPoints() + 1);
|
this.databaseHandler.SavePlayerPoint(player.getName(), databaseHandler.getPoints() + 1);
|
||||||
|
this.databaseHandler.SavePlayerPoint(killed, killedpoint - 1);
|
||||||
}
|
}
|
||||||
this.databaseHandler.SavePlayerFame(player.getName(), fame);
|
this.databaseHandler.SavePlayerFame(player.getName(), fame);
|
||||||
|
|
||||||
final String newRank = this.ranks.GetRank(fame);
|
final String newRank = this.ranks.GetRank(fame);
|
||||||
|
|
||||||
if (!currentRank.equalsIgnoreCase(newRank)) {
|
if (!currentRank.equalsIgnoreCase(newRank)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user