-
Notifications
You must be signed in to change notification settings - Fork 86
Chat recording changes #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c30e831
33ecb00
255e073
8064886
08d50af
173301e
0d6bb3d
d120844
fe05d43
bd75d38
06d429d
649605f
19da463
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * PacketWrapper - ProtocolLib wrappers for Minecraft packets | ||
| * Copyright (C) dmulloy2 <http://dmulloy2.net> | ||
| * Copyright (C) Kristian S. Strangeland | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.comphenix.packetwrapper; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import com.comphenix.protocol.PacketType; | ||
| import com.comphenix.protocol.events.PacketContainer; | ||
| import com.comphenix.protocol.wrappers.EnumWrappers; | ||
| import com.comphenix.protocol.wrappers.EnumWrappers.ChatType; | ||
| import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
|
|
||
| public class WrapperPlayServerChat extends AbstractPacket { | ||
| public static final PacketType TYPE = PacketType.Play.Server.CHAT; | ||
|
|
||
| public WrapperPlayServerChat() { | ||
| super(new PacketContainer(TYPE), TYPE); | ||
| handle.getModifier().writeDefaults(); | ||
| } | ||
|
|
||
| public WrapperPlayServerChat(PacketContainer packet) { | ||
| super(packet, TYPE); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve the chat message. | ||
| * <p> | ||
| * Limited to 32767 bytes | ||
| * | ||
| * @return The current message | ||
| */ | ||
| public WrappedChatComponent getMessage() { | ||
| return handle.getChatComponents().read(0); | ||
| } | ||
|
|
||
| /** | ||
| * Set the message. | ||
| * | ||
| * @param value - new value. | ||
| */ | ||
| public void setMessage(WrappedChatComponent value) { | ||
| handle.getChatComponents().write(0, value); | ||
| } | ||
|
|
||
| public ChatType getChatType() { | ||
| return handle.getChatTypes().read(0); | ||
| } | ||
|
|
||
| public void setChatType(ChatType type) { | ||
| handle.getChatTypes().write(0, type); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve Position. | ||
| * <p> | ||
| * Notes: 0 - Chat (chat box) ,1 - System Message (chat box), 2 - Above | ||
| * action bar | ||
| * | ||
| * @return The current Position | ||
| * @deprecated Magic values replaced by enum | ||
| */ | ||
| @Deprecated | ||
| public byte getPosition() { | ||
| Byte position = handle.getBytes().readSafely(0); | ||
| if (position != null) { | ||
| return position; | ||
| } else { | ||
| return getChatType().getId(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set Position. | ||
| * | ||
| * @param value - new value. | ||
| * @deprecated Magic values replaced by enum | ||
| */ | ||
| @Deprecated | ||
| public void setPosition(byte value) { | ||
| handle.getBytes().writeSafely(0, value); | ||
|
|
||
| if (EnumWrappers.getChatTypeClass() != null) | ||
| { | ||
| Arrays.stream(ChatType.values()).filter(t -> t.getId() == value).findAny() | ||
| .ifPresent(t -> handle.getChatTypes().writeSafely(0, t)); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| import org.bukkit.entity.EntityType; | ||
| import org.bukkit.entity.Item; | ||
| import org.bukkit.entity.Player; | ||
| import net.md_5.bungee.chat.ComponentSerializer; | ||
| import net.md_5.bungee.api.chat.TextComponent; | ||
|
|
||
| import com.comphenix.packetwrapper.WrapperPlayClientBlockDig; | ||
| import com.comphenix.packetwrapper.WrapperPlayClientEntityAction; | ||
|
|
@@ -32,6 +34,7 @@ | |
| import com.comphenix.packetwrapper.WrapperPlayServerRelEntityMoveLook; | ||
| import com.comphenix.packetwrapper.WrapperPlayServerSpawnEntity; | ||
| import com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLiving; | ||
| import com.comphenix.packetwrapper.WrapperPlayServerChat; | ||
| import com.comphenix.protocol.PacketType; | ||
| import com.comphenix.protocol.ProtocolLibrary; | ||
| import com.comphenix.protocol.events.ListenerPriority; | ||
|
|
@@ -102,7 +105,7 @@ public void register() { | |
| this.packetAdapter = new PacketAdapter(ReplaySystem.getInstance(), ListenerPriority.HIGHEST, | ||
| PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Client.LOOK, PacketType.Play.Client.ENTITY_ACTION, PacketType.Play.Client.ARM_ANIMATION, | ||
| PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Server.SPAWN_ENTITY, PacketType.Play.Server.ENTITY_DESTROY, PacketType.Play.Server.ENTITY_VELOCITY, PacketType.Play.Server.SPAWN_ENTITY_LIVING, | ||
| PacketType.Play.Server.REL_ENTITY_MOVE, PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.POSITION, PacketType.Play.Server.ENTITY_TELEPORT) { | ||
| PacketType.Play.Server.REL_ENTITY_MOVE, PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.POSITION, PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Server.CHAT) { | ||
| @Override | ||
| public void onPacketReceiving(PacketEvent event) { | ||
|
|
||
|
|
@@ -306,6 +309,16 @@ public void onPacketSending(PacketEvent event) { | |
| addData(p.getName(), new EntityMovingData(packet.getEntityID(), loc.getX(), loc.getY(), loc.getZ(), packet.getPitch(), packet.getYaw())); | ||
| } | ||
| } | ||
| if(event.getPacketType() == PacketType.Play.Server.CHAT) { | ||
| if(ConfigManager.RECORD_CHAT && ConfigManager.RECORD_PLUGIN_MESSAGES) { | ||
|
|
||
| WrapperPlayServerChat packet = new WrapperPlayServerChat(event.getPacket()); | ||
|
|
||
| String message = new TextComponent(ComponentSerializer.parse(packet.getMessage().getJson())).toLegacyText(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some tests on Spigot 1.8.8 and there is an error message with plugin_messages enabled while trying to record death messages. I think the ComponentSerializer cannot parse the message.
|
||
| recorder.recordChat(p.getName(), message); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.