Add chat event
This commit is contained in:
@@ -111,4 +111,45 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
|
||||
return new ComponentResult(false, reason);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatResult implements Result {
|
||||
private static final ChatResult ALLOWED = new ChatResult(true, null);
|
||||
private static final ChatResult DENIED = new ChatResult(false, null);
|
||||
|
||||
// The server can not accept formatted text from clients!
|
||||
private @Nullable String message;
|
||||
private final boolean allowed;
|
||||
|
||||
protected ChatResult(boolean allowed, @Nullable String message) {
|
||||
this.allowed = allowed;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowed() {
|
||||
return allowed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return allowed ? "allowed" : "denied";
|
||||
}
|
||||
|
||||
public static ChatResult allowed() {
|
||||
return ALLOWED;
|
||||
}
|
||||
|
||||
public static ChatResult denied() {
|
||||
return DENIED;
|
||||
}
|
||||
|
||||
public Optional<String> getMessage() {
|
||||
return Optional.ofNullable(message);
|
||||
}
|
||||
|
||||
public static ChatResult message(@NonNull String message) {
|
||||
Preconditions.checkNotNull(message, "message");
|
||||
return new ChatResult(true, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
package com.velocitypowered.api.event.player;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* This event is fired once the player has been authenticated but before they connect to a server on the proxy.
|
||||
*/
|
||||
public class PlayerChatEvent implements ResultedEvent<ResultedEvent.ChatResult> {
|
||||
private final Player player;
|
||||
private final String message;
|
||||
private ChatResult result;
|
||||
|
||||
public PlayerChatEvent(Player player, String message) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.message = Preconditions.checkNotNull(message, "message");
|
||||
this.result = (ChatResult) ChatResult.allowed();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(@NonNull ChatResult result) {
|
||||
this.result = Preconditions.checkNotNull(result, "result");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlayerChatEvent{" +
|
||||
"player=" + player +
|
||||
", message=" + message +
|
||||
", result=" + result +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user