Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/main/java/org/polyfrost/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ public class HytilsConfig extends Config {
private static boolean autoQueueInfo;

@Switch(
name = "Auto Queue",
description = "Automatically queues for another game once you win or die.",
name = "Auto Queue Game End",
description = "Automatically queues for another game once your game ends.",
category = "General", subcategory = "Automatic"
)
public static boolean autoQueue;
public static boolean autoQueueGameEnd;

@Switch(
name = "Auto Queue Die",
description = "Automatically queues for another game once you die.",
category = "General", subcategory = "Automatic"
)
public static boolean autoQueueDie;

@Slider(
name = "Auto Queue Delay",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void initialize() {
processJson(cached);
return;
}
final String gotten = NetworkUtils.getString("https://data.woverflow.cc/regex.json");
final String gotten = NetworkUtils.getString("https://data.polyfrost.org/regex.json");
if (gotten != null) {
processJson(JsonUtils.parseString(gotten).getAsJsonObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


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

import cc.polyfrost.oneconfig.events.event.WorldLoadEvent;
Expand All @@ -30,6 +31,7 @@
import org.polyfrost.hytils.handlers.cache.PatternHandler;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;

import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

Expand All @@ -46,9 +48,12 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {

if (!matchFound) {
matchFound = true;
Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage), (long) (HytilsConfig.autoGGFirstPhraseDelay * 1000), TimeUnit.MILLISECONDS);
String ggMessage1 = "random".equals(HytilsConfig.ggMessage) ? getRandomGG() : HytilsConfig.ggMessage;
String ggMessage2 = "random".equals(HytilsConfig.ggMessage2) ? getRandomGG() : HytilsConfig.ggMessage2;

Multithreading.schedule(() -> UChat.say("/ac " + ggMessage1), (long) (HytilsConfig.autoGGFirstPhraseDelay * 1000), TimeUnit.MILLISECONDS);
if (HytilsConfig.autoGGSecondMessage) {
Multithreading.schedule(() -> UChat.say("/ac " + HytilsConfig.ggMessage2), (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000), TimeUnit.MILLISECONDS);
Multithreading.schedule(() -> UChat.say("/ac " + ggMessage2), (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000), TimeUnit.MILLISECONDS);
}
// Schedule the reset of matchFound after the second message has been sent
Multithreading.schedule(() -> matchFound = false, (long) ((HytilsConfig.autoGGSecondPhraseDelay + HytilsConfig.autoGGFirstPhraseDelay) * 1000) + 5000, TimeUnit.MILLISECONDS);
Expand All @@ -65,7 +70,10 @@ private boolean hasGameEnded(String message) {
}

// TODO: UNTESTED!
return getLanguage().casualGameEndRegex.matcher(message).matches();
if (HytilsConfig.casualAutoGG) {
return getLanguage().casualGameEndRegex.matcher(message).matches();
}
return false;
}

@Subscribe
Expand All @@ -82,5 +90,50 @@ public boolean isEnabled() {
public int getPriority() {
return 3;
}
}

private static final Random random = new Random();

public static String getRandomGG() {
String base;

int roll = random.nextInt(258);

if (roll < 2) {
base = "gg";
} else if (roll < 130) {
base = "goodgame";
} else {
base = "good game";
}

char[] chars = base.toCharArray();
int capsCount = 0;

for (int i = 0; i < chars.length; i++) {
if (!Character.isLetter(chars[i])) continue; // Skip spaces

if (random.nextBoolean()) {
chars[i] = Character.toUpperCase(chars[i]);
capsCount++;
} else {
chars[i] = Character.toLowerCase(chars[i]);
}
}

if (capsCount % 2 != 0) {
for (int i = chars.length - 1; i >= 0; i--) {
if (Character.isLetter(chars[i])) {
// Flip case of the last letter
if (Character.isUpperCase(chars[i])) {
chars[i] = Character.toLowerCase(chars[i]);
} else {
chars[i] = Character.toUpperCase(chars[i]);
}
break;
}
}
}

return new String(chars);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,55 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


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

import cc.polyfrost.oneconfig.utils.Multithreading;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.LocrawGamesHandler;
import org.polyfrost.hytils.handlers.cache.PatternHandler;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

public class AutoQueue implements ChatReceiveModule {
public class AutoQueue
implements ChatReceiveModule {
private String command = null;
private boolean sentCommand;

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (!HytilsConfig.autoQueue) {
if (!HytilsConfig.autoQueueGameEnd && !HytilsConfig.autoQueueDie) {
return;
}
String message = this.getStrippedMessage(event.message);
Matcher matcher = this.getLanguage().autoQueuePrefixGlobalRegex.matcher(message);

final String message = getStrippedMessage(event.message);
Matcher matcher = getLanguage().autoQueuePrefixGlobalRegex.matcher(message);
if (matcher.matches() && getLocraw() != null) {
String game = getLocraw().getGameMode();
String value = LocrawGamesHandler.locrawGames.get(getLocraw().getRawGameType().toLowerCase() + "_" + game.toLowerCase());
if (((matcher.matches() && HytilsConfig.autoQueueDie) ||
(this.hasGameEnded(message) && HytilsConfig.autoQueueGameEnd)) &&
this.getLocraw() != null) {
String game = this.getLocraw().getGameMode();
String value = LocrawGamesHandler.locrawGames.get(this.getLocraw().getRawGameType().toLowerCase() + "_" + game.toLowerCase());
if (value != null) {
game = value;
}
this.command = "/play " + game.toLowerCase();
}
}

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (this.command != null) {
this.switchGame();
}
}

@SubscribeEvent
public void onMouseEvent(InputEvent.MouseInputEvent event) {
if (this.command != null) {
this.switchGame();
}
}

@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
// stop the command from being spammed, to prevent chat from filling with "please do not spam commands"
if (event.world.provider.getDimensionId() == 0 && this.sentCommand) {
this.sentCommand = false;
private boolean hasGameEnded(String message) {
if (!PatternHandler.INSTANCE.gameEnd.isEmpty()) {
for (Pattern triggers : PatternHandler.INSTANCE.gameEnd) {
if (!triggers.matcher(message).matches()) continue;
return true;
}
}
return false;
}

private void switchGame() {
Expand All @@ -83,13 +74,15 @@ private void switchGame() {
this.sentCommand = true;
this.command = null;
}

Multithreading.schedule(() -> {
this.sentCommand = false;
}, 5L, TimeUnit.SECONDS);
}, HytilsConfig.autoQueueDelay, TimeUnit.SECONDS);
}

@Override
public boolean isEnabled() {
return HytilsConfig.autoQueue;
return HytilsConfig.autoQueueGameEnd || HytilsConfig.autoQueueDie;
}

/**
Expand Down