From 6067b3b5bd41a75692dd3e6284da229252dd7f28 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sun, 25 Feb 2024 18:55:32 +0100 Subject: [PATCH 001/242] - points should be saved as double, but displayed only with 2 decimal places --- pom.xml | 2 +- .../mine/game/betterelo/BetterEloCommand.java | 7 +++++ .../betterbox/mine/game/betterelo/Event.java | 19 +++++++------ .../mine/game/betterelo/Placeholders.java | 27 ++++++++++++++----- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 39a762b..6ffb8dd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 3.1.53-SNAPSHOT + 3.1.54-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 a22dac4..0c6839c 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -53,6 +53,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St Player player = (Player) sender; int rank = dataManager.getPlayerRank(player.getUniqueId().toString()); double points = dataManager.getPoints(player.getUniqueId().toString(), "main"); + points = (double)Math.round(points*100)/100; sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Your rank: " + ChatColor.GREEN + rank); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + "Your points: " + ChatColor.GREEN + points); } else { @@ -91,6 +92,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St for (int i = 1; i <= 10; i++) { String playerName = dataManager.getPlayerAtPosition(i, dataManager.playerPoints); double points = dataManager.getPointsAtPosition(i, dataManager.playerPoints); + points = (double)Math.round(points*100)/100; if (playerName != null) { sender.sendMessage(ChatColor.AQUA.toString() + i + ". " + ChatColor.GREEN + playerName + ChatColor.AQUA + " - Points: " + ChatColor.GREEN + points); } @@ -101,6 +103,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St for (int i = 1; i <= 10; i++) { String playerName = dataManager.getPlayerAtPosition(i, dataManager.dailyPlayerPoints); double points = dataManager.getPointsAtPosition(i, dataManager.dailyPlayerPoints); + points = (double)Math.round(points*100)/100; if (playerName != null) { sender.sendMessage(ChatColor.AQUA.toString() + i + ". " + ChatColor.GREEN + playerName + ChatColor.AQUA + " - Points: " + ChatColor.GREEN + points); } @@ -111,6 +114,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St for (int i = 1; i <= 10; i++) { String playerName = dataManager.getPlayerAtPosition(i, dataManager.weeklyPlayerPoints); double points = dataManager.getPointsAtPosition(i, dataManager.weeklyPlayerPoints); + points = (double)Math.round(points*100)/100; if (playerName != null) { sender.sendMessage(ChatColor.AQUA.toString() + i + ". " + ChatColor.GREEN + playerName + ChatColor.AQUA + " - Points: " + ChatColor.GREEN + points); } @@ -121,6 +125,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St for (int i = 1; i <= 10; i++) { String playerName = dataManager.getPlayerAtPosition(i, dataManager.monthlyPayerPoints); double points = dataManager.getPointsAtPosition(i, dataManager.monthlyPayerPoints); + points = (double)Math.round(points*100)/100; if (playerName != null) { sender.sendMessage(ChatColor.AQUA.toString() + i + ". " + ChatColor.GREEN + playerName + ChatColor.AQUA + " - Points: " + ChatColor.GREEN + points); } @@ -215,6 +220,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } double points = dataManager.getPoints(playerUUID, "main"); + points = (double)Math.round(points*100)/100; sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Player " + ChatColor.GREEN + playerName + ChatColor.AQUA + " is ranked " + ChatColor.GREEN + rank + ChatColor.AQUA + " in main ranking."); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Player's points: " + ChatColor.GREEN + points+ ChatColor.AQUA + " in main ranking."); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Player " + ChatColor.GREEN + playerName + ChatColor.AQUA + " is ranked " + ChatColor.GREEN + dataManager.getPlayerRank(playerUUID,"daily") + ChatColor.AQUA + "."); @@ -233,6 +239,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St int position = Integer.parseInt(args[1]); String playerName = dataManager.getPlayerAtPosition(position, dataManager.playerPoints); double points = dataManager.getPointsAtPosition(position, dataManager.playerPoints); + points = (double)Math.round(points*100)/100; if (playerName != null) { sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Player in position " + ChatColor.GREEN + position + ": " + ChatColor.GREEN + playerName); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.AQUA + " Player's points: " + ChatColor.GREEN + points); diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index 3965754..79ad2c1 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -255,7 +255,7 @@ private void notifyPlayersAboutPoints(Player killer, Player victim, double point Duration stay = Duration.ofMillis(900); // czas wyświetlania Duration fadeOut = Duration.ofMillis(300); // czas znikania Title.Times times = Title.Times.times(fadeIn, stay, fadeOut); - Component killerTitleComponent = Component.text(ChatColor.GREEN +""+ChatColor.BOLD+ "+"+df.format(pointsEarned)+" Elo"); + Component killerTitleComponent = Component.text(ChatColor.GREEN +""+ChatColor.BOLD+ "+"+df.format((double)Math.round(pointsEarned*100)/100)+" Elo"); Component killerSubtitleComponent = Component.text(ChatColor.GOLD +"Victim: "+victim.getName()); // Notify the killer Title killerTitle = Title.title(killerTitleComponent,killerSubtitleComponent,times); @@ -263,7 +263,7 @@ private void notifyPlayersAboutPoints(Player killer, Player victim, double point victim.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.RED + "You have lost "+ChatColor.DARK_RED + "" + ChatColor.BOLD +df.format(pointsEarned)+" Elo"); } - private void notifyPlayerAboutPoints(Player player, double pointsEarned) { + private void notifyPlayerAboutPoints(Player player, double pointsEarned, Double blockReward) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event: notifyPlayersAboutPoints called with parameters: "+player+" "+pointsEarned); DecimalFormat df = new DecimalFormat("#.##"); @@ -271,8 +271,8 @@ private void notifyPlayerAboutPoints(Player player, double pointsEarned) { Duration stay = Duration.ofMillis(900); // czas wyświetlania Duration fadeOut = Duration.ofMillis(300); // czas znikania Title.Times times = Title.Times.times(fadeIn, stay, fadeOut); - Component killerTitleComponent = Component.text(ChatColor.GREEN +""+ChatColor.BOLD+ "+"+df.format(pointsEarned)+" Elo"); - Component killerSubtitleComponent = Component.text(ChatColor.GOLD +"Current Elo: "+dataManager.getPoints(player.getUniqueId().toString(),"main")); + Component killerTitleComponent = Component.text(ChatColor.GREEN +""+ChatColor.BOLD+ "+"+df.format((double)Math.round(pointsEarned*100)/100)+" Elo"); + Component killerSubtitleComponent = Component.text(ChatColor.GOLD +"Block multiplier: x"+blockReward); // Notify the killer Title killerTitle = Title.title(killerTitleComponent,killerSubtitleComponent,times); player.showTitle(killerTitle); @@ -288,7 +288,8 @@ private double calculatePointsEarned(double base, double killerelo, double victi pluginLogger.log(PluginLogger.LogLevel.DEBUG,"Event: calculatePointsEarned: eloDifference: "+eloDifference+" normalizedDifference: "+normalizedDifference+" points: "+points+" maxElo: "+maxElo+" minElo: "+minElo); pluginLogger.log(PluginLogger.LogLevel.DEBUG,"Event: calculatePointsEarned: PointsEarnedOut: "+(double)Math.round(points*100)); pluginLogger.log(PluginLogger.LogLevel.DEBUG,"Event: calculatePointsEarned: PointsEarnedOut/100: "+(double)Math.round(points*100)/100); - return (double)Math.round(points*100)/100; + return points; + //return (double)Math.round(points*100)/100; } private double calculatePointsEarnedFromBlock(double base, double playerElo,double blockReward, double maxElo, double minElo) { pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL4,"Event: calculatePointsEarnedFromBlock called with parameters : base "+base+" playerElo "+playerElo+" blockReward "+blockReward+" maxElo "+maxElo+" minElo "+minElo); @@ -300,7 +301,8 @@ private double calculatePointsEarnedFromBlock(double base, double playerElo,doub pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL4, "Event: calculatePointsEarnedFromBlock: eloDifference: "+eloDifference+", S: "+S+", points: "+points); pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL4,"Event: calculatePointsEarnedFromBlock: PointsEarnedOut: "+(double)Math.round(points*100)); pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL4,"Event: calculatePointsEarnedFromBlock: PointsEarnedOut/100: "+(double)Math.round(points*100)/100); - return (double)Math.round(points*100)/100; + return points; + //return (double)Math.round(points*100)/100; } else { return 0; @@ -314,7 +316,8 @@ private void updatePoints(String playerUUID, double points, String rankingType, currentPoints = isAdding ? currentPoints + points : currentPoints - points; pluginLogger.log(PluginLogger.LogLevel.DEBUG,String.format("Event: %sPoints: currentPoints: %sAfter: %s", (isAdding ? "add" : "subtract"), rankingType, currentPoints)); - dataManager.setPoints(playerUUID, Math.round(currentPoints * 100) / 100.0, rankingType); + dataManager.setPoints(playerUUID, currentPoints, rankingType); + //dataManager.setPoints(playerUUID, Math.round(currentPoints * 100) / 100.0, rankingType); pluginLogger.log(PluginLogger.LogLevel.DEBUG,String.format("Event: %sPoints: currentPoints: %s ranking saved", (isAdding ? "add" : "subtract"), rankingType)); } @@ -394,7 +397,7 @@ public void onBreak(BlockBreakEvent event) { pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL4,"Event: onBlockBreak: player: "+player.getName()+", blockType: "+blockType+", pointsEarned: "+pointsEarned+", ranking monthly"); if(pointsEarnedMain>0.001) { - notifyPlayerAboutPoints(player, pointsEarnedMain); + notifyPlayerAboutPoints(player, pointsEarnedMain, blockReward); } } else{ diff --git a/src/main/java/betterbox/mine/game/betterelo/Placeholders.java b/src/main/java/betterbox/mine/game/betterelo/Placeholders.java index c4b29ce..7cae78d 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Placeholders.java +++ b/src/main/java/betterbox/mine/game/betterelo/Placeholders.java @@ -70,6 +70,7 @@ private String processRankingPlaceholder(String identifier, String prefix, Map Date: Fri, 1 Mar 2024 13:36:36 +0100 Subject: [PATCH 002/242] - added notifications for banned player - added notification for every online player when any time ranking ends --- pom.xml | 2 +- .../mine/game/betterelo/BetterElo.java | 45 +++++++++++++++++++ .../mine/game/betterelo/BetterEloCommand.java | 4 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6ffb8dd..74dc94f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 3.1.54-SNAPSHOT + 3.1.55-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java index adacc6e..c244464 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java @@ -5,11 +5,15 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.title.Title; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import java.io.File; import java.io.IOException; +import java.text.DecimalFormat; +import java.time.Duration; import java.util.*; import java.util.concurrent.TimeUnit; public final class BetterElo extends JavaPlugin { @@ -237,6 +241,9 @@ public void run() { }.runTaskLater(this, delay); } private void rewardAndReschedule(String period, long periodMillis, boolean useNextMonthTime) { + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.rewardAndReschedule called"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.rewardAndReschedule calling notifyTopPlayers("+period+")"); + notifyTopPlayers(period); pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: rewardAndReschedule: Starting rewardTopPlayers"); rewardTopPlayers(period); pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo: rewardAndReschedule: rewardTopPlayers done"); @@ -354,5 +361,43 @@ private void saveOfflineReward(String playerName, List rewardItems) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "BetterElo: saveOfflineReward: Exception while saving rewards: " + e); } } + public void notifyTopPlayers(String period) { + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterElo.notifyTopPlayers called with period=" + period); + DecimalFormat df = new DecimalFormat("#.##"); + Duration fadeIn = Duration.ofMillis(500); // czas pojawiania się + Duration stay = Duration.ofMillis(5000); // czas wyświetlania + Duration fadeOut = Duration.ofMillis(500); // czas znikania + Title.Times times = Title.Times.times(fadeIn, stay, fadeOut); + Component rankingNotificationTileComponent = Component.text(ChatColor.GOLD + "" + ChatColor.BOLD + period.toUpperCase() + " ranking has ended!"); + Component rankingNotificationSubtileComponent; + // Notify all players + for (Player player : Bukkit.getOnlinePlayers()){ + pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL2, "BetterElo.notifyTopPlayers." + period+" notifying "+player.getName()); + double points = dataManager.getPoints(player.getUniqueId().toString(),period); + int rank = dataManager.getPlayerRank(player.getUniqueId().toString(),period); + rankingNotificationSubtileComponent = Component.text(ChatColor.AQUA + "Your position: " + ChatColor.RED+""+ChatColor.BOLD+rank+". "+ChatColor.AQUA +"Your points: "+ ChatColor.RED+""+ChatColor.BOLD+points); + Title killerTitle = Title.title(rankingNotificationTileComponent, rankingNotificationSubtileComponent, times); + player.showTitle(killerTitle); + } + } + public void notiyBannedPlayer(String bannedPlayer){ + Player player = Bukkit.getPlayer(bannedPlayer); + DecimalFormat df = new DecimalFormat("#.##"); + + Duration fadeIn = Duration.ofMillis(300); // czas pojawiania się + Duration stay = Duration.ofMillis(10000); // czas wyświetlania + Duration fadeOut = Duration.ofMillis(5000); // czas znikania + Title.Times times = Title.Times.times(fadeIn, stay, fadeOut); + Component BannedTitleComponent = Component.text(ChatColor.DARK_RED +"You have been flagged as "+ChatColor.BLACK+""+ChatColor.BOLD+" CHEATER"); + Component BannedSubtitleComponent = Component.text(ChatColor.GREEN +"Buy unban on website "+ChatColor.GOLD+ChatColor.BOLD+" BetterBox.top" ); + // Notify the killer + Title bannedTitle = Title.title(BannedTitleComponent,BannedSubtitleComponent,times); + if (player !=null) { + player.showTitle(bannedTitle); + }else{ + pluginLogger.log(PluginLogger.LogLevel.WARNING, "Banned player "+bannedPlayer+" is offline - cannot send notification"); + } + + } } diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java index 0c6839c..94e8949 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -253,6 +253,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if(args[0].equalsIgnoreCase("ban")){ handleBanCommand(sender,args[1]); + betterElo.notiyBannedPlayer(args[1]); } break; case 4: @@ -307,6 +308,7 @@ private boolean handleReloadCommand(CommandSender sender){ private boolean handleBanCommand(CommandSender sender, String banName) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand: handleBanCommand called with parameters "+banName); if (sender.hasPermission("betterelo.ban")) { + /* if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo] " + ChatColor.DARK_RED +"You don't have permission to use this command!"); @@ -314,6 +316,8 @@ private boolean handleBanCommand(CommandSender sender, String banName) { return false; } + */ + Player player = (Player) sender; pluginLogger.log(PluginLogger.LogLevel.INFO, "Banning "+banName+". Points in main ranking: "+dataManager.getPoints(getOfflinePlayerUUID(banName),"main")+", points to redeem "+(dataManager.getPoints(getOfflinePlayerUUID(banName),"main")-1000d)); pluginLogger.log(PluginLogger.LogLevel.INFO, "Banning "+banName+". Points in daily ranking: "+dataManager.getPoints(getOfflinePlayerUUID(banName),"daily")+", points to redeem "+(dataManager.getPoints(getOfflinePlayerUUID(banName),"daily")-1000d)); From 4f696e1ad6181a72647f940e57eb7b25604c4f7d Mon Sep 17 00:00:00 2001 From: Grzybol Date: Fri, 1 Mar 2024 13:46:59 +0100 Subject: [PATCH 003/242] - changed ban notification --- src/main/java/betterbox/mine/game/betterelo/BetterElo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java index c244464..9986567 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java @@ -388,7 +388,7 @@ public void notiyBannedPlayer(String bannedPlayer){ Duration stay = Duration.ofMillis(10000); // czas wyświetlania Duration fadeOut = Duration.ofMillis(5000); // czas znikania Title.Times times = Title.Times.times(fadeIn, stay, fadeOut); - Component BannedTitleComponent = Component.text(ChatColor.DARK_RED +"You have been flagged as "+ChatColor.BLACK+""+ChatColor.BOLD+" CHEATER"); + Component BannedTitleComponent = Component.text(ChatColor.DARK_RED +"!!!"+ChatColor.BLACK+""+ChatColor.BOLD+"CHEATER"+ChatColor.DARK_RED +"!!!"); Component BannedSubtitleComponent = Component.text(ChatColor.GREEN +"Buy unban on website "+ChatColor.GOLD+ChatColor.BOLD+" BetterBox.top" ); // Notify the killer Title bannedTitle = Title.title(BannedTitleComponent,BannedSubtitleComponent,times); From 907606bbf1daf774d94742c7292b98b55874cb89 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sun, 3 Mar 2024 02:49:30 +0100 Subject: [PATCH 004/242] - added /be event