Skip to content

Commit

Permalink
add migration for Sk1er's AutoGG
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 20, 2024
1 parent e1501ce commit c3ba647
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/dummy/java/club/sk1er/mods/autogg/AutoGG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 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 club.sk1er.mods.autogg;

import club.sk1er.mods.autogg.config.AutoGGConfig;

public class AutoGG {
public static AutoGG INSTANCE = new AutoGG();

public AutoGGConfig getAutoGGConfig() {
return new AutoGGConfig();
}
}
69 changes: 69 additions & 0 deletions src/dummy/java/club/sk1er/mods/autogg/config/AutoGGConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 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 club.sk1er.mods.autogg.config;

public class AutoGGConfig {

// these arent the actual default values
private boolean autoGGEnabled = true;
private boolean casualAutoGGEnabled = true;
private boolean antiGGEnabled = true;
private boolean antiKarmaEnabled = true;
private int autoGGDelay = 5;
private int autoGGPhrase = 0;
private boolean secondaryEnabled = true;
private int autoGGPhrase2 = 0;
private int secondaryDelay = 5;

public boolean isModEnabled() {
return autoGGEnabled;
}

public boolean isCasualAutoGGEnabled() {
return casualAutoGGEnabled;
}

public boolean isAntiGGEnabled() {
return antiGGEnabled;
}

public boolean isAntiKarmaEnabled() {
return antiKarmaEnabled;
}

public int getAutoGGDelay() {
return autoGGDelay;
}

public int getAutoGGPhrase() {
return autoGGPhrase;
}

public boolean isSecondaryEnabled() {
return secondaryEnabled;
}

public int getAutoGGPhrase2() {
return autoGGPhrase2;
}

public int getSecondaryDelay() {
return secondaryDelay;
}
}
1 change: 1 addition & 0 deletions src/main/java/org/polyfrost/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class HytilsReborn {

public boolean isPatcher;
public boolean isChatting;
public boolean isSk1erAutoGG;
private boolean loadedCall;

private RankType rank;
Expand Down
52 changes: 47 additions & 5 deletions src/main/java/org/polyfrost/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.config.data.PageLocation;
import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator;
import cc.polyfrost.oneconfig.utils.Notifications;
import club.sk1er.mods.autogg.AutoGG;
import org.polyfrost.hytils.HytilsReborn;
import org.polyfrost.hytils.handlers.chat.modules.modifiers.GameStartCompactor;
import org.polyfrost.hytils.util.DarkColorUtils;
Expand All @@ -35,11 +37,13 @@

import java.awt.Color;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Supplier;

@SuppressWarnings("unused")
public class HytilsConfig extends Config {
Expand Down Expand Up @@ -133,7 +137,7 @@ public class HytilsConfig extends Config {
description = "Send a \"gg\" message at the end of a game.",
category = "Chat", subcategory = "Automatic"
)
public static boolean autoGG;
public static boolean autoGG = true;

@Switch(
name = "Auto GG Second Message",
Expand All @@ -147,7 +151,7 @@ public class HytilsConfig extends Config {
description = "Send a \"gg\" message at the end of minigames/events that don't give out Karma, such as SkyBlock and The Pit events.",
category = "Chat", subcategory = "Automatic"
)
public static boolean casualAutoGG;
public static boolean casualAutoGG = true;

@Switch(
name = "Anti GG",
Expand Down Expand Up @@ -1224,7 +1228,6 @@ public class HytilsConfig extends Config {

public HytilsConfig() {
super(new Mod("Hytils Reborn", ModType.HYPIXEL, "/assets/hytils/hypixel.png", new VigilanceMigrator(new File(HytilsReborn.INSTANCE.oldModDir, "hytilsreborn.toml").getAbsolutePath())), "hytilsreborn.json");
initialize();
try {
File modDir = HytilsReborn.INSTANCE.oldModDir;
File oldModDir = new File(modDir.getParentFile(), "Hytilities Reborn");
Expand All @@ -1239,11 +1242,40 @@ public HytilsConfig() {
e.printStackTrace();
}

if (configNumber != 2) { // Config version has not been set or is outdated
initialize();

if (configNumber != 3) { // Config version has not been set or is outdated
if (configNumber == 1) {
overlayAmount = 300;
}
configNumber = 2; // set this to the current config version
if (configNumber <= 2) {
try {
Class<?> clazz = Class.forName("club.sk1er.mods.autogg.config.AutoGGConfig");

HytilsReborn.INSTANCE.isSk1erAutoGG = true;

autoGG = AutoGG.INSTANCE.getAutoGGConfig().isModEnabled();
autoGGSecondMessage = AutoGG.INSTANCE.getAutoGGConfig().isSecondaryEnabled();
casualAutoGG = AutoGG.INSTANCE.getAutoGGConfig().isCasualAutoGGEnabled();
autoGGMessage = AutoGG.INSTANCE.getAutoGGConfig().getAutoGGPhrase();
autoGGFirstPhraseDelay = AutoGG.INSTANCE.getAutoGGConfig().getAutoGGDelay();
autoGGMessage2 = AutoGG.INSTANCE.getAutoGGConfig().getAutoGGPhrase2();
autoGGSecondPhraseDelay = AutoGG.INSTANCE.getAutoGGConfig().getSecondaryDelay();

try {
Field sk1erEnabled = clazz.getDeclaredField("autoGGEnabled");
sk1erEnabled.setAccessible(true);
sk1erEnabled.set(AutoGG.INSTANCE.getAutoGGConfig(), false);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}

Notifications.INSTANCE.send("Hytils Reborn", "AutoGG settings have been migrated to Hytils Reborn. You can now configure them in the Hytils Reborn settings.", 5);
} catch (ClassNotFoundException ignored) {

}
}
configNumber = 3; // set this to the current config version
save();
}

Expand All @@ -1258,6 +1290,16 @@ public HytilsConfig() {
addDependency("autoGGMessage2", "autoGG");
addDependency("autoGGSecondPhraseDelay", "autoGG");

Supplier<Boolean> autoGGEnabled = () -> HytilsReborn.INSTANCE.isSk1erAutoGG && AutoGG.INSTANCE.getAutoGGConfig().isModEnabled();

addDependency("autoGG", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("autoGGSecondMessage", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("casualAutoGG", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("autoGGMessage", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("autoGGFirstPhraseDelay", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("autoGGMessage2", "Sk1er's AutoGG Enabled", autoGGEnabled);
addDependency("autoGGSecondPhraseDelay", "Sk1er's AutoGG Enabled", autoGGEnabled);

addDependency("glPhrase", "autoGL");

addDependency("guildAutoWB", "autoWB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.hytils.HytilsReborn;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.cache.PatternHandler;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;
Expand Down Expand Up @@ -65,7 +66,7 @@ private boolean hasGameEnded(String message) {

@Override
public boolean isEnabled() {
return HytilsConfig.autoGG;
return HytilsConfig.autoGG && (!HytilsReborn.INSTANCE.isSk1erAutoGG || club.sk1er.mods.autogg.AutoGG.INSTANCE.getAutoGGConfig().isModEnabled()); // If Sk1er's AutoGG is enabled, we don't want to interfere with it.
}

@Override
Expand Down

0 comments on commit c3ba647

Please sign in to comment.