Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de24ca4437 | ||
|
|
e351e86bea | ||
|
|
4e92285261 | ||
|
|
a377bdfe48 |
@@ -543,4 +543,12 @@ public final class Config {
|
|||||||
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes", List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&r"));
|
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes", List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&r"));
|
||||||
NICK_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
NICK_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int DEATH_MESSAGES_MAX_PER_PERIOD = 5;
|
||||||
|
public static int DEATH_MESSAGES_LIMIT_PERIOD_MINUTES = 15;
|
||||||
|
|
||||||
|
private static void deathMessagesSettings() {
|
||||||
|
DEATH_MESSAGES_MAX_PER_PERIOD = getInt("death-messages.max-per-period", DEATH_MESSAGES_MAX_PER_PERIOD);
|
||||||
|
DEATH_MESSAGES_LIMIT_PERIOD_MINUTES = getInt("death-messages.limit-period-minutes", DEATH_MESSAGES_LIMIT_PERIOD_MINUTES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ public class ALogger {
|
|||||||
logger.warn(message);
|
logger.warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void warn(String message, Throwable throwable) {
|
||||||
|
logger.warn(message, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
@@ -23,4 +27,8 @@ public class ALogger {
|
|||||||
public static void error(String message) {
|
public static void error(String message) {
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void error(String message, Throwable throwable) {
|
||||||
|
logger.error(message, throwable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,25 @@ import com.alttd.chat.objects.Toggleable;
|
|||||||
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;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
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 org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -86,4 +96,29 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final HashMap<UUID, Stack<Instant>> sendPlayerDeaths = new HashMap<>();
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
|
||||||
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
Stack<Instant> playerDeathsStack = sendPlayerDeaths.computeIfAbsent(uuid, key -> new Stack<>());
|
||||||
|
Instant cutOff = Instant.now().minus(Config.DEATH_MESSAGES_LIMIT_PERIOD_MINUTES, ChronoUnit.MINUTES);
|
||||||
|
|
||||||
|
while (playerDeathsStack.peek().isBefore(cutOff)) {
|
||||||
|
playerDeathsStack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerDeathsStack.size() > Config.DEATH_MESSAGES_MAX_PER_PERIOD || serverConfig.MUTED) {
|
||||||
|
event.deathMessage(Component.empty());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Component component = event.deathMessage();
|
||||||
|
if (component != null) {
|
||||||
|
component = Component.text("* ").append(component);
|
||||||
|
component = component.style(Style.style(TextColor.color(82, 80, 77), TextDecoration.ITALIC));
|
||||||
|
event.deathMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerDeathsStack.push(Instant.now());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user