Bugfixes on the AsyncChatHookEvents (#26)

* fix a bug where hooked channels wouldn't get the messages sent to their recipients

* fix on AsyncChatHookEvent message setter
This commit is contained in:
Steven Rebstew authored and GitHub committed 2020-06-01 14:12:28 -05:00
1 parent 956411ed9b
commit 1bec7f8f7a
1 file changed
+7 -4
@@ -6,6 +6,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
/* /*
@@ -30,12 +31,14 @@ public class AsyncChatHookEvent extends Event {
protected AsyncPlayerChatEvent event; protected AsyncPlayerChatEvent event;
protected boolean changed; protected boolean changed;
protected Channel channel; protected Channel channel;
protected Set<Player> recipients;
public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel, boolean async) { public AsyncChatHookEvent(AsyncPlayerChatEvent event, Channel channel, boolean async) {
super(async); super(async);
this.event = event; this.event = event;
this.changed = false; this.changed = false;
this.channel = channel; this.channel = channel;
this.recipients = new HashSet<>(event.getRecipients());
} }
public Channel getChannel() { public Channel getChannel() {
@@ -69,7 +72,7 @@ public class AsyncChatHookEvent extends Event {
} }
public Set<Player> getRecipients() { public Set<Player> getRecipients() {
return event.getRecipients(); return this.recipients;
} }
public boolean isCancelled() { public boolean isCancelled() {
@@ -82,8 +85,8 @@ public class AsyncChatHookEvent extends Event {
public void setRecipients(Set<Player> recipients) { public void setRecipients(Set<Player> recipients) {
changed = true; changed = true;
event.getRecipients().clear(); this.recipients.clear();
event.getRecipients().addAll(recipients); this.recipients.addAll(recipients);
} }
public void setFormat(String format) { public void setFormat(String format) {
@@ -93,7 +96,7 @@ public class AsyncChatHookEvent extends Event {
public void setMessage(String message) { public void setMessage(String message) {
changed = true; changed = true;
event.setFormat(message); event.setMessage(message);
} }
public void setCancelled(boolean cancel) { public void setCancelled(boolean cancel) {