Skip to content

Commit

Permalink
fix smaller bugs and move some regexes to LanguageData (#53)
Browse files Browse the repository at this point in the history
* beta2

* use DataStorage for ArmorStandHandler

* fix wrong casing
  • Loading branch information
xthe-dev authored Jan 10, 2023
1 parent 691b784 commit 5a04762
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 129 deletions.
2 changes: 2 additions & 0 deletions src/main/java/cc/woverflow/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.woverflow.hytils.command.*;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.cache.ArmorStandHandler;
import cc.woverflow.hytils.handlers.cache.CosmeticsHandler;
import cc.woverflow.hytils.handlers.cache.HeightHandler;
import cc.woverflow.hytils.handlers.cache.PatternHandler;
Expand Down Expand Up @@ -128,6 +129,7 @@ public void init(FMLInitializationEvent event) {
// GameNameParser to be initialized, and that depends on networking.
PlayCommand.init();

ArmorStandHandler.INSTANCE.initialize();
CosmeticsHandler.INSTANCE.initialize();
PatternHandler.INSTANCE.initialize();
HeightHandler.INSTANCE.initialize();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cc.woverflow.hytils.handlers.cache;

import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;

public class ArmorStandHandler {
public static ArmorStandHandler INSTANCE = new ArmorStandHandler();
public List<String> armorStandNames = new ArrayList<>();

public void initialize() {
Multithreading.runAsync(() -> {
final JsonElement gotten = NetworkUtils.getJsonElement("https://data.woverflow.cc/armorstands.json");
if (gotten != null) {
JsonObject jsonObject = gotten.getAsJsonObject();
for (JsonElement tag : jsonObject.getAsJsonArray("tags")) {
armorStandNames.add(tag.getAsString());
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public ChatHandler() {

// Modifiers

this.registerModule(new ColoredFriendStatuses());
this.registerModule(new DefaultChatRestyler());
this.registerModule(new GameStartCompactor());
this.registerModule(new WhiteChat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.chat.ChatReceiveModule;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
import java.util.regex.Pattern;

public class AdBlocker implements ChatReceiveModule {

Expand All @@ -48,26 +48,20 @@ public int getPriority() {
* Blocks advertisements to join German SkyBlock guilds
* <p>
* Blocks stuff related with lowballing
*
* <p>
* TODO: add more phrases to regex
*/
private final Pattern commonAdvertisements = Pattern.compile("(?!.+: )(/?(((party join|join party)|p join|(guild join)|(join guild)|g join) \\w{1,16})|/?(party me|visit me|duel me|my ah|my smp)|(twitch.tv)|(youtube.com|youtu.be)|(/(visit|ah) \\w{1,16}|(visit /\\w{1,16})|(/gift)|(gilde)|(lowballing|lowbaling|lowvaling|lowvaluing|lowballer)))",
Pattern.CASE_INSENSITIVE);

// common phrases used in messages where people beg for a rank gift
private final Pattern rankBegging = Pattern.compile("(?!.+: )([^\\[](vip|mvp|mpv|vpi)|(please|pls|plz|give|giving)|(rank|buy me|upgrade me)|(gift|gifting|gifters)|(beg|begging|beggers))",
Pattern.CASE_INSENSITIVE);

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String message = event.message.getUnformattedText().toLowerCase(Locale.ENGLISH);
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": "))) return;
if (commonAdvertisements.matcher(message).find(0)) {
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": ")) || (message.contains(Minecraft.getMinecraft().getSession().getUsername().toLowerCase())))
return;
if (getLanguage().chatCommonAdvertisementsRegex.matcher(message).find(0)) {
event.setCanceled(true);
}

if (!HytilsReborn.INSTANCE.getLobbyChecker().playerIsInLobby()) return;
if (rankBegging.matcher(message).find(0)) {
if (getLanguage().chatRankBeggingRegex.matcher(message).find(0)) {
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@

import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.chat.ChatReceiveModule;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
import java.util.regex.Pattern;

public class AntiGL implements ChatReceiveModule {
private final Pattern cancelGlMessages = Pattern.compile("(?!.+: )(gl|glhf|good luck|have a good game|autogl by sk1er)",
Pattern.CASE_INSENSITIVE);


@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String message = event.message.getUnformattedText().toLowerCase(Locale.ENGLISH);
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": "))) return;
if (cancelGlMessages.matcher(message).find(0)) {
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": ")) || (message.contains(Minecraft.getMinecraft().getSession().getUsername().toLowerCase())))
return;
if (getLanguage().cancelGlMessagesRegex.matcher(message).find(0)) {
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.chat.ChatReceiveModule;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -32,7 +33,7 @@ public class BedwarsAdvertisementsRemover implements ChatReceiveModule {
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
LocrawInfo locrawInformation = HypixelUtils.INSTANCE.getLocrawInfo();
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": "))) return;
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (message.startsWith("?") && message.endsWith("?")) || (!message.contains(": ")) || (message.contains(Minecraft.getMinecraft().getSession().getUsername().toLowerCase()))) return;
if (locrawInformation != null && locrawInformation.getGameType() == LocrawInfo.GameType.BEDWARS && HytilsReborn.INSTANCE.getLobbyChecker().playerIsInLobby()
&& getLanguage().chatCleanerBedwarsPartyAdvertisementRegex.matcher(message).find()) {
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Pattern;

public class LobbyStatusRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
if (message.contains(":")) return;
for (Pattern messages : getLanguage().chatCleanerJoinMessageTypes) {
if (messages.matcher(message).find()) {
event.setCanceled(true);
return;
}
if (message.contains(": ")) return;
if (getLanguage().chatCleanerJoinRegex.matcher(message).find()) {
event.setCanceled(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String unformattedText = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
final Matcher matcher = getLanguage().hypixelLevelUpRegex.matcher(unformattedText.trim());
if (matcher.find()) {
if (unformattedText.contains(":")) return; // TODO: This is a temporary solution to prevent regular player messages from triggering it. Fix the regex!
if (unformattedText.contains(": ")) return; // TODO: This is a temporary solution to prevent regular player messages from triggering it. Fix the regex!
final String level = matcher.group("level");
if (StringUtils.isNumeric(level)) {
MinecraftForge.EVENT_BUS.post(new HypixelLevelupEvent(Integer.parseInt(level)));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
}
}

if (HytilsConfig.coloredStatuses) {
Matcher statusMatcher = getLanguage().chatRestylerStatusPatternRegex.matcher(event.message.getFormattedText().trim());
if (statusMatcher.matches()) {
final String status = statusMatcher.group("status");
if (status.equalsIgnoreCase("joined")) {
event.message = colorMessage(statusMatcher.group("type") + " > &r" + statusMatcher.group("player") + " &r&ajoined&e.");
} else if (status.equalsIgnoreCase("left")) {
event.message = colorMessage(statusMatcher.group("type") + " > &r" + statusMatcher.group("player") + " &r&cleft&e.");
}
}
}

// Currently unformattedMessage doesn't need to be changed but I'm leaving these in, commented, in case it's
// changed in the future and they need to be padded.
if (HytilsConfig.padPlayerCount) {
Expand Down Expand Up @@ -142,8 +154,10 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
// if the format (below) is changed, remember to update the regex for it (chatRestylerGameStartCounterOutputStyle)
event.message = colorMessage("&e&l* &a" + (startCounterMatcher.group("title")) + " &b&l" + startCounterMatcher.group("time") + " &a" + startCounterMatcher.group("unit"));
} else {
if ("We don't have enough players! Start cancelled.".equals(unformattedMessage) || ("We don't have enough players! Start delayed.".equals(unformattedMessage))) {
if ("We don't have enough players! Start cancelled.".equals(unformattedMessage)) {
event.message = colorMessage("&e&l* &cStart cancelled.");
} else if ("We don't have enough players! Start delayed.".equals(unformattedMessage)) {
event.message = colorMessage("&e&l* &cStart delayed.");
}
}
}
Expand Down Expand Up @@ -174,9 +188,9 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
* Handles the replacement of channel names
* Loops through all siblings to find a replacement
*
* @param message The message being modified
* @param pattern The regular expression to check the message and it's components against
* @param replacement The text that replaces what is matched by the regular expression
* @param message The message being modified
* @param pattern The regular expression to check the message and it's components against
* @param replacement The text that replaces what is matched by the regular expression
* @param checkParentComponent Whether or not to check the parent chat component
*/
private ChatComponentText shortenChannelName(IChatComponent message, String pattern, String replacement, boolean checkParentComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.chat.ChatReceiveModule;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;

Expand All @@ -29,19 +30,21 @@
/**
* Taken and adapted from AutoFriend under MIT
* https://github.com/minemanpi/AutoFriend/blob/master/LICENSE
*
* @author 2Pi
*/
public class AutoFriend implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = event.message.getUnformattedText().replace("\n", "");
Matcher matcher = getLanguage().autoFriendPatternRegex.matcher(message);
if (matcher.matches()) {
if (matcher.find()) {
String name = matcher.group("name");
if (name.startsWith("[")) {
name = name.substring(name.indexOf("] ") + 2);
HytilsReborn.INSTANCE.getCommandQueue().queue("/friend " + name);
}
HytilsReborn.INSTANCE.getCommandQueue().queue("/friend " + name);
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.GREEN + "Automatically added " + name + " to your friend list.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int getPriority() {

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (event.message.getUnformattedText().equals("[WATCHDOG ANNOUNCEMENT]")) {
if (event.message.getUnformattedText().equals("[WATCHDOG ANNOUNCEMENT]") || event.message.getUnformattedText().startsWith("A player has been removed from your")) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/achat Thanks Watchdog!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onTitle(TitleEvent event) {
return;
}

switch (EnumChatFormatting.getTextWithoutFormattingCodes(event.getTitle())) {
switch (EnumChatFormatting.getTextWithoutFormattingCodes(event.getTitle().toUpperCase())) {
case "YOU WIN!":
case "YOU DIED!":
case "YOU LOSE!":
Expand All @@ -41,9 +41,6 @@ public void onTitle(TitleEvent event) {
case "RESPAWNED!":
case "DEFEAT!":
case "GAME END":
case "You Win!":
case "You Lose!":
case "Game Over!":
case "YOU DIED":
case "DEFEAT":
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ public void onTitle(TitleEvent event) {
return;
}

switch (EnumChatFormatting.getTextWithoutFormattingCodes(event.getTitle())) {
case "10 seconds":
switch (EnumChatFormatting.getTextWithoutFormattingCodes(event.getTitle().toUpperCase())) {
case "10 SECONDS":
case "10":
case "5":
case "4":
case "3":
case "2":
case "1":
case "Waiting for more players...":
case "SkyWars":
case "❸":
case "❷":
case "❶":
case "WAITING FOR MORE PLAYERS...":
case "SKYWARS":
case "INSANE MODE":
case "Fight!":
case "Zombies":
case "FIGHT!":
case "ZOMBIES":
case "ASSASSINS":
case "YOU ARE RED":
case "YOU ARE BLUE":
case "YOU ARE YELLOW":
case "YOU ARE GREEN":
case "PRE ROUND":
case "ROUND START":
case "❸":
case "❷":
case "❶":
event.setCanceled(true);
break;
}
Expand Down
Loading

0 comments on commit 5a04762

Please sign in to comment.