Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Fire Event on spoofChatInput
Dieser Commit ist enthalten in:
Ursprung
7598918d93
Commit
d71f863045
@ -13,6 +13,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.*;
|
||||
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
|
||||
import com.velocitypowered.proxy.util.EventUtil;
|
||||
import com.velocitypowered.proxy.util.ThrowableUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
@ -97,18 +98,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
PlayerChatEvent event = new PlayerChatEvent(player, msg);
|
||||
server.getEventManager().fire(event)
|
||||
.thenAcceptAsync(pme -> {
|
||||
if (pme.getResult().equals(ResultedEvent.ChatResult.allowed())){
|
||||
player.getConnectedServer().getMinecraftConnection().write(chat);
|
||||
} else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){
|
||||
Chat modifiedChat = new Chat();
|
||||
modifiedChat.setType(Chat.CHAT);
|
||||
modifiedChat.setMessage(pme.getResult().getMessage().get());
|
||||
player.getConnectedServer().getMinecraftConnection().write(modifiedChat);
|
||||
}
|
||||
}, player.getConnectedServer().getMinecraftConnection().getChannel().eventLoop());
|
||||
EventUtil.callPlayerChatEvent(server, player, msg, chat);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolConstants;
|
||||
import com.velocitypowered.proxy.protocol.packet.*;
|
||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||
import com.velocitypowered.proxy.util.EventUtil;
|
||||
import com.velocitypowered.proxy.util.ThrowableUtils;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
@ -420,7 +421,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
@Override
|
||||
public void spoofChatInput(String input) {
|
||||
Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH, "input cannot be greater than " + Chat.MAX_SERVERBOUND_MESSAGE_LENGTH + " characters in length");
|
||||
connectedServer.getMinecraftConnection().write(Chat.createServerbound(input));
|
||||
EventUtil.callPlayerChatEvent(server, this, input, Chat.createServerbound(input));
|
||||
}
|
||||
|
||||
private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
|
||||
|
25
proxy/src/main/java/com/velocitypowered/proxy/util/EventUtil.java
Normale Datei
25
proxy/src/main/java/com/velocitypowered/proxy/util/EventUtil.java
Normale Datei
@ -0,0 +1,25 @@
|
||||
package com.velocitypowered.proxy.util;
|
||||
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class EventUtil {
|
||||
|
||||
public static void callPlayerChatEvent(VelocityServer server, ConnectedPlayer player, String message, Chat original){
|
||||
PlayerChatEvent event = new PlayerChatEvent(player, message);
|
||||
server.getEventManager().fire(event)
|
||||
.thenAcceptAsync(pme -> {
|
||||
if (pme.getResult().equals(ResultedEvent.ChatResult.allowed())){
|
||||
player.getConnectedServer().getMinecraftConnection().write(original);
|
||||
} else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){
|
||||
player.getConnectedServer().getMinecraftConnection().write(Chat.createServerbound(pme.getResult().getMessage().get()));
|
||||
}
|
||||
}, player.getConnectedServer().getMinecraftConnection().getChannel().eventLoop());
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren