Titles update
This commit is contained in:
parent
0f742ea8b4
commit
53dbcb6800
33 changed files with 330 additions and 22 deletions
|
|
@ -3,8 +3,12 @@ package org.gsdistance.grimmsServer.Stats;
|
|||
import com.google.gson.Gson;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.LeaderboardEntry;
|
||||
import org.gsdistance.grimmsServer.Data.PlayerTitleManager;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerStatLeaderBoard {
|
||||
|
|
@ -42,16 +46,25 @@ public class PlayerStatLeaderBoard {
|
|||
public boolean checkPlayer(Player player) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
boolean pass = false;
|
||||
List<String> overtakes = new ArrayList<>();
|
||||
for (String stat : leaderboard.keySet()) {
|
||||
Number playerStatValue = (Number) playerStats.getStat(stat);
|
||||
Number leaderboardStatValue = leaderboard.get(stat).getStatValue();
|
||||
|
||||
if (playerStatValue != null && playerStatValue.doubleValue() > leaderboardStatValue.doubleValue()) {
|
||||
if(!player.getName().equalsIgnoreCase(leaderboard.get(stat).getPlayerName())){
|
||||
overtakes.add(stat);
|
||||
}
|
||||
leaderboard.put(stat, new LeaderboardEntry(player.getName(), playerStatValue.intValue()));
|
||||
savePlayerStatLeaderBoard();
|
||||
pass = true;
|
||||
}
|
||||
}
|
||||
if(pass){
|
||||
for (String stat : overtakes){
|
||||
GrimmsServer.instance.getServer().broadcastMessage("The leader of stat " + stat + " is now " + player.getDisplayName());
|
||||
}
|
||||
PlayerTitleManager.gotOnLeaderboard(player);
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.gsdistance.grimmsServer.Stats;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
|
|
@ -7,6 +8,7 @@ import org.bukkit.persistence.PersistentDataType;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
|
@ -24,6 +26,7 @@ public class PlayerStats {
|
|||
Stats.put("level", PersistentDataType.INTEGER);
|
||||
Stats.put("xp", PersistentDataType.DOUBLE);
|
||||
Stats.put("xp_required", PersistentDataType.DOUBLE);
|
||||
Stats.put("titles", PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
public static final Dictionary<String, String> StatNames = new Hashtable<>();
|
||||
|
|
@ -38,6 +41,7 @@ public class PlayerStats {
|
|||
StatNames.put("level", "Level");
|
||||
StatNames.put("xp", "Experience");
|
||||
StatNames.put("xp_required", "Experience Required");
|
||||
StatNames.put("titles", "Player Titles");
|
||||
}
|
||||
|
||||
public static final List<String> StatOrder = List.of(
|
||||
|
|
@ -58,6 +62,9 @@ public class PlayerStats {
|
|||
public PlayerStats(JavaPlugin plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.dataContainer = player.getPersistentDataContainer();
|
||||
if(!hasExactStat("titles")){
|
||||
setStat("titles", new Gson().toJson(new ArrayList<String>().toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerStats getPlayerStats(Player player) {
|
||||
|
|
@ -73,6 +80,14 @@ public class PlayerStats {
|
|||
return dataContainer.getOrDefault(new NamespacedKey(plugin, stat), type, 0);
|
||||
}
|
||||
|
||||
public boolean hasStat(String stat){
|
||||
return dataContainer.has(new NamespacedKey(plugin, stat));
|
||||
}
|
||||
|
||||
public boolean hasExactStat(String stat){
|
||||
return dataContainer.has(new NamespacedKey(plugin,stat),Stats.get(stat));
|
||||
}
|
||||
|
||||
public void setStat(String stat, Object value) {
|
||||
PersistentDataType type = Stats.get(stat);
|
||||
if (type == null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package org.gsdistance.grimmsServer.Stats;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Data.PlayerTitleManager;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerTitles {
|
||||
private final String[] playerTitles;
|
||||
public static final Map<String, String> titles = Map.ofEntries(
|
||||
Map.entry("Dictator","The title of a dictator, not to be messed with."),
|
||||
Map.entry("Executioner","The title and power of execution."),
|
||||
Map.entry("Murderer","Someone whose crimes follow him till death."),
|
||||
Map.entry("Victim","Got murdered, unfortunate."),
|
||||
Map.entry("DragonSlayer","The fabled warrior to defeat the fabled dragon or something like that."),
|
||||
Map.entry("Newbie","Wowie! Joining the game gives a title!"),
|
||||
Map.entry("Millionaire","Wow, that's quite a lot ya' know!"),
|
||||
Map.entry("Billionaire","Capitalism at it's finest."),
|
||||
Map.entry("Trillionaire","Literally insane, no comment."),
|
||||
Map.entry("Titlemaxxer", "Get more than 5 titles"),
|
||||
Map.entry("Leader","You got on the leaderboard."),
|
||||
Map.entry("Null","Not a title bro.")
|
||||
);
|
||||
private final Player player;
|
||||
public PlayerTitles(Player player) {
|
||||
this.player = player;
|
||||
this.playerTitles = new Gson().fromJson((String) PlayerStats.getPlayerStats(player).getStat("titles"),String[].class);
|
||||
}
|
||||
public static PlayerTitles getPlayerTitles(Player player) {
|
||||
return new PlayerTitles(player);
|
||||
}
|
||||
public String[] getTitles() {
|
||||
return playerTitles;
|
||||
}
|
||||
public void addTitle(String title) {
|
||||
if(!hasTitle(title)) {
|
||||
String[] newTitles = new String[playerTitles.length + 1];
|
||||
System.arraycopy(playerTitles, 0, newTitles, 0, playerTitles.length);
|
||||
newTitles[playerTitles.length] = title;
|
||||
PlayerStats.getPlayerStats(player).setStat("titles", new Gson().toJson(newTitles));
|
||||
GrimmsServer.instance.getServer().broadcastMessage("Title " + title + " was bestowed upon " + player.getDisplayName() + ".");
|
||||
PlayerTitleManager.checkTitles(player);
|
||||
}
|
||||
}
|
||||
public boolean hasTitle(String title) {
|
||||
for (String playerTitle : playerTitles) {
|
||||
if (playerTitle.equals(title)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue