-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add async constructor for CancellableEvent and add ClientLocalPlayerC…
…hatEvent
- Loading branch information
1 parent
e38d5bb
commit b66d23a
Showing
5 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...rry-API/src/main/java/net/blueberrymc/client/event/player/ClientLocalPlayerChatEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.blueberrymc.client.event.player; | ||
|
||
import net.blueberrymc.common.Blueberry; | ||
import net.blueberrymc.common.bml.event.CancellableEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Fired when the local player (the client) tries to send a chat message. If the event is cancelled, the chat message | ||
* will not be sent. If the message was changed through {@link #setMessage(String)}, the new message will be sent. | ||
*/ | ||
public class ClientLocalPlayerChatEvent extends CancellableEvent { | ||
@NotNull | ||
private String message; | ||
|
||
public ClientLocalPlayerChatEvent(@NotNull String message) { | ||
super(!Blueberry.getUtil().isOnGameThread()); | ||
this.message = message; | ||
} | ||
|
||
/** | ||
* Gets the message that the player is trying to send. | ||
* @return the message | ||
*/ | ||
@NotNull | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
/** | ||
* Sets the message that the player is trying to send. | ||
* @param message the message | ||
*/ | ||
public void setMessage(@NotNull String message) { | ||
this.message = message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
...be-Patches/0015-Fire-network-events.patch → MagmaCube-Patches/0015-Fire-events.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: acrylic-style <[email protected]> | ||
Date: Wed, 10 Nov 2021 14:38:53 +0900 | ||
Subject: [PATCH] Fire network events | ||
Date: Mon, 4 Apr 2022 13:59:39 +0900 | ||
Subject: [PATCH] Fire events | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/client/player/LocalPlayer.java b/src/main/java/net/minecraft/client/player/LocalPlayer.java | ||
index 78e1e2a3e068a38a406619cf3d9a17ad677b2835..5244eb5acb4b793fa07e90a4f7f113ace1ae432c 100644 | ||
--- a/src/main/java/net/minecraft/client/player/LocalPlayer.java | ||
+++ b/src/main/java/net/minecraft/client/player/LocalPlayer.java | ||
@@ -269,7 +269,13 @@ public class LocalPlayer extends AbstractClientPlayer { | ||
} | ||
|
||
public void chat(String s) { | ||
- this.connection.send(new ServerboundChatPacket(s)); | ||
+ // Blueberry start - fire ClientLocalPlayerChatEvent | ||
+ var event = new net.blueberrymc.client.event.player.ClientLocalPlayerChatEvent(s); | ||
+ if (!event.callEvent()) { | ||
+ return; | ||
+ } | ||
+ this.connection.send(new ServerboundChatPacket(event.getMessage())); | ||
+ // Blueberry end - fire ClientLocalPlayerChatEvent | ||
} | ||
|
||
public void swing(InteractionHand interactionHand) { | ||
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java | ||
index dba3ba3bd696eb6707f9f5670f42e318561cc1df..f93f1dc7c545a164d3e500da57c1326cff9f01f2 100644 | ||
--- a/src/main/java/net/minecraft/network/Connection.java | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters