use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.
the class ActionBar method process.
protected void process(PacketEvent packetEvent) {
PsrUser user = getEventUser(packetEvent);
if (user == null) {
return;
}
PacketContainer packet = packetEvent.getPacket();
String json = packet.getChatComponents().read(0).getJson();
WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
if (replaced != null) {
packet.getChatComponents().write(0, replaced);
}
}
use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.
the class Chat method process.
protected void process(PacketEvent packetEvent) {
PacketContainer packet = packetEvent.getPacket();
Optional<Boolean> isFiltered = packet.getMeta("psr_filtered_packet");
if (!(isFiltered.isPresent() && isFiltered.get())) {
PsrUser user = getEventUser(packetEvent);
if (user == null) {
return;
}
StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
WrappedChatComponent wrappedChatComponent = wrappedChatComponentStructureModifier.read(0);
String json;
if (wrappedChatComponent != null) {
json = wrappedChatComponent.getJson();
WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
if (replaced != null) {
wrappedChatComponentStructureModifier.write(0, replaced);
}
} else {
StructureModifier<Object> modifier = packet.getModifier();
setupFields(modifier.getFields());
if (bungeeComponentsField != -1) {
Object obj = modifier.read(bungeeComponentsField);
if (obj == null) {
if (paperComponentField != -1) {
obj = modifier.read(paperComponentField);
Component component = (Component) obj;
json = getPaperGsonComponentSerializer().serialize(component);
WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
if (replaced != null) {
wrappedChatComponentStructureModifier.write(0, replaced);
modifier.write(paperComponentField, null);
}
}
return;
}
BaseComponent[] components = (BaseComponent[]) obj;
json = ComponentSerializer.toString(components);
WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
if (replaced != null) {
wrappedChatComponentStructureModifier.write(0, replaced);
modifier.write(bungeeComponentsField, null);
}
}
}
}
}
use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.
the class OpenWindow method process.
protected void process(PacketEvent packetEvent) {
PsrUser user = getEventUser(packetEvent);
if (user == null) {
return;
}
PacketContainer packet = packetEvent.getPacket();
StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
WrappedChatComponent wrappedChatComponent = wrappedChatComponentStructureModifier.read(0);
String json = wrappedChatComponent.getJson();
WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter, true);
if (replaced != null) {
wrappedChatComponentStructureModifier.write(0, replaced);
}
}
use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.
the class BossBarUpper17 method process.
protected void process(PacketEvent packetEvent) {
if (!hooked) {
return;
}
PsrUser user = getEventUser(packetEvent);
if (user == null) {
return;
}
Object handle = packetEvent.getPacket().getHandle();
try {
Object action = actionField.get(handle);
if (action == null) {
return;
}
Field field = actionComponentField.get(action.getClass());
if (field != null) {
WrappedChatComponent wrappedChatComponent = WrappedChatComponent.fromHandle(field.get(action));
String replacedJson = getReplacedJson(packetEvent, user, listenType, wrappedChatComponent.getJson(), filter);
if (replacedJson != null) {
wrappedChatComponent.setJson(replacedJson);
field.set(action, wrappedChatComponent.getHandle());
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ChangeSkin by games647.
the class SkinApplier method sendPacketsSelf.
private void sendPacketsSelf(WrappedGameProfile gameProfile) {
PacketContainer removeInfo;
PacketContainer addInfo;
PacketContainer respawn;
PacketContainer teleport;
try {
NativeGameMode gamemode = NativeGameMode.fromBukkit(receiver.getGameMode());
WrappedChatComponent displayName = WrappedChatComponent.fromText(receiver.getPlayerListName());
PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, 0, gamemode, displayName);
// remove the old skin - client updates it only on a complete remove and add
removeInfo = new PacketContainer(PLAYER_INFO);
removeInfo.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
removeInfo.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
// add info containing the skin data
addInfo = removeInfo.deepClone();
addInfo.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
// Respawn packet - notify the client that it should update the own skin
respawn = createRespawnPacket(gamemode);
// prevent the moved too quickly message
teleport = createTeleportPacket(receiver.getLocation().clone());
} catch (ReflectiveOperationException reflectiveEx) {
plugin.getLog().error("Error occurred preparing packets. Cancelling self update", reflectiveEx);
return;
}
sendPackets(removeInfo, addInfo, respawn, teleport);
}
Aggregations