Hotfix
This commit is contained in:
parent
4db1164963
commit
edd74c799e
18 changed files with 229 additions and 58 deletions
|
|
@ -1,10 +1,14 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GLogCommand;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Data;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LogLeaderboard {
|
||||
public LogLeaderboard() {
|
||||
}
|
||||
|
|
@ -12,13 +16,59 @@ public class LogLeaderboard {
|
|||
public static boolean subCommand(Player player) {
|
||||
PlayerStatLeaderBoard leaderBoard = PlayerStatLeaderBoard.getPlayerStatLeaderBoard();
|
||||
leaderBoard.checkPlayer(player);
|
||||
player.sendMessage("__Leaderboard:");
|
||||
|
||||
player.sendMessage(ChatColor.GOLD + "=" + ChatColor.YELLOW + "=".repeat(40) + ChatColor.GOLD + "=");
|
||||
player.sendMessage(ChatColor.GOLD + "=" + ChatColor.YELLOW + "=".repeat(15) + ChatColor.BOLD + " LEADERBOARD " + ChatColor.YELLOW + "=".repeat(16) + ChatColor.GOLD + "=");
|
||||
player.sendMessage(ChatColor.GOLD + "=" + ChatColor.YELLOW + "=".repeat(40) + ChatColor.GOLD + "=");
|
||||
player.sendMessage("");
|
||||
|
||||
for (String stat : leaderBoard.leaderboard.keySet()) {
|
||||
String var10001 = PlayerStats.StatNames.get(stat);
|
||||
player.sendMessage("|Leader of stat " + var10001 + " is " + ((Data) leaderBoard.leaderboard.get(stat)).key() + " with " + ((Data) leaderBoard.leaderboard.get(stat)).value());
|
||||
String statName = PlayerStats.StatNames.get(stat);
|
||||
List<Data<String, Number>> statLeaders = leaderBoard.leaderboard.get(stat);
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "[" + statName + "]");
|
||||
|
||||
if (statLeaders.isEmpty()) {
|
||||
player.sendMessage(ChatColor.GRAY + " No data yet");
|
||||
} else {
|
||||
for (int i = 0; i < statLeaders.size(); i++) {
|
||||
Data<String, Number> entry = statLeaders.get(i);
|
||||
String rankColor;
|
||||
String rankSymbol;
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
rankColor = ChatColor.GOLD.toString();
|
||||
rankSymbol = "🥇";
|
||||
break;
|
||||
case 1:
|
||||
rankColor = ChatColor.GRAY.toString();
|
||||
rankSymbol = "🥈";
|
||||
break;
|
||||
case 2:
|
||||
rankColor = ChatColor.RED.toString();
|
||||
rankSymbol = "🥉";
|
||||
break;
|
||||
default:
|
||||
rankColor = ChatColor.WHITE.toString();
|
||||
rankSymbol = " ";
|
||||
}
|
||||
|
||||
String formattedValue;
|
||||
if (stat.equals("money") || stat.equals("tPoint") || stat.equals("block_break_count") || stat.equals("prestigePoints") || stat.equals("sent_messages")) {
|
||||
formattedValue = Shared.formatNumber(entry.value().doubleValue());
|
||||
} else {
|
||||
formattedValue = entry.value().toString();
|
||||
}
|
||||
|
||||
player.sendMessage(rankColor + rankSymbol + " " + ChatColor.YELLOW + entry.key() + ChatColor.GRAY + " - " + ChatColor.AQUA + formattedValue);
|
||||
}
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.GOLD + "=" + ChatColor.YELLOW + "=".repeat(40) + ChatColor.GOLD + "=");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GUtilCommand;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
|
||||
public class Broadcast {
|
||||
public Broadcast() {
|
||||
}
|
||||
|
||||
public static boolean subCommand(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("grimmsserver.util.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /gUtil broadcast <message>");
|
||||
return false;
|
||||
}
|
||||
|
||||
StringBuilder messageBuilder = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
messageBuilder.append(args[i]);
|
||||
if (i < args.length - 1) {
|
||||
messageBuilder.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
String message = messageBuilder.toString();
|
||||
String prefix = sender instanceof Player player ? ChatColor.GOLD + "[" + ChatColor.YELLOW + player.getName() + ChatColor.GOLD + "] " : ChatColor.GOLD + "[CONSOLE] ";
|
||||
|
||||
Shared.Broadcast(message, prefix);
|
||||
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Broadcast sent successfully!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,27 +13,39 @@ public class GUtilBaseCommand implements CommandExecutor {
|
|||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
} else if (sender instanceof Player player) {
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "version" -> {
|
||||
return Version.subCommand(player, args);
|
||||
if (sender instanceof Player player) {
|
||||
return Version.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "relic" -> {
|
||||
return Relic.subCommand(player, args);
|
||||
if (sender instanceof Player player) {
|
||||
return Relic.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "capability" -> {
|
||||
return Capability.subCommand(player, args);
|
||||
if (sender instanceof Player player) {
|
||||
return Capability.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "setting" -> {
|
||||
return Setting.subCommand(player, args);
|
||||
if (sender instanceof Player player) {
|
||||
return Setting.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "broadcast" -> {
|
||||
return Broadcast.subCommand(sender, args);
|
||||
}
|
||||
default -> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("This command can only be used by players.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
public class GUtilTabCompleter implements TabCompleter {
|
||||
public static final List<String> defSubCommands = List.of("version", "setting");
|
||||
public static final List<String> adminSubCommands = List.of("relic", "capability");
|
||||
public static final List<String> adminSubCommands = List.of("relic", "capability", "broadcast");
|
||||
|
||||
public GUtilTabCompleter() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,5 +20,8 @@ public class PlayerQuitEvent {
|
|||
// Clean up GUIs
|
||||
PrestigeShop.closeGUI(event.getPlayer());
|
||||
SettingGUI.closeGUI(event.getPlayer());
|
||||
|
||||
// Clean up login time tracking
|
||||
PlayerTickEvent.onPlayerQuit(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,34 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.gsdistance.grimmsServer.Commands.GAuthCommand.GAuthBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerCapability;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerTitleChecker;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerTickEvent {
|
||||
private static final List<Player> magnetPlayers = new ArrayList();
|
||||
private static final Map<Player, Integer> saturationPerkPlayers = new HashMap();
|
||||
private static final Map<UUID, Long> playerLoginTimes = new HashMap();
|
||||
private static final long LOGIN_KICK_TIMEOUT_MS = 60000L; // 60 seconds
|
||||
private static final long TITLE_CHECK_INTERVAL_MS = 50000L; // ~50 seconds (was 1000 ticks)
|
||||
private static final long PAYCHECK_INTERVAL_MS = 1200000L; // ~20 minutes (was 24000 ticks)
|
||||
|
||||
public PlayerTickEvent() {
|
||||
}
|
||||
|
|
@ -31,12 +45,48 @@ public class PlayerTickEvent {
|
|||
int currentDuration = saturationPerkPlayers.getOrDefault(player, 0);
|
||||
saturationPerkPlayers.put(player, currentDuration + 1);
|
||||
|
||||
// Apply saturation effect with lowest level (1) for 10 seconds
|
||||
// Apply saturation effect with the lowest level (1) for 10 seconds
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 200, 0, false, false));
|
||||
} else {
|
||||
saturationPerkPlayers.remove(player);
|
||||
}
|
||||
|
||||
// Track player login time for real-time kick timer
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (!playerLoginTimes.containsKey(playerId)) {
|
||||
playerLoginTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long loginTime = playerLoginTimes.get(playerId);
|
||||
|
||||
// Real-time login kick check
|
||||
if (!GAuthBaseCommand.isLoggedIn(player) && (currentTime - loginTime) >= LOGIN_KICK_TIMEOUT_MS) {
|
||||
player.kickPlayer("Not logged in for too long.");
|
||||
playerLoginTimes.remove(playerId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Title checks (was every 1000 ticks, now every ~50 seconds)
|
||||
if ((currentTime - loginTime) % TITLE_CHECK_INTERVAL_MS < 50L) {
|
||||
PlayerStatLeaderBoard.getPlayerStatLeaderBoard().checkPlayer(player);
|
||||
PlayerTitleChecker.checkForMoney(player);
|
||||
PlayerTitleChecker.checkTitles(player);
|
||||
PlayerTitleChecker.checkForBlockBreaks(player);
|
||||
PlayerTitleChecker.checkForTotalKills(player);
|
||||
}
|
||||
|
||||
// Paycheck (was every 24000 ticks, now every ~20 minutes)
|
||||
if ((currentTime - loginTime) % PAYCHECK_INTERVAL_MS < 50L) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
String jobTitleId = playerStats.getStat("jobTitle", String.class);
|
||||
if (jobTitleId != null && !jobTitleId.isEmpty()) {
|
||||
double multiplier = (double) 1.0F + Math.pow((double) playerStats.getStat("level", Integer.class), 2.0F) * Math.pow(playerStats.getStat("prestige", Integer.class) + 1,2) / (double) 100.0F;
|
||||
double payCheck = Math.ceil(JobTitlesBaseValues.jobTitleBaseValues.getOrDefault(jobTitleId, null).paycheckSize() * multiplier);
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) + payCheck);
|
||||
player.sendMessage(ChatColor.GREEN + "You have received your paycheck: " + ChatColor.GOLD + Shared.formatNumber(payCheck));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void processMagnets() {
|
||||
|
|
@ -53,4 +103,8 @@ public class PlayerTickEvent {
|
|||
magnetPlayers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPlayerQuit(Player player) {
|
||||
playerLoginTimes.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,8 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Commands.GAuthCommand.GAuthBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerTitleChecker;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
public class ServerTickEvent {
|
||||
public static long ticks = 0L;
|
||||
|
|
@ -25,34 +18,9 @@ public class ServerTickEvent {
|
|||
PlayerTickEvent.processMagnets();
|
||||
++ticks;
|
||||
if (ticks % 1000L == 0L) {
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStatLeaderBoard.getPlayerStatLeaderBoard().checkPlayer(player);
|
||||
PlayerTitleChecker.checkForMoney(player);
|
||||
PlayerTitleChecker.checkTitles(player);
|
||||
PlayerTitleChecker.checkForBlockBreaks(player);
|
||||
PlayerTitleChecker.checkForTotalKills(player);
|
||||
if (!GAuthBaseCommand.isLoggedIn(player)) {
|
||||
player.kickPlayer("Not logged in for too long.");
|
||||
}
|
||||
}
|
||||
|
||||
Market market = Market.getMarket();
|
||||
market.reCalcNegMarketSaturation();
|
||||
market.saveMarket();
|
||||
}
|
||||
|
||||
if (ticks % 24000L == 0L) {
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
String jobTitleId = playerStats.getStat("jobTitle", String.class);
|
||||
if (jobTitleId != null && !jobTitleId.isEmpty()) {
|
||||
double multiplier = (double) 1.0F + Math.pow((double) playerStats.getStat("level", Integer.class), 2.0F) * Math.pow(playerStats.getStat("prestige", Integer.class) + 1,2) / (double) 100.0F;
|
||||
double payCheck = Math.ceil(JobTitlesBaseValues.jobTitleBaseValues.getOrDefault(jobTitleId, null).paycheckSize() * multiplier);
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) + payCheck);
|
||||
player.sendMessage(ChatColor.GREEN + "You have received your paycheck: " + ChatColor.GOLD + Shared.formatNumber(payCheck));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,22 +13,33 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
public class PlayerStatLeaderBoard {
|
||||
public static final Map<String, Type> Stats = Map.of("total_kill_count", Integer.class, "death_count", Integer.class, "join_count", Integer.class, "tPoint", Double.class, "block_break_count", Long.class, "money", Double.class, "level", Integer.class, "sent_messages", Long.class);
|
||||
public final Map<String, Data<String, Number>> leaderboard = new HashMap();
|
||||
public static final Map<String, Type> Stats = Map.of("total_kill_count", Integer.class, "death_count", Integer.class, "join_count", Integer.class, "tPoint", Double.class, "block_break_count", Long.class, "money", Double.class, "level", Integer.class, "sent_messages", Long.class, "prestige", Integer.class, "prestigePoints", Long.class);
|
||||
public final Map<String, List<Data<String, Number>>> leaderboard = new HashMap<>();
|
||||
|
||||
public PlayerStatLeaderBoard() {
|
||||
for (String stat : Stats.keySet()) {
|
||||
this.leaderboard.put(stat, Data.of("None", 0));
|
||||
this.leaderboard.put(stat, new ArrayList<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard() {
|
||||
PlayerStatLeaderBoard playerStatLeaderBoard = (new Gson()).fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
|
||||
PlayerStatLeaderBoard playerStatLeaderBoard;
|
||||
try {
|
||||
playerStatLeaderBoard = (new Gson()).fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
|
||||
} catch (Exception e) {
|
||||
// If JSON parsing fails (e.g., corrupted data or wrong structure), create a new empty leaderboard
|
||||
playerStatLeaderBoard = new PlayerStatLeaderBoard();
|
||||
playerStatLeaderBoard.savePlayerStatLeaderBoard();
|
||||
}
|
||||
|
||||
if (playerStatLeaderBoard == null) {
|
||||
playerStatLeaderBoard = new PlayerStatLeaderBoard();
|
||||
}
|
||||
|
||||
for (String stat : Stats.keySet()) {
|
||||
if (!playerStatLeaderBoard.leaderboard.containsKey(stat)) {
|
||||
playerStatLeaderBoard.leaderboard.put(stat, Data.of("None", 0));
|
||||
playerStatLeaderBoard.leaderboard.put(stat, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,19 +57,50 @@ public class PlayerStatLeaderBoard {
|
|||
|
||||
for (String stat : this.leaderboard.keySet()) {
|
||||
Number playerStatValue = playerStats.getStat(stat, Number.class);
|
||||
Number leaderboardStatValue = (Number) ((Data) this.leaderboard.get(stat)).value();
|
||||
if (playerStatValue != null && playerStatValue.doubleValue() > leaderboardStatValue.doubleValue()) {
|
||||
if (!player.getName().equalsIgnoreCase((String) ((Data) this.leaderboard.get(stat)).key())) {
|
||||
overtakes.add(stat);
|
||||
List<Data<String, Number>> statLeaders = this.leaderboard.get(stat);
|
||||
|
||||
if (playerStatValue != null) {
|
||||
// Check if player was already #1 before update
|
||||
boolean wasAlreadyLeader = !statLeaders.isEmpty() && statLeaders.get(0).key().equalsIgnoreCase(player.getName());
|
||||
|
||||
// Check if player should be in top 3
|
||||
boolean shouldAdd = true;
|
||||
if (statLeaders.size() >= 3) {
|
||||
Number lowestValue = statLeaders.get(statLeaders.size() - 1).value();
|
||||
if (playerStatValue.doubleValue() <= lowestValue.doubleValue()) {
|
||||
shouldAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAdd) {
|
||||
// Remove existing entry for this player if present
|
||||
statLeaders.removeIf(entry -> entry.key().equalsIgnoreCase(player.getName()));
|
||||
|
||||
// Add new entry
|
||||
statLeaders.add(Data.of(player.getName(), playerStatValue));
|
||||
|
||||
// Sort by value descending
|
||||
statLeaders.sort((a, b) -> Double.compare(b.value().doubleValue(), a.value().doubleValue()));
|
||||
|
||||
// Keep only top 3
|
||||
while (statLeaders.size() > 3) {
|
||||
statLeaders.remove(statLeaders.size() - 1);
|
||||
}
|
||||
|
||||
// Check if player is now #1 (for backwards compatibility)
|
||||
if (!statLeaders.isEmpty() && statLeaders.get(0).key().equalsIgnoreCase(player.getName())) {
|
||||
pass = true;
|
||||
// Only broadcast if player wasn't already the leader
|
||||
if (!wasAlreadyLeader) {
|
||||
overtakes.add(stat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.leaderboard.put(stat, Data.of(player.getName(), playerStatValue.intValue()));
|
||||
this.savePlayerStatLeaderBoard();
|
||||
pass = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pass) {
|
||||
this.savePlayerStatLeaderBoard();
|
||||
for (String stat : overtakes) {
|
||||
Shared.Broadcast("The leader of stat " + PlayerStats.StatNames.get(stat) + " is now " + player.getDisplayName(), null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue