diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index c1d38bf..7b116cb 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -4,5 +4,5 @@ object Versions { const val FINDBUGS = "3.0.2" const val NETTYIO = "4.1.72.Final" const val GSON = "2.9.0" - const val VELOCITY = "1.1.0-SNAPSHOT" + const val VELOCITY = "3.1.0" } diff --git a/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/NuVotifier.java b/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/NuVotifier.java index cc5f89d..217edfb 100644 --- a/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/NuVotifier.java +++ b/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/NuVotifier.java @@ -364,11 +364,12 @@ public class NuVotifier extends Plugin implements VoteHandler, ProxyVotifierPlug } } - getProxy().getScheduler().runAsync(this, () -> getProxy().getPluginManager().callEvent(new VotifierEvent(vote))); - - if (forwardingMethod != null) { - getProxy().getScheduler().runAsync(this, () -> forwardingMethod.forward(vote)); - } + getProxy().getScheduler().runAsync(this, () -> { + VotifierEvent event = getProxy().getPluginManager().callEvent(new VotifierEvent(vote)); + if (!event.isCancelled() && forwardingMethod != null) { + forwardingMethod.forward(vote); + } + }); } @Override diff --git a/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/events/VotifierEvent.java b/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/events/VotifierEvent.java index d7999b9..abeb168 100644 --- a/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/events/VotifierEvent.java +++ b/bungeecord/src/main/java/com/vexsoftware/votifier/bungee/events/VotifierEvent.java @@ -1,18 +1,21 @@ package com.vexsoftware.votifier.bungee.events; import com.vexsoftware.votifier.model.Vote; +import net.md_5.bungee.api.plugin.Cancellable; import net.md_5.bungee.api.plugin.Event; /** * {@code VotifierEvent} is a custom BungeeCord event class that is sent * asynchronously allowing other plugins to listen for votes. */ -public class VotifierEvent extends Event { +public class VotifierEvent extends Event implements Cancellable { /** * The vote. **/ private final Vote vote; + private boolean cancelled; + public VotifierEvent(Vote vote) { this.vote = vote; } @@ -20,4 +23,14 @@ public class VotifierEvent extends Event { public Vote getVote() { return vote; } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } } diff --git a/velocity/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlugin.java b/velocity/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlugin.java index 4161cac..b36872c 100644 --- a/velocity/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlugin.java +++ b/velocity/src/main/java/com/vexsoftware/votifier/velocity/VotifierPlugin.java @@ -391,10 +391,11 @@ public class VotifierPlugin implements VoteHandler, ProxyVotifierPlugin { } } - server.getEventManager().fireAndForget(new VotifierEvent(vote)); - if (forwardingMethod != null) { - forwardingMethod.forward(vote); - } + server.getEventManager().fire(new VotifierEvent(vote)).thenAccept(v -> { + if (v.getResult().isAllowed() && forwardingMethod != null) { + forwardingMethod.forward(v.getVote()); + } + }); } @Override diff --git a/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/NVReloadCmd.java b/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/NVReloadCmd.java index 5fe4072..85b0290 100644 --- a/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/NVReloadCmd.java +++ b/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/NVReloadCmd.java @@ -1,5 +1,6 @@ package com.vexsoftware.votifier.velocity.cmd; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; import com.vexsoftware.votifier.velocity.VotifierPlugin; import net.kyori.adventure.text.Component; @@ -13,18 +14,20 @@ public class NVReloadCmd implements SimpleCommand { this.plugin = plugin; } + @Override - public void execute(SimpleCommand.Invocation invocation) { - invocation.source().sendMessage(Component.text("Reloading NuVotifier...", NamedTextColor.GRAY)); + public void execute(Invocation invocation) { + CommandSource sender = invocation.source(); + sender.sendMessage(Component.text("Reloading NuVotifier...", NamedTextColor.GRAY)); if (plugin.reload()) { - invocation.source().sendMessage(Component.text("NuVotifier has been reloaded!", NamedTextColor.DARK_GREEN)); + sender.sendMessage(Component.text("NuVotifier has been reloaded!", NamedTextColor.DARK_GREEN)); } else { - invocation.source().sendMessage(Component.text("Looks like there was a problem reloading NuVotifier, check the console!", NamedTextColor.DARK_RED)); + sender.sendMessage(Component.text("Looks like there was a problem reloading NuVotifier, check the console!", NamedTextColor.DARK_RED)); } } @Override - public boolean hasPermission(SimpleCommand.Invocation invocation) { + public boolean hasPermission(Invocation invocation) { return invocation.source().hasPermission("nuvotifier.reload"); } } diff --git a/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/TestVoteCmd.java b/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/TestVoteCmd.java index b2f3d64..9d899e7 100644 --- a/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/TestVoteCmd.java +++ b/velocity/src/main/java/com/vexsoftware/votifier/velocity/cmd/TestVoteCmd.java @@ -1,5 +1,6 @@ package com.vexsoftware.votifier.velocity.cmd; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; import com.vexsoftware.votifier.model.Vote; import com.vexsoftware.votifier.net.VotifierSession; @@ -17,22 +18,24 @@ public class TestVoteCmd implements SimpleCommand { } @Override - public void execute(SimpleCommand.Invocation invocation) { + public void execute(Invocation invocation) { + CommandSource sender = invocation.source(); + Vote v; try { v = ArgsToVote.parse(invocation.arguments()); } catch (IllegalArgumentException e) { - invocation.source().sendMessage(Component.text("Error while parsing arguments to create test vote: " + e.getMessage(), NamedTextColor.DARK_RED)); - invocation.source().sendMessage(Component.text("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]", NamedTextColor.GRAY)); + sender.sendMessage(Component.text("Error while parsing arguments to create test vote: " + e.getMessage(), NamedTextColor.DARK_RED)); + sender.sendMessage(Component.text("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]", NamedTextColor.GRAY)); return; } plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test"); - invocation.source().sendMessage(Component.text("Test vote executed: " + v.toString(), NamedTextColor.GREEN)); + sender.sendMessage(Component.text("Test vote executed: " + v.toString(), NamedTextColor.GREEN)); } @Override - public boolean hasPermission(SimpleCommand.Invocation invocation) { + public boolean hasPermission(Invocation invocation) { return invocation.source().hasPermission("nuvotifier.testvote"); } } diff --git a/velocity/src/main/java/com/vexsoftware/votifier/velocity/event/VotifierEvent.java b/velocity/src/main/java/com/vexsoftware/votifier/velocity/event/VotifierEvent.java index 1e18086..d92a7b0 100644 --- a/velocity/src/main/java/com/vexsoftware/votifier/velocity/event/VotifierEvent.java +++ b/velocity/src/main/java/com/vexsoftware/votifier/velocity/event/VotifierEvent.java @@ -1,18 +1,31 @@ package com.vexsoftware.votifier.velocity.event; +import com.velocitypowered.api.event.ResultedEvent; import com.vexsoftware.votifier.model.Vote; -public class VotifierEvent { +public class VotifierEvent implements ResultedEvent { private final Vote vote; + private GenericResult result; public VotifierEvent(Vote vote) { this.vote = vote; + this.result = GenericResult.allowed(); } public Vote getVote() { return vote; } + @Override + public GenericResult getResult() { + return this.result; + } + + @Override + public void setResult(GenericResult result) { + this.result = result; + } + @Override public String toString() { return "VotifierEvent{" +