Compare commits
8
Commits
matrix
...
5a508fdf28
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a508fdf28 | ||
|
|
dc513ac2f0 | ||
|
|
c48d4f5c86 | ||
|
|
7f00bc104b | ||
|
|
133cebd1ec | ||
|
|
fc20c9a276 | ||
|
|
ea8e952108 | ||
|
|
3d010e4139 |
@@ -3,6 +3,9 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation(project(":web-api")) // Web-API
|
||||||
|
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||||
// Cosmos
|
// Cosmos
|
||||||
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
||||||
isChanging = true
|
isChanging = true
|
||||||
|
|||||||
@@ -15,15 +15,22 @@ import java.util.concurrent.CompletionException;
|
|||||||
public class ChatLogQueries {
|
public class ChatLogQueries {
|
||||||
|
|
||||||
protected static void createChatLogTable() {
|
protected static void createChatLogTable() {
|
||||||
String nicknamesTableQuery = "CREATE TABLE IF NOT EXISTS chat_log("
|
String nicknamesTableQuery = """
|
||||||
+ "uuid CHAR(48) NOT NULL,"
|
CREATE TABLE chat_log (
|
||||||
+ "time_stamp TIMESTAMP(6) NOT NULL, "
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
+ "server VARCHAR(50) NOT NULL, "
|
uuid CHAR(36) NOT NULL,
|
||||||
+ "chat_message VARCHAR(300) NOT NULL, "
|
time_stamp TIMESTAMP(6) NOT NULL,
|
||||||
+ "blocked BIT(1) NOT NULL DEFAULT 0"
|
server VARCHAR(50) NOT NULL,
|
||||||
+ ")";
|
chat_message VARCHAR(300) NOT NULL,
|
||||||
|
mini_message JSON,
|
||||||
|
blocked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
try (PreparedStatement preparedStatement = DatabaseConnection.getConnection().prepareStatement(nicknamesTableQuery)) {
|
INDEX idx_time_stamp (time_stamp)
|
||||||
|
)
|
||||||
|
""";
|
||||||
|
|
||||||
|
try (PreparedStatement preparedStatement = DatabaseConnection.getConnection().prepareStatement(
|
||||||
|
nicknamesTableQuery)) {
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
ALogger.error("Failed to create chat log table", throwable);
|
ALogger.error("Failed to create chat log table", throwable);
|
||||||
@@ -31,7 +38,7 @@ public class ChatLogQueries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull CompletableFuture<Boolean> storeMessages(HashMap<UUID, List<ChatLog>> chatMessages) {
|
public static @NotNull CompletableFuture<Boolean> storeMessages(HashMap<UUID, List<ChatLog>> chatMessages) {
|
||||||
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, blocked) VALUES (?, ?, ?, ?, ?)";
|
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, mini_message, blocked) VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try (Connection connection = DatabaseConnection.createTransactionConnection()) {
|
try (Connection connection = DatabaseConnection.createTransactionConnection()) {
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
||||||
@@ -76,7 +83,9 @@ public class ChatLogQueries {
|
|||||||
return chatLogs;
|
return chatLogs;
|
||||||
} catch (SQLException sqlException) {
|
} catch (SQLException sqlException) {
|
||||||
ALogger.error(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
ALogger.error(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
||||||
throw new CompletionException(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
throw new CompletionException(String.format("Failed to retrieve messages for user %s", uuid),
|
||||||
|
sqlException
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -90,8 +99,13 @@ public class ChatLogQueries {
|
|||||||
preparedStatement.setTimestamp(1, Timestamp.from(Instant.now().minus(duration)));
|
preparedStatement.setTimestamp(1, Timestamp.from(Instant.now().minus(duration)));
|
||||||
return preparedStatement.execute();
|
return preparedStatement.execute();
|
||||||
} catch (SQLException sqlException) {
|
} catch (SQLException sqlException) {
|
||||||
ALogger.error(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
ALogger.error(String.format("Failed to delete messages older than %s days", duration.toDays()),
|
||||||
throw new CompletionException(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
sqlException
|
||||||
|
);
|
||||||
|
throw new CompletionException(String.format("Failed to delete messages older than %s days",
|
||||||
|
duration.toDays()
|
||||||
|
), sqlException
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.alttd.chat.objects.chat_log;
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
import com.alttd.chat.objects.BatchInsertable;
|
import com.alttd.chat.objects.BatchInsertable;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -9,44 +14,44 @@ import java.sql.Timestamp;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
public class ChatLog implements BatchInsertable {
|
public class ChatLog implements BatchInsertable {
|
||||||
|
|
||||||
|
@Getter
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
@Getter
|
||||||
private final Instant timestamp;
|
private final Instant timestamp;
|
||||||
private final String server;
|
private final String server;
|
||||||
|
@Getter
|
||||||
private final String message;
|
private final String message;
|
||||||
|
@Getter
|
||||||
|
private final Component miniMessage;
|
||||||
|
@Getter
|
||||||
private final boolean blocked;
|
private final boolean blocked;
|
||||||
|
|
||||||
protected ChatLog(UUID uuid, Instant timestamp, String server, String message, boolean blocked) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.server = server;
|
|
||||||
this.message = message;
|
|
||||||
this.blocked = blocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareStatement(@NotNull PreparedStatement preparedStatement) throws SQLException {
|
public void prepareStatement(@NotNull PreparedStatement preparedStatement) throws SQLException {
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
preparedStatement.setTimestamp(2, Timestamp.from(timestamp));
|
preparedStatement.setTimestamp(2, Timestamp.from(timestamp));
|
||||||
preparedStatement.setString(3, server);
|
preparedStatement.setString(3, server);
|
||||||
preparedStatement.setString(4, message);
|
preparedStatement.setString(4, message);
|
||||||
preparedStatement.setInt(5, blocked ? 1 : 0);
|
preparedStatement.setString(5,
|
||||||
|
miniMessage == null ? null : GsonComponentSerializer.gson().serialize(miniMessage)
|
||||||
|
);
|
||||||
|
preparedStatement.setInt(6, blocked ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public ChatMessageDto toDto() {
|
||||||
return uuid;
|
ChatMessageDto chatMessageDto = new ChatMessageDto();
|
||||||
|
if (miniMessage == null) {
|
||||||
|
throw new IllegalArgumentException("MiniMessage cannot be null");
|
||||||
}
|
}
|
||||||
|
chatMessageDto.setMessage(GsonComponentSerializer.gson().serialize(miniMessage));
|
||||||
public Instant getTimestamp() {
|
chatMessageDto.setChannel(ChatMessageDto.ChannelEnum.CHAT);
|
||||||
return timestamp;
|
chatMessageDto.setServer(server);
|
||||||
}
|
chatMessageDto.setTimestamp(timestamp);
|
||||||
|
chatMessageDto.setUuid(uuid);
|
||||||
public String getMessage() {
|
chatMessageDto.setBlocked(blocked);
|
||||||
return message;
|
return chatMessageDto;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlocked() {
|
|
||||||
return blocked;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.alttd.chat.objects.chat_log;
|
|||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.ChatLogQueries;
|
import com.alttd.chat.database.ChatLogQueries;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -14,12 +16,14 @@ import java.util.concurrent.*;
|
|||||||
|
|
||||||
public class ChatLogHandler {
|
public class ChatLogHandler {
|
||||||
|
|
||||||
|
private final ChatLogWebHandler chatLogWebHandler = new ChatLogWebHandler();
|
||||||
private static ChatLogHandler instance = null;
|
private static ChatLogHandler instance = null;
|
||||||
private ScheduledExecutorService executorService = null;
|
private ScheduledExecutorService executorService = null;
|
||||||
|
|
||||||
public static ChatLogHandler getInstance(boolean enableLogging) {
|
public static ChatLogHandler getInstance(boolean enableLogging) {
|
||||||
if (instance == null)
|
if (instance == null) {
|
||||||
instance = new ChatLogHandler(enableLogging);
|
instance = new ChatLogHandler(enableLogging);
|
||||||
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,23 +39,30 @@ public class ChatLogHandler {
|
|||||||
Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
||||||
ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> {
|
ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> {
|
||||||
if (success) {
|
if (success) {
|
||||||
ALogger.info(String.format("Deleted all messages older than %s days from chat log database.", deleteThreshold.toDays()));
|
ALogger.info(String.format("Deleted all messages older than %s days from chat log database.",
|
||||||
|
deleteThreshold.toDays()
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
ALogger.warn(String.format("Failed to delete all messages older than %s days from chat log database.", deleteThreshold.toDays()));
|
ALogger.warn(String.format("Failed to delete all messages older than %s days from chat log database.",
|
||||||
|
deleteThreshold.toDays()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
executorService = Executors.newSingleThreadScheduledExecutor();
|
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
executorService.scheduleAtFixedRate(() -> {
|
executorService.scheduleAtFixedRate(() -> {
|
||||||
saveToDatabase(false);
|
saveToDatabase(false);
|
||||||
ALogger.info(String.format("Running scheduler to save messages with a %d delay", Config.CHAT_LOG_SAVE_DELAY_MINUTES));
|
ALogger.info(String.format("Running scheduler to save messages with a %d delay",
|
||||||
|
Config.CHAT_LOG_SAVE_DELAY_MINUTES
|
||||||
|
));
|
||||||
},
|
},
|
||||||
Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES);
|
Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES
|
||||||
|
);
|
||||||
ALogger.info("Logging has started!");
|
ALogger.info("Logging has started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shuts down the executor service and saves the chat logs to the database.
|
* Shuts down the executor service and saves the chat logs to the database. Will throw an error if called on a
|
||||||
* Will throw an error if called on a ChatLogHandler that was started without logging
|
* ChatLogHandler that was started without logging
|
||||||
*/
|
*/
|
||||||
public void shutDown() {
|
public void shutDown() {
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
@@ -66,7 +77,7 @@ public class ChatLogHandler {
|
|||||||
return isSaving;
|
return isSaving;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addLog(ChatLog chatLog) {
|
private synchronized void addLog(ChatLog chatLog) {
|
||||||
if (isBlocked()) {
|
if (isBlocked()) {
|
||||||
chatLogQueue.add(chatLog);
|
chatLogQueue.add(chatLog);
|
||||||
} else {
|
} else {
|
||||||
@@ -105,12 +116,17 @@ public class ChatLogHandler {
|
|||||||
Instant chatTimestamp = resultSet.getTimestamp("time_stamp").toInstant();
|
Instant chatTimestamp = resultSet.getTimestamp("time_stamp").toInstant();
|
||||||
String server = resultSet.getString("server");
|
String server = resultSet.getString("server");
|
||||||
String chatMessage = resultSet.getString("chat_message");
|
String chatMessage = resultSet.getString("chat_message");
|
||||||
|
String stringMiniMessage = resultSet.getString("mini_message");
|
||||||
|
Component miniMessage = stringMiniMessage == null ? null : GsonComponentSerializer.gson().deserialize(
|
||||||
|
stringMiniMessage);
|
||||||
boolean chatMessageBlocked = resultSet.getInt("blocked") == 1;
|
boolean chatMessageBlocked = resultSet.getInt("blocked") == 1;
|
||||||
return new ChatLog(chatLogUUID, chatTimestamp, server, chatMessage, chatMessageBlocked);
|
return new ChatLog(chatLogUUID, chatTimestamp, server, chatMessage, miniMessage, chatMessageBlocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChatLog(UUID uuid, String server, String message, boolean blocked) {
|
public void addChatLog(UUID uuid, String server, String message, Component miniMessage, boolean blocked) {
|
||||||
addLog(new ChatLog(uuid, Instant.now(), server, message, blocked));
|
ChatLog chatLog = new ChatLog(uuid, Instant.now(), server, message, miniMessage, blocked);
|
||||||
|
addLog(chatLog);
|
||||||
|
chatLogWebHandler.forwardChatLogToWeb(chatLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<List<ChatLog>> retrieveChatLogs(UUID uuid, Duration duration, String server) {
|
public CompletableFuture<List<ChatLog>> retrieveChatLogs(UUID uuid, Duration duration, String server) {
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
|
import com.alttd.altitudeweb.api.ChatApi;
|
||||||
|
import com.alttd.altitudeweb.invoker.ApiClient;
|
||||||
|
import com.alttd.altitudeweb.invoker.ApiException;
|
||||||
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class ChatLogWebHandler {
|
||||||
|
|
||||||
|
private static final int MAX_QUEUE_SIZE = 100;
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ChatLogWebHandler.class);
|
||||||
|
|
||||||
|
private final Queue<ChatLog> queue = new ConcurrentLinkedQueue<>();
|
||||||
|
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
private final ChatApi chatApi;
|
||||||
|
|
||||||
|
public ChatLogWebHandler() {
|
||||||
|
ApiClient apiClient = new ApiClient();
|
||||||
|
apiClient.setBasePath("http://10.0.0.109");
|
||||||
|
|
||||||
|
chatApi = new ChatApi(apiClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
private volatile boolean sending;
|
||||||
|
|
||||||
|
public void forwardChatLogToWeb(ChatLog chatLog) {
|
||||||
|
if (queue.size() >= MAX_QUEUE_SIZE) {
|
||||||
|
queue.clear();
|
||||||
|
log.error("Chat log queue overflow, is the web backend still running?");
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.add(chatLog);
|
||||||
|
triggerSend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerSend() {
|
||||||
|
if (sending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
if (sending || queue.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
executor.execute(this::sendBatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendBatch() {
|
||||||
|
try {
|
||||||
|
ArrayList<ChatLog> chatLogList = new ArrayList<>();
|
||||||
|
|
||||||
|
ChatLog log;
|
||||||
|
while ((log = queue.poll()) != null) {
|
||||||
|
if (log.getMiniMessage() == null) {
|
||||||
|
ALogger.warn("No mini message for message, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
chatLogList.add(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ChatMessageDto> batch = chatLogList.stream().map(ChatLog::toDto).toList();
|
||||||
|
|
||||||
|
if (!chatLogList.isEmpty()) {
|
||||||
|
try {
|
||||||
|
chatApi.sendChatMessages(batch);
|
||||||
|
} catch (ApiException e) {
|
||||||
|
ALogger.error("Failed to send chat messages to web backend, " +
|
||||||
|
"adding messages back to queue for another try", e
|
||||||
|
);
|
||||||
|
queue.addAll(chatLogList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
synchronized (this) {
|
||||||
|
sending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerSend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,20 @@ plugins {
|
|||||||
id("io.github.goooler.shadow")
|
id("io.github.goooler.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME")
|
||||||
|
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api")) // API
|
implementation(project(":api")) // API
|
||||||
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
||||||
isChanging = true
|
isChanging = true
|
||||||
}
|
}
|
||||||
|
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.6.1") // move to proxy
|
compileOnly("com.gitlab.ruany:LiteBansAPI:0.6.1") // move to proxy
|
||||||
compileOnly("org.apache.commons:commons-lang3:3.17.0") // needs an alternative, already removed from upstream api and will be removed in server
|
compileOnly("org.apache.commons:commons-lang3:3.17.0") // needs an alternative, already removed from upstream api and will be removed in server
|
||||||
compileOnly("net.luckperms:api:5.5") // Luckperms
|
compileOnly("net.luckperms:api:5.5") // Luckperms
|
||||||
|
implementation("com.alttd.inventory_gui:InventoryGUI:1.1.5-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ public class ChatListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component formatComponent = Component.text("%message%");
|
Component formatComponent = Component.text("%message%");
|
||||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
ComponentLike message = parseMessageContent(event.player(),
|
||||||
|
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||||
|
);
|
||||||
|
|
||||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,9 @@ public class ChatListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component formatComponent = Component.text("%message%");
|
Component formatComponent = Component.text("%message%");
|
||||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
ComponentLike message = parseMessageContent(event.player(),
|
||||||
|
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||||
|
);
|
||||||
|
|
||||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||||
}
|
}
|
||||||
@@ -92,8 +96,9 @@ public class ChatListener implements Listener {
|
|||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||||
|
Component inputComponent = input.asComponent();
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(input.asComponent());
|
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
||||||
|
|
||||||
// todo a better way for this
|
// todo a better way for this
|
||||||
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||||
@@ -107,12 +112,15 @@ public class ChatListener implements Listener {
|
|||||||
out.writeUTF(uuid.toString());
|
out.writeUTF(uuid.toString());
|
||||||
out.writeUTF(modifiableString.string());
|
out.writeUTF(modifiableString.string());
|
||||||
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
})) {
|
}
|
||||||
|
)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||||
modifiableString.component(),
|
modifiableString.component(),
|
||||||
"");
|
""
|
||||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input.asComponent()), true);
|
);
|
||||||
|
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
||||||
|
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), originalMessage, inputComponent, true);
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +128,8 @@ public class ChatListener implements Listener {
|
|||||||
.map(audience -> (Player) audience);
|
.map(audience -> (Player) audience);
|
||||||
|
|
||||||
if (!player.hasPermission("chat.ignorebypass")) {
|
if (!player.hasPermission("chat.ignorebypass")) {
|
||||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(
|
||||||
|
uuid)
|
||||||
|| receiver.hasPermission("chat.ignorebypass"));
|
|| receiver.hasPermission("chat.ignorebypass"));
|
||||||
}
|
}
|
||||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||||
@@ -135,8 +144,13 @@ public class ChatListener implements Listener {
|
|||||||
for (Player pingPlayer : playersToPing) {
|
for (Player pingPlayer : playersToPing) {
|
||||||
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||||
}
|
}
|
||||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
chatLogHandler.addChatLog(uuid,
|
||||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input.asComponent()));
|
ServerName.getServerName(),
|
||||||
|
modifiableString.string(),
|
||||||
|
modifiableString.component(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
ALogger.info(PlainTextComponentSerializer.plainText().serialize(inputComponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
||||||
|
|||||||
@@ -45,13 +45,83 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||||
if (sender instanceof Player player) {
|
if (!(sender instanceof Player player)) {
|
||||||
|
sender.sendMessage("Console commands are disabled.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "set":
|
case "set" -> setNickname(sender, args, player);
|
||||||
|
case "review" -> reviewNickname(sender, args, player);
|
||||||
|
case "request" -> requestNickname(sender, args, player);
|
||||||
|
case "try" -> tryNickname(sender, args, player);
|
||||||
|
case "current" -> showCurrentNickname(sender, player);
|
||||||
|
case "help" ->
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.ALL) + "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>");
|
||||||
|
default -> sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCurrentNickname(@NotNull CommandSender sender, Player player) {
|
||||||
|
if (!hasPermission(sender, "chat.command.nick.current")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.component("nickname", chatUser.getDisplayName()),
|
||||||
|
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
|
||||||
|
);
|
||||||
|
player.sendRichMessage(Config.NICK_CURRENT, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryNickname(@NotNull CommandSender sender, String[] args, Player player) {
|
||||||
|
if (args.length != 2 || !hasPermission(sender, "chat.command.nick.try")) {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.TRY));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LuckPerms api = ChatAPI.get().getLuckPerms();
|
||||||
|
if (api == null) {
|
||||||
|
sender.sendRichMessage(Config.NICK_NO_LUCKPERMS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!NickUtilities.validNick(player, player, args[1])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender.sendRichMessage(Config.NICK_TRYOUT,
|
||||||
|
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
||||||
|
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
||||||
|
Placeholder.component("nick", Utility.applyColor(args[1])),
|
||||||
|
Placeholder.unparsed("nickrequest", args[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestNickname(@NotNull CommandSender sender, String[] args, Player player) {
|
||||||
|
if (args.length != 2 || !hasPermission(sender, "chat.command.nick.request")) {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.REQUEST));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleNickRequest(player, args[1]);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reviewNickname(@NotNull CommandSender sender, String[] args, Player player) {
|
||||||
|
if (args.length != 1 || !hasPermission(sender, "chat.command.nick.review")) {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.REVIEW));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NicknamesGui nicknamesGui = new NicknamesGui(player);
|
||||||
|
ChatPlugin.getInstance().getServer().getPluginManager().registerEvents(nicknamesGui, ChatPlugin.getInstance());
|
||||||
|
nicknamesGui.openInventory(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNickname(@NotNull CommandSender sender, String[] args, Player player) {
|
||||||
if (args.length == 2 && hasPermission(sender, "chat.command.nick.set")) {
|
if (args.length == 2 && hasPermission(sender, "chat.command.nick.set")) {
|
||||||
handleNick(player, player, args[1]);
|
handleNick(player, player, args[1]);
|
||||||
} else if (args.length == 3 && hasPermission(sender, "chat.command.nick.set.others")) {
|
} else if (args.length == 3 && hasPermission(sender, "chat.command.nick.set.others")) {
|
||||||
@@ -65,67 +135,6 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
} else if (args.length > 3) {
|
} else if (args.length > 3) {
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS));
|
sender.sendRichMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case "review":
|
|
||||||
if (args.length == 1 && hasPermission(sender, "chat.command.nick.review")) {
|
|
||||||
NicknamesGui nicknamesGui = new NicknamesGui();
|
|
||||||
ChatPlugin.getInstance().getServer().getPluginManager().registerEvents(nicknamesGui, ChatPlugin.getInstance());
|
|
||||||
nicknamesGui.openInventory(player);
|
|
||||||
} else {
|
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.REVIEW));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "request":
|
|
||||||
if (args.length == 2 && hasPermission(sender, "chat.command.nick.request")) {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handleNickRequest(player, args[1]);
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
|
||||||
} else {
|
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.REQUEST));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "try":
|
|
||||||
if (args.length == 2 && hasPermission(sender, "chat.command.nick.try")) {
|
|
||||||
LuckPerms api = ChatAPI.get().getLuckPerms();
|
|
||||||
if (api != null) {
|
|
||||||
if (NickUtilities.validNick(player, player, args[1])) {
|
|
||||||
sender.sendRichMessage(Config.NICK_TRYOUT,
|
|
||||||
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
|
||||||
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
|
||||||
Placeholder.component("nick", Utility.applyColor(args[1])),
|
|
||||||
Placeholder.unparsed("nickrequest", args[1]));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendRichMessage(Config.NICK_NO_LUCKPERMS);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.TRY));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "current":
|
|
||||||
if (hasPermission(sender, "chat.command.nick.current")) {
|
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
|
||||||
Placeholder.component("nickname", chatUser.getDisplayName()),
|
|
||||||
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
|
|
||||||
);
|
|
||||||
player.sendRichMessage(Config.NICK_CURRENT, placeholders);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "help":
|
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL)
|
|
||||||
+ "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("Console commands are disabled.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -136,6 +145,33 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
|
tabCompleteArgLengthOne(sender, args, completions);
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
tabCompleteArgLengthTwo(sender, args, completions);
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void tabCompleteArgLengthTwo(CommandSender sender, String[] args, List<String> completions) {
|
||||||
|
if (!args[0].equalsIgnoreCase("set")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> choices = new ArrayList<>();
|
||||||
|
List<String> onlinePlayers = new ArrayList<>();
|
||||||
|
Bukkit.getOnlinePlayers().forEach(a -> onlinePlayers.add(a.getName()));
|
||||||
|
|
||||||
|
if (sender.hasPermission("chat.command.nick.set.others")) {
|
||||||
|
choices.addAll(onlinePlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : choices) {
|
||||||
|
if (s.startsWith(args[1])) {
|
||||||
|
completions.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void tabCompleteArgLengthOne(CommandSender sender, String[] args, List<String> completions) {
|
||||||
List<String> choices = new ArrayList<>();
|
List<String> choices = new ArrayList<>();
|
||||||
if (sender.hasPermission("chat.command.nick.set")) {
|
if (sender.hasPermission("chat.command.nick.set")) {
|
||||||
choices.add("set");
|
choices.add("set");
|
||||||
@@ -159,24 +195,6 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
completions.add(s);
|
completions.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (args.length == 2) {
|
|
||||||
if (args[0].equalsIgnoreCase("set")) {
|
|
||||||
List<String> choices = new ArrayList<>();
|
|
||||||
List<String> onlinePlayers = new ArrayList<>();
|
|
||||||
Bukkit.getOnlinePlayers().forEach(a -> onlinePlayers.add(a.getName()));
|
|
||||||
|
|
||||||
if (sender.hasPermission("chat.command.nick.set.others")) {
|
|
||||||
choices.addAll(onlinePlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String s : choices) {
|
|
||||||
if (s.startsWith(args[1])) {
|
|
||||||
completions.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return completions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNickRequest(Player player, String nickName) {
|
private void handleNickRequest(Player player, String nickName) {
|
||||||
@@ -261,31 +279,13 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
private void handleNick(Player sender, OfflinePlayer target, final String nickName) {
|
private void handleNick(Player sender, OfflinePlayer target, final String nickName) {
|
||||||
if (nickName.equalsIgnoreCase("off")) {
|
if (nickName.equalsIgnoreCase("off")) {
|
||||||
|
handleNickOff(sender, target);
|
||||||
try {
|
|
||||||
if (target.isOnline()) {
|
|
||||||
resetNick(Objects.requireNonNull(target.getPlayer()));
|
|
||||||
}
|
|
||||||
Queries.removePlayerFromDataBase(target.getUniqueId());
|
|
||||||
NickCache.remove(target.getUniqueId());
|
|
||||||
nickCacheUpdate.add(target.getUniqueId());
|
|
||||||
} catch (SQLException e) {
|
|
||||||
ALogger.error("Failed to remove nickname from database", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sender.equals(target)) {
|
|
||||||
sender.sendRichMessage(Config.NICK_RESET_OTHERS,
|
|
||||||
Placeholder.unparsed("player", Objects.requireNonNull(target.getName())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target.isOnline() && target.getPlayer() != null) {
|
|
||||||
target.getPlayer().sendRichMessage(Config.NICK_RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), null, NickEvent.NickEventType.RESET);
|
|
||||||
nickEvent.callEvent();
|
|
||||||
|
|
||||||
} else if (NickUtilities.validNick(sender, target, nickName)) {
|
} else if (NickUtilities.validNick(sender, target, nickName)) {
|
||||||
|
setValidNick(sender, target, nickName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setValidNick(Player sender, OfflinePlayer target, String nickName) {
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
setNick(target.getPlayer(), nickName);
|
setNick(target.getPlayer(), nickName);
|
||||||
} else {
|
} else {
|
||||||
@@ -322,6 +322,30 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
|||||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())));
|
Placeholder.unparsed("nickname", getNick(target.getPlayer())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleNickOff(Player sender, OfflinePlayer target) {
|
||||||
|
try {
|
||||||
|
if (target.isOnline()) {
|
||||||
|
resetNick(Objects.requireNonNull(target.getPlayer()));
|
||||||
|
}
|
||||||
|
Queries.removePlayerFromDataBase(target.getUniqueId());
|
||||||
|
NickCache.remove(target.getUniqueId());
|
||||||
|
nickCacheUpdate.add(target.getUniqueId());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.error("Failed to remove nickname from database", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.equals(target)) {
|
||||||
|
sender.sendRichMessage(Config.NICK_RESET_OTHERS,
|
||||||
|
Placeholder.unparsed("player", Objects.requireNonNull(target.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.isOnline() && target.getPlayer() != null) {
|
||||||
|
target.getPlayer().sendRichMessage(Config.NICK_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), null, NickEvent.NickEventType.RESET);
|
||||||
|
nickEvent.callEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String helpMessage(final CommandSender sender, final HelpType... helpTypes) {
|
private String helpMessage(final CommandSender sender, final HelpType... helpTypes) {
|
||||||
|
|||||||
@@ -5,24 +5,22 @@ import com.alttd.chat.config.Config;
|
|||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.events.NickEvent;
|
import com.alttd.chat.events.NickEvent;
|
||||||
import com.alttd.chat.objects.Nick;
|
import com.alttd.chat.objects.Nick;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.inventory_gui.click.GuiItem;
|
||||||
|
import com.alttd.inventory_gui.gui.InventoryGui;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
@@ -31,39 +29,45 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class NicknamesGui implements Listener {
|
public class NicknamesGui implements Listener {
|
||||||
|
|
||||||
private final Inventory inv;
|
public static final String UNKNOWN_PLAYER_NAME = "UNKNOWN PLAYER NAME";
|
||||||
private final int currentPage;
|
private final int currentPage;
|
||||||
|
private final ChatPlugin plugin = ChatPlugin.getInstance();
|
||||||
|
private final InventoryGui nicknamesGui;
|
||||||
|
|
||||||
public NicknamesGui() {
|
public NicknamesGui(Player player) {
|
||||||
// Create a new inventory, with no owner (as this isn't a real inventory)
|
nicknamesGui = InventoryGui.builder()
|
||||||
inv = Bukkit.createInventory(null, 36, Utility.parseMiniMessage("Nicknames GUI").asComponent());
|
.plugin(plugin)
|
||||||
|
.title(Component.text("Nicknames GUI"))
|
||||||
// Put the items into the inventory
|
.rows(6)
|
||||||
|
.build();
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
setItems(currentPage);
|
setItems(currentPage, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(int currentPage) {
|
public void setItems(int currentPage, Player player) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
inv.clear();
|
|
||||||
NickUtilities.updateCache();
|
NickUtilities.updateCache();
|
||||||
boolean hasNextPage = false;
|
boolean hasNextPage = false;
|
||||||
int i = (currentPage - 1) * 27; //TODO set to 1 or 2 to test
|
int i = (currentPage - 1) * 27; //TODO set to 1 or 2 to test
|
||||||
int limit = i / 27;
|
int limit = i / 27;
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
for (Nick nick : Nicknames.getInstance().NickCache.values()) {
|
for (Nick nick : Nicknames.getInstance().NickCache.values()) {
|
||||||
if (nick.hasRequest()) {
|
if (nick.hasRequest()) {
|
||||||
if (limit >= i / 27) {
|
if (limit >= i / 27) {
|
||||||
inv.setItem(i % 27, createPlayerSkull(nick, Config.NICK_ITEM_LORE));
|
ItemStack playerSkull = createPlayerSkull(nick, Config.NICK_ITEM_LORE);
|
||||||
|
nicknamesGui.getRoot().setItem(i % 27, GuiItem.clickable(playerSkull, inventoryClickEvent ->
|
||||||
|
handleInventoryClick(nick, inventoryClickEvent, miniMessage, playerSkull)));
|
||||||
|
ALogger.info("Added nick " + i + " to gui: " + nick.getUuid());
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
|
ALogger.info("Reached end of nicknames gui page");
|
||||||
hasNextPage = true;
|
hasNextPage = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -71,20 +75,137 @@ public class NicknamesGui implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentPage != 1) {
|
if (currentPage != 1) {
|
||||||
inv.setItem(28, createGuiItem(Material.PAPER, "§bPrevious page",
|
ItemStack itemStack = createGuiItem(Material.PAPER, "§bPrevious page",
|
||||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||||
"§aPrevious page: %previousPage%".replace("%previousPage%", String.valueOf(currentPage - 1))));
|
"§aPrevious page: %previousPage%".replace("%previousPage%", String.valueOf(currentPage - 1)));
|
||||||
|
GuiItem previousPage = GuiItem.clickable(itemStack, e -> setItems(currentPage - 1, player));
|
||||||
|
nicknamesGui.getRoot().setItem(28, previousPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNextPage) {
|
if (hasNextPage) {
|
||||||
inv.setItem(36, createGuiItem(Material.PAPER, "§bNext page",
|
ItemStack itemStack = createGuiItem(Material.PAPER, "§bNext page",
|
||||||
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||||
"§aNext page: §b%nextPage%".replace("%nextPage%", String.valueOf(currentPage + 1))));
|
"§aNext page: §b%nextPage%".replace("%nextPage%", String.valueOf(currentPage + 1)));
|
||||||
|
GuiItem nextPage = GuiItem.clickable(itemStack, e -> setItems(currentPage + 1, player));
|
||||||
|
nicknamesGui.getRoot().setItem(36, nextPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nicknamesGui.render(player);
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleInventoryClick(Nick nick, InventoryClickEvent inventoryClickEvent, MiniMessage miniMessage, ItemStack playerSkull) {
|
||||||
|
final Player playerWhoClicked = (Player) inventoryClickEvent.getWhoClicked();
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(nick.getUuid());
|
||||||
|
Component offlinePlayerName = miniMessage.deserialize(getOfflinePlayerName(offlinePlayer));
|
||||||
|
if (!nick.hasRequest()) {
|
||||||
|
playerWhoClicked.sendRichMessage(Config.NICK_ALREADY_HANDLED,
|
||||||
|
Placeholder.component("targetplayer", offlinePlayerName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (inventoryClickEvent.isLeftClick()) {
|
||||||
|
handleLeftClickPlayerSkull(nick, inventoryClickEvent, offlinePlayer, playerWhoClicked, offlinePlayerName, playerSkull);
|
||||||
|
} else if (inventoryClickEvent.isRightClick()) {
|
||||||
|
handleRightClickPlayerSkull(nick, inventoryClickEvent, offlinePlayer, playerWhoClicked, offlinePlayerName, playerSkull);
|
||||||
|
}
|
||||||
|
//TODO what do we do no click?
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRightClickPlayerSkull(Nick nick, InventoryClickEvent inventoryClickEvent, OfflinePlayer offlinePlayer, Player playerWhoClicked, Component offlinePlayerName, ItemStack playerSkull) {
|
||||||
|
Queries.denyNewNickname(nick.getUuid());
|
||||||
|
|
||||||
|
String newNick = nick.getNewNick();
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NickEvent nickEvent = new NickEvent(inventoryClickEvent.getWhoClicked().getName(), getOfflinePlayerName(offlinePlayer), newNick, NickEvent.NickEventType.DENIED);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
}
|
||||||
|
}.runTask(ChatPlugin.getInstance());
|
||||||
|
|
||||||
|
playerWhoClicked.sendRichMessage(Config.NICK_DENIED,
|
||||||
|
Placeholder.unparsed("targetplayer", getOfflinePlayerName(offlinePlayer)),
|
||||||
|
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? getOfflinePlayerName(offlinePlayer) : nick.getCurrentNick())));
|
||||||
|
|
||||||
|
if (Nicknames.getInstance().NickCache.containsKey(nick.getUuid())
|
||||||
|
&& Nicknames.getInstance().NickCache.get(nick.getUuid()).getCurrentNick() != null) {
|
||||||
|
nick.setNewNick(null);
|
||||||
|
nick.setRequestedDate(0);
|
||||||
|
Nicknames.getInstance().NickCache.put(nick.getUuid(), nick);
|
||||||
|
} else {
|
||||||
|
Nicknames.getInstance().NickCache.remove(nick.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offlinePlayer.isOnline() && offlinePlayer.getPlayer() != null) {
|
||||||
|
Nicknames.getInstance().setNick(offlinePlayer.getPlayer(), nick.getCurrentNick() == null ? getOfflinePlayerName(offlinePlayer) : nick.getCurrentNick());
|
||||||
|
offlinePlayer.getPlayer().sendRichMessage(Config.NICK_NOT_CHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
|
NickUtilities.bungeeMessageHandled(nick.getUuid(), inventoryClickEvent.getWhoClicked().getServer().getPlayer(inventoryClickEvent.getWhoClicked().getName()), "Denied");
|
||||||
|
final ComponentLike messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
||||||
|
Placeholder.unparsed("name", getOfflinePlayerName(offlinePlayer)));
|
||||||
|
ChatPlugin.getInstance().getServer().getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.hasPermission("chat.command.nick.review"))
|
||||||
|
.forEach(player -> player.sendMessage(messageDenied));
|
||||||
|
|
||||||
|
ItemStack completedNickRequestItem = createCompletedNickRequestItem(offlinePlayerName, playerSkull);
|
||||||
|
inventoryClickEvent.getInventory().setItem(inventoryClickEvent.getSlot(), completedNickRequestItem);
|
||||||
|
nicknamesGui.render(playerWhoClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLeftClickPlayerSkull(Nick nick, InventoryClickEvent inventoryClickEvent, OfflinePlayer offlinePlayer, Player playerWhoClicked, Component offlinePlayerName, ItemStack playerSkull) {
|
||||||
|
Queries.acceptNewNickname(nick.getUuid(), nick.getNewNick());
|
||||||
|
|
||||||
|
String newNick = nick.getNewNick();
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NickEvent nickEvent = new NickEvent(inventoryClickEvent.getWhoClicked().getName(), getOfflinePlayerName(offlinePlayer), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
}
|
||||||
|
}.runTask(ChatPlugin.getInstance());
|
||||||
|
|
||||||
|
playerWhoClicked.sendRichMessage(Config.NICK_ACCEPTED,
|
||||||
|
Placeholder.component("targetplayer", offlinePlayerName),
|
||||||
|
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
Placeholder.component("oldnick", nick.getCurrentNick() == null ? offlinePlayerName : Utility.applyColor(nick.getCurrentNick())));
|
||||||
|
|
||||||
|
Player affectedPlayer = offlinePlayer.getPlayer();
|
||||||
|
if (offlinePlayer.isOnline() && affectedPlayer != null) {
|
||||||
|
Nicknames.getInstance().setNick(affectedPlayer, nick.getNewNick());
|
||||||
|
}
|
||||||
|
|
||||||
|
NickUtilities.bungeeMessageHandled(nick.getUuid(), inventoryClickEvent.getWhoClicked().getServer().getPlayer(inventoryClickEvent.getWhoClicked().getName()), "Accepted");
|
||||||
|
|
||||||
|
nick.setCurrentNick(nick.getNewNick());
|
||||||
|
nick.setLastChangedDate(new Date().getTime());
|
||||||
|
nick.setNewNick(null);
|
||||||
|
nick.setRequestedDate(0);
|
||||||
|
|
||||||
|
Nicknames.getInstance().NickCache.put(nick.getUuid(), nick);
|
||||||
|
|
||||||
|
ItemStack completedNickRequestItem = createCompletedNickRequestItem(offlinePlayerName, playerSkull);
|
||||||
|
inventoryClickEvent.getInventory().setItem(inventoryClickEvent.getSlot(), completedNickRequestItem);
|
||||||
|
nicknamesGui.render(playerWhoClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack createCompletedNickRequestItem(Component offlinePlayerName, ItemStack playerSkull) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
itemMeta.displayName(offlinePlayerName);
|
||||||
|
itemMeta.lore(playerSkull.lore());
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getOfflinePlayerName(OfflinePlayer offlinePlayer) {
|
||||||
|
return offlinePlayer.getName() == null ? UNKNOWN_PLAYER_NAME : offlinePlayer.getName();
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack createPlayerSkull(Nick nick, List<String> lore) {
|
private ItemStack createPlayerSkull(Nick nick, List<String> lore) {
|
||||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
|
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
|
||||||
@@ -94,9 +215,9 @@ public class NicknamesGui implements Listener {
|
|||||||
meta.setOwningPlayer(offlinePlayer);
|
meta.setOwningPlayer(offlinePlayer);
|
||||||
String name = offlinePlayer.getName();
|
String name = offlinePlayer.getName();
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
meta.displayName(miniMessage.deserialize("UNKNOWN PLAYER NAME"));
|
meta.displayName(miniMessage.deserialize("<red>" + getOfflinePlayerName(offlinePlayer) + "</red>"));
|
||||||
} else {
|
} else {
|
||||||
meta.displayName(miniMessage.deserialize(offlinePlayer.getName()));
|
meta.displayName(miniMessage.deserialize(getOfflinePlayerName(offlinePlayer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TagResolver resolver = TagResolver.resolver(
|
TagResolver resolver = TagResolver.resolver(
|
||||||
@@ -128,185 +249,6 @@ public class NicknamesGui implements Listener {
|
|||||||
|
|
||||||
// You can open the inventory with this
|
// You can open the inventory with this
|
||||||
public void openInventory(final HumanEntity ent) {//Possibly with a boolean to show if it should get from cache or update cache
|
public void openInventory(final HumanEntity ent) {//Possibly with a boolean to show if it should get from cache or update cache
|
||||||
ent.openInventory(inv);
|
nicknamesGui.open(ent);
|
||||||
}
|
|
||||||
|
|
||||||
// Check for clicks on items
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
|
||||||
public void onInventoryClick(InventoryClickEvent e) {
|
|
||||||
if (e.getInventory() != inv) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
final ItemStack clickedItem = e.getCurrentItem();
|
|
||||||
|
|
||||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Player p = (Player) e.getWhoClicked();
|
|
||||||
|
|
||||||
if (clickedItem.getType().equals(Material.PAPER)) {
|
|
||||||
Component component = clickedItem.getItemMeta().displayName();
|
|
||||||
if (component == null) {
|
|
||||||
throw new IllegalStateException("Nicknames GUI: Item with no display name clicked!");
|
|
||||||
}
|
|
||||||
String serialize = PlainTextComponentSerializer.plainText().serialize(component);
|
|
||||||
if (serialize.equals("Next Page")) {
|
|
||||||
setItems(currentPage + 1);
|
|
||||||
}
|
|
||||||
} else if (clickedItem.getType().equals(Material.PLAYER_HEAD)) {
|
|
||||||
ItemMeta itemMeta = clickedItem.getItemMeta();
|
|
||||||
if (itemMeta == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SkullMeta meta = (SkullMeta) itemMeta;
|
|
||||||
if (meta.hasEnchants()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
OfflinePlayer owningPlayer = meta.getOwningPlayer();
|
|
||||||
|
|
||||||
if (owningPlayer == null) {
|
|
||||||
p.sendRichMessage(Config.NICK_USER_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
NickUtilities.updateCache();
|
|
||||||
|
|
||||||
Nick nick;
|
|
||||||
UUID uniqueId = owningPlayer.getUniqueId();
|
|
||||||
if (Nicknames.getInstance().NickCache.containsKey(uniqueId)) {
|
|
||||||
nick = Nicknames.getInstance().NickCache.get(uniqueId);
|
|
||||||
} else {
|
|
||||||
nick = Queries.getNick(uniqueId);
|
|
||||||
}
|
|
||||||
Component itemDisplayName = itemMeta.displayName();
|
|
||||||
if (itemDisplayName == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nick == null || !nick.hasRequest()) {
|
|
||||||
p.sendRichMessage(Config.NICK_ALREADY_HANDLED,
|
|
||||||
Placeholder.component("targetplayer", itemDisplayName))
|
|
||||||
;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.isLeftClick()) {
|
|
||||||
if (owningPlayer.hasPlayedBefore()) {
|
|
||||||
Queries.acceptNewNickname(uniqueId, nick.getNewNick());
|
|
||||||
|
|
||||||
String newNick = nick.getNewNick();
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
|
||||||
nickEvent.callEvent();
|
|
||||||
}
|
|
||||||
}.runTask(ChatPlugin.getInstance());
|
|
||||||
|
|
||||||
p.sendRichMessage(Config.NICK_ACCEPTED,
|
|
||||||
Placeholder.component("targetplayer", itemDisplayName),
|
|
||||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
|
||||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? itemMeta.getDisplayName() : nick.getCurrentNick())));
|
|
||||||
|
|
||||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
|
||||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getNewNick());
|
|
||||||
}
|
|
||||||
|
|
||||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Accepted");
|
|
||||||
|
|
||||||
nick.setCurrentNick(nick.getNewNick());
|
|
||||||
nick.setLastChangedDate(new Date().getTime());
|
|
||||||
nick.setNewNick(null);
|
|
||||||
nick.setRequestedDate(0);
|
|
||||||
|
|
||||||
Nicknames.getInstance().NickCache.put(uniqueId, nick);
|
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.displayName(itemMeta.displayName());
|
|
||||||
itemMeta.lore(clickedItem.lore());
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
|
||||||
p.updateInventory();
|
|
||||||
} else {
|
|
||||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (e.isRightClick()) {
|
|
||||||
if (owningPlayer.hasPlayedBefore()) {
|
|
||||||
Queries.denyNewNickname(uniqueId);
|
|
||||||
|
|
||||||
String newNick = nick.getNewNick();
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
|
||||||
nickEvent.callEvent();
|
|
||||||
}
|
|
||||||
}.runTask(ChatPlugin.getInstance());
|
|
||||||
|
|
||||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_DENIED,
|
|
||||||
Placeholder.unparsed("targetplayer", owningPlayer.getName()),
|
|
||||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
|
||||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick()))));
|
|
||||||
|
|
||||||
if (Nicknames.getInstance().NickCache.containsKey(uniqueId)
|
|
||||||
&& Nicknames.getInstance().NickCache.get(uniqueId).getCurrentNick() != null) {
|
|
||||||
nick.setNewNick(null);
|
|
||||||
nick.setRequestedDate(0);
|
|
||||||
Nicknames.getInstance().NickCache.put(uniqueId, nick);
|
|
||||||
} else {
|
|
||||||
Nicknames.getInstance().NickCache.remove(uniqueId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
|
||||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
|
||||||
owningPlayer.getPlayer().sendRichMessage(Config.NICK_NOT_CHANGED);
|
|
||||||
}
|
|
||||||
|
|
||||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Denied");
|
|
||||||
final ComponentLike messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
|
||||||
Placeholder.unparsed("name", owningPlayer.getName()));
|
|
||||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
|
||||||
if (p.hasPermission("chat.command.nick.review")) {
|
|
||||||
p.sendMessage(messageDenied);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.displayName(itemDisplayName);
|
|
||||||
itemMeta.lore(clickedItem.lore());
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
|
||||||
p.updateInventory();
|
|
||||||
} else {
|
|
||||||
if (itemDisplayName == null) {
|
|
||||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.parsed("player", "UNKNOWN PLAYER NAME"));
|
|
||||||
} else {
|
|
||||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel dragging in our inventory
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
|
||||||
public void onInventoryClick(InventoryDragEvent e) {
|
|
||||||
if (e.getInventory() == inv) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -9,13 +9,12 @@ val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
|
|||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositories {
|
repositories {
|
||||||
// mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://repo.alttd.com/snapshots") // Altitude - Galaxy
|
maven("https://repo.alttd.com/snapshots") // Altitude - Galaxy
|
||||||
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
||||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
||||||
maven("https://nexus.velocitypowered.com/repository/") // Velocity
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
|
||||||
maven("https://repo.spongepowered.org/maven") // Configurate
|
maven("https://repo.spongepowered.org/maven") // Configurate
|
||||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
||||||
maven("https://jitpack.io")
|
maven("https://jitpack.io")
|
||||||
@@ -36,3 +35,5 @@ pluginManagement {
|
|||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include("web-api")
|
||||||
@@ -5,8 +5,10 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api")) // API
|
implementation(project(":api")) // API
|
||||||
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||||
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||||
|
compileOnly("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||||
|
annotationProcessor("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||||
implementation("mysql:mysql-connector-java:8.0.33") // mysql
|
implementation("mysql:mysql-connector-java:8.0.33") // mysql
|
||||||
implementation("org.spongepowered", "configurate-yaml", "4.2.0")
|
implementation("org.spongepowered", "configurate-yaml", "4.2.0")
|
||||||
compileOnly("net.kyori:adventure-text-minimessage:4.23.0")
|
compileOnly("net.kyori:adventure-text-minimessage:4.23.0")
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.alttd.chat.util.Utility;
|
|||||||
import com.alttd.velocitychat.VelocityChat;
|
import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.events.GlobalAdminChatEvent;
|
import com.alttd.velocitychat.events.GlobalAdminChatEvent;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
@@ -19,7 +18,7 @@ public class ChatListener {
|
|||||||
plugin = VelocityChat.getPlugin();
|
plugin = VelocityChat.getPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(priority = 0)
|
||||||
public void onGlobalStaffChat(GlobalAdminChatEvent event) {
|
public void onGlobalStaffChat(GlobalAdminChatEvent event) {
|
||||||
String senderName = Config.CONSOLENAME;
|
String senderName = Config.CONSOLENAME;
|
||||||
String serverName = "Altitude";
|
String serverName = "Altitude";
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import com.alttd.velocitychat.VelocityChat;
|
|||||||
import com.alttd.velocitychat.commands.vote_to_mute.ActiveVoteToMute;
|
import com.alttd.velocitychat.commands.vote_to_mute.ActiveVoteToMute;
|
||||||
import com.alttd.velocitychat.data.ServerWrapper;
|
import com.alttd.velocitychat.data.ServerWrapper;
|
||||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
import com.alttd.velocitychat.handlers.ServerHandler;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||||
@@ -34,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class ProxyPlayerListener {
|
public class ProxyPlayerListener {
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(priority = 0)
|
||||||
public void onPlayerLogin(LoginEvent event) {
|
public void onPlayerLogin(LoginEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
@@ -57,7 +56,7 @@ public class ProxyPlayerListener {
|
|||||||
ServerHandler.addPlayerUUID(player.getUsername(), uuid);
|
ServerHandler.addPlayerUUID(player.getUsername(), uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(priority = 4)
|
||||||
public void afterPlayerLogin(ServerPostConnectEvent event) {
|
public void afterPlayerLogin(ServerPostConnectEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
RegisteredServer previousServer = event.getPreviousServer();
|
RegisteredServer previousServer = event.getPreviousServer();
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
plugins {
|
||||||
|
java
|
||||||
|
id("org.openapi.generator") version "7.12.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.alttd.chat"
|
||||||
|
version = "2.0.0-SNAPSHOT"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("io.swagger.core.v3:swagger-annotations:2.2.28")
|
||||||
|
|
||||||
|
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||||
|
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
|
||||||
|
|
||||||
|
implementation("com.google.code.gson:gson:2.12.1")
|
||||||
|
implementation("io.gsonfire:gson-fire:1.9.0")
|
||||||
|
|
||||||
|
implementation("javax.annotation:javax.annotation-api:1.3.2")
|
||||||
|
implementation("jakarta.annotation:jakarta.annotation-api:2.1.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
srcDir("${projectDir}/build/generated-sources/client/src/main/java")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerate") {
|
||||||
|
generatorName.set("java")
|
||||||
|
inputSpec.set("${projectDir}/src/main/resources/chat-api.yml")
|
||||||
|
configFile.set("${projectDir}/src/main/resources/config_backend.json")
|
||||||
|
outputDir.set("${projectDir}/build/generated-sources/client")
|
||||||
|
|
||||||
|
apiPackage.set("com.alttd.altitudeweb.api")
|
||||||
|
modelPackage.set("com.alttd.altitudeweb.model")
|
||||||
|
|
||||||
|
modelNameSuffix.set("Dto")
|
||||||
|
|
||||||
|
additionalProperties.set(
|
||||||
|
mapOf(
|
||||||
|
"dateLibrary" to "java8",
|
||||||
|
"library" to "okhttp-gson"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
typeMappings.set(mapOf("OffsetDateTime" to "Instant"))
|
||||||
|
importMappings.set(mapOf("OffsetDateTime" to "java.time.Instant"))
|
||||||
|
|
||||||
|
generateApiTests.set(false)
|
||||||
|
generateApiDocumentation.set(false)
|
||||||
|
generateModelTests.set(false)
|
||||||
|
generateModelDocumentation.set(false)
|
||||||
|
|
||||||
|
generateAliasAsModel.set(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
srcDir(layout.buildDirectory.dir("generated/openapi/src/main/java"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.compileJava {
|
||||||
|
dependsOn("openApiGenerate")
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
|
||||||
|
info:
|
||||||
|
title: Minecraft Network API
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
|
servers:
|
||||||
|
- url: http://localhost:8080/api
|
||||||
|
|
||||||
|
tags:
|
||||||
|
- name: chat
|
||||||
|
description: Data for displaying Chat messages to clients
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/chat/send/chat/message:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- chat
|
||||||
|
summary: Sends one or more chat messages
|
||||||
|
operationId: sendChatMessages
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/ChatMessage"
|
||||||
|
responses:
|
||||||
|
"202":
|
||||||
|
description: Accepted
|
||||||
|
|
||||||
|
/chat/send/servers/state:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- chat
|
||||||
|
summary: Update server states
|
||||||
|
operationId: updateServerStates
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/ServerState"
|
||||||
|
responses:
|
||||||
|
"202":
|
||||||
|
description: Accepted
|
||||||
|
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
User:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- uuid
|
||||||
|
- name
|
||||||
|
- styledName
|
||||||
|
|
||||||
|
properties:
|
||||||
|
uuid:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
styledName:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
ChatMessage:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- uuid
|
||||||
|
- message
|
||||||
|
- channel
|
||||||
|
- server
|
||||||
|
- timestamp
|
||||||
|
- blocked
|
||||||
|
properties:
|
||||||
|
uuid:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
channel:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- CHAT
|
||||||
|
- PARTY
|
||||||
|
- AC
|
||||||
|
- GAC
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
server:
|
||||||
|
type: string
|
||||||
|
timestamp:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
blocked:
|
||||||
|
type: boolean
|
||||||
|
|
||||||
|
PrivateMessage:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- sender
|
||||||
|
- receiver
|
||||||
|
- message
|
||||||
|
- senderServer
|
||||||
|
- receiverServer
|
||||||
|
properties:
|
||||||
|
sender:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
receiver:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
senderServer:
|
||||||
|
type: string
|
||||||
|
receiverServer:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
Server:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
players:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/User"
|
||||||
|
|
||||||
|
ServerState:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
servers:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/Server"
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"library": "okhttp-gson",
|
||||||
|
"hideGenerationTimestamp": true,
|
||||||
|
"modelPackage": "com.alttd.altitudeweb.model",
|
||||||
|
"apiPackage": "com.alttd.altitudeweb.api",
|
||||||
|
"invokerPackage": "com.alttd.altitudeweb.invoker",
|
||||||
|
"serializableModel": true,
|
||||||
|
"openApiNullable": false,
|
||||||
|
"useTags": true,
|
||||||
|
"generateApis": true,
|
||||||
|
"generateApiTests": false,
|
||||||
|
"generateApiDocumentation": false,
|
||||||
|
"generateModels": true,
|
||||||
|
"generateModelTests": false,
|
||||||
|
"generateSupportingFiles": true,
|
||||||
|
"modelNameSuffix": "Dto",
|
||||||
|
"generateTests": false,
|
||||||
|
"dateLibrary": "java8",
|
||||||
|
"enumUnknownDefaultCase": true,
|
||||||
|
"disallowAdditionalPropertiesIfNotPresent": false,
|
||||||
|
"useJakartaEe": true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user