From 618953415416b1a64e149581df6bb0e682e9b37e Mon Sep 17 00:00:00 2001 From: Grzybol Date: Mon, 4 Mar 2024 01:58:10 +0100 Subject: [PATCH 1/2] - fixes - added /be event command fo player - added placeholders for event ranking --- .../mine/game/betterelo/BetterEloCommand.java | 34 ++++++++++++++++--- .../mine/game/betterelo/Placeholders.java | 23 +++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java index 80c77ef..43c8b5b 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -205,9 +205,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St case "event": if(sender.isOp()){ sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " Usage /be event "); - }else{ - sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!"); - return true; + } + if(sender instanceof Player){ + if(betterElo.isEventEnabled){ + double points = dataManager.getPoints(player.getUniqueId().toString(), "event"); + points = (double)Math.round(points*100)/100; + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Event active! Time left: "+formatTime(betterElo.getRemainingTimeForRewards("event"))); + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Your rank: "+dataManager.getPlayerRank(player.getUniqueId().toString(), "event")); + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Your points: "+points); + } + else { + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + "Event is not active!"); + } } default: @@ -454,7 +463,24 @@ private String formatTime(long millis) { long minutes = seconds / 60; long hours = minutes / 60; long days = hours / 24; - return String.format("%d days, %d hours, %d minutes, %d seconds", days, hours % 24, minutes % 60, seconds % 60); + + StringBuilder formattedTime = new StringBuilder(); + + if (days > 0) { + formattedTime.append(days).append("d "); + } + if (hours % 24 > 0) { + formattedTime.append(hours % 24).append("h "); + } + if (minutes % 60 > 0) { + formattedTime.append(minutes % 60).append("m "); + } + if (seconds % 60 > 0 || formattedTime.length() == 0) { + formattedTime.append(seconds % 60).append("s"); + } + + return formattedTime.toString().trim(); // Usunięcie ewentualnych spacji na końcu } + } diff --git a/src/main/java/betterbox/mine/game/betterelo/Placeholders.java b/src/main/java/betterbox/mine/game/betterelo/Placeholders.java index 7cae78d..3fe42bc 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Placeholders.java +++ b/src/main/java/betterbox/mine/game/betterelo/Placeholders.java @@ -97,6 +97,12 @@ public String onPlaceholderRequest(Player player, String identifier) { return formatTime(betterElo.getRemainingTimeForRewards("weekly")); case "monthly_tl": return formatTime(betterElo.getRemainingTimeForRewards("monthly")); + case "event_tl": + if(betterElo.isEventEnabled) { + return formatTime(betterElo.getRemainingTimeForRewards("event")); + }else{ + return "Event is not active!"; + } case "player_daily": points = dataManager.getPoints(player.getUniqueId().toString(), "daily"); points = (double)Math.round(points*100)/100; @@ -109,12 +115,26 @@ public String onPlaceholderRequest(Player player, String identifier) { points = dataManager.getPoints(player.getUniqueId().toString(), "monthly"); points = (double)Math.round(points*100)/100; return String.valueOf(points); + case "player_event": + if(betterElo.isEventEnabled) { + points = dataManager.getPoints(player.getUniqueId().toString(), "event"); + points = (double)Math.round(points*100)/100; + return String.valueOf(points); + }else{ + return "Event is not active!"; + } case "rank_daily": return String.valueOf(dataManager.getPlayerRank(player.getUniqueId().toString(), "daily")); case "rank_weekly": return String.valueOf(dataManager.getPlayerRank(player.getUniqueId().toString(), "weekly")); case "rank_monthly": return String.valueOf(dataManager.getPlayerRank(player.getUniqueId().toString(), "monthly")); + case "rank_event": + if(betterElo.isEventEnabled) { + return String.valueOf(dataManager.getPlayerRank(player.getUniqueId().toString(), "event")); + }else{ + return "Event is not active!"; + } default: String result; if ((result = processRankingPlaceholder(identifier, "", dataManager.playerPoints)) != null) { @@ -126,6 +146,9 @@ public String onPlaceholderRequest(Player player, String identifier) { } else if ((result = processRankingPlaceholder(identifier, "monthly_", dataManager.monthlyPayerPoints)) != null) { return result; } + else if ((result = processRankingPlaceholder(identifier, "event_", dataManager.monthlyPayerPoints)) != null&&betterElo.isEventEnabled) { + return result; + } } } else { OfflinePlayer offlinePlayer = dataManager.getOfflinePlayer(identifier); From 751b7e44518970dd40a3b26ee9b2500cd00843ba Mon Sep 17 00:00:00 2001 From: Grzybol Date: Mon, 4 Mar 2024 02:00:17 +0100 Subject: [PATCH 2/2] -fix --- pom.xml | 2 +- .../java/betterbox/mine/game/betterelo/BetterEloCommand.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 365d942..0fbfa41 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 3.2.2-SNAPSHOT + 3.2.5-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java index 43c8b5b..ec51f41 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -208,6 +208,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if(sender instanceof Player){ if(betterElo.isEventEnabled){ + player = (Player) sender; double points = dataManager.getPoints(player.getUniqueId().toString(), "event"); points = (double)Math.round(points*100)/100; sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Event active! Time left: "+formatTime(betterElo.getRemainingTimeForRewards("event")));