mirror of
https://e.coding.net/circlecloud/PvPTitles.git
synced 2024-12-21 15:28:46 +00:00
修复玩家点数小于1时可以刷分的BUG...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
e1d7d9ccae
commit
13c94b14dc
@ -13,92 +13,92 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class HandlePlayerPrefix implements Listener {
|
public class HandlePlayerPrefix implements Listener {
|
||||||
private final DatabaseHandler databaseHandler;
|
private final DatabaseHandler databaseHandler;
|
||||||
private final Ranks ranks;
|
private final Ranks ranks;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final PvPTitles pvpTitles;
|
private final PvPTitles pvpTitles;
|
||||||
|
|
||||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||||
|
|
||||||
public HandlePlayerPrefix(final DatabaseHandler databaseHandler, final Ranks ranks, final PvPTitles pvpTitles) {
|
public HandlePlayerPrefix(final DatabaseHandler databaseHandler, final Ranks ranks, final PvPTitles pvpTitles) {
|
||||||
this.databaseHandler = databaseHandler;
|
this.databaseHandler = databaseHandler;
|
||||||
this.ranks = ranks;
|
this.ranks = ranks;
|
||||||
this.pvpTitles = pvpTitles;
|
this.pvpTitles = pvpTitles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onKill(final PlayerDeathEvent death) {
|
public void onKill(final PlayerDeathEvent death) {
|
||||||
int kills = 0;
|
int kills = 0;
|
||||||
if (death.getEntity().getKiller() != null) {
|
if (death.getEntity().getKiller() != null) {
|
||||||
final String killed = death.getEntity().getName();
|
final String killed = death.getEntity().getName();
|
||||||
final Player player = death.getEntity().getKiller();
|
final Player player = death.getEntity().getKiller();
|
||||||
|
|
||||||
if (this.map.containsKey(player.getName())) {
|
if (this.map.containsKey(player.getName())) {
|
||||||
kills = this.map.get(player.getName());
|
kills = this.map.get(player.getName());
|
||||||
}
|
}
|
||||||
if (this.map.containsKey(killed)) {
|
if (this.map.containsKey(killed)) {
|
||||||
this.map.put(killed, 0);
|
this.map.put(killed, 0);
|
||||||
}
|
}
|
||||||
this.databaseHandler.LoadPlayerData(killed);
|
this.databaseHandler.LoadPlayerData(killed);
|
||||||
final int killedpoint = databaseHandler.getPoints();
|
final int killedpoint = databaseHandler.getPoints();
|
||||||
this.databaseHandler.LoadPlayerData(player.getName());
|
this.databaseHandler.LoadPlayerData(player.getName());
|
||||||
final int fame = this.databaseHandler.getFame();
|
final int fame = this.databaseHandler.getFame();
|
||||||
if (!player.getName().equalsIgnoreCase(killed)) {
|
if (!player.getName().equalsIgnoreCase(killed)) {
|
||||||
this.calculateFame(killed, player, fame, kills, killedpoint);
|
this.calculateFame(killed, player, fame, kills, killedpoint);
|
||||||
}
|
}
|
||||||
kills++;
|
kills++;
|
||||||
this.map.put(player.getName(), kills);
|
this.map.put(player.getName(), kills);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
||||||
String rank = null;
|
String rank = null;
|
||||||
this.databaseHandler.LoadPlayerData(event.getPlayer().getName());
|
this.databaseHandler.LoadPlayerData(event.getPlayer().getName());
|
||||||
this.databaseHandler.LoadConfig();
|
this.databaseHandler.LoadConfig();
|
||||||
rank = this.ranks.GetRank(this.databaseHandler.getFame());
|
rank = this.ranks.GetRank(this.databaseHandler.getFame());
|
||||||
if (rank != null && rank != "") {
|
if (rank != null && rank != "") {
|
||||||
final String a = String.format(ChatColor.WHITE + "[" + this.databaseHandler.PrefixColor + rank + ChatColor.WHITE + "] ");
|
final String a = String.format(ChatColor.WHITE + "[" + this.databaseHandler.PrefixColor + rank + ChatColor.WHITE + "] ");
|
||||||
final String format = event.getFormat();
|
final String format = event.getFormat();
|
||||||
event.setFormat(a + format);
|
event.setFormat(a + format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLogin(final PlayerLoginEvent event) {
|
public void onPlayerLogin(final PlayerLoginEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.databaseHandler.FirstRun(player.getName());
|
this.databaseHandler.FirstRun(player.getName());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
this.map.put(player.getName(), 0);
|
this.map.put(player.getName(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateFame(final String killed, final Player player, int fame, final int kills, final int killedpoint) {
|
private void calculateFame(final String killed, final Player player, int fame, final int kills, final int killedpoint) {
|
||||||
final String currentRank = this.ranks.GetRank(fame);
|
final String currentRank = this.ranks.GetRank(fame);
|
||||||
final String tag = this.databaseHandler.getTag();
|
final String tag = this.databaseHandler.getTag();
|
||||||
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 <= 0) {
|
||||||
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.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)) {
|
||||||
player.sendMessage(ChatColor.GREEN + "恭喜! 您已晋升为 " + newRank);
|
player.sendMessage(ChatColor.GREEN + "恭喜! 您已晋升为 " + newRank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user