Compare commits
No commits in common. "e72f79cb2927149f880044e365d026985845f90f" and "421f6655fdbecb94ff852c4f6787355493677262" have entirely different histories.
e72f79cb29
...
421f6655fd
|
|
@ -3,10 +3,7 @@ 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;
|
||||||
|
|
@ -92,15 +89,9 @@ public class ChatUser {
|
||||||
return Utility.getStaffPrefix(uuid);
|
return Utility.getStaffPrefix(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComponentLike getPrefixAll(boolean isWebMessage) {
|
public ComponentLike getPrefixAll() {
|
||||||
//return prefixAll;
|
//return prefixAll;
|
||||||
ComponentLike prefix = Utility.getPrefix(uuid, false);
|
return 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,8 +1,6 @@
|
||||||
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,8 +2,6 @@ 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;
|
||||||
|
|
@ -20,13 +18,13 @@ import java.util.concurrent.*;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ChatLogHandler {
|
public class ChatLogHandler {
|
||||||
|
|
||||||
private final WebHandler webHandler;
|
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(WebHandler webHandler, boolean enableLogging) {
|
public static ChatLogHandler getInstance(boolean enableLogging) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new ChatLogHandler(webHandler, enableLogging);
|
instance = new ChatLogHandler(enableLogging);
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
@ -35,8 +33,7 @@ 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(WebHandler webHandler, boolean enableLogging) {
|
public ChatLogHandler(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;
|
||||||
|
|
@ -159,7 +156,7 @@ public class ChatLogHandler {
|
||||||
blocked
|
blocked
|
||||||
);
|
);
|
||||||
addLog(chatLog);
|
addLog(chatLog);
|
||||||
webHandler.forwardChatLogToWeb(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) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.alttd.chat.objects.chat_log.mapper.chat_log;
|
package com.alttd.chat.objects.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.mapper.chat_log;
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
public enum ChatLogType {
|
public enum ChatLogType {
|
||||||
PUBLIC,
|
PUBLIC,
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects.chat_log.mapper.chat_log;
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
import com.alttd.altitudeweb.model.ChatMessageDto;
|
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
@ -5,11 +5,9 @@ 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 lombok.extern.slf4j.Slf4j;
|
import org.slf4j.Logger;
|
||||||
import org.bukkit.entity.Player;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -19,17 +17,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;
|
||||||
|
|
||||||
@Slf4j
|
public class ChatLogWebHandler {
|
||||||
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 WebHandler() {
|
public ChatLogWebHandler() {
|
||||||
ApiClient apiClient = new ApiClient();
|
ApiClient apiClient = new ApiClient();
|
||||||
apiClient.setBasePath(Config.CHAT_WEB_SERVER_BASE_URL);
|
apiClient.setBasePath(Config.CHAT_WEB_SERVER_BASE_URL);
|
||||||
|
|
||||||
|
|
@ -48,14 +46,6 @@ public class WebHandler {
|
||||||
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,31 +0,0 @@
|
||||||
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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
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,7 +13,6 @@ 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;
|
||||||
|
|
@ -43,13 +42,12 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
instance = this;
|
instance = this;
|
||||||
ALogger.init(getSLF4JLogger());
|
ALogger.init(getSLF4JLogger());
|
||||||
chatAPI = new ChatImplementation();
|
chatAPI = new ChatImplementation();
|
||||||
WebHandler webHandler = new WebHandler();
|
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||||
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(webHandler, serverConfig),
|
registerListener(new PlayerListener(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.mapper.chat_log.ChatLogType;
|
import com.alttd.chat.objects.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,28 +50,27 @@ 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, true);
|
sendMessage(offlinePlayer, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(@NotNull OfflinePlayer offlinePlayer, Component message, boolean isFromWeb) {
|
public void sendMessage(@NotNull OfflinePlayer offlinePlayer, Component message) {
|
||||||
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, isFromWeb);
|
sendMessage(user, offlinePlayer, message);
|
||||||
} 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, isFromWeb);
|
sendMessage(user, offlinePlayer, message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(User user, OfflinePlayer offlinePlayer, Component message, boolean isFromWeb) {
|
private void sendMessage(User user, OfflinePlayer offlinePlayer, Component message) {
|
||||||
if (offlinePlayer == null) {
|
if (offlinePlayer == null) {
|
||||||
ALogger.error("OfflinePlayer is null");
|
ALogger.error("OfflinePlayer is null");
|
||||||
return;
|
return;
|
||||||
|
|
@ -88,7 +87,7 @@ public class ChatMessageSender {
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
ModifiableString modifiableString = new ModifiableString(inputComponent);
|
||||||
|
|
||||||
if (parseMessage(offlinePlayer, uuid, modifiableString, inputComponent, isFromWeb)) {
|
if (parseMessage(offlinePlayer, uuid, modifiableString, inputComponent)) {
|
||||||
//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;
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +118,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(), false);
|
Optional<ComponentLike> render = render(offlinePlayer, modifiableString.component());
|
||||||
if (render.isEmpty()) {
|
if (render.isEmpty()) {
|
||||||
//Already logged
|
//Already logged
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -143,7 +142,7 @@ public class ChatMessageSender {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseMessage(OfflinePlayer offlinePlayer, UUID uuid, ModifiableString modifiableString, Component inputComponent, boolean isWebMessage) {
|
private boolean parseMessage(OfflinePlayer offlinePlayer, UUID uuid, ModifiableString modifiableString, Component inputComponent) {
|
||||||
// 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)
|
||||||
|
|
@ -153,10 +152,7 @@ public class ChatMessageSender {
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
||||||
Optional<Component> component = render(offlinePlayer,
|
Optional<Component> component = render(offlinePlayer, inputComponent).map(ComponentLike::asComponent);
|
||||||
inputComponent,
|
|
||||||
isWebMessage
|
|
||||||
).map(ComponentLike::asComponent);
|
|
||||||
if (component.isEmpty()) {
|
if (component.isEmpty()) {
|
||||||
//Already logged
|
//Already logged
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -224,7 +220,7 @@ public class ChatMessageSender {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ComponentLike> render(@NotNull OfflinePlayer offlinePlayer, @NotNull Component message, boolean isWebMessage) {
|
private Optional<ComponentLike> render(@NotNull OfflinePlayer offlinePlayer, @NotNull Component message) {
|
||||||
if (offlinePlayer.getName() == null) {
|
if (offlinePlayer.getName() == null) {
|
||||||
ALogger.error("Invalid offline player");
|
ALogger.error("Invalid offline player");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -235,7 +231,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(isWebMessage)),
|
Placeholder.component("prefixall", user.getPrefixAll()),
|
||||||
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.mapper.chat_log.ChatLogType;
|
import com.alttd.chat.objects.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(), false);
|
chatMessageSender.sendMessage(event.getPlayer(), event.message());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ 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;
|
||||||
|
|
@ -31,7 +30,6 @@ 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;
|
||||||
|
|
@ -40,10 +38,8 @@ 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(WebHandler webHandler, ServerConfig serverConfig) {
|
public PlayerListener(ServerConfig serverConfig) {
|
||||||
this.webHandler = webHandler;
|
|
||||||
this.serverConfig = serverConfig;
|
this.serverConfig = serverConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,16 +50,13 @@ 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(
|
if (serverConfig.FIRST_JOIN_MESSAGES && (!player.hasPlayedBefore() || System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(10))) {
|
||||||
10))) {
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
||||||
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) {
|
if(user != null) return;
|
||||||
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);
|
||||||
|
|
@ -71,7 +64,6 @@ 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
|
||||||
|
|
@ -79,24 +71,8 @@ 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) {
|
||||||
|
|
@ -112,8 +88,7 @@ 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();
|
||||||
|
|
@ -124,7 +99,6 @@ 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();
|
||||||
|
|
@ -158,9 +132,7 @@ public class PlayerListener implements Listener {
|
||||||
.build();
|
.build();
|
||||||
component = component.replaceText(killerReplacement);
|
component = component.replaceText(killerReplacement);
|
||||||
}
|
}
|
||||||
component = MiniMessage.miniMessage()
|
component = MiniMessage.miniMessage().deserialize("<dark_red>[</dark_red><red>☠</red><dark_red>]</dark_red> ").append(component);
|
||||||
.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.mapper.chat_log.ChatLogType;
|
import com.alttd.chat.objects.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,7 +8,6 @@ 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;
|
||||||
|
|
@ -68,9 +67,7 @@ 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();
|
||||||
WebHandler webHandler = new WebHandler();
|
ChatLogHandler chatLogHandler = new ChatLogHandler(true);
|
||||||
|
|
||||||
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());
|
||||||
|
|
@ -79,7 +76,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(webHandler);
|
loadCommands();
|
||||||
// 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);
|
||||||
|
|
@ -116,8 +113,8 @@ public class VelocityChat {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommands(WebHandler webHandler) {
|
public void loadCommands() {
|
||||||
ChatLogHandler instance = ChatLogHandler.getInstance(webHandler, false);
|
ChatLogHandler instance = ChatLogHandler.getInstance(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.mapper.chat_log.ChatLogType;
|
import com.alttd.chat.objects.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