Skip to content

Commit

Permalink
Added sounds and boss bar to show time left
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Nov 5, 2019
1 parent 2beeb82 commit 640385b
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 39 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>2.4</version>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
Expand Down Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<version>1.14-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.zcraft</groupId>
Expand Down
Empty file modified src/main/java/fr/zcraft/VoteBan/Config.java
100644 → 100755
Empty file.
Empty file modified src/main/java/fr/zcraft/VoteBan/Permissions.java
100644 → 100755
Empty file.
Empty file modified src/main/java/fr/zcraft/VoteBan/VoteBan.java
100644 → 100755
Empty file.
Empty file.
18 changes: 9 additions & 9 deletions src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansStartCommand.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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()));
Expand All @@ -81,9 +81,9 @@ protected List<String> complete() throws CommandException
{
if (args.length == 1)
{
List<String> playersNames = new ArrayList<>();
final List<String> playersNames = new ArrayList<>();

for (Player player : Bukkit.getOnlinePlayers())
for (final Player player : Bukkit.getOnlinePlayers())
if (!Permissions.EXEMPTED.grantedTo(player))
playersNames.add(player.getName());

Expand All @@ -94,7 +94,7 @@ protected List<String> complete() throws CommandException
}

@Override
public boolean canExecute(CommandSender sender)
public boolean canExecute(final CommandSender sender)
{
return Permissions.START_VOTE.grantedTo(sender);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fr/zcraft/VoteBan/commands/votebans/VoteBansVoteCommand.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -114,9 +114,9 @@ protected List<String> complete() throws CommandException
{
if (args.length == 1)
{
List<String> currentVotedPlayers = new ArrayList<>();
final List<String> 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]);
Expand All @@ -126,7 +126,7 @@ protected List<String> complete() throws CommandException
}

@Override
public boolean canExecute(CommandSender sender)
public boolean canExecute(final CommandSender sender)
{
return Permissions.VOTE.grantedTo(sender);
}
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions src/main/java/fr/zcraft/VoteBan/votes/CannotRegisterVoteException.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
80 changes: 65 additions & 15 deletions src/main/java/fr/zcraft/VoteBan/votes/Vote.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -59,7 +65,11 @@ public class Vote
private final Set<UUID> votesYes = new HashSet<>();
private final Set<UUID> 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();
Expand Down Expand Up @@ -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") + " ]")
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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<Player> 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();

Expand Down Expand Up @@ -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()));
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/config.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -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}"
Empty file modified src/main/resources/i18n/fr_FR.po
100644 → 100755
Empty file.
7 changes: 4 additions & 3 deletions src/main/resources/plugin.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 640385b

Please sign in to comment.