From 640385beaa450a7274d4b49e2fd7022afd135e42 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Tue, 5 Nov 2019 17:00:30 +0100 Subject: [PATCH] Added sounds and boss bar to show time left --- .gitignore | 0 pom.xml | 8 +- src/main/java/fr/zcraft/VoteBan/Config.java | 0 .../java/fr/zcraft/VoteBan/Permissions.java | 0 src/main/java/fr/zcraft/VoteBan/VoteBan.java | 0 .../commands/votebans/VoteBansNoCommand.java | 0 .../votebans/VoteBansStartCommand.java | 18 ++--- .../votebans/VoteBansVoteCommand.java | 8 +- .../commands/votebans/VoteBansYesCommand.java | 0 .../votes/CannotRegisterVoteException.java | 4 +- .../java/fr/zcraft/VoteBan/votes/Vote.java | 80 +++++++++++++++---- src/main/resources/config.yml | 4 +- src/main/resources/i18n/fr_FR.po | 0 src/main/resources/plugin.yml | 7 +- 14 files changed, 90 insertions(+), 39 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 pom.xml mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/Config.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/Permissions.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/VoteBan.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansNoCommand.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansYesCommand.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java mode change 100644 => 100755 src/main/java/fr/zcraft/VoteBan/votes/Vote.java mode change 100644 => 100755 src/main/resources/config.yml mode change 100644 => 100755 src/main/resources/i18n/fr_FR.po mode change 100644 => 100755 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 70d727e..0e8b033 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 @@ -21,7 +21,7 @@ org.apache.maven.plugins maven-shade-plugin - 2.3 + 2.4 true @@ -63,7 +63,7 @@ org.bukkit bukkit - 1.9-R0.1-SNAPSHOT + 1.14-R0.1-SNAPSHOT fr.zcraft diff --git a/src/main/java/fr/zcraft/VoteBan/Config.java b/src/main/java/fr/zcraft/VoteBan/Config.java old mode 100644 new mode 100755 diff --git a/src/main/java/fr/zcraft/VoteBan/Permissions.java b/src/main/java/fr/zcraft/VoteBan/Permissions.java old mode 100644 new mode 100755 diff --git a/src/main/java/fr/zcraft/VoteBan/VoteBan.java b/src/main/java/fr/zcraft/VoteBan/VoteBan.java old mode 100644 new mode 100755 diff --git a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansNoCommand.java b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansNoCommand.java old mode 100644 new mode 100755 diff --git a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java old mode 100644 new mode 100755 index 0ef06c7..a9698da --- a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java +++ b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java @@ -28,21 +28,21 @@ protected void run() throws CommandException if (args.length < 2) throwInvalidArgument(I.t("A player name and a reason are required.")); - Player target = getPlayerParameter(0); + final Player target = getPlayerParameter(0); if (target.equals(playerSender())) error(I.t("You cannot vote-ban yourself")); - String reason = ""; + final StringBuilder reason = new StringBuilder(); for (int i = 1; i < args.length; i++) - reason += " " + args[i]; + reason.append(" ").append(args[i]); try { - Vote vote = VoteBan.get().registerVote(target, playerSender(), reason.trim()); + final Vote vote = VoteBan.get().registerVote(target, playerSender(), reason.toString().trim()); vote.start(); } - catch (CannotRegisterVoteException e) + catch (final CannotRegisterVoteException e) { switch (e.getReason()) { @@ -55,7 +55,7 @@ protected void run() throws CommandException break; case ALREADY_RUNNING: - Vote vote = VoteBan.get().getVote(target); + final Vote vote = VoteBan.get().getVote(target); warning(I.t("A vote against {0} is already running (started by {1}).", target.getName(), vote.getLauncherPlayer().getName())); warning(I.t("The reason is: {0}", vote.getReason())); @@ -81,9 +81,9 @@ protected List complete() throws CommandException { if (args.length == 1) { - List playersNames = new ArrayList<>(); + final List playersNames = new ArrayList<>(); - for (Player player : Bukkit.getOnlinePlayers()) + for (final Player player : Bukkit.getOnlinePlayers()) if (!Permissions.EXEMPTED.grantedTo(player)) playersNames.add(player.getName()); @@ -94,7 +94,7 @@ protected List complete() throws CommandException } @Override - public boolean canExecute(CommandSender sender) + public boolean canExecute(final CommandSender sender) { return Permissions.START_VOTE.grantedTo(sender); } diff --git a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java old mode 100644 new mode 100755 index 5cc9751..a3f747e --- a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java +++ b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java @@ -78,7 +78,7 @@ protected void run() throws CommandException else if (args.length >= 1) { - Player target = getPlayerParameter(0); + final Player target = getPlayerParameter(0); vote = votes.get(target.getUniqueId()); if (vote == null) @@ -114,9 +114,9 @@ protected List complete() throws CommandException { if (args.length == 1) { - List currentVotedPlayers = new ArrayList<>(); + final List currentVotedPlayers = new ArrayList<>(); - for (Vote vote : VoteBan.get().getVotes().values()) + for (final Vote vote : VoteBan.get().getVotes().values()) currentVotedPlayers.add(vote.getTargetPlayer().getName()); return getMatchingSubset(currentVotedPlayers, args[0]); @@ -126,7 +126,7 @@ protected List complete() throws CommandException } @Override - public boolean canExecute(CommandSender sender) + public boolean canExecute(final CommandSender sender) { return Permissions.VOTE.grantedTo(sender); } diff --git a/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansYesCommand.java b/src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansYesCommand.java old mode 100644 new mode 100755 diff --git a/src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java b/src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java old mode 100644 new mode 100755 index fc4d82b..5a3cdbf --- a/src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java +++ b/src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java @@ -33,9 +33,9 @@ public class CannotRegisterVoteException extends RuntimeException { - private Reason reason; + private final Reason reason; - public CannotRegisterVoteException(Reason reason) + public CannotRegisterVoteException(final Reason reason) { super(); diff --git a/src/main/java/fr/zcraft/VoteBan/votes/Vote.java b/src/main/java/fr/zcraft/VoteBan/votes/Vote.java old mode 100644 new mode 100755 index a703f9d..257af77 --- a/src/main/java/fr/zcraft/VoteBan/votes/Vote.java +++ b/src/main/java/fr/zcraft/VoteBan/votes/Vote.java @@ -42,9 +42,15 @@ import fr.zcraft.zlib.tools.text.RawMessage; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -59,7 +65,11 @@ public class Vote private final Set votesYes = new HashSet<>(); private final Set votesNo = new HashSet<>(); - public Vote(Player target, Player launcher, String reason) + private float secondsLeft = 0.0f; + private BossBar bar = null; + private BukkitTask task = null; + + public Vote(final Player target, final Player launcher, final String reason) { this.target = target.getUniqueId(); this.launcher = launcher.getUniqueId(); @@ -116,11 +126,13 @@ public void start() /* ** Broadcasts the vote ** */ + Bukkit.broadcastMessage(""); separator(); Bukkit.broadcastMessage(I.t("{gold}{bold}{0} started a vote to ban {1}", getLauncherPlayer().getName(), targetPlayer.getName())); Bukkit.broadcastMessage(""); Bukkit.broadcastMessage(I.t("{yellow}Reason: {gold}{0}", reason)); + Bukkit.broadcastMessage(""); RawText invite = new RawText("") .then("[ " + I.t("I agree") + " ]") @@ -139,11 +151,9 @@ public void start() .build(); - for (Player player : Bukkit.getOnlinePlayers()) + for (final Player player : Bukkit.getOnlinePlayers()) { - Bukkit.broadcastMessage(""); - - if (Permissions.VOTE.grantedTo(player)) + if (Permissions.VOTE.grantedTo(player) && !player.equals(targetPlayer)) RawMessage.send(player, invite); else @@ -152,16 +162,18 @@ public void start() separator(); + /* ** Broadcasts the vote of the sender (clearer for players) & the sound ** */ + + RunTask.later(() -> broadcastVote(getLauncherPlayer(), true), 10); + Bukkit.getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), Sound.ITEM_TRIDENT_THUNDER, 1f, 1f)); + /* ** Schedules the end ** */ - RunTask.later(new Runnable() { - @Override - public void run() - { - end(); - } - }, Config.VOTES.DELAY.get() * 20); + secondsLeft = (float) Config.VOTES.DELAY.get(); + bar = Bukkit.createBossBar(I.t("{red}{bold}{0} wants to ban {1} {gray}-{yellow} {2}", getLauncherPlayer().getName(), targetPlayer.getName(), reason), BarColor.RED, BarStyle.SOLID); + + task = RunTask.timer(this::tick, 1L, 1L); } public boolean vote(Player player, boolean vote) @@ -172,18 +184,41 @@ public boolean vote(Player player, boolean vote) if (vote) { votesYes.add(player.getUniqueId()); - Bukkit.broadcastMessage(I.t("{darkgreen}\u271A {green}{0} wants {1} to be banned", player.getName(), getTargetPlayer().getName())); + Bukkit.getOnlinePlayers().forEach(p -> p.playSound(p.getLocation(), Sound.BLOCK_BAMBOO_FALL, 1f, .1f)); } else { votesNo.add(player.getUniqueId()); - Bukkit.broadcastMessage(I.t("{darkred}\u2716 {red}{0} is against the ban of {1}", player.getName(), getTargetPlayer().getName())); + Bukkit.getOnlinePlayers().forEach(p -> p.playSound(p.getLocation(), Sound.BLOCK_BAMBOO_FALL, 1f, 2f)); } + broadcastVote(player, vote); return true; } - public void end() + private void tick() + { + if (secondsLeft <= 0) + { + task.cancel(); + task = null; + + bar.removeAll(); + bar = null; + + end(); + return; + } + + final List barPlayers = bar.getPlayers(); + + Bukkit.getOnlinePlayers().stream().filter(player -> !barPlayers.contains(player)).forEach(bar::addPlayer); + bar.setProgress(secondsLeft / (float) Config.VOTES.DELAY.get()); + + secondsLeft -= .05f; + } + + private void end() { separator(); @@ -232,12 +267,27 @@ else if ((int) Math.floor(getYesPercentage() * 100) < Config.VOTES.POSITIVE_PERC Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandLine); } + + Bukkit.getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), Sound.ENTITY_EVOKER_PREPARE_WOLOLO, 1f, 1.2f)); } else { VoteBan.get().immunize(target); + Bukkit.getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), Sound.ENTITY_CAT_AMBIENT, 1f, .6f)); } VoteBan.get().unregisterVote(this); } + + private void broadcastVote(final Player voter, final boolean vote) + { + if (vote) + { + Bukkit.broadcastMessage(I.t("{darkgreen}\u271A {green}{0} wants {1} to be banned", voter.getName(), getTargetPlayer().getName())); + } + else + { + Bukkit.broadcastMessage(I.t("{darkred}\u2716 {red}{0} is against the ban of {1}", voter.getName(), getTargetPlayer().getName())); + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml old mode 100644 new mode 100755 index 32cd5af..7276b08 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,7 +5,7 @@ locale: votes: # The delay allowed to vote. After this delay, the votes will be counted and # the actions taken. (Seconds.) - delay: 40 + delay: 60 # The minimal time to wait between two votebans against the same player. # (Seconds.) @@ -27,4 +27,4 @@ votes: # {votesAgainstBan} (number of votes against) # {votes} (total amount of votes) ban_commands: - - "ban {targetName} VoteBan started by {launcherName}: {reason}" + - "ban {targetName} VoteBan started by {launcherName} ({votesForBan}/{votes}): {reason}" diff --git a/src/main/resources/i18n/fr_FR.po b/src/main/resources/i18n/fr_FR.po old mode 100644 new mode 100755 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml old mode 100644 new mode 100755 index 92e911f..eea3f29 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: VoteBanRevamped -version: 1.0 +version: "1.0" main: fr.zcraft.VoteBan.VoteBan +api-version: "1.13" description: Vote for bans if moderators are away. A rewrite of a plugin by niquecraft. author: Amaury Carrade @@ -28,11 +29,11 @@ permissions: voteban.start: description: "Start a voteban." - default: false + default: op voteban.vote: description: "Vote against a player during a voteban." - default: false + default: op voteban.exempt: description: "Players with this permission cannot be vote-banned against."