Move ChatResult to PlayerChatEvent and don't call event on spoofChatInput()

This commit is contained in:
Thomas Vanmellaerts
2018-09-26 19:47:38 +02:00
parent d71f863045
commit 3acc00de5e
5 changed files with 51 additions and 53 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}