Merge pull request #296 from JOO200/feat/velocity3

Update to velocity 3, Make Proxy Events cancellable
This commit is contained in:
Andrew Steinborn authored and GitHub committed 2022-04-11 22:36:49 -04:00
commit fcf6c93404
7 files changed
+56 -22

No files matched your search

+1 -1
View File
@@ -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"
}
@@ -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
@@ -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;
}
}
@@ -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
@@ -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");
}
}
@@ -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");
}
}
@@ -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<ResultedEvent.GenericResult> {
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{" +