Buy enchantment + Misc Update

This commit is contained in:
tyuXX 2025-04-03 18:37:43 +03:00
parent 53dbcb6800
commit a24db4dbcd
41 changed files with 488 additions and 122 deletions

View file

@ -8,6 +8,7 @@ import org.gsdistance.grimmsServer.GrimmsServer;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -19,24 +20,26 @@ public class PlayerStatLeaderBoard {
"tPoint", Double.class,
"block_break_count", Long.class,
"money", Double.class,
"level", Integer.class
"level", Integer.class,
"sent_messages", Long.class
);
public Map<String, LeaderboardEntry> leaderboard;
public PlayerStatLeaderBoard() {
this.leaderboard = Map.of(
"total_kill_count", new LeaderboardEntry("None", 0),
"death_count", new LeaderboardEntry("None", 0),
"join_count", new LeaderboardEntry("None", 0),
"tPoint", new LeaderboardEntry("None", 0),
"block_break_count", new LeaderboardEntry("None", 0),
"money", new LeaderboardEntry("None", 0),
"level", new LeaderboardEntry("None", 0)
);
leaderboard = new HashMap<>();
for (String stat : Stats.keySet()) {
leaderboard.put(stat, new LeaderboardEntry("None", 0));
}
}
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard() {
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
PlayerStatLeaderBoard playerStatLeaderBoard = new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
for (String stat : Stats.keySet()) {
if (!playerStatLeaderBoard.leaderboard.containsKey(stat)) {
playerStatLeaderBoard.leaderboard.put(stat, new LeaderboardEntry("None", 0));
}
}
return playerStatLeaderBoard;
}
public void savePlayerStatLeaderBoard() {
@ -51,7 +54,7 @@ public class PlayerStatLeaderBoard {
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())){
if (!player.getName().equalsIgnoreCase(leaderboard.get(stat).getPlayerName())) {
overtakes.add(stat);
}
leaderboard.put(stat, new LeaderboardEntry(player.getName(), playerStatValue.intValue()));
@ -59,9 +62,9 @@ public class PlayerStatLeaderBoard {
pass = true;
}
}
if(pass){
for (String stat : overtakes){
GrimmsServer.instance.getServer().broadcastMessage("The leader of stat " + stat + " is now " + player.getDisplayName());
if (pass) {
for (String stat : overtakes) {
GrimmsServer.instance.getServer().broadcastMessage("The leader of stat " + PlayerStats.StatNames.get(stat) + " is now " + player.getDisplayName());
}
PlayerTitleManager.gotOnLeaderboard(player);
}

View file

@ -27,6 +27,7 @@ public class PlayerStats {
Stats.put("xp", PersistentDataType.DOUBLE);
Stats.put("xp_required", PersistentDataType.DOUBLE);
Stats.put("titles", PersistentDataType.STRING);
Stats.put("sent_messages", PersistentDataType.LONG);
}
public static final Dictionary<String, String> StatNames = new Hashtable<>();
@ -42,6 +43,7 @@ public class PlayerStats {
StatNames.put("xp", "Experience");
StatNames.put("xp_required", "Experience Required");
StatNames.put("titles", "Player Titles");
StatNames.put("sent_messages", "Messages Sent");
}
public static final List<String> StatOrder = List.of(
@ -51,6 +53,7 @@ public class PlayerStats {
"join_count",
"tPoint",
"block_break_count",
"sent_messages",
"level",
"xp",
"xp_required"
@ -62,7 +65,7 @@ public class PlayerStats {
public PlayerStats(JavaPlugin plugin, Player player) {
this.plugin = plugin;
this.dataContainer = player.getPersistentDataContainer();
if(!hasExactStat("titles")){
if (!hasExactStat("titles")) {
setStat("titles", new Gson().toJson(new ArrayList<String>().toArray()));
}
}
@ -80,12 +83,12 @@ public class PlayerStats {
return dataContainer.getOrDefault(new NamespacedKey(plugin, stat), type, 0);
}
public boolean hasStat(String stat){
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 boolean hasExactStat(String stat) {
return dataContainer.has(new NamespacedKey(plugin, stat), Stats.get(stat));
}
public void setStat(String stat, Object value) {

View file

@ -10,32 +10,43 @@ 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("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("Richie", "Money talks, well at least that's what I've been told!"),
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("Miner", "Minin' to the earths core."),
Map.entry("Anti-block", "DEMOLISH 10000 blocks"),
Map.entry("UltimateMiner", "Mine 100000 blocks"),
Map.entry("Titlemaxxer", "Get more than 5 titles"),
Map.entry("Leader","You got on the leaderboard."),
Map.entry("Null","Not a title bro.")
Map.entry("KillingMachine", "Kill 100 things(?)."),
Map.entry("ProGamer", "Kill 1000 things(?)."),
Map.entry("Hitman", "Professional killerguy."),
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);
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)) {
if (!hasTitle(title)) {
String[] newTitles = new String[playerTitles.length + 1];
System.arraycopy(playerTitles, 0, newTitles, 0, playerTitles.length);
newTitles[playerTitles.length] = title;
@ -44,6 +55,7 @@ public class PlayerTitles {
PlayerTitleManager.checkTitles(player);
}
}
public boolean hasTitle(String title) {
for (String playerTitle : playerTitles) {
if (playerTitle.equals(title)) {