1.4r3H
This commit is contained in:
parent
53d991e74a
commit
5871f02946
11 changed files with 27 additions and 11 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -11,6 +11,6 @@ public class EnchantBaseValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
enchantBaseValues = Map.ofEntries(Map.entry(Enchantment.SHARPNESS, (double) 3000.0F), Map.entry(Enchantment.EFFICIENCY, (double) 3500.0F), Map.entry(Enchantment.KNOCKBACK, (double) 2000.0F), Map.entry(Enchantment.BANE_OF_ARTHROPODS, (double) 2500.0F), Map.entry(Enchantment.SMITE, (double) 2500.0F), Map.entry(Enchantment.BINDING_CURSE, (double) 10000.0F), Map.entry(Enchantment.VANISHING_CURSE, (double) 10000.0F), Map.entry(Enchantment.PROTECTION, (double) 3500.0F), Map.entry(Enchantment.BLAST_PROTECTION, (double) 2500.0F), Map.entry(Enchantment.PROJECTILE_PROTECTION, (double) 2500.0F), Map.entry(Enchantment.FIRE_PROTECTION, (double) 2500.0F), Map.entry(Enchantment.SWIFT_SNEAK, (double) 2000.0F), Map.entry(Enchantment.BREACH, (double) 5000.0F), Map.entry(Enchantment.DENSITY, (double) 5000.0F), Map.entry(Enchantment.MENDING, (double) 12500.0F), Map.entry(Enchantment.FEATHER_FALLING, (double) 2500.0F), Map.entry(Enchantment.RESPIRATION, (double) 4750.0F), Map.entry(Enchantment.AQUA_AFFINITY, (double) 3000.0F), Map.entry(Enchantment.THORNS, (double) 5000.0F), Map.entry(Enchantment.DEPTH_STRIDER, (double) 4000.0F), Map.entry(Enchantment.FROST_WALKER, (double) 3500.0F), Map.entry(Enchantment.FIRE_ASPECT, (double) 4000.0F), Map.entry(Enchantment.LOOTING, (double) 4000.0F), Map.entry(Enchantment.SWEEPING_EDGE, (double) 4500.0F), Map.entry(Enchantment.SILK_TOUCH, (double) 5000.0F), Map.entry(Enchantment.UNBREAKING, (double) 4000.0F), Map.entry(Enchantment.FORTUNE, (double) 5500.0F), Map.entry(Enchantment.POWER, (double) 4500.0F), Map.entry(Enchantment.PUNCH, (double) 2000.0F), Map.entry(Enchantment.FLAME, (double) 4000.0F), Map.entry(Enchantment.INFINITY, (double) 9000.0F), Map.entry(Enchantment.LUCK_OF_THE_SEA, (double) 3500.0F), Map.entry(Enchantment.LURE, (double) 4500.0F), Map.entry(Enchantment.LOYALTY, (double) 6000.0F), Map.entry(Enchantment.IMPALING, (double) 2500.0F), Map.entry(Enchantment.RIPTIDE, (double) 6000.0F), Map.entry(Enchantment.CHANNELING, (double) 6000.0F), Map.entry(Enchantment.MULTISHOT, (double) 4500.0F), Map.entry(Enchantment.QUICK_CHARGE, (double) 4000.0F), Map.entry(Enchantment.PIERCING, (double) 5000.0F), Map.entry(Enchantment.WIND_BURST, (double) 5000.0F), Map.entry(Enchantment.SOUL_SPEED, (double) 3000.0F));
|
enchantBaseValues = Map.ofEntries(Map.entry(Enchantment.SHARPNESS, 3000.0D), Map.entry(Enchantment.EFFICIENCY, 3500.0D), Map.entry(Enchantment.KNOCKBACK, 2000.0D), Map.entry(Enchantment.BANE_OF_ARTHROPODS, 2500.0D), Map.entry(Enchantment.SMITE, 2500.0D), Map.entry(Enchantment.BINDING_CURSE, 10000.0D), Map.entry(Enchantment.VANISHING_CURSE, 10000.0D), Map.entry(Enchantment.PROTECTION, 3500.0D), Map.entry(Enchantment.BLAST_PROTECTION, 2500.0D), Map.entry(Enchantment.PROJECTILE_PROTECTION, 2500.0D), Map.entry(Enchantment.FIRE_PROTECTION, 2500.0D), Map.entry(Enchantment.SWIFT_SNEAK, 2000.0D), Map.entry(Enchantment.BREACH, 5000.0D), Map.entry(Enchantment.DENSITY, 5000.0D), Map.entry(Enchantment.MENDING, 12500.0D), Map.entry(Enchantment.FEATHER_FALLING, 2500.0D), Map.entry(Enchantment.RESPIRATION, 4750.0D), Map.entry(Enchantment.AQUA_AFFINITY, 3000.0D), Map.entry(Enchantment.THORNS, 5000.0D), Map.entry(Enchantment.DEPTH_STRIDER, 4000.0D), Map.entry(Enchantment.FROST_WALKER, 3500.0D), Map.entry(Enchantment.FIRE_ASPECT, 4000.0D), Map.entry(Enchantment.LOOTING, 4000.0D), Map.entry(Enchantment.SWEEPING_EDGE, 4500.0D), Map.entry(Enchantment.SILK_TOUCH, 5000.0D), Map.entry(Enchantment.UNBREAKING, 4000.0D), Map.entry(Enchantment.FORTUNE, 5500.0D), Map.entry(Enchantment.POWER, 4500.0D), Map.entry(Enchantment.PUNCH, 2000.0D), Map.entry(Enchantment.FLAME, 4000.0D), Map.entry(Enchantment.INFINITY, 9000.0D), Map.entry(Enchantment.LUCK_OF_THE_SEA, 3500.0D), Map.entry(Enchantment.LURE, 4500.0D), Map.entry(Enchantment.LOYALTY, 6000.0D), Map.entry(Enchantment.IMPALING, 2500.0D), Map.entry(Enchantment.RIPTIDE, 6000.0D), Map.entry(Enchantment.CHANNELING, 6000.0D), Map.entry(Enchantment.MULTISHOT, 4500.0D), Map.entry(Enchantment.QUICK_CHARGE, 4000.0D), Map.entry(Enchantment.PIERCING, 5000.0D), Map.entry(Enchantment.WIND_BURST, 5000.0D), Map.entry(Enchantment.SOUL_SPEED, 3000.0D), Map.entry(Enchantment.LUNGE, 4500.0D));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,32 +39,48 @@ public class GeneralChatHandler {
|
||||||
public static String handleMessage(String message, Player player) {
|
public static String handleMessage(String message, Player player) {
|
||||||
PlayerMetadata metadata = PlayerMetadata.getPlayerMetadata(player);
|
PlayerMetadata metadata = PlayerMetadata.getPlayerMetadata(player);
|
||||||
String nickname = metadata != null ? metadata.nickname : player.getName();
|
String nickname = metadata != null ? metadata.nickname : player.getName();
|
||||||
PlayerMetadata playerMetadata = PlayerMetadata.getPlayerMetadata(player);
|
|
||||||
Faction faction = Faction.getFaction(playerMetadata.factionUUID);
|
// Optimized: Don't fetch metadata twice
|
||||||
if (PlayerTitles.titles.get(playerMetadata.decoTitle) != null) {
|
if (metadata != null && PlayerTitles.titles.get(metadata.decoTitle) != null) {
|
||||||
nickname = "(" + playerMetadata.decoTitle + ") " + nickname;
|
nickname = "(" + metadata.decoTitle + ") " + nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metadata != null) {
|
||||||
|
Faction faction = Faction.getFaction(metadata.factionUUID);
|
||||||
if (faction != null) {
|
if (faction != null) {
|
||||||
nickname = "[" + faction.name + "] " + nickname;
|
nickname = "[" + faction.name + "] " + nickname;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String formattedMessage = String.format("%s: %s", nickname, message).replace("&timeF", LocalDateTime.now().toString()).replace("&world", player.getWorld().getName()).replace("&pos", player.getLocation().toString()).replace("&player", player.getName()).replace("&uuid", player.getUniqueId().toString()).replace("&date", LocalDateTime.now().toLocalDate().toString()).replace("&time", LocalDateTime.now().toLocalTime().toString()).replace("&nickname", nickname).replace("&day", String.valueOf(player.getWorld().getTime() / 24000L));
|
// 1. RUN THE FILTER FIRST before doing heavy string formatting
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<String> bannedWords = ActiveConfig.getConfigValue(ConfigKey.BANNED_WORDS, List.class);
|
List<String> bannedWords = ActiveConfig.getConfigValue(ConfigKey.BANNED_WORDS, List.class);
|
||||||
if (bannedWords != null) {
|
if (bannedWords != null) {
|
||||||
String regex = "[ .-_,:;!?()\\[\\]{}\"'`~@#$%^&*+=|<>/\\\\]+";
|
String regex = "[^\\p{L}\\p{N}]+"; // Safely keeps all letters and numbers across languages
|
||||||
String normalizedMessage = message.replaceAll(regex, "").toLowerCase();
|
String normalizedMessage = message.replaceAll(regex, "").toLowerCase();
|
||||||
|
|
||||||
for (String word : bannedWords) {
|
for (String word : bannedWords) {
|
||||||
if (normalizedMessage.contains(word.replaceAll(regex, "").toLowerCase())) {
|
String normalizedBannedWord = word.replaceAll(regex, "").toLowerCase();
|
||||||
|
if (normalizedMessage.contains(normalizedBannedWord)) {
|
||||||
GrimmsServer.logger.info("Message interrupted: '" + message + "' by player: " + player.getName() + ". Contains banned word: " + word);
|
GrimmsServer.logger.info("Message interrupted: '" + message + "' by player: " + player.getName() + ". Contains banned word: " + word);
|
||||||
return String.format("<%s>: %s", nickname, "§c[REDACTED]");
|
return String.format("<%s>: %s", nickname, "§c[REDACTED]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formattedMessage;
|
// 2. NOW formatting happens only if the message is safe
|
||||||
|
LocalDateTime now = LocalDateTime.now(); // Instantiated once instead of 3 separate times
|
||||||
|
|
||||||
|
return String.format("%s: %s", nickname, message)
|
||||||
|
.replace("&timeF", now.toString())
|
||||||
|
.replace("&world", player.getWorld().getName())
|
||||||
|
.replace("&pos", player.getLocation().toString()) // Consider formatting this cleanly later
|
||||||
|
.replace("&player", player.getName())
|
||||||
|
.replace("&uuid", player.getUniqueId().toString())
|
||||||
|
.replace("&date", now.toLocalDate().toString())
|
||||||
|
.replace("&time", now.toLocalTime().toString())
|
||||||
|
.replace("&nickname", nickname)
|
||||||
|
.replace("&day", String.valueOf(player.getWorld().getTime() / 24000L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void joinMessage(Player player) {
|
public static void joinMessage(Player player) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue