1
0
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:
502647092 2016-01-08 21:02:16 +08:00
parent 1973fd217e
commit 2381eb7268
4 changed files with 264 additions and 254 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.mikeundead</groupId>
<artifactId>PvPTitles</artifactId>
<version>1.3</version>
<version>1.3.1</version>
<build>
<finalName>${project.name}</finalName>
<resources>

View File

@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
@ -13,201 +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 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);
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();
}
}
}
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");
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("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());
}
}

View File

@ -13,88 +13,94 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class HandlePlayerPrefix implements Listener {
private final DatabaseHandler databaseHandler;
private final Ranks ranks;
@SuppressWarnings("unused")
private final PvPTitles pvpTitles;
private final DatabaseHandler databaseHandler;
private final Ranks ranks;
@SuppressWarnings("unused")
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) {
this.databaseHandler = databaseHandler;
this.ranks = ranks;
this.pvpTitles = pvpTitles;
}
public HandlePlayerPrefix(final DatabaseHandler databaseHandler, final Ranks ranks, final PvPTitles pvpTitles) {
this.databaseHandler = databaseHandler;
this.ranks = ranks;
this.pvpTitles = pvpTitles;
}
@EventHandler
public void onKill(final PlayerDeathEvent death) {
int kills = 0;
if (death.getEntity().getKiller() != null) {
final String killed = death.getEntity().getName();
final Player player = death.getEntity().getKiller();
@EventHandler
public void onKill(final PlayerDeathEvent death) {
int kills = 0;
if (death.getEntity().getKiller() != null) {
final String killed = death.getEntity().getName();
final Player player = death.getEntity().getKiller();
if (this.map.containsKey(player.getName())) {
kills = this.map.get(player.getName());
}
if (this.map.containsKey(killed)) {
this.map.put(killed, 0);
}
this.databaseHandler.LoadPlayerData(player.getName());
final int fame = this.databaseHandler.getFame();
if (!player.getName().equalsIgnoreCase(killed)) {
this.calculateFame(killed, player, fame, kills);
}
kills++;
this.map.put(player.getName(), kills);
}
}
if (this.map.containsKey(player.getName())) {
kills = this.map.get(player.getName());
}
if (this.map.containsKey(killed)) {
this.map.put(killed, 0);
}
this.databaseHandler.LoadPlayerData(player.getName());
final int killedpoint = databaseHandler.getPoints();
this.databaseHandler.LoadPlayerData(player.getName());
final int fame = this.databaseHandler.getFame();
if (!player.getName().equalsIgnoreCase(killed)) {
this.calculateFame(killed, player, fame, kills, killedpoint);
}
kills++;
this.map.put(player.getName(), kills);
}
}
@EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent event) {
String rank = null;
this.databaseHandler.LoadPlayerData(event.getPlayer().getName());
this.databaseHandler.LoadConfig();
rank = this.ranks.GetRank(this.databaseHandler.getFame());
if (rank != null && rank != "") {
final String a = String.format(ChatColor.WHITE + "[" + this.databaseHandler.PrefixColor + rank + ChatColor.WHITE + "] ");
final String format = event.getFormat();
event.setFormat(a + format);
}
}
@EventHandler
public void onPlayerChat(final AsyncPlayerChatEvent event) {
String rank = null;
this.databaseHandler.LoadPlayerData(event.getPlayer().getName());
this.databaseHandler.LoadConfig();
rank = this.ranks.GetRank(this.databaseHandler.getFame());
if (rank != null && rank != "") {
final String a = String.format(ChatColor.WHITE + "[" + this.databaseHandler.PrefixColor + rank + ChatColor.WHITE + "] ");
final String format = event.getFormat();
event.setFormat(a + format);
}
}
@EventHandler
public void onPlayerLogin(final PlayerLoginEvent event) {
final Player player = event.getPlayer();
@EventHandler
public void onPlayerLogin(final PlayerLoginEvent event) {
final Player player = event.getPlayer();
try {
this.databaseHandler.FirstRun(player.getName());
} catch (final Exception e) {
e.printStackTrace();
}
}
try {
this.databaseHandler.FirstRun(player.getName());
} catch (final Exception e) {
e.printStackTrace();
}
}
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) {
final Player player = event.getPlayer();
this.map.put(player.getName(), 0);
}
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) {
final Player player = event.getPlayer();
this.map.put(player.getName(), 0);
}
private void calculateFame(final String killed, final Player player, int fame, final int kills) {
final int a = this.databaseHandler.getFame();
final String tag = this.databaseHandler.getTag();
if (kills == 0) {
fame++;
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得一点 " + tag + ".");
}
this.databaseHandler.LoadPlayerData(player.getName());
this.databaseHandler.SavePlayerPoint(player.getName(), databaseHandler.getPoints() + 1);
this.databaseHandler.SavePlayerFame(player.getName(), fame);
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 tag = this.databaseHandler.getTag();
if (kills == 0) {
fame++;
player.sendMessage(ChatColor.GREEN + "你击杀了 " + killed + " 获得一点 " + tag + ".");
}
this.databaseHandler.LoadPlayerData(player.getName());
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.SavePlayerFame(player.getName(), fame);
final String currentRank = this.ranks.GetRank(a);
final String newRank = this.ranks.GetRank(fame);
final String newRank = this.ranks.GetRank(fame);
if (!currentRank.equalsIgnoreCase(newRank)) {
player.sendMessage(ChatColor.GREEN + "恭喜! 您已晋升为 " + newRank);
}
}
if (!currentRank.equalsIgnoreCase(newRank)) {
player.sendMessage(ChatColor.GREEN + "恭喜! 您已晋升为 " + newRank);
}
}
}

View File

@ -1,5 +1,6 @@
Tag: Fame
PrefixColor: green
defaultPoints: 50
RankNames:
- None
- Hero
@ -35,7 +36,6 @@ ReqFame:
- 60000
- 100000
Cash:
5: give {player} 1
10: give {player} 1
30: give {player} 1
80: give {player} 1
10: give {player} 2 1
20: give {player} 2 1
30: give {player} 2 1