From aaba3292f08498f9c639971d923d569a18818075 Mon Sep 17 00:00:00 2001 From: TheOptimisticFactory Date: Sat, 18 Apr 2020 23:09:36 +0200 Subject: [PATCH 1/2] feat: added the details of how many total votes there is --- .../java/fr/leomelki/loupgarou/classes/LGVote.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java index b352131..7bf3982 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java @@ -327,16 +327,20 @@ public class LGVote { spawn.setY(loc.getY()+0.3); spawn.setZ(loc.getZ()); - int votesNbr = votes.get(voted).size(); + final int numberOfParticipants = participants.size(); + final double votePercentage = (double) (votesNbr / numberOfParticipants) * 100; + final String votePercentageFormated = String.format("%.0f%%", votePercentage); + final String voteContent = "§6§l" + votesNbr + " / " + numberOfParticipants + "§e vote" + (votesNbr > 1 ? "s" : "") + " (§6§l" + votePercentageFormated + "§e)"; + /*WrapperPlayServerEntityMetadata meta = new WrapperPlayServerEntityMetadata(); meta.setEntityID(entityId); meta.setMetadata(Arrays.asList(new WrappedWatchableObject(invisible, (byte)0x20), new WrappedWatchableObject(noGravity, true), new WrappedWatchableObject(customNameVisible, true), new WrappedWatchableObject(customName, IChatBaseComponent.ChatSerializer.b("§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : ""))))); */ DataWatcher datawatcher = new DataWatcher(eas); datawatcher.register(T, (byte)0x20); - datawatcher.register(az, Optional.ofNullable(IChatBaseComponent.ChatSerializer.a("{\"text\":\"§6§l"+votesNbr+"§e vote"+(votesNbr > 1 ? "s" : "")+"\"}"))); - datawatcher.register(aA, true); + datawatcher.register(az, Optional.ofNullable(IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + voteContent + "\"}"))); + datawatcher.register(aA, true); PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(entityId, datawatcher, true); for(LGPlayer lgp : viewers) { From c08e59477df528354445ec061a5e4933989bb319 Mon Sep 17 00:00:00 2001 From: TheOptimisticFactory Date: Mon, 27 Apr 2020 01:52:21 +0200 Subject: [PATCH 2/2] fix: Corrected percentage calculation --- src/main/java/fr/leomelki/loupgarou/classes/LGVote.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java index 7bf3982..c354c4a 100644 --- a/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java +++ b/src/main/java/fr/leomelki/loupgarou/classes/LGVote.java @@ -329,7 +329,7 @@ public class LGVote { int votesNbr = votes.get(voted).size(); final int numberOfParticipants = participants.size(); - final double votePercentage = (double) (votesNbr / numberOfParticipants) * 100; + final double votePercentage = ((double)votesNbr / numberOfParticipants) * 100; final String votePercentageFormated = String.format("%.0f%%", votePercentage); final String voteContent = "§6§l" + votesNbr + " / " + numberOfParticipants + "§e vote" + (votesNbr > 1 ? "s" : "") + " (§6§l" + votePercentageFormated + "§e)";