-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spigot): translate signed chat packet on 1.19+ (#353)
Behind `chat.signed-enabled` config option, which is ~~disabled~~ ENABLED by default in v4 (versus disabled in v3). Closes #350 Port of 1d7afbd to v4
- Loading branch information
1 parent
e56dff9
commit 31115c1
Showing
4 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
...spigot/src/main/java/com/rexcantor64/triton/spigot/wrappers/WrappedPlayerChatMessage.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,61 @@ | ||
package com.rexcantor64.triton.wrappers; | ||
|
||
import com.comphenix.protocol.reflect.EquivalentConverter; | ||
import com.comphenix.protocol.reflect.FuzzyReflection; | ||
import com.comphenix.protocol.reflect.accessors.Accessors; | ||
import com.comphenix.protocol.reflect.accessors.FieldAccessor; | ||
import com.comphenix.protocol.utility.MinecraftReflection; | ||
import com.comphenix.protocol.wrappers.AbstractWrapper; | ||
import com.comphenix.protocol.wrappers.BukkitConverters; | ||
import com.comphenix.protocol.wrappers.Converters; | ||
import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Custom ProtocolLib Wrapper of NMS' PlayerChatMessage (added to NMS in 1.19 and removed in 1.19.3) | ||
* Tested with 1.19.2 | ||
*/ | ||
public class WrappedPlayerChatMessage extends AbstractWrapper { | ||
|
||
private static Class<?> PLAYER_CHAT_MESSAGE = MinecraftReflection.getMinecraftClass("network.chat.PlayerChatMessage"); | ||
private static FuzzyReflection FUZZY_REFLECTION = FuzzyReflection.fromClass(PLAYER_CHAT_MESSAGE, true); | ||
private static FieldAccessor CHAT_COMPONENT = Accessors.getFieldAccessor(FUZZY_REFLECTION.getParameterizedField(Optional.class, MinecraftReflection.getIChatBaseComponentClass())); | ||
private static EquivalentConverter<Optional<WrappedChatComponent>> CHAT_COMPONENT_CONVERTER = Converters.optional(BukkitConverters.getWrappedChatComponentConverter()); | ||
|
||
public static final EquivalentConverter<WrappedPlayerChatMessage> CONVERTER = Converters.ignoreNull(Converters.handle(WrappedPlayerChatMessage::getHandle, WrappedPlayerChatMessage::fromHandle, WrappedPlayerChatMessage.class)); | ||
|
||
/** | ||
* Construct a new PlayerChatMessage wrapper. | ||
*/ | ||
private WrappedPlayerChatMessage(Object handle) { | ||
super(getWrappedClass()); | ||
setHandle(handle); | ||
} | ||
|
||
public Optional<WrappedChatComponent> getMessage() { | ||
return CHAT_COMPONENT_CONVERTER.getSpecific(CHAT_COMPONENT.get(handle)); | ||
} | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public void setMessage(Optional<WrappedChatComponent> message) { | ||
CHAT_COMPONENT.set(handle, CHAT_COMPONENT_CONVERTER.getGeneric(message)); | ||
} | ||
|
||
/** | ||
* Construct a player chat message from a native NMS object. | ||
* | ||
* @param handle - the native object. | ||
* @return The wrapped player chat message object. | ||
*/ | ||
@Contract("_ -> new") | ||
public static @NotNull WrappedPlayerChatMessage fromHandle(Object handle) { | ||
return new WrappedPlayerChatMessage(handle); | ||
} | ||
|
||
public static Class<?> getWrappedClass() { | ||
return PLAYER_CHAT_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