Skip to content

Commit

Permalink
Port a sizable chunk using new OneConfig events
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 27, 2024
1 parent cb82d6e commit 79333d2
Show file tree
Hide file tree
Showing 60 changed files with 188 additions and 132 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ preprocess {

toolkitLoomHelper {
// Adds OneConfig to our project
useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.43", mcData, "commands", "config-impl", "events", "hud", "internal", "ui")
useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.46", mcData, "commands", "config-impl", "events", "hud", "internal", "ui")
useDevAuth()

// Removes the server configs from IntelliJ IDEA, leaving only client runs.
Expand Down Expand Up @@ -69,7 +69,7 @@ dependencies {

// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (mcData.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
compileOnly("org.polyfrost:polymixin:0.8.4+build.2")
} else if (mcData.isFabric) {
if (mcData.isLegacyFabric) {
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}")
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/org/polyfrost/hytils/forge/HytilsMixinPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

//#if FORGE
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
import org.spongepowered.asm.lib.tree.*;
//#else
//$$ import org.objectweb.asm.tree.*;
//#endif

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import org.polyfrost.oneconfig.api.platform.v1.DeobfuscationRemapper;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

Expand Down Expand Up @@ -79,11 +78,7 @@ public List<String> getMixins() {
@Override
public void preApply(
String targetClassName,
//#if FORGE && MC <= 1.12.2
org.spongepowered.asm.lib.tree.ClassNode targetClass,
//#else
//$$ org.objectweb.asm.tree.ClassNode targetClass,
//#endif
ClassNode targetClass,
String mixinClassName,
IMixinInfo mixinInfo
) {
Expand All @@ -93,17 +88,13 @@ public void preApply(
@Override
public void postApply(
String targetClassName,
//#if FORGE && MC <= 1.12.2
org.spongepowered.asm.lib.tree.ClassNode targetClass,
//#else
//$$ org.objectweb.asm.tree.ClassNode targetClass,
//#endif
ClassNode targetClass,
String mixinClassName,
IMixinInfo mixinInfo
) {
if (!hasAppliedModifyName && !hasAppliedRenderHeads && targetClass != null && Objects.equals(targetClassName, "net.minecraft.client.gui.GuiPlayerTabOverlay")) {
for (MethodNode method : targetClass.methods) {
final String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(targetClass.name, method.name, method.desc);
final String methodName = DeobfuscationRemapper.INSTANCE.mapMethodName(targetClass.name, method.name, method.desc);
final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
switch (methodName) {
case "renderPlayerlist":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.polyfrost.oneconfig.api.event.v1.events.ChatReceiveEvent;
import org.polyfrost.oneconfig.api.event.v1.events.WorldUnloadEvent;
import org.polyfrost.oneconfig.api.event.v1.invoke.impl.Subscribe;
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;

Expand Down Expand Up @@ -133,7 +134,7 @@ private <T extends ChatReceiveModule & ChatSendModule> void registerDualModule(T
}

@Subscribe
public void handleWorldLeave(WorldEvent.Unload e) { // TODO
public void handleWorldLeave(WorldUnloadEvent e) {
for (ChatReceiveResetModule module : this.resetModules) {
module.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class BridgeOwnGoalDeathRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.equals(getLanguage().chatCleanerBridgeOwnGoalDeath)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class ConnectedMessage implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().connectedServerConnectMessageRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class ConnectionStatusRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerConnectionStatusRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class CurseOfSpamRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.equals(getLanguage().chatCleanerCurseOfSpam)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class DiscordSafetyWarningRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.equals(getLanguage().chatDiscordSafetyWarning)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class DuelsBlockTrail implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.equals(getLanguage().chatCleanerDuelsBlockTrail)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class DuelsNoStatsChange implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerDuelsNoStatsChangeRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class EarnedCoinsAndExpRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText().replace("\n", "")); // Support doubled coins (guild rewards) message
String message = event.getFullyUnformattedMessage().replace("\n", ""); // Support doubled coins (guild rewards) message
if (getLanguage().chatCleanerEarnedCoinsAndExpRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class GameAnnouncementsRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerGameAnnouncementRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class GameTipsRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerGameTipsRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class GiftBlocker implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatGiftBlockerRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.polyfrost.hytils.handlers.chat.modules.blockers;

import org.polyfrost.oneconfig.api.event.v1.EventManager;
import org.polyfrost.oneconfig.api.event.v1.events.ServerJoinEvent;
import org.polyfrost.oneconfig.api.event.v1.invoke.impl.Subscribe;
import org.polyfrost.oneconfig.utils.v1.Multithreading;
import org.polyfrost.hytils.config.HytilsConfig;
Expand Down Expand Up @@ -46,7 +47,7 @@ public GuildMOTD() {
}

@Subscribe
public void onConnectedToServer(FMLNetworkEvent.ClientConnectedToServerEvent event) { // TODO
public void onConnectedToServer(ServerJoinEvent event) {
// Allow checking of MOTD immediately after joining Hypixel.
canCheckMOTD = true;
isMOTD = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class HotPotatoRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerHotPotatoRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class HypeLimitReminderRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.startsWith(getLanguage().chatCleanerHypeLimit)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class KarmaRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerKarmaMessagesRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class LobbyFishingAnnouncementRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerLobbyFishingAnnouncementRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class LobbyStatusRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
final String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
final String message = event.getFullyUnformattedMessage();
if (message.contains(": ")) return;
if (getLanguage().chatCleanerJoinRegex.matcher(message).find()) {
event.cancelled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.polyfrost.hytils.handlers.chat.modules.blockers;

import net.minecraft.util.IChatComponent;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;
import org.polyfrost.hytils.handlers.language.LanguageData;
Expand All @@ -31,11 +32,12 @@ public class MvpEmotesRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
final LanguageData language = getLanguage();
Matcher matcher = language.chatCleanerMvpEmotesRegex.matcher(event.message.getFormattedText());
Matcher matcher = language.chatCleanerMvpEmotesRegex.matcher(event.getFullyUnformattedMessage());
if (matcher.find(0)) {
event.message = new ChatComponentText(event.message.getFormattedText().replaceAll(
IChatComponent message = event.getMessage();
event.setMessage(new ChatComponentText(message.getFormattedText().replaceAll(
language.chatCleanerMvpEmotesRegex.pattern(), "")
);
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class OnlineStatusRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerOnlineStatusRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class QuestBlocker implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull final ChatReceiveEvent event) {
final String message = event.message.getUnformattedText();
final String message = event.getFullyUnformattedMessage();
if (message.startsWith("§aAutomatically activated:")) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class ReplayRecordedRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerReplayRecordedRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class SeasonalCollectedRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerGrinchPresentsRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.polyfrost.hytils.handlers.chat.modules.blockers;

import net.hypixel.data.type.GameType;
import net.minecraft.util.IChatComponent;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;
import org.polyfrost.hytils.handlers.chat.ChatSendModule;
Expand Down Expand Up @@ -84,10 +85,11 @@ private long getCooldownLengthInSeconds() {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
HypixelUtils.Location location = HypixelUtils.getLocation();
if (location.getGameType().orElse(null) == GameType.SKYWARS && event.message.getFormattedText().equals(getLanguage().cannotShoutBeforeSkywars) || // fun fact: there is no message when you shout after a skywars game
event.message.getFormattedText().equals(getLanguage().cannotShoutAfterGame) ||
event.message.getFormattedText().equals(getLanguage().cannotShoutBeforeGame) ||
event.message.getFormattedText().equals(getLanguage().noSpectatorCommands)
IChatComponent message = event.getMessage();
if (location.getGameType().orElse(null) == GameType.SKYWARS && message.getFormattedText().equals(getLanguage().cannotShoutBeforeSkywars) || // fun fact: there is no message when you shout after a skywars game
message.getFormattedText().equals(getLanguage().cannotShoutAfterGame) ||
message.getFormattedText().equals(getLanguage().cannotShoutBeforeGame) ||
message.getFormattedText().equals(getLanguage().noSpectatorCommands)
) {
shoutCooldown = 0L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class SkyblockWelcomeRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (message.equals(getLanguage().chatCleanerSkyblockWelcome)) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class SoulWellAnnouncerRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerSoulWellFindRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class StatsMessageRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (getLanguage().chatCleanerStatsRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TicketMachineRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
HypixelUtils.Location location = HypixelUtils.getLocation();
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
String message = event.getFullyUnformattedMessage();
if (location.getGameType().orElse(null) == GameType.BEDWARS && !location.inGame()
&& getLanguage().chatCleanerTicketAnnouncerRegex.matcher(message).matches()) {
event.cancelled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class TipMessageRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ChatReceiveEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText().replace("\n", ""));
String message = event.getFullyUnformattedMessage().replace("\n", "");
if (getLanguage().chatCleanerTipRegex.matcher(message).matches()) {
event.cancelled = true;
}
Expand Down
Loading

0 comments on commit 79333d2

Please sign in to comment.