Compare commits
4 Commits
421f6655fd
...
e72f79cb29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e72f79cb29 | ||
|
|
5eb470cfb6 | ||
|
|
d99ac4c597 | ||
|
|
5a4140c2e2 |
|
|
@ -3,7 +3,10 @@ package com.alttd.chat.objects;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -89,9 +92,15 @@ public class ChatUser {
|
||||||
return Utility.getStaffPrefix(uuid);
|
return Utility.getStaffPrefix(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComponentLike getPrefixAll() {
|
public ComponentLike getPrefixAll(boolean isWebMessage) {
|
||||||
//return prefixAll;
|
//return prefixAll;
|
||||||
return Utility.getPrefix(uuid, false);
|
ComponentLike prefix = Utility.getPrefix(uuid, false);
|
||||||
|
if (isWebMessage) {
|
||||||
|
//TODO [Stijn] [2026-08-08]: Check icon
|
||||||
|
TextComponent webIcon = Component.text("\uD83D\uDEDC").color(NamedTextColor.DARK_AQUA);
|
||||||
|
prefix = webIcon.append(prefix);
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReplyTarget() {
|
public String getReplyTarget() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.alttd.chat.objects.chat_log;
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
import com.alttd.chat.objects.BatchInsertable;
|
import com.alttd.chat.objects.BatchInsertable;
|
||||||
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogTypeMapper;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,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.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogTypeMapper;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
@ -18,13 +20,13 @@ import java.util.concurrent.*;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ChatLogHandler {
|
public class ChatLogHandler {
|
||||||
|
|
||||||
private final ChatLogWebHandler chatLogWebHandler = new ChatLogWebHandler();
|
private final WebHandler webHandler;
|
||||||
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(WebHandler webHandler, boolean enableLogging) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new ChatLogHandler(enableLogging);
|
instance = new ChatLogHandler(webHandler, enableLogging);
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +35,8 @@ public class ChatLogHandler {
|
||||||
private final Queue<ChatLog> chatLogQueue = new ConcurrentLinkedQueue<>();
|
private final Queue<ChatLog> chatLogQueue = new ConcurrentLinkedQueue<>();
|
||||||
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
|
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
|
||||||
|
|
||||||
public ChatLogHandler(boolean enableLogging) {
|
public ChatLogHandler(WebHandler webHandler, boolean enableLogging) {
|
||||||
|
this.webHandler = webHandler;
|
||||||
if (!enableLogging) {
|
if (!enableLogging) {
|
||||||
ALogger.info("Logging is not enabled on this server.");
|
ALogger.info("Logging is not enabled on this server.");
|
||||||
return;
|
return;
|
||||||
|
|
@ -156,7 +159,7 @@ public class ChatLogHandler {
|
||||||
blocked
|
blocked
|
||||||
);
|
);
|
||||||
addLog(chatLog);
|
addLog(chatLog);
|
||||||
chatLogWebHandler.forwardChatLogToWeb(chatLog);
|
webHandler.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,31 @@
|
||||||
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
|
import com.alttd.altitudeweb.invoker.ApiCallback;
|
||||||
|
import com.alttd.altitudeweb.invoker.ApiException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SilentApiHandler implements ApiCallback<Void> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
|
||||||
|
log.error("Failed to update server states", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void result, int statusCode, Map<String, List<String>> responseHeaders) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,9 +5,11 @@ import com.alttd.altitudeweb.invoker.ApiClient;
|
||||||
import com.alttd.altitudeweb.invoker.ApiException;
|
import com.alttd.altitudeweb.invoker.ApiException;
|
||||||
import com.alttd.altitudeweb.model.ChatMessageDto;
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogMapper;
|
||||||
|
import com.alttd.chat.objects.chat_log.mapper.server_state.ServerMapper;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -17,17 +19,17 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class ChatLogWebHandler {
|
@Slf4j
|
||||||
|
public class WebHandler {
|
||||||
|
|
||||||
private static final int MAX_QUEUE_SIZE = 100;
|
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 Queue<ChatLog> queue = new ConcurrentLinkedQueue<>();
|
||||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
private final ChatApi chatApi;
|
private final ChatApi chatApi;
|
||||||
|
|
||||||
public ChatLogWebHandler() {
|
public WebHandler() {
|
||||||
ApiClient apiClient = new ApiClient();
|
ApiClient apiClient = new ApiClient();
|
||||||
apiClient.setBasePath(Config.CHAT_WEB_SERVER_BASE_URL);
|
apiClient.setBasePath(Config.CHAT_WEB_SERVER_BASE_URL);
|
||||||
|
|
||||||
|
|
@ -46,6 +48,14 @@ public class ChatLogWebHandler {
|
||||||
triggerSend();
|
triggerSend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateServerState(String serverName, List<Player> playerList) {
|
||||||
|
try {
|
||||||
|
chatApi.updateServerStatesAsync(ServerMapper.toDto(serverName, playerList), new SilentApiHandler());
|
||||||
|
} catch (ApiException e) {
|
||||||
|
log.error("Failed to update server state", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void triggerSend() {
|
private void triggerSend() {
|
||||||
if (sending) {
|
if (sending) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.chat.objects.chat_log;
|
package com.alttd.chat.objects.chat_log.mapper.chat_log;
|
||||||
|
|
||||||
import com.alttd.altitudeweb.model.ChatMessageDto;
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLog;
|
||||||
import jakarta.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
import jakarta.validation.Validation;
|
import jakarta.validation.Validation;
|
||||||
import jakarta.validation.Validator;
|
import jakarta.validation.Validator;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects.chat_log;
|
package com.alttd.chat.objects.chat_log.mapper.chat_log;
|
||||||
|
|
||||||
public enum ChatLogType {
|
public enum ChatLogType {
|
||||||
PUBLIC,
|
PUBLIC,
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects.chat_log;
|
package com.alttd.chat.objects.chat_log.mapper.chat_log;
|
||||||
|
|
||||||
import com.alttd.altitudeweb.model.ChatMessageDto;
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.alttd.chat.objects.chat_log.mapper.server_state;
|
||||||
|
|
||||||
|
import com.alttd.altitudeweb.model.ServerDto;
|
||||||
|
import com.alttd.altitudeweb.model.ServerStateDto;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class ServerMapper {
|
||||||
|
|
||||||
|
public static ServerStateDto toDto(String serverName, List<Player> playerList) {
|
||||||
|
ServerStateDto serverStateDto = new ServerStateDto();
|
||||||
|
ServerDto serverDto = new ServerDto();
|
||||||
|
|
||||||
|
serverDto.setName(serverName);
|
||||||
|
serverDto.setPlayers(playerList.stream().map(UserMapper::toDto).toList());
|
||||||
|
serverStateDto.setServers(List.of(serverDto));
|
||||||
|
return serverStateDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.alttd.chat.objects.chat_log.mapper.server_state;
|
||||||
|
|
||||||
|
import com.alttd.altitudeweb.model.UserDto;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class UserMapper {
|
||||||
|
public static UserDto toDto(Player player) {
|
||||||
|
UserDto userDto = new UserDto();
|
||||||
|
userDto.setName(player.getName());
|
||||||
|
userDto.setUuid(player.getUniqueId());
|
||||||
|
userDto.setStyledName(GsonComponentSerializer.gson().serialize(player.displayName()));
|
||||||
|
return userDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ import com.alttd.chat.nicknames.NicknamesEvents;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import com.alttd.chat.objects.chat_log.WebHandler;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.ServerName;
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
|
@ -42,12 +43,13 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
instance = this;
|
instance = this;
|
||||||
ALogger.init(getSLF4JLogger());
|
ALogger.init(getSLF4JLogger());
|
||||||
chatAPI = new ChatImplementation();
|
chatAPI = new ChatImplementation();
|
||||||
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
WebHandler webHandler = new WebHandler();
|
||||||
|
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(webHandler, true);
|
||||||
chatHandler = new ChatHandler(chatLogHandler);
|
chatHandler = new ChatHandler(chatLogHandler);
|
||||||
DatabaseConnection.initialize();
|
DatabaseConnection.initialize();
|
||||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||||
ChatMessageSender chatMessageSender = new ChatMessageSender(chatLogHandler, chatAPI.getLuckPerms());
|
ChatMessageSender chatMessageSender = new ChatMessageSender(chatLogHandler, chatAPI.getLuckPerms());
|
||||||
registerListener(new PlayerListener(serverConfig),
|
registerListener(new PlayerListener(webHandler, serverConfig),
|
||||||
new ChatListener(chatMessageSender),
|
new ChatListener(chatMessageSender),
|
||||||
new BookListener(),
|
new BookListener(),
|
||||||
new ShutdownListener(chatLogHandler, this)
|
new ShutdownListener(chatLogHandler, this)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.FilterType;
|
import com.alttd.chat.objects.FilterType;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogType;
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
import com.alttd.chat.util.ServerName;
|
import com.alttd.chat.util.ServerName;
|
||||||
|
|
@ -50,27 +50,28 @@ public class ChatMessageSender {
|
||||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
public void sendMessage(UUID sender, String message) {
|
public void sendMessage(UUID sender, String message) {
|
||||||
|
//TODO [Stijn] [2026-08-02]: Mark as from website
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender);
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender);
|
||||||
Component component = miniMessage.deserialize(message);
|
Component component = miniMessage.deserialize(message);
|
||||||
sendMessage(offlinePlayer, component);
|
sendMessage(offlinePlayer, component, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(@NotNull OfflinePlayer offlinePlayer, Component message) {
|
public void sendMessage(@NotNull OfflinePlayer offlinePlayer, Component message, boolean isFromWeb) {
|
||||||
UUID uuid = offlinePlayer.getUniqueId();
|
UUID uuid = offlinePlayer.getUniqueId();
|
||||||
if (luckPerms.getUserManager().isLoaded(uuid)) {
|
if (luckPerms.getUserManager().isLoaded(uuid)) {
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
sendMessage(user, offlinePlayer, message);
|
sendMessage(user, offlinePlayer, message, isFromWeb);
|
||||||
} else {
|
} else {
|
||||||
luckPerms.getUserManager().loadUser(uuid).whenComplete((user, throwable) -> {
|
luckPerms.getUserManager().loadUser(uuid).whenComplete((user, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
ALogger.error("Failed to load user: " + uuid, throwable);
|
ALogger.error("Failed to load user: " + uuid, throwable);
|
||||||
}
|
}
|
||||||
sendMessage(user, offlinePlayer, message);
|
sendMessage(user, offlinePlayer, message, isFromWeb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(User user, OfflinePlayer offlinePlayer, Component message) {
|
private void sendMessage(User user, OfflinePlayer offlinePlayer, Component message, boolean isFromWeb) {
|
||||||
if (offlinePlayer == null) {
|
if (offlinePlayer == null) {
|
||||||
ALogger.error("OfflinePlayer is null");
|
ALogger.error("OfflinePlayer is null");
|
||||||
return;
|
return;
|
||||||
|
|
@ -87,7 +88,7 @@ public class ChatMessageSender {
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
||||||
|
|
||||||
if (parseMessage(offlinePlayer, uuid, modifiableString, inputComponent)) {
|
if (parseMessage(offlinePlayer, uuid, modifiableString, inputComponent, isFromWeb)) {
|
||||||
//Parse message failed likely due to something the player said, already logged
|
//Parse message failed likely due to something the player said, already logged
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +119,7 @@ public class ChatMessageSender {
|
||||||
Set<Player> playersToPing = new HashSet<>();
|
Set<Player> playersToPing = new HashSet<>();
|
||||||
pingPlayers(playersToPing, modifiableString, offlinePlayer, user);
|
pingPlayers(playersToPing, modifiableString, offlinePlayer, user);
|
||||||
|
|
||||||
Optional<ComponentLike> render = render(offlinePlayer, modifiableString.component());
|
Optional<ComponentLike> render = render(offlinePlayer, modifiableString.component(), false);
|
||||||
if (render.isEmpty()) {
|
if (render.isEmpty()) {
|
||||||
//Already logged
|
//Already logged
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -142,7 +143,7 @@ public class ChatMessageSender {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseMessage(OfflinePlayer offlinePlayer, UUID uuid, ModifiableString modifiableString, Component inputComponent) {
|
private boolean parseMessage(OfflinePlayer offlinePlayer, UUID uuid, ModifiableString modifiableString, Component inputComponent, boolean isWebMessage) {
|
||||||
// todo a better way for this
|
// todo a better way for this
|
||||||
if (!RegexManager.filterText(offlinePlayer.getName(), uuid, modifiableString, true, "chat",
|
if (!RegexManager.filterText(offlinePlayer.getName(), uuid, modifiableString, true, "chat",
|
||||||
filterType -> punishOnlinePlayer(filterType, uuid, modifiableString)
|
filterType -> punishOnlinePlayer(filterType, uuid, modifiableString)
|
||||||
|
|
@ -152,7 +153,10 @@ public class ChatMessageSender {
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
||||||
Optional<Component> component = render(offlinePlayer, inputComponent).map(ComponentLike::asComponent);
|
Optional<Component> component = render(offlinePlayer,
|
||||||
|
inputComponent,
|
||||||
|
isWebMessage
|
||||||
|
).map(ComponentLike::asComponent);
|
||||||
if (component.isEmpty()) {
|
if (component.isEmpty()) {
|
||||||
//Already logged
|
//Already logged
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -220,7 +224,7 @@ public class ChatMessageSender {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ComponentLike> render(@NotNull OfflinePlayer offlinePlayer, @NotNull Component message) {
|
private Optional<ComponentLike> render(@NotNull OfflinePlayer offlinePlayer, @NotNull Component message, boolean isWebMessage) {
|
||||||
if (offlinePlayer.getName() == null) {
|
if (offlinePlayer.getName() == null) {
|
||||||
ALogger.error("Invalid offline player");
|
ALogger.error("Invalid offline player");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -231,7 +235,7 @@ public class ChatMessageSender {
|
||||||
Placeholder.component("sender", user.getDisplayName()),
|
Placeholder.component("sender", user.getDisplayName()),
|
||||||
Placeholder.parsed("sendername", offlinePlayer.getName()),
|
Placeholder.parsed("sendername", offlinePlayer.getName()),
|
||||||
Placeholder.component("prefix", user.getPrefix()),
|
Placeholder.component("prefix", user.getPrefix()),
|
||||||
Placeholder.component("prefixall", user.getPrefixAll()),
|
Placeholder.component("prefixall", user.getPrefixAll(isWebMessage)),
|
||||||
Placeholder.component("staffprefix", user.getStaffPrefix()),
|
Placeholder.component("staffprefix", user.getStaffPrefix()),
|
||||||
Placeholder.component("message", message)
|
Placeholder.component("message", message)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogType;
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
import com.alttd.chat.util.ServerName;
|
import com.alttd.chat.util.ServerName;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ public class ChatListener implements Listener {
|
||||||
toggleable.sendMessage(event.getPlayer(), event.message());
|
toggleable.sendMessage(event.getPlayer(), event.message());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chatMessageSender.sendMessage(event.getPlayer(), event.message());
|
chatMessageSender.sendMessage(event.getPlayer(), event.message(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.objects.Toggleable;
|
import com.alttd.chat.objects.Toggleable;
|
||||||
|
import com.alttd.chat.objects.chat_log.WebHandler;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
@ -30,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -38,8 +40,10 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
private final ServerConfig serverConfig;
|
private final ServerConfig serverConfig;
|
||||||
|
private final WebHandler webHandler;
|
||||||
|
|
||||||
public PlayerListener(ServerConfig serverConfig) {
|
public PlayerListener(WebHandler webHandler, ServerConfig serverConfig) {
|
||||||
|
this.webHandler = webHandler;
|
||||||
this.serverConfig = serverConfig;
|
this.serverConfig = serverConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,13 +54,16 @@ public class PlayerListener implements Listener {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
Toggleable.disableToggles(uuid);
|
Toggleable.disableToggles(uuid);
|
||||||
|
|
||||||
if (serverConfig.FIRST_JOIN_MESSAGES && (!player.hasPlayedBefore() || System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(10))) {
|
if (serverConfig.FIRST_JOIN_MESSAGES && (!player.hasPlayedBefore() || System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
10))) {
|
||||||
|
Bukkit.broadcast(MiniMessage.miniMessage()
|
||||||
|
.deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
if(user != null) return;
|
if (user != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// user failed to load - create a new one
|
// user failed to load - create a new one
|
||||||
ChatUser chatUser = new ChatUser(uuid, -1, null);
|
ChatUser chatUser = new ChatUser(uuid, -1, null);
|
||||||
|
|
@ -64,6 +71,7 @@ public class PlayerListener implements Listener {
|
||||||
Queries.saveUser(chatUser);
|
Queries.saveUser(chatUser);
|
||||||
|
|
||||||
//TODO load player on other servers with plugin message?
|
//TODO load player on other servers with plugin message?
|
||||||
|
updateServerState(event.getPlayer(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
@ -71,8 +79,24 @@ public class PlayerListener implements Listener {
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
ChatUserManager.removeUser(user);
|
ChatUserManager.removeUser(user);
|
||||||
|
updateServerState(event.getPlayer(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateServerState(Player triggerPlayer, boolean add) {
|
||||||
|
ArrayList<Player> playerList = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||||
|
if (add) {
|
||||||
|
if (playerList.stream()
|
||||||
|
.filter(player -> player.getUniqueId().equals(triggerPlayer.getUniqueId()))
|
||||||
|
.findFirst()
|
||||||
|
.isEmpty()) {
|
||||||
|
playerList.add(triggerPlayer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
playerList.removeIf(player -> player.getUniqueId().equals(triggerPlayer.getUniqueId()));
|
||||||
|
}
|
||||||
|
String name = Bukkit.getServer().getName();
|
||||||
|
webHandler.updateServerState(name, playerList);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true) // untested
|
@EventHandler(ignoreCancelled = true) // untested
|
||||||
public void onSignChangeE(SignChangeEvent event) {
|
public void onSignChangeE(SignChangeEvent event) {
|
||||||
|
|
@ -88,7 +112,8 @@ public class PlayerListener implements Listener {
|
||||||
GalaxyUtility.sendBlockedNotification("Sign Language",
|
GalaxyUtility.sendBlockedNotification("Sign Language",
|
||||||
player,
|
player,
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
"");
|
""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
component = modifiableString.component() == null ? Component.empty() : modifiableString.component();
|
component = modifiableString.component() == null ? Component.empty() : modifiableString.component();
|
||||||
|
|
@ -99,6 +124,7 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final HashMap<UUID, Stack<Instant>> sendPlayerDeaths = new HashMap<>();
|
private final HashMap<UUID, Stack<Instant>> sendPlayerDeaths = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
|
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
|
@ -113,7 +139,7 @@ public class PlayerListener implements Listener {
|
||||||
event.deathMessage(Component.empty());
|
event.deathMessage(Component.empty());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Component component = event.deathMessage();
|
Component component = event.deathMessage();
|
||||||
|
|
||||||
playerDeathsStack.push(Instant.now());
|
playerDeathsStack.push(Instant.now());
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
|
|
@ -132,7 +158,9 @@ public class PlayerListener implements Listener {
|
||||||
.build();
|
.build();
|
||||||
component = component.replaceText(killerReplacement);
|
component = component.replaceText(killerReplacement);
|
||||||
}
|
}
|
||||||
component = MiniMessage.miniMessage().deserialize("<dark_red>[</dark_red><red>☠</red><dark_red>]</dark_red> ").append(component);
|
component = MiniMessage.miniMessage()
|
||||||
|
.deserialize("<dark_red>[</dark_red><red>☠</red><dark_red>]</dark_red> ")
|
||||||
|
.append(component);
|
||||||
component = component.style(Style.style(TextColor.color(255, 155, 48), TextDecoration.ITALIC));
|
component = component.style(Style.style(TextColor.color(255, 155, 48), TextDecoration.ITALIC));
|
||||||
event.deathMessage(component);
|
event.deathMessage(component);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import com.alttd.chat.objects.PartyUser;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogType;
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.ServerName;
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import com.alttd.chat.objects.chat_log.WebHandler;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.velocitychat.commands.*;
|
import com.alttd.velocitychat.commands.*;
|
||||||
import com.alttd.velocitychat.handlers.ChatHandler;
|
import com.alttd.velocitychat.handlers.ChatHandler;
|
||||||
|
|
@ -67,7 +68,9 @@ public class VelocityChat {
|
||||||
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
|
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
|
||||||
|
|
||||||
serverHandler = new ServerHandler();
|
serverHandler = new ServerHandler();
|
||||||
ChatLogHandler chatLogHandler = new ChatLogHandler(true);
|
WebHandler webHandler = new WebHandler();
|
||||||
|
|
||||||
|
ChatLogHandler chatLogHandler = new ChatLogHandler(webHandler, true);
|
||||||
chatHandler = new ChatHandler(chatLogHandler);
|
chatHandler = new ChatHandler(chatLogHandler);
|
||||||
server.getEventManager().register(this, new ChatListener());
|
server.getEventManager().register(this, new ChatListener());
|
||||||
server.getEventManager().register(this, new ProxyPlayerListener());
|
server.getEventManager().register(this, new ProxyPlayerListener());
|
||||||
|
|
@ -76,7 +79,7 @@ public class VelocityChat {
|
||||||
channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]);
|
channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]);
|
||||||
server.getChannelRegistrar().register(channelIdentifier);
|
server.getChannelRegistrar().register(channelIdentifier);
|
||||||
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||||
loadCommands();
|
loadCommands(webHandler);
|
||||||
// setup console chatuser
|
// setup console chatuser
|
||||||
ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null);
|
ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null);
|
||||||
console.setDisplayName(Config.CONSOLENAME);
|
console.setDisplayName(Config.CONSOLENAME);
|
||||||
|
|
@ -113,8 +116,8 @@ public class VelocityChat {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommands() {
|
public void loadCommands(WebHandler webHandler) {
|
||||||
ChatLogHandler instance = ChatLogHandler.getInstance(false);
|
ChatLogHandler instance = ChatLogHandler.getInstance(webHandler, false);
|
||||||
new SilentJoinCommand(server);
|
new SilentJoinCommand(server);
|
||||||
new GlobalAdminChat(server);
|
new GlobalAdminChat(server);
|
||||||
new Reload(server);
|
new Reload(server);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.*;
|
import com.alttd.chat.objects.*;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import com.alttd.chat.objects.chat_log.ChatLogType;
|
import com.alttd.chat.objects.chat_log.mapper.chat_log.ChatLogType;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.alttd.velocitychat.VelocityChat;
|
import com.alttd.velocitychat.VelocityChat;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user