Move ChatResult to PlayerChatEvent and don't call event on spoofChatInput()
This commit is contained in:
@@ -111,45 +111,4 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,14 @@ 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;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
public class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.ChatResult> {
|
||||
private final Player player;
|
||||
private final String message;
|
||||
private ChatResult result;
|
||||
@@ -16,7 +19,7 @@ public class PlayerChatEvent implements ResultedEvent<ResultedEvent.ChatResult>
|
||||
public PlayerChatEvent(Player player, String message) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.message = Preconditions.checkNotNull(message, "message");
|
||||
this.result = (ChatResult) ChatResult.allowed();
|
||||
this.result = ChatResult.allowed();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
@@ -46,5 +49,49 @@ public class PlayerChatEvent implements ResultedEvent<ResultedEvent.ChatResult>
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the result of the {@link PlayerChatEvent}.
|
||||
*/
|
||||
public static class ChatResult implements ResultedEvent.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user