diff --git a/.gitignore b/.gitignore index c63ba5d..ba3bd7e 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ gradle-app.setting **/build/ # End of https://www.gitignore.io/api/java,gradle,intellij +/common/src/main/corrected/ diff --git a/build.gradle b/build.gradle index 7d6ec5c..6a2bf78 100644 --- a/build.gradle +++ b/build.gradle @@ -1,208 +1,59 @@ -buildscript { - repositories { - maven { url = 'https://maven.minecraftforge.net' } - mavenCentral() - gradlePluginPortal() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2' - } -} - -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'com.github.johnrengelman.shadow' -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'maven-publish' - -version = mod_version -group = "igoodie.twitchspawn" -archivesBaseName = "twitchspawn_" + minecraft_version - -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) - -minecraft { - // The mappings can be changed at any time, and must be in the following format. - // snapshot_YYYYMMDD Snapshot are built nightly. - // stable_# Stables are built at the discretion of the MCP team. - // Use non-default mappings at your own risk. they may not always work. - // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: mcpMappings_channel, version: mcpMappings_version - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. - - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - // Default run configurations. - // These can be tweaked, removed, or duplicated as needed. - runs { - client { - workingDirectory project.file('run') - - // Recommended logging data for a userdev environment - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - - // Recommended logging level for the console - property 'forge.logging.console.level', 'debug' - - mods { - examplemod { - source sourceSets.main - } - } - } - - server { - workingDirectory project.file('run') - - // Recommended logging data for a userdev environment - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - - // Recommended logging level for the console - property 'forge.logging.console.level', 'debug' - - mods { - examplemod { - source sourceSets.main - } - } - } - - data { - workingDirectory project.file('run') - - // Recommended logging data for a userdev environment - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - - // Recommended logging level for the console - property 'forge.logging.console.level', 'debug' - - args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') - - mods { - examplemod { - source sourceSets.main - } - } - } - } -} - -repositories { - jcenter() - mavenCentral() +plugins { + id "architectury-plugin" version "3.4-SNAPSHOT" + id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false } -configurations { - shade - implementation.extendsFrom shade -} - -dependencies { - // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed - // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. - // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - - // Nightly Config by Electronwill -// shadow group: 'com.electronwill.night-config', name: 'core', version: '3.6.0' -// shadow group: 'com.electronwill.night-config', name: 'toml', version: '3.6.0' - - // SocketIO Client - shade "io.socket:socket.io-client:1.0.0" - minecraftLibrary "io.socket:socket.io-client:1.0.0" - - // JUnit 5 for testings - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.0' - - // For more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html - +architectury { + minecraft = rootProject.minecraft_version } -//// Fix the classpath the right way and once and for all -//afterEvaluate { -// // Collect deps in runtimeClasspath but NOT in minecraft -// def deps = (configurations.runtimeClasspath - configurations.minecraft).join(';') -// // Add deps to classpath -// minecraft.runs.each { run -> -// run.token 'minecraft_classpath', deps -// } -//} - -//jar { -// configurations.shade.each { dep -> -// from(project.zipTree(dep)) { -// exclude 'META-INF', 'META-INF/**' -// } -// } -//} - -//shadowJar { -// configurations = [project.configurations.shadow] -// classifier "" -//// relocate 'com.electronwill.nightconfig.core', "com.electronwill.nightconfig.${mod_id}.core" -//// relocate 'com.electronwill.nightconfig.toml', "com.electronwill.nightconfig.${mod_id}.toml" -//// relocate "io.socket.client", "io.socket.${mod_id}.client" -//} +subprojects { + apply plugin: "dev.architectury.loom" -// ==================================== + loom { + silentMojangMappingsLicense() + } -// Example for how to get properties into the manifest for reading by the runtime.. -jar { - archiveClassifier = 'slim' - //noinspection GroovyAssignabilityCheck - manifest { - attributes([ - "Specification-Title" : mod_id, - "Specification-Vendor" : mod_group, - "Specification-Version" : "1.0", - "Implementation-Title" : project.name, - "Implementation-Version" : "${mod_version}", - "Implementation-Vendor" : mod_group, - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) + dependencies { + minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" + // The following line declares the mojmap mappings, you may use other mappings as well + mappings loom.officialMojangMappings() + // The following line declares the yarn mappings you may select this one as well. + // mappings "net.fabricmc:yarn:@YARN_MAPPINGS@:v2" } } -shadowJar { - archiveClassifier = '' - configurations = [project.configurations.shade] - finalizedBy 'reobfShadowJar' -} +allprojects { + apply plugin: "java" + apply plugin: "architectury-plugin" + apply plugin: "maven-publish" -assemble.dependsOn shadowJar + base { + archivesName = rootProject.archives_base_name + } -reobf { - shadowJar {} -} + version = rootProject.mod_version + group = rootProject.maven_group -// ==================================== + repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + } -// Example configuration to allow publishing using the maven-publish task -// This is the preferred method to reobfuscate your jar file -jar.finalizedBy('reobfJar') -// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing -//publish.dependsOn('reobfJar') -publishing { - publications { - mavenJava(MavenPublication) { - artifact jar - } + dependencies { + implementation 'org.json:json:20231013' } - repositories { - maven { - url "file:///${project.projectDir}/mcmodsrepo" - } + + tasks.withType(JavaCompile) { + options.encoding = "UTF-8" + options.release.set(17) } -} -test { - useJUnitPlatform() + java { + withSourcesJar() + } } diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..0933e7b --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,37 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" +} + + +dependencies { + // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies + // Do NOT use other classes from fabric loader + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + // Remove the next line if you don't want to depend on the API + modApi "dev.architectury:architectury:${rootProject.architectury_version}" + + // Add JSON dependency + compileOnly "com.electronwill.night-config:core:3.6.4" + compileOnly "com.electronwill.night-config:toml:3.6.4" + + implementation 'com.squareup.okhttp3:okhttp:3.8.1' + implementation 'io.socket:socket.io-client:1.0.2' +} + +architectury { + common("fabric", "forge") +} + +publishing { + publications { + mavenCommon(MavenPublication) { + artifactId = rootProject.archives_base_name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } +} \ No newline at end of file diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java new file mode 100644 index 0000000..af0cf20 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java @@ -0,0 +1,222 @@ +package net.programmer.igoodie.twitchspawn; + + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import dev.architectury.event.events.client.ClientPlayerEvent; +import dev.architectury.event.events.common.CommandRegistrationEvent; +import dev.architectury.event.events.common.LifecycleEvent; +import dev.architectury.event.events.common.PlayerEvent; +import dev.architectury.utils.Env; +import dev.architectury.utils.EnvExecutor; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import net.programmer.igoodie.twitchspawn.client.gui.GlobalChatCooldownOverlay; +import net.programmer.igoodie.twitchspawn.client.gui.StatusIndicatorOverlay; +import net.programmer.igoodie.twitchspawn.client.gui.screens.LoadingErrorScreen; +import net.programmer.igoodie.twitchspawn.command.TwitchSpawnCommand; +import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; +import net.programmer.igoodie.twitchspawn.configuration.PreferencesConfig; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnEventHandler; +import net.programmer.igoodie.twitchspawn.network.NetworkManager; +import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket; +import net.programmer.igoodie.twitchspawn.registries.TwitchSpawnArgumentTypes; +import net.programmer.igoodie.twitchspawn.registries.TwitchSpawnSoundEvent; +import net.programmer.igoodie.twitchspawn.tracer.TraceManager; +import net.programmer.igoodie.twitchspawn.udl.NotepadUDLUpdater; + + +public class TwitchSpawn +{ + /** + * The plugin mod-id + */ + public static final String MOD_ID = "twitchspawn"; + + /** + * Minecraft server instance. + */ + public static MinecraftServer SERVER; + + /** + * Trace manager. + */ + public static TraceManager TRACE_MANAGER; + + /** + * Logger. + */ + public static final Logger LOGGER = LogManager.getLogger(); + + + /** + * The main init class. + */ + public static void init() + { + TwitchSpawnEventHandler.init(); + + CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> + TwitchSpawnCommand.register(dispatcher)); + + EnvExecutor.runInEnv(Env.CLIENT, () -> TwitchSpawn.Client::initializeClient); + EnvExecutor.runInEnv(Env.SERVER, () -> TwitchSpawn.Server::initializeServer); + } + + + /** + * List of common tasks initialized by both environments. + */ + private static void initializeCommon() + { + // Trigger tracer on server start. + LifecycleEvent.SERVER_BEFORE_START.register(server -> { + SERVER = server; + TRACE_MANAGER = new TraceManager(); + }); + + // Trigger autostart if that is enabled. + LifecycleEvent.SERVER_STARTING.register(server -> { + if (ConfigManager.PREFERENCES.autoStart == PreferencesConfig.AutoStartEnum.ENABLED) { + LOGGER.info("Auto-start is enabled. Attempting to start tracers."); + TRACE_MANAGER.start(); + } + }); + + // Trigger server stop that would disable tracers. + LifecycleEvent.SERVER_STOPPING.register(server -> { + SERVER = null; + + if (TRACE_MANAGER.isRunning()) + { + TRACE_MANAGER.stop(null, "Server stopping"); + } + + ConfigManager.RULESET_COLLECTION.clearQueue(); + }); + + // Do stuff on player joining the server. + PlayerEvent.PLAYER_JOIN.register(player -> + { + String translationKey = TRACE_MANAGER.isRunning() ? + "commands.twitchspawn.status.on" : "commands.twitchspawn.status.off"; + + player.sendSystemMessage(Component.translatable(translationKey)); + + if (TRACE_MANAGER.isRunning()) + { + TRACE_MANAGER.connectStreamer(player.getName().getString()); + } + + NetworkManager.CHANNEL.sendToPlayer(player, new StatusChangedPacket(TRACE_MANAGER.isRunning())); + }); + + // Do stuff on player leaving the server. + PlayerEvent.PLAYER_QUIT.register(player -> + { + if (TRACE_MANAGER.isRunning()) + { + TRACE_MANAGER.disconnectStreamer(player.getName().getString()); + } + }); + + try + { + TwitchSpawnSoundEvent.REGISTRY.register(); + TwitchSpawnArgumentTypes.registerArgumentType(); + + NetworkManager.initialize(); + ConfigManager.loadConfigs(); + } + catch (TwitchSpawnLoadingErrors exception) + { + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> Client.notifyCrash(exception)); + EnvExecutor.runInEnv(Env.SERVER, () -> () -> Server.notifyCrash(exception)); + } + } + + + /** + * Client related tasks. + */ + @Environment(EnvType.CLIENT) + public static class Client + { + /** + * The client initialization. + */ + @Environment(EnvType.CLIENT) + public static void initializeClient() + { + TwitchSpawn.initializeCommon(); + NotepadUDLUpdater.attemptUpdate(); + + ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> + { + StatusIndicatorOverlay.register(); + GlobalChatCooldownOverlay.register(); + }); + + ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> + { + StatusIndicatorOverlay.unregister(); + GlobalChatCooldownOverlay.unregister(); + }); + } + + + /** + * Notify the client about the config crash. + * @param errors The errors that caused the config crash. + */ + @Environment(EnvType.CLIENT) + public static void notifyCrash(TwitchSpawnLoadingErrors errors) + { + TwitchSpawnClientGuiEvent.FINISH_LOADING_OVERLAY.register((client, screen) -> + { + if (screen instanceof TitleScreen) + { + LoadingErrorScreen errorScreen = new LoadingErrorScreen(errors.getExceptions()); + errorScreen.init(client, + client.getWindow().getGuiScaledWidth(), + client.getWindow().getGuiScaledHeight()); + client.setScreen(errorScreen); + } + }); + } + } + + + /** + * Server related tasks + */ + @Environment(EnvType.SERVER) + public static class Server + { + /** + * The server initialization. + */ + @Environment(EnvType.SERVER) + public static void initializeServer() + { + TwitchSpawn.initializeCommon(); + } + + + /** + * Notify the server about the config crash. + * @param errors The errors that caused the config crash. + */ + @Environment(EnvType.SERVER) + public static void notifyCrash(TwitchSpawnLoadingErrors errors) + { + LOGGER.warn("TwitchSpawn config contains errors:"); + LOGGER.warn("\n" + errors.toString()); + } + } +} diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java new file mode 100644 index 0000000..986c57e --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java @@ -0,0 +1,49 @@ +package net.programmer.igoodie.twitchspawn; + + +import java.util.LinkedList; +import java.util.List; + +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxErrors; + +public class TwitchSpawnLoadingErrors extends Exception { + + List exceptions; + + public TwitchSpawnLoadingErrors() { + this.exceptions = new LinkedList<>(); + } + + public void addException(Exception exception) { + if (exception instanceof TSLSyntaxErrors) + this.exceptions.addAll(((TSLSyntaxErrors) exception).getErrors()); + else + this.exceptions.add(exception); + } + + public boolean isEmpty() { + return exceptions.isEmpty(); + } + + + /** + * Returns the list of exceptions + * @return The exception list. + */ + public List getExceptions() { + return this.exceptions; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + String delimiter = ""; + for (Exception exception : exceptions) { + sb.append(delimiter); + sb.append(exception.getMessage()); + delimiter = "\n"; + } + return sb.toString(); + } + +} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java similarity index 55% rename from src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java index b8a3a42..2eb27f1 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/GlobalChatCooldownOverlay.java @@ -1,17 +1,19 @@ package net.programmer.igoodie.twitchspawn.client.gui; + import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.client.ClientGuiEvent; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.configuration.PreferencesConfig; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; import net.programmer.igoodie.twitchspawn.util.CooldownBucket; public class GlobalChatCooldownOverlay { @@ -20,20 +22,47 @@ public class GlobalChatCooldownOverlay { new ResourceLocation(TwitchSpawn.MOD_ID, "textures/cooldown.png"); private static long timestamp = -1; + private static boolean drew = false; + /** + * Render indicator + */ + private static final TwitchSpawnClientGuiEvent.OverlayRenderPre PRE_RENDER = + (graphics, resourceLocation) -> drew = false; + + /** + * Render the gui + */ + private static final TwitchSpawnClientGuiEvent.OverlayRenderPost POST_RENDER = + GlobalChatCooldownOverlay::onRenderGuiPost; + + + /** + * Register rendering events. + */ + public static void register() { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.register(PRE_RENDER); + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_POST.register(POST_RENDER); + } + + + /** + * Unregister rendering events. + */ + public static void unregister() { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.unregister(PRE_RENDER); + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_POST.unregister(POST_RENDER); + } + + public static void setCooldownTimestamp(long timestamp) { GlobalChatCooldownOverlay.timestamp = timestamp; } - @SubscribeEvent - public static void onRenderGuiPre(RenderGameOverlayEvent.Pre event) { - drew = false; - } - @SubscribeEvent - public static void onRenderGuiPost(RenderGameOverlayEvent.Post event) { - if (event.getType() != ElementType.TEXT) + private static void onRenderGuiPost(GuiGraphics graphics, ResourceLocation resourceLocation) { + if (!resourceLocation.equals(ResourceLocation.of("hotbar", ':'))) return; // Render only on HOTBAR // Already drew, stop here @@ -61,23 +90,20 @@ public static void onRenderGuiPost(RenderGameOverlayEvent.Post event) { y = 5; } - PoseStack matrixStack = event.getMatrixStack(); - + PoseStack matrixStack = graphics.pose(); matrixStack.pushPose(); matrixStack.scale(scale, scale, scale); - renderGlyph(matrixStack, String.format("%02d", minutes), x, (int) (y / scale)); - renderGlyph(matrixStack, ":", x + 32, (int) (y / scale)); - renderGlyph(matrixStack, String.format("%02d", seconds), (x + 10 + 2 * 18), (int) (y / scale)); - renderGlyph(matrixStack, "i", (int) (x + 10 + 4.25f * 18), (int) ((y - 2) / scale)); + renderGlyph(graphics, matrixStack, String.format("%02d", minutes), x, (int) (y / scale)); + renderGlyph(graphics, matrixStack, ":", x + 32, (int) (y / scale)); + renderGlyph(graphics, matrixStack, String.format("%02d", seconds), (x + 10 + 2 * 18), (int) (y / scale)); + renderGlyph(graphics, matrixStack, "i", (int) (x + 10 + 4.25f * 18), (int) ((y - 2) / scale)); matrixStack.popPose(); } drew = true; } - public static void renderGlyph(PoseStack ms, String number, int x, int y) { - Minecraft minecraft = Minecraft.getInstance(); - + private static void renderGlyph(GuiGraphics guiGraphics, PoseStack ms, String number, int x, int y) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, cooldownGlyphs); @@ -92,30 +118,27 @@ public static void renderGlyph(PoseStack ms, String number, int x, int y) { int w = 28; int h = 25; - minecraft.gui.blit( - ms, - x, y, - ux, uy, - w, h + guiGraphics.blit(ResourceLocation.tryParse("hotbar"), + x, y, + ux, uy, + w, h ); } else { char[] chars = number.toCharArray(); for (int i = 0, offset = 0; i < chars.length; i++) { - int digit = number.equals(":") ? 10 - : Character.digit(number.charAt(i), 10); + int digit = number.equals(":") ? 10 : Character.digit(number.charAt(i), 10); int ux = 18 * digit; int uy = 0; int w = 18; int h = 18; - minecraft.gui.blit( - ms, - x + offset, y, - ux, uy, - w, h + guiGraphics.blit(ResourceLocation.tryParse("hotbar"), + x + offset, y, + ux, uy, + w, h ); offset += w; @@ -127,7 +150,6 @@ public static void renderGlyph(PoseStack ms, String number, int x, int y) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, Gui.GUI_ICONS_LOCATION); + RenderSystem.setShaderTexture(0, new ResourceLocation("hud/hotbar")); } - } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java similarity index 55% rename from src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java index f9aec20..dbbe562 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/StatusIndicatorOverlay.java @@ -1,20 +1,26 @@ package net.programmer.igoodie.twitchspawn.client.gui; + import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.client.ClientGuiEvent; +import dev.architectury.hooks.client.screen.ScreenAccess; +import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.configuration.PreferencesConfig; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; +import net.programmer.igoodie.twitchspawn.registries.TwitchSpawnSoundEvent; + public class StatusIndicatorOverlay { @@ -22,43 +28,59 @@ public class StatusIndicatorOverlay { new ResourceLocation(TwitchSpawn.MOD_ID, "textures/indicators.png"); private static boolean running = false; + private static boolean drew = false; + /** + * Render indicator + */ + private static final TwitchSpawnClientGuiEvent.OverlayRenderPre PRE_RENDER = + (graphics, resourceLocation) -> drew = false; + + /** + * Render the gui + */ + private static final TwitchSpawnClientGuiEvent.RenderDebugHud POST_RENDER = + StatusIndicatorOverlay::onRenderGuiPost; + + + /** + * Register rendering events. + */ + public static void register() { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.register(PRE_RENDER); + TwitchSpawnClientGuiEvent.DEBUG_TEXT.register(POST_RENDER); + } + + + /** + * Unregister rendering events. + */ + public static void unregister() { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.unregister(PRE_RENDER); + TwitchSpawnClientGuiEvent.DEBUG_TEXT.unregister(POST_RENDER); + } + + public static void setRunning(boolean running) { StatusIndicatorOverlay.running = running; - String soundName = running ? "pop_in" : "pop_out"; + ResourceLocation soundEvent = running ? + TwitchSpawnSoundEvent.POP_IN.getId() : TwitchSpawnSoundEvent.POP_OUT.getId(); Minecraft minecraft = Minecraft.getInstance(); LocalPlayer self = minecraft.player; if (self != null) { // Here to hopefully fix an obscure Null Pointer (From UNKNOWN PENGUIN's log) - self.playSound(new SoundEvent(new ResourceLocation(TwitchSpawn.MOD_ID, soundName)), 1f, 1f); + self.playSound(SoundEvent.createVariableRangeEvent(soundEvent), 1f, 1f); } } - @SubscribeEvent - public static void onClientTick(TickEvent.ClientTickEvent event) { - if (event.phase != TickEvent.Phase.END) - return; - } - - @SubscribeEvent - public static void onRenderGuiPre(RenderGameOverlayEvent.Pre event) { - drew = false; - } - @SubscribeEvent - public static void onRenderGuiPost(RenderGameOverlayEvent.Post event) { + private static void onRenderGuiPost(GuiGraphics gui) { if (ConfigManager.PREFERENCES.indicatorDisplay == PreferencesConfig.IndicatorDisplay.DISABLED) return; // The display is disabled, stop here - Minecraft minecraft = Minecraft.getInstance(); - PoseStack matrixStack = event.getMatrixStack(); - - if (event.getType() != ElementType.TEXT) - return; // Render only on HOTBAR - // Already drew, stop here if (drew) return; @@ -68,7 +90,7 @@ public static void onRenderGuiPost(RenderGameOverlayEvent.Post event) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0, indicatorIcons); - matrixStack.pushPose(); + gui.pose().pushPose(); int x = 5, y = 5; int ux = -1, uy = -1; @@ -86,15 +108,15 @@ public static void onRenderGuiPost(RenderGameOverlayEvent.Post event) { h = 12; } - matrixStack.scale(1f, 1f, 1f); - minecraft.gui.blit(matrixStack, x, y, ux, uy, w, h); + gui.pose().scale(1f, 1f, 1f); + gui.blit(indicatorIcons, x, y, ux, uy, w, h); - matrixStack.popPose(); + gui.pose().popPose(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableBlend(); - RenderSystem.setShaderTexture(0, Gui.GUI_ICONS_LOCATION); +// RenderSystem.setShaderTexture(0, Gui.GUI_ICONS_LOCATION); drew = true; } diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/screens/LoadingErrorScreen.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/screens/LoadingErrorScreen.java new file mode 100644 index 0000000..baf0007 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/client/gui/screens/LoadingErrorScreen.java @@ -0,0 +1,253 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.client.gui.screens; + + +import com.electronwill.nightconfig.core.io.ParsingException; +import com.google.gson.JsonSyntaxException; +import java.io.File; +import java.util.List; +import java.util.Objects; + +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ObjectSelectionList; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; +import net.programmer.igoodie.twitchspawn.TwitchSpawnLoadingErrors; +import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; + + +/** + * Very simplistic error screen for fabric. + */ +public class LoadingErrorScreen extends Screen +{ + /** + * Creates a new error screen with the given exceptions. + * @param configLoadingExceptions The exceptions to display. + */ + public LoadingErrorScreen(List configLoadingExceptions) + { + super(Component.literal("Loading Error")); + this.configLoadingExceptions = configLoadingExceptions; + } + + + @Override + public void init() + { + super.init(); + this.clearWidgets(); + + this.errorScreenTitle = Component.translatable("modloader.twitchspawn.error.title"). + withStyle(ChatFormatting.YELLOW); + + this.addRenderableWidget(Button.builder( + Component.translatable("modloader.twitchspawn.error.folder"), + onPress -> Util.getPlatform().openFile(new File(ConfigManager.CONFIG_DIR_PATH))). + size(this.width / 2 - 55, 20). + pos(50, this.height - 46). + build()); + this.addRenderableWidget(Button.builder( + Component.translatable("modloader.twitchspawn.error.reload"), + onPress -> reloadConfigs()). + size(this.width / 2 - 55, 20). + pos(this.width / 2 + 5, this.height - 46). + build()); + this.addRenderableWidget(Button.builder( + Component.translatable("modloader.twitchspawn.error.continue"), + onPress -> this.minecraft.setScreen(null)). + size(this.width / 2, 20). + pos(this.width / 4, this.height - 24). + build()); + + this.entryList = new LoadingEntryList(this, this.configLoadingExceptions); + this.addWidget(this.entryList); + this.setFocused(this.entryList); + } + + + @Override + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) + { + super.render(guiGraphics, mouseX, mouseY, partialTick); + this.entryList.render(guiGraphics, mouseX, mouseY, partialTick); + drawMultiLineCenteredString(guiGraphics, + font, + errorScreenTitle, + this.width / 2, + 10); + } + + + @Override + public void renderBackground(GuiGraphics guiGraphics, int i, int j, float f) + { + guiGraphics.fillGradient(0, 0, this.width, this.height, -12574688, -11530224); + } + + + /** + * This method reloads configs and repopulates list with new exceptions or close screen if everything + * is correct. + */ + private void reloadConfigs() + { + try + { + ConfigManager.loadConfigs(); + this.minecraft.setScreen(null); + } + catch (TwitchSpawnLoadingErrors e) + { + this.configLoadingExceptions.clear(); + this.configLoadingExceptions.addAll(e.getExceptions()); + this.init(); + } + } + + + /** + * This method draws multiline centered string. + * @param guiGraphics GuiGraphics instance. + * @param font FontRenderer instance. + * @param component String to draw. + * @param x X coordinate. + * @param y Y coordinate. + */ + private void drawMultiLineCenteredString(GuiGraphics guiGraphics, Font font, Component component, int x, int y) + { + for (FormattedCharSequence chars : font.split(component, this.width)) + { + guiGraphics.drawString(font, chars, (int) ((x - font.width(chars) / 2.0)), y, 0xFFFFFF, true); + y += font.lineHeight; + } + } + + + /** + * This class contains and renders all error entries. + */ + private static class LoadingEntryList extends ObjectSelectionList + { + LoadingEntryList(final LoadingErrorScreen parent, final List errors) + { + super(parent.minecraft, + parent.width, + parent.height, + 35, + parent.height - 50, + errors.stream().mapToInt(warning -> + parent.font.split(Component.literal(warning.getMessage()), parent.width - 20).size()). + max(). + orElse(0) * parent.minecraft.font.lineHeight + 8); + + errors.forEach(exception -> { + String i18nMessage; + + if (exception instanceof TSLSyntaxError) + { + i18nMessage = "modloader.twitchspawn.error.tsl"; + } + else if (exception instanceof ParsingException) + { + i18nMessage = "modloader.twitchspawn.error.toml"; + } + else if (exception instanceof JsonSyntaxException) + { + i18nMessage = "modloader.twitchspawn.error.json"; + } + else + { + i18nMessage = "modloader.twitchspawn.error.unknown"; + } + + this.addEntry(new LoadingMessageEntry( + Component.translatable(i18nMessage, exception.getMessage(), exception.getClass().toString()))); + }); + } + + + @Override + protected int getScrollbarPosition() + { + return this.width - 6; + } + + + @Override + public int getRowWidth() + { + return this.width; + } + + + public class LoadingMessageEntry extends ObjectSelectionList.Entry + { + private final Component message; + + LoadingMessageEntry(final Component message) + { + this.message = Objects.requireNonNull(message); + } + + + @Override + public Component getNarration() + { + return Component.translatable("narrator.select", message); + } + + + @Override + public void render(GuiGraphics guiGraphics, + int entryIdx, + int top, + int left, + final int entryWidth, + final int entryHeight, + final int mouseX, + final int mouseY, + final boolean p_194999_5_, + final float partialTick) + { + Font font = Minecraft.getInstance().font; + var strings = font.split(message, LoadingEntryList.this.width - 20); + int y = top + 2; + + for (var string : strings) + { + guiGraphics.drawString(font, string, left + 5, y, 0xFFFFFF, false); + y += font.lineHeight; + } + } + } + } + + + /** + * List of config exceptions + */ + private final List configLoadingExceptions; + + /** + * The component that displays error entries. + */ + private LoadingEntryList entryList; + + /** + * The title of the error screen. + */ + private Component errorScreenTitle; +} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java similarity index 86% rename from src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java index 933f0c6..99e8afc 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/CommandArguments.java @@ -1,14 +1,14 @@ package net.programmer.igoodie.twitchspawn.command; + import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.RequiredArgumentBuilder; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.CompoundTagArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.nbt.CompoundTag; @@ -26,9 +26,11 @@ public static RequiredArgumentBuilder integer(Strin return Commands.argument(name, IntegerArgumentType.integer(min, max)); } - public static RequiredArgumentBuilder item(String name) { - return Commands.argument(name, ItemArgument.item()); - } +// I just commented out, as it is not used. ItemArgument.item() requires CommandBuildContext that +// I do not know how to provide here. +// public static RequiredArgumentBuilder item(String name) { +// return Commands.argument(name, ItemArgument.item()); +// } public static RequiredArgumentBuilder player(String name) { return Commands.argument(name, EntityArgument.player()); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java similarity index 97% rename from src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java index a7922ed..676e138 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/RulesetNameArgumentType.java @@ -1,15 +1,16 @@ package net.programmer.igoodie.twitchspawn.command; + import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; - import java.util.concurrent.CompletableFuture; +import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; + public class RulesetNameArgumentType implements ArgumentType { public static RulesetNameArgumentType rulesetName() { @@ -22,7 +23,7 @@ public static String getRulesetName(final CommandContext context, final Strin /* ------------------------------ */ - private RulesetNameArgumentType() { } + public RulesetNameArgumentType() { } @Override public String parse(StringReader reader) throws CommandSyntaxException { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java similarity index 97% rename from src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java index 358b2bc..8b3c908 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/StreamerArgumentType.java @@ -1,15 +1,16 @@ package net.programmer.igoodie.twitchspawn.command; + import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; - import java.util.concurrent.CompletableFuture; +import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; + public class StreamerArgumentType implements ArgumentType { public static StreamerArgumentType streamerNick() { @@ -23,7 +24,7 @@ public static String getStreamer(final CommandContext context, final String n /* ---------------------------------------- */ - private StreamerArgumentType() { } + public StreamerArgumentType() { } @Override public String parse(StringReader reader) throws CommandSyntaxException { @@ -46,5 +47,4 @@ public CompletableFuture listSuggestions(CommandContext cont public String toString() { return "streamer()"; } - } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java similarity index 96% rename from src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java index 842a675..6c7e63a 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/TSLWordsArgumentType.java @@ -17,7 +17,7 @@ public static String getWords(final CommandContext context, final String name /* ------------------------------------ */ - private TSLWordsArgumentType() { } + public TSLWordsArgumentType() { } @Override public String parse(StringReader reader) throws CommandSyntaxException { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java similarity index 89% rename from src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java index 8f2024b..58e5bdd 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/command/TwitchSpawnCommand.java @@ -1,16 +1,21 @@ package net.programmer.igoodie.twitchspawn.command; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.BuiltInExceptions; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandRuntimeException; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; @@ -31,12 +36,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLTokenizer; import net.programmer.igoodie.twitchspawn.util.MCPHelpers; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - public class TwitchSpawnCommand { public static final String[] COMMAND_NAMES = {"twitchspawn", "ts"}; @@ -86,7 +85,7 @@ public static int statusModule(CommandContext context) { String translationKey = TwitchSpawn.TRACE_MANAGER.isRunning() ? "commands.twitchspawn.status.on" : "commands.twitchspawn.status.off"; - context.getSource().sendSuccess(new TranslatableComponent(translationKey), false); + context.getSource().sendSuccess(() -> Component.translatable(translationKey), false); return 1; } @@ -96,7 +95,7 @@ public static int startModule(CommandContext context) { // If has no permission if (!ConfigManager.CREDENTIALS.hasPermission(sourceNickname)) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.start.no_perm"), true); TwitchSpawn.LOGGER.info("{} tried to run TwitchSpawn, but no permission", sourceNickname); return 0; @@ -107,7 +106,7 @@ public static int startModule(CommandContext context) { return 1; } catch (IllegalStateException e) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.start.illegal_state"), true); return 0; } @@ -118,7 +117,7 @@ public static int stopModule(CommandContext context) { // If has no permission if (!ConfigManager.CREDENTIALS.hasPermission(sourceNickname)) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.stop.no_perm"), true); TwitchSpawn.LOGGER.info("{} tried to stop TwitchSpawn, but no permission", sourceNickname); return 0; @@ -129,7 +128,7 @@ public static int stopModule(CommandContext context) { return 1; } catch (IllegalStateException e) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.stop.illegal_state"), true); return 0; } @@ -145,27 +144,27 @@ public static int reloadModule(CommandContext context) { // If is not OP or has no permission if (!isOp && !ConfigManager.CREDENTIALS.hasPermission(sourceNickname)) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.reloadcfg.no_perm"), true); TwitchSpawn.LOGGER.info("{} tried to reload TwitchSpawn configs, but no permission", sourceNickname); return 0; } if (TwitchSpawn.TRACE_MANAGER.isRunning()) { - source.sendSuccess(new TranslatableComponent( + source.sendSuccess(() -> Component.translatable( "commands.twitchspawn.reloadcfg.already_started"), false); return 0; } try { ConfigManager.loadConfigs(); - source.sendSuccess(new TranslatableComponent( + source.sendSuccess(() -> Component.translatable( "commands.twitchspawn.reloadcfg.success"), false); return 1; } catch (TwitchSpawnLoadingErrors e) { String errorLog = "• " + e.toString().replace("\n", "\n• "); - source.sendSuccess(new TranslatableComponent( + source.sendSuccess(() -> Component.translatable( "commands.twitchspawn.reloadcfg.invalid_syntax", errorLog), false); return 0; } @@ -175,7 +174,7 @@ public static int quickRefreshModule(CommandContext context) String sourceNickname = context.getSource().getTextName(); if (!ConfigManager.CREDENTIALS.hasPermission(sourceNickname)) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.reloadcfg.no_perm"), true); TwitchSpawn.LOGGER.info("{} tried to run TwitchSpawn, but no permission", sourceNickname); return 0; @@ -194,7 +193,7 @@ public static int quickRefreshModule(CommandContext context) public static int rulesModule(CommandContext context, String rulesetName) { if (rulesetName == null) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.rules.list", ConfigManager.RULESET_COLLECTION.getStreamers()), true); return 1; @@ -203,7 +202,7 @@ public static int rulesModule(CommandContext context, String TSLRuleset ruleset = ConfigManager.RULESET_COLLECTION.getRuleset(rulesetName); if (ruleset == null) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.rules.one.fail", rulesetName), true); return 0; @@ -211,7 +210,7 @@ public static int rulesModule(CommandContext context, String String translationKey = rulesetName.equalsIgnoreCase("default") ? "commands.twitchspawn.rules.default" : "commands.twitchspawn.rules.one"; - context.getSource().sendSuccess(new TranslatableComponent(translationKey, + context.getSource().sendSuccess(() -> Component.translatable(translationKey, rulesetName, ruleset.toString()), true); return 1; } @@ -225,7 +224,7 @@ public static int simulateModule(CommandContext context, Str // If has no permission if (!ConfigManager.CREDENTIALS.hasPermission(sourceName)) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.simulate.no_perm"), true); TwitchSpawn.LOGGER.info("{} tried to simulate an event, but no permission", sourceName); return 0; @@ -235,7 +234,7 @@ public static int simulateModule(CommandContext context, Str String eventName = nbt.getString("event"); if (eventName.isEmpty()) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.simulate.missing"), true); return 0; } @@ -243,7 +242,7 @@ public static int simulateModule(CommandContext context, Str Set eventPairs = TSLEventKeyword.toPairs(eventName); if (eventPairs == null) { - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.simulate.invalid_event", eventName), true); return 0; } @@ -272,7 +271,7 @@ public static int simulateModule(CommandContext context, Str ConfigManager.RULESET_COLLECTION.handleEvent(simulatedEvent); - context.getSource().sendSuccess(new TranslatableComponent( + context.getSource().sendSuccess(() -> Component.translatable( "commands.twitchspawn.simulate.success", nbt), true); return 1; @@ -294,7 +293,7 @@ public static int executeModule(CommandContext context) thro tslAction.process(eventArguments); } catch (TSLSyntaxError e) { - throw new CommandRuntimeException(new TextComponent(e.getMessage())); + throw new CommandSyntaxException(new BuiltInExceptions().dispatcherParseException(), Component.translatable(e.getMessage())); } return 1; @@ -307,7 +306,7 @@ public static int executeModule(CommandContext context) thro public static int testModule(CommandContext context, String streamerNick) throws CommandSyntaxException { if (!ConfigManager.RULESET_COLLECTION.hasStreamer(streamerNick)) { TwitchSpawn.LOGGER.info("There are no ruleset associated with {}", streamerNick); - context.getSource().sendSuccess(new TranslatableComponent("commands.twitchspawn.test.not_found", streamerNick), true); + context.getSource().sendSuccess(() -> Component.translatable("commands.twitchspawn.test.not_found", streamerNick), true); return 0; } @@ -356,7 +355,7 @@ public static int testModule(CommandContext context, String } TwitchSpawn.LOGGER.info("Tests queued for {}", streamerNick); - context.getSource().sendSuccess(new TranslatableComponent("commands.twitchspawn.test.success", streamerNick), true); + context.getSource().sendSuccess(() -> Component.translatable("commands.twitchspawn.test.success", streamerNick), true); return 1; } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java similarity index 90% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java index e3affa9..a38650c 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/ConfigManager.java @@ -1,20 +1,27 @@ package net.programmer.igoodie.twitchspawn.configuration; -import net.minecraftforge.fml.loading.FMLPaths; + +import java.io.File; + + +import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.platform.Platform; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.TwitchSpawnLoadingErrors; import net.programmer.igoodie.twitchspawn.tslanguage.TSLRulesetCollection; -import java.io.File; - public class ConfigManager { - public static final String CONFIG_DIR_PATH = FMLPaths.CONFIGDIR.get().toString() + File.separator + "TwitchSpawn"; + public static final String CONFIG_DIR_PATH = Platform.getConfigFolder().toString() + File.separator + "TwitchSpawn"; public static CredentialsConfig CREDENTIALS; + public static TSLRulesetCollection RULESET_COLLECTION; + public static TitlesConfig TITLES; + public static SubtitlesConfig SUBTITLES; + public static PreferencesConfig PREFERENCES; public static void loadConfigs() throws TwitchSpawnLoadingErrors { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java index 900bbe7..1c0b825 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/CredentialsConfig.java @@ -1,15 +1,13 @@ package net.programmer.igoodie.twitchspawn.configuration; + import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.conversion.ObjectConverter; import com.electronwill.nightconfig.core.io.ParsingException; import com.electronwill.nightconfig.toml.TomlFormat; import com.electronwill.nightconfig.toml.TomlParser; -import net.programmer.igoodie.twitchspawn.TwitchSpawn; -import net.programmer.igoodie.twitchspawn.tracer.Platform; import org.apache.commons.io.FileUtils; - import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -18,6 +16,9 @@ import java.util.List; import java.util.stream.Collectors; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.tracer.Platform; + public class CredentialsConfig { public static CredentialsConfig create(String filepath) throws ParsingException { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java index 1ba3ef5..581a32b 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/PreferencesConfig.java @@ -1,20 +1,22 @@ package net.programmer.igoodie.twitchspawn.configuration; + import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; import com.electronwill.nightconfig.toml.TomlParser; import com.google.common.io.Resources; -import net.programmer.igoodie.twitchspawn.TwitchSpawn; import org.apache.commons.io.FileUtils; - import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; -public class PreferencesConfig { +import net.programmer.igoodie.twitchspawn.TwitchSpawn; + +public class PreferencesConfig +{ public enum IndicatorDisplay { DISABLED, CIRCLE_ONLY, ENABLED } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java index 84b466f..6af2c3f 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/RulesConfig.java @@ -1,12 +1,8 @@ package net.programmer.igoodie.twitchspawn.configuration; + import com.google.common.io.Resources; -import net.programmer.igoodie.twitchspawn.TwitchSpawn; -import net.programmer.igoodie.twitchspawn.tslanguage.TSLRuleset; -import net.programmer.igoodie.twitchspawn.tslanguage.TSLRulesetCollection; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxErrors; import org.apache.commons.io.FileUtils; - import java.io.File; import java.io.IOException; import java.net.URL; @@ -16,6 +12,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.tslanguage.TSLRuleset; +import net.programmer.igoodie.twitchspawn.tslanguage.TSLRulesetCollection; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxErrors; + public class RulesConfig { public static TSLRulesetCollection createRules(String directory) throws TSLSyntaxErrors { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java index 40793b1..08db822 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/SubtitlesConfig.java @@ -1,7 +1,7 @@ package net.programmer.igoodie.twitchspawn.configuration; -import com.google.gson.JsonArray; +import com.google.gson.JsonArray; import java.io.File; public class SubtitlesConfig extends TextComponentConfig { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java index c485cce..fc30efb 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TextComponentConfig.java @@ -1,18 +1,19 @@ package net.programmer.igoodie.twitchspawn.configuration; + import com.google.common.io.Resources; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; -import net.programmer.igoodie.twitchspawn.util.GsonUtils; import org.apache.commons.io.FileUtils; - import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; +import net.programmer.igoodie.twitchspawn.util.GsonUtils; + public abstract class TextComponentConfig { protected JsonObject componentJson; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java index 6011d4b..798fa2e 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/configuration/TitlesConfig.java @@ -1,7 +1,7 @@ package net.programmer.igoodie.twitchspawn.configuration; -import com.google.gson.JsonArray; +import com.google.gson.JsonArray; import java.io.File; public class TitlesConfig extends TextComponentConfig { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java similarity index 94% rename from src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java index eb8d6a4..8e7e439 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/easteregg/Developers.java @@ -7,6 +7,6 @@ public class Developers { public static final Set TWITCH_NICKS = new HashSet<>( - Arrays.asList("iGoodiex", "TheDiaval", "Girloflegend")); + Arrays.asList("iGoodiex", "TheDiaval", "Girloflegend", "BONNe1704")); } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java similarity index 93% rename from src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java index 749f61b..724bcfa 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueue.java @@ -1,18 +1,19 @@ package net.programmer.igoodie.twitchspawn.eventqueue; + +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkDirection; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.network.NetworkManager; import net.programmer.igoodie.twitchspawn.network.packet.GlobalChatCooldownPacket; +import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEvent; import net.programmer.igoodie.twitchspawn.util.CooldownBucket; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; - public class EventQueue { private final Thread innerThread; @@ -136,11 +137,8 @@ public void queue(TSLEvent eventNode, EventArguments args, CooldownBucket cooldo .getPlayerByName(args.streamerNickname); if (playerEntity != null) { - NetworkManager.CHANNEL.sendTo( - new GlobalChatCooldownPacket(cooldownBucket.getGlobalCooldownTimestamp()), - playerEntity.connection.connection, - NetworkDirection.PLAY_TO_CLIENT - ); + NetworkManager.CHANNEL.sendToPlayer(playerEntity, + new GlobalChatCooldownPacket(cooldownBucket.getGlobalCooldownTimestamp())); } } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueState.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueState.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueState.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueState.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueTask.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueTask.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueTask.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/eventqueue/EventQueueTask.java diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnClientGuiEvent.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnClientGuiEvent.java new file mode 100644 index 0000000..9df5811 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnClientGuiEvent.java @@ -0,0 +1,84 @@ +package net.programmer.igoodie.twitchspawn.events; + + +import dev.architectury.event.Event; +import dev.architectury.event.EventFactory; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; + + +@Environment(EnvType.CLIENT) +public interface TwitchSpawnClientGuiEvent +{ + /** + * This event is fired when the debug text is rendered. + */ + Event DEBUG_TEXT = EventFactory.createLoop(); + + /** + * This event is fired before overlay is rendered. + */ + Event OVERLAY_RENDER_PRE = EventFactory.createLoop(); + + /** + * This event is fired after overlay is rendered. + */ + Event OVERLAY_RENDER_POST = EventFactory.createLoop(); + + /** + * This event is fired after loading screen is removed. + */ + Event FINISH_LOADING_OVERLAY = EventFactory.createLoop(); + + + /** + * The forge event is {@link net.minecraftforge.client.event.CustomizeGuiOverlayEvent.DebugText} + * The fabric triggers it via {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinGui#renderDebugText} + */ + @Environment(EnvType.CLIENT) + interface RenderDebugHud + { + void renderHud(GuiGraphics graphics); + } + + + /** + * The forge event is {@link net.minecraftforge.client.event.RenderGuiOverlayEvent.Pre} + * The fabric triggers it via {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinGui#preRenderHotbar} + * and {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinGui#preRenderHotbarSpectator} + */ + @Environment(EnvType.CLIENT) + interface OverlayRenderPre + { + void renderHud(GuiGraphics graphics, ResourceLocation overlay); + } + + + /** + * This event is fired when the debug text is rendered. + * The forge event is {@link net.minecraftforge.client.event.RenderGuiOverlayEvent.Post} + * The fabric triggers it via {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinGui#postRenderHotbar} + * and {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinGui#postRenderHotbarSpectator} + */ + @Environment(EnvType.CLIENT) + interface OverlayRenderPost + { + void renderHud(GuiGraphics graphics, ResourceLocation overlay); + } + + + /** + * This event is fired when the debug text is rendered. + * The forge triggers it via {@link net.programmer.igoodie.twitchspawn.mixin.forge.MixinLoadingOverlay#overlayRemoveEvent} + * The fabric triggers it via {@link net.programmer.igoodie.twitchspawn.mixin.fabric.MixinLoadingOverlay#overlayRemoveEvent} + */ + @Environment(EnvType.CLIENT) + interface LoadingScreenFinish + { + void removeOverlay(Minecraft client, Screen screen); + } +} diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnEventHandler.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnEventHandler.java new file mode 100644 index 0000000..3380654 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/events/TwitchSpawnEventHandler.java @@ -0,0 +1,40 @@ +package net.programmer.igoodie.twitchspawn.events; + + +import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + + +public final class TwitchSpawnEventHandler +{ + private TwitchSpawnEventHandler() + { + } + + + private static boolean initialized = false; + + + public static void init() + { + if (initialized) return; + + initialized = true; + + if (Platform.getEnvironment() == Env.CLIENT) + { + registerClient(); + } + } + + + @ExpectPlatform + @Environment(EnvType.CLIENT) + private static void registerClient() + { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java new file mode 100644 index 0000000..1430b1a --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java @@ -0,0 +1,39 @@ +package net.programmer.igoodie.twitchspawn.network; + + +import dev.architectury.networking.NetworkChannel; +import net.minecraft.resources.ResourceLocation; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.network.packet.GlobalChatCooldownPacket; +import net.programmer.igoodie.twitchspawn.network.packet.OsRunPacket; +import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket; + + +public class NetworkManager { + /** + * Channel for network communication. + */ + public static final NetworkChannel CHANNEL = NetworkChannel. + create(new ResourceLocation(TwitchSpawn.MOD_ID, "network")); + + + /** + * The method that initializes the network channel. + */ + public static void initialize() { + CHANNEL.register(StatusChangedPacket.class, + StatusChangedPacket::encode, + StatusChangedPacket::decode, + StatusChangedPacket::handle); + + CHANNEL.register(OsRunPacket.class, + OsRunPacket::encode, + OsRunPacket::decode, + OsRunPacket::handle); + + CHANNEL.register(GlobalChatCooldownPacket.class, + GlobalChatCooldownPacket::encode, + GlobalChatCooldownPacket::decode, + GlobalChatCooldownPacket::handle); + } +} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java similarity index 60% rename from src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java index abedc9c..f7105ea 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/GlobalChatCooldownPacket.java @@ -1,13 +1,19 @@ package net.programmer.igoodie.twitchspawn.network.packet; + +import java.util.function.Supplier; + +import dev.architectury.networking.NetworkManager; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; import net.programmer.igoodie.twitchspawn.client.gui.GlobalChatCooldownOverlay; -import java.util.function.Supplier; public class GlobalChatCooldownPacket { + public GlobalChatCooldownPacket(long timestamp) { + this.timestamp = timestamp; + } + public static void encode(GlobalChatCooldownPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.timestamp); } @@ -16,20 +22,12 @@ public static GlobalChatCooldownPacket decode(FriendlyByteBuf buffer) { return new GlobalChatCooldownPacket(buffer.readLong()); } - public static void handle(final GlobalChatCooldownPacket packet, - Supplier context) { - context.get().enqueueWork(() -> { - GlobalChatCooldownOverlay.setCooldownTimestamp(packet.timestamp); - }); - context.get().setPacketHandled(true); - } - - /* -------------------------------- */ - - private long timestamp; - - public GlobalChatCooldownPacket(long timestamp) { - this.timestamp = timestamp; + public void handle(Supplier context) { + context.get().queue(() -> GlobalChatCooldownOverlay.setCooldownTimestamp(this.timestamp)); } + /** + * Timestamp of the cooldown. + */ + private final long timestamp; } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java similarity index 65% rename from src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java index ae401a5..30ed253 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/OsRunPacket.java @@ -1,13 +1,20 @@ package net.programmer.igoodie.twitchspawn.network.packet; + +import java.util.function.Supplier; + +import dev.architectury.networking.NetworkManager; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; import net.programmer.igoodie.twitchspawn.tslanguage.action.OsRunAction; -import java.util.function.Supplier; public class OsRunPacket { + public OsRunPacket(OsRunAction.Shell shell, String script) { + this.shell = shell; + this.script = script; + } + public static void encode(OsRunPacket packet, FriendlyByteBuf buffer) { buffer.writeInt(packet.shell.ordinal()); buffer.writeUtf(packet.script); @@ -20,19 +27,18 @@ public static OsRunPacket decode(FriendlyByteBuf buffer) { return new OsRunPacket(shell, script); } - public static void handle(final OsRunPacket packet, Supplier context) { - context.get().enqueueWork(() -> OsRunAction.handleLocalScript(packet.shell, packet.script)); - context.get().setPacketHandled(true); + public void handle(Supplier context) { + context.get().queue(() -> OsRunAction.handleLocalScript(this.shell, this.script)); } - /* ------------------------------------------------ */ - private OsRunAction.Shell shell; - private String script; - - public OsRunPacket(OsRunAction.Shell shell, String script) { - this.shell = shell; - this.script = script; - } + /** + * Shell to run the script with. + */ + private final OsRunAction.Shell shell; + /** + * Script to run. + */ + private final String script; } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java similarity index 60% rename from src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java index 97b54ac..7ec552b 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/network/packet/StatusChangedPacket.java @@ -1,13 +1,19 @@ package net.programmer.igoodie.twitchspawn.network.packet; + +import java.util.function.Supplier; + +import dev.architectury.networking.NetworkManager; import net.minecraft.network.FriendlyByteBuf; -import net.minecraftforge.network.NetworkEvent; import net.programmer.igoodie.twitchspawn.client.gui.StatusIndicatorOverlay; -import java.util.function.Supplier; public class StatusChangedPacket { + public StatusChangedPacket(boolean status) { + this.status = status; + } + public static void encode(StatusChangedPacket packet, FriendlyByteBuf buffer) { buffer.writeBoolean(packet.status); } @@ -16,20 +22,12 @@ public static StatusChangedPacket decode(FriendlyByteBuf buffer) { return new StatusChangedPacket(buffer.readBoolean()); } - public static void handle(final StatusChangedPacket packet, - Supplier context) { - context.get().enqueueWork(() -> { - StatusIndicatorOverlay.setRunning(packet.status); - }); - context.get().setPacketHandled(true); - } - - /* ---------------------------- */ - - private boolean status; - - public StatusChangedPacket(boolean status) { - this.status = status; + public void handle(Supplier context) { + context.get().queue(() -> StatusIndicatorOverlay.setRunning(this.status)); } + /** + * True if the status is running, false if stopped. + */ + private final boolean status; } diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnArgumentTypes.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnArgumentTypes.java new file mode 100644 index 0000000..02409b5 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnArgumentTypes.java @@ -0,0 +1,18 @@ +package net.programmer.igoodie.twitchspawn.registries; + + +import dev.architectury.injectables.annotations.ExpectPlatform; + + +/** + * This class registers argument types. + */ +public class TwitchSpawnArgumentTypes +{ + @ExpectPlatform + public static void registerArgumentType() + { + // Just throw an error, the content should get replaced at runtime. + throw new AssertionError(); + } +} diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnSoundEvent.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnSoundEvent.java new file mode 100644 index 0000000..8a329a4 --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/registries/TwitchSpawnSoundEvent.java @@ -0,0 +1,34 @@ +package net.programmer.igoodie.twitchspawn.registries; + + +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; + + +/** + * This class registers sound events. + */ +public class TwitchSpawnSoundEvent +{ + /** + * Registry for sound events. + */ + public static final DeferredRegister REGISTRY = + DeferredRegister.create(TwitchSpawn.MOD_ID, Registries.SOUND_EVENT); + + /** + * Sound event for popping in. + */ + public static final RegistrySupplier POP_IN = REGISTRY.register("pop_in", + () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(TwitchSpawn.MOD_ID))); + + /** + * Sound event for popping out. + */ + public static final RegistrySupplier POP_OUT = REGISTRY.register("pop_out", + () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(TwitchSpawn.MOD_ID))); +} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/Platform.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/Platform.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/Platform.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/Platform.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java similarity index 95% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java index 0812c5b..01636dd 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/SocketIOTracer.java @@ -1,12 +1,11 @@ package net.programmer.igoodie.twitchspawn.tracer; + +import java.net.URISyntaxException; + import io.socket.client.IO; import io.socket.client.Socket; import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; -import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; - -import java.net.URISyntaxException; public abstract class SocketIOTracer { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java similarity index 83% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java index 78c2cad..8a9396a 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/TraceManager.java @@ -1,11 +1,17 @@ package net.programmer.igoodie.twitchspawn.tracer; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + import io.socket.client.IO; import io.socket.client.Socket; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkDirection; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; @@ -18,9 +24,6 @@ import okhttp3.Dispatcher; import okhttp3.OkHttpClient; -import java.util.*; -import java.util.concurrent.TimeUnit; - public class TraceManager { private boolean running; @@ -62,6 +65,8 @@ public void start() { this.webSocketTracers.add(new TwitchChatTracer(this)); // TODO: Extract to a worker, not master webSocketTracers.forEach(WebSocketTracer::start); + TwitchSpawn.LOGGER.info("Connecting Streamers..."); + // Connect online players from credentials.toml for (CredentialsConfig.Streamer streamer : ConfigManager.CREDENTIALS.streamers) { if (TwitchSpawn.SERVER.getPlayerList().getPlayerByName(streamer.minecraftNick) != null) { @@ -69,13 +74,12 @@ public void start() { } } + TwitchSpawn.LOGGER.info("Notify Players..."); + for (ServerPlayer player : TwitchSpawn.SERVER.getPlayerList().getPlayers()) { - UUID uuid = player.getUUID(); - TranslatableComponent successText = new TranslatableComponent("commands.twitchspawn.start.success"); - player.sendMessage(successText, uuid); - NetworkManager.CHANNEL.sendTo(new StatusChangedPacket(true), - player.connection.connection, - NetworkDirection.PLAY_TO_CLIENT); + Component successText = Component.translatable("commands.twitchspawn.start.success"); + player.sendSystemMessage(successText); + NetworkManager.CHANNEL.sendToPlayer(player, new StatusChangedPacket(true)); } } @@ -98,13 +102,10 @@ public void stop(CommandSourceStack source, String reason) { if (TwitchSpawn.SERVER != null) { for (ServerPlayer player : TwitchSpawn.SERVER.getPlayerList().getPlayers()) { - UUID uuid = player.getUUID(); - TranslatableComponent successText = new TranslatableComponent("commands.twitchspawn.stop.success", - source == null ? "Server" : source.getTextName(), reason); - player.sendMessage(successText, uuid); - NetworkManager.CHANNEL.sendTo(new StatusChangedPacket(false), - player.connection.connection, - NetworkDirection.PLAY_TO_CLIENT); + Component successText = Component.translatable("commands.twitchspawn.stop.success", + source == null ? "Server" : source.getTextName(), reason); + player.sendSystemMessage(successText); + NetworkManager.CHANNEL.sendToPlayer(player, new StatusChangedPacket(false)); } } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java similarity index 94% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java index 7123b3a..b849d12 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/WebSocketTracer.java @@ -1,13 +1,19 @@ package net.programmer.igoodie.twitchspawn.tracer; -import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; -import okhttp3.*; -import okio.ByteString; import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; +import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; +import okhttp3.Dispatcher; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; +import okio.ByteString; + public abstract class WebSocketTracer { protected TraceManager manager; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java index 011d2fe..56a3c42 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/chat/TwitchChatTracer.java @@ -1,5 +1,10 @@ package net.programmer.igoodie.twitchspawn.tracer.chat; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; @@ -13,10 +18,6 @@ import okhttp3.WebSocket; import okhttp3.WebSocketListener; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - public class TwitchChatTracer extends WebSocketTracer { // Streamer Nickname -> CooldownBucket diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java similarity index 96% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java index da34f04..447e9e8 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/model/TwitchChatMessage.java @@ -1,12 +1,16 @@ package net.programmer.igoodie.twitchspawn.tracer.model; -import net.programmer.igoodie.twitchspawn.easteregg.Developers; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; +import net.programmer.igoodie.twitchspawn.easteregg.Developers; + public class TwitchChatMessage { public static final Pattern TWITCH_CHAT_PATTERN = Pattern.compile("^@(?.*?) (:(?.*?)!.*?\\.tmi\\.twitch\\.tv) PRIVMSG #(?.*?) :(?.*)$"); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java index a9dcab6..d888293 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamElementsSocketTracer.java @@ -1,5 +1,11 @@ package net.programmer.igoodie.twitchspawn.tracer.socket; + +import org.json.JSONException; +import org.json.JSONObject; +import java.util.Timer; +import java.util.TimerTask; + import io.socket.client.Socket; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; @@ -12,11 +18,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.event.builder.EventBuilder; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLEventKeyword; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Timer; -import java.util.TimerTask; public class StreamElementsSocketTracer extends SocketIOTracer { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java index 62f5897..fe9add4 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/StreamlabsSocketTracer.java @@ -1,5 +1,10 @@ package net.programmer.igoodie.twitchspawn.tracer.socket; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import io.socket.client.IO; import io.socket.client.Socket; import net.programmer.igoodie.twitchspawn.TwitchSpawn; @@ -13,10 +18,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.event.builder.EventBuilder; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLEventKeyword; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import net.programmer.igoodie.twitchspawn.util.TSHelper; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; public class StreamlabsSocketTracer extends SocketIOTracer { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java index f979e48..5d73598 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tracer/socket/TwitchPubSubTracer.java @@ -1,5 +1,15 @@ package net.programmer.igoodie.twitchspawn.tracer.socket; + +import org.json.JSONException; +import org.json.JSONObject; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.*; + import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; @@ -10,15 +20,6 @@ import okhttp3.Response; import okhttp3.WebSocket; import okhttp3.WebSocketListener; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.*; public class TwitchPubSubTracer extends WebSocketTracer { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLFlowNode.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLFlowNode.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLFlowNode.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLFlowNode.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java index a870380..c115b96 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRuleset.java @@ -1,5 +1,11 @@ package net.programmer.igoodie.twitchspawn.tslanguage; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEvent; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; @@ -7,11 +13,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxErrors; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLTokenizer; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class TSLRuleset { private String streamer; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java index 58a1c07..40b85c4 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/TSLRulesetCollection.java @@ -1,18 +1,19 @@ package net.programmer.igoodie.twitchspawn.tslanguage; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; +import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEvent; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLEventKeyword; import net.programmer.igoodie.twitchspawn.util.CooldownBucket; -import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; public class TSLRulesetCollection { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java index c501ba6..50b52d4 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/BothAction.java @@ -1,6 +1,11 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + import com.google.gson.JsonArray; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue; @@ -9,10 +14,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - public class BothAction extends TSLAction { public static final String DELIMITER = "AND"; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java similarity index 65% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java index a2eb728..5d2b418 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ChangeAction.java @@ -1,19 +1,23 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import net.programmer.igoodie.twitchspawn.util.ExpressionEvaluator; - -import java.util.LinkedList; -import java.util.List; +import net.programmer.igoodie.twitchspawn.util.ItemProcessingHelper; public class ChangeAction extends ItemSelectiveAction { @@ -85,8 +89,9 @@ private void parseItem(List itemPart) throws TSLSyntaxError { EventArguments randomEvent = EventArguments.createRandom("RandomStreamer"); String randomItem = ExpressionEvaluator.replaceExpressions(this.itemRaw, expression -> ExpressionEvaluator.fromArgs(expression, randomEvent)); - new ItemParser(new StringReader(randomItem), true).parse(); + // This is an ugly way, but I do not know if there is other way how to get lookup class. + ItemParser.parseForTesting(BuiltInRegistries.ITEM.asLookup(), new StringReader(randomItem)); } catch (CommandSyntaxException e) { throw new TSLSyntaxError(e.getRawMessage().getString()); } @@ -94,37 +99,41 @@ private void parseItem(List itemPart) throws TSLSyntaxError { @Override protected void performAction(ServerPlayer player, EventArguments args) { - ItemStack itemStack = createItemStack(args); - - if (selectionType == SelectionType.WITH_INDEX) { - getInventory(player, inventoryType).set(inventoryIndex, itemStack.copy()); - - } else if (selectionType == SelectionType.EVERYTHING) { - if (inventoryType == null) { - setAll(player.getInventory().items, itemStack); - setAll(player.getInventory().armor, itemStack); - setAll(player.getInventory().offhand, itemStack); - - } else { - setAll(getInventory(player, inventoryType), itemStack); - } - - } else if (selectionType == SelectionType.RANDOM) { - InventorySlot randomSlot = inventoryType == null + try { + // Why whole in try-catch? Well, I think it fits better here. Can change if not needed. + ItemStack itemStack = ItemProcessingHelper.createItemStack( + this.replaceExpressions(this.itemRaw, args), + this.itemAmount); + + if (this.selectionType == SelectionType.WITH_INDEX) { + this.getInventory(player, this.inventoryType).set(this.inventoryIndex, itemStack.copy()); + } else if (this.selectionType == SelectionType.EVERYTHING) { + if (this.inventoryType == null) { + this.setAll(player.getInventory().items, itemStack); + this.setAll(player.getInventory().armor, itemStack); + this.setAll(player.getInventory().offhand, itemStack); + } else { + this.setAll(getInventory(player, this.inventoryType), itemStack); + } + } else if (this.selectionType == SelectionType.RANDOM) { + InventorySlot randomSlot = this.inventoryType == null ? randomInventorySlot(player, true) - : randomInventorySlot(getInventory(player, inventoryType), true); - if (randomSlot != null) { - randomSlot.inventory.set(randomSlot.index, itemStack.copy()); - } - - } else if (selectionType == SelectionType.ONLY_HELD_ITEM) { - int selectedHotbarIndex = player.getInventory().selected; - player.getInventory().items.set(selectedHotbarIndex, itemStack.copy()); - - } else if (selectionType == SelectionType.HOTBAR) { - for (int i = 0; i <= 8; i++) { - player.getInventory().items.set(i, itemStack.copy()); + : randomInventorySlot(this.getInventory(player, this.inventoryType), true); + + if (randomSlot != null) { + randomSlot.inventory.set(randomSlot.index, itemStack.copy()); + } + } else if (this.selectionType == SelectionType.ONLY_HELD_ITEM) { + int selectedHotbarIndex = player.getInventory().selected; + player.getInventory().items.set(selectedHotbarIndex, itemStack.copy()); + } else if (this.selectionType == SelectionType.HOTBAR) { + for (int i = 0; i <= 8; i++) + { + player.getInventory().items.set(i, itemStack.copy()); + } } + } catch (CommandSyntaxException e) { + TwitchSpawn.LOGGER.error("Failed to parse item: " + this.itemRaw + " with error: " + e.getRawMessage()); } MinecraftServer server = player.getServer(); @@ -132,9 +141,9 @@ protected void performAction(ServerPlayer player, EventArguments args) { if (server != null) { CommandSourceStack commandSource = player.createCommandSourceStack() .withPermission(9999).withSuppressedOutput(); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/playsound minecraft:item.armor.equip_leather master @s"); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/particle minecraft:entity_effect ~ ~ ~ 2 2 2 0.1 400"); } } @@ -144,20 +153,4 @@ private void setAll(List inventory, ItemStack itemStack) { inventory.set(i, itemStack.copy()); } } - - private ItemStack createItemStack(EventArguments args) { - try { - String input = replaceExpressions(itemRaw, args); - - ItemParser itemParser = new ItemParser(new StringReader(input), true).parse(); - ItemStack itemStack = new ItemStack(itemParser.getItem(), itemAmount); - itemStack.setTag(itemParser.getNbt()); - - return itemStack; - - } catch (CommandSyntaxException e) { - throw new InternalError("Invalid item format occurred after validation... Something fishy here.."); - } - } - } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java similarity index 95% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java index 447da72..aa44d4e 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ClearAction.java @@ -1,5 +1,8 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.List; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -8,8 +11,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.List; - public class ClearAction extends ItemSelectiveAction { public ClearAction(List words) throws TSLSyntaxError { @@ -62,9 +63,9 @@ protected void performAction(ServerPlayer player, EventArguments args) { if (server != null) { CommandSourceStack commandSource = player.createCommandSourceStack() .withPermission(9999).withSuppressedOutput(); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/playsound minecraft:entity.item.break master @s"); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/particle minecraft:smoke ~ ~ ~ 2 2 2 0.1 400"); } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java similarity index 63% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java index 92fe35b..f68ed98 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/DropAction.java @@ -2,15 +2,18 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import java.util.List; + import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import net.programmer.igoodie.twitchspawn.util.ExpressionEvaluator; - -import java.util.List; +import net.programmer.igoodie.twitchspawn.util.ItemProcessingHelper; public class DropAction extends TSLAction { @@ -43,8 +46,9 @@ public DropAction(List words) throws TSLSyntaxError { EventArguments randomEvent = EventArguments.createRandom("RandomStreamer"); String randomItem = ExpressionEvaluator.replaceExpressions(this.itemRaw, expression -> ExpressionEvaluator.fromArgs(expression, randomEvent)); - new ItemParser(new StringReader(randomItem), true).parse(); + // This is an ugly way, but I do not know if there is other way how to get lookup class. + ItemParser.parseForTesting(BuiltInRegistries.ITEM.asLookup(), new StringReader(randomItem)); } catch (CommandSyntaxException e) { throw new TSLSyntaxError(e.getRawMessage().getString()); } @@ -52,35 +56,34 @@ public DropAction(List words) throws TSLSyntaxError { @Override protected void performAction(ServerPlayer player, EventArguments args) { - ItemStack itemStack = createItemStack(args); - player.drop(itemStack, false, false); - } - - private ItemStack createItemStack(EventArguments args) { try { - String input = replaceExpressions(itemRaw, args); - - ItemParser itemParser = new ItemParser(new StringReader(input), true).parse(); - ItemStack itemStack = new ItemStack(itemParser.getItem(), itemAmount); - itemStack.setTag(itemParser.getNbt()); - - return itemStack; - + ItemStack itemStack = ItemProcessingHelper.createItemStack( + this.replaceExpressions(this.itemRaw, args), + this.itemAmount); + player.drop(itemStack, false, false); } catch (CommandSyntaxException e) { - throw new InternalError("Invalid item format occurred after validation... Something fishy here.."); + TwitchSpawn.LOGGER.error("Failed to parse item: " + this.itemRaw + " with error: " + e.getRawMessage()); } } + @Override protected String subtitleEvaluator(String expression, EventArguments args) { - ItemStack itemStack = createItemStack(args); + try { + ItemStack itemStack = ItemProcessingHelper.createItemStack( + this.replaceExpressions(this.itemRaw, args), + this.itemAmount); - if (expression.equals("itemName")) - return itemStack.getItem().getName(itemStack).getString(); -// return itemStack.getItem().getName().getString(); // getName() is client only... + if (expression.equals("itemName")) { + return itemStack.getItem().getName(itemStack).getString(); + } - if (expression.equals("itemCount")) - return String.valueOf(itemStack.getCount()); + if (expression.equals("itemCount")) { + return String.valueOf(itemStack.getCount()); + } + } catch (CommandSyntaxException e) { + TwitchSpawn.LOGGER.error("Failed to parse item: " + this.itemRaw + " with error: " + e.getRawMessage()); + } return null; } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java index 98ca4cb..3459ec9 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/EitherAction.java @@ -1,6 +1,10 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + import com.google.gson.JsonArray; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLActionKeyword; @@ -8,9 +12,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import net.programmer.igoodie.twitchspawn.util.PercentageRandomizer; -import java.util.LinkedList; -import java.util.List; - public class EitherAction extends TSLAction { public static final String DELIMITER = "OR"; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java similarity index 90% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java index 9d3ccc2..0a5ba46 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ExecuteAction.java @@ -1,5 +1,9 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.LinkedList; +import java.util.List; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.TwitchSpawn; @@ -7,9 +11,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.LinkedList; -import java.util.List; - public class ExecuteAction extends TSLAction { private List commands; @@ -37,8 +38,8 @@ protected void performAction(ServerPlayer player, EventArguments args) { for (String command : commands) { TwitchSpawn.SERVER.execute(() -> { int result = TwitchSpawn.SERVER - .getCommands() - .performCommand(source, replaceExpressions(command, args)); + .getCommands() + .performPrefixedCommand(source, replaceExpressions(command, args)); if (result <= 0) { // Wohooo we knew iGoodie liked hacky solutions. ( ? :/ ) // If it yielded an error, and not worked as expected @@ -46,8 +47,8 @@ protected void performAction(ServerPlayer player, EventArguments args) { CommandSourceStack newSource = player.createCommandSourceStack() .withPermission(9999); TwitchSpawn.SERVER - .getCommands() - .performCommand(newSource, replaceExpressions(command, args)); + .getCommands() + .performPrefixedCommand(newSource, replaceExpressions(command, args)); } TwitchSpawn.LOGGER.info("Executed (Status:{}) -> {}", result, replaceExpressions(command, args)); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java index c6f726a..9c9a7e9 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ForAction.java @@ -1,5 +1,8 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.List; + import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLActionKeyword; @@ -7,8 +10,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import net.programmer.igoodie.twitchspawn.util.ExpressionEvaluator; -import java.util.List; - public class ForAction extends TSLAction { private TSLAction action; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java index 8a64b64..72088c2 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ItemSelectiveAction.java @@ -1,12 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.item.ItemStack; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import java.util.LinkedList; import java.util.List; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; + public abstract class ItemSelectiveAction extends TSLAction { public enum InventoryType { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java index 0bbb0c5..69804e9 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/NothingAction.java @@ -1,12 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.List; + import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.List; - public class NothingAction extends TSLAction { public NothingAction(List words) throws TSLSyntaxError { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java similarity index 95% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java index 5533c47..1350f50 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/OsRunAction.java @@ -1,7 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.network.NetworkDirection; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.network.NetworkManager; import net.programmer.igoodie.twitchspawn.network.packet.OsRunPacket; @@ -9,12 +15,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - public class OsRunAction extends TSLAction { public static void handleLocalScript(Shell shell, String script) { @@ -176,9 +176,8 @@ protected void performAction(ServerPlayer player, EventArguments args) { handleLocalScript(shell, replaceExpressions(shellScript, args)); } else if (scriptLocation == ScriptLocation.REMOTE) { - NetworkManager.CHANNEL.sendTo(new OsRunPacket(shell, replaceExpressions(shellScript, args)), - player.connection.connection, - NetworkDirection.PLAY_TO_CLIENT); + NetworkManager.CHANNEL.sendToPlayer(player, + new OsRunPacket(shell, replaceExpressions(shellScript, args))); } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java index 4ceb345..7d96e30 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ReflectAction.java @@ -1,5 +1,11 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.server.level.ServerPlayer; import net.programmer.igoodie.twitchspawn.TwitchSpawn; import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; @@ -9,11 +15,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - public class ReflectAction extends TSLAction { private boolean onlyReflectedPlayers; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java similarity index 96% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java index f2941b0..2875e63 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ShuffleAction.java @@ -1,5 +1,8 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.List; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -8,8 +11,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.List; - public class ShuffleAction extends ItemSelectiveAction { private int firstIndex; @@ -93,9 +94,9 @@ protected void performAction(ServerPlayer player, EventArguments args) { if (server != null) { CommandSourceStack commandSource = player.createCommandSourceStack() .withPermission(9999).withSuppressedOutput(); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/playsound minecraft:block.conduit.activate master @s"); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/particle minecraft:end_rod ~ ~ ~ 2 2 2 0.0001 400"); } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java similarity index 88% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java index 4375afe..bf38a91 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/SummonAction.java @@ -1,7 +1,11 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import java.util.List; + +import net.minecraft.client.resources.language.I18n; import net.minecraft.nbt.TagParser; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; @@ -9,8 +13,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.List; - public class SummonAction extends TSLAction { private EntityType entityType; @@ -69,21 +71,20 @@ private String validateCoordinateExpression(String expression) throws TSLSyntaxE @Override protected void performAction(ServerPlayer player, EventArguments args) { String command = String.format("/summon %s %s %s %s %s", - entityType.getRegistryName(), + entityType.builtInRegistryHolder().key().location(), rawCoordX, rawCoordY, rawCoordZ, replaceExpressions(rawNbt, args)); - player.getServer().getCommands().performCommand(player.createCommandSourceStack() - .withPermission(9999).withSuppressedOutput(), command); + player.getServer().getCommands().performPrefixedCommand(player.createCommandSourceStack() + .withPermission(9999).withSuppressedOutput(), command); } @Override protected String subtitleEvaluator(String expression, EventArguments args) { - // XXX: Dunno where that went... Fix that later? -// if (expression.equals("mobName")) -// return entityType.getName().getString(); + if (expression.equals("mobName")) + return I18n.get(entityType.getDescriptionId()); return null; } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java similarity index 92% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java index 7209ea6..782e30a 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/TSLAction.java @@ -1,8 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + import com.google.gson.JsonArray; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.core.Holder; +import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; @@ -23,10 +28,6 @@ import net.programmer.igoodie.twitchspawn.util.ExpressionEvaluator; import net.programmer.igoodie.twitchspawn.util.MCPHelpers; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - public abstract class TSLAction implements TSLFlowNode { private static final int DEFAULT_FADE_IN_TICKS = 10; @@ -209,7 +210,18 @@ protected void notifyPlayer(ServerPlayer player, String title, String subtitle) SoundEvent soundLocation = SoundEvents.PLAYER_LEVELUP; SoundSource category = SoundSource.MASTER; Vec3 position = player.position(); - ClientboundSoundPacket packetSound = new ClientboundSoundPacket(soundLocation, category, position.x, position.y, position.z, volume, pitch); + Holder lookup = player.getServer().registryAccess(). + registryOrThrow(Registries.SOUND_EVENT). + wrapAsHolder(soundLocation); + + ClientboundSoundPacket packetSound = new ClientboundSoundPacket(lookup, + category, + position.x, + position.y, + position.z, + volume, + pitch, + 0); player.connection.send(packetSound); if (ConfigManager.PREFERENCES.messageDisplay == PreferencesConfig.MessageDisplay.DISABLED) @@ -225,8 +237,8 @@ protected void notifyPlayer(ServerPlayer player, String title, String subtitle) if (ConfigManager.PREFERENCES.messageDisplay == PreferencesConfig.MessageDisplay.TITLES) { // Form title and subtitle packets - ClientboundSetTitleTextPacket packet = new ClientboundSetTitleTextPacket(text); - ClientboundSetSubtitleTextPacket subtitlePacket = new ClientboundSetSubtitleTextPacket(subtext); // 20 + ClientboundSetTitleTextPacket packet = new ClientboundSetTitleTextPacket(text != null ? text : Component.empty()); + ClientboundSetSubtitleTextPacket subtitlePacket = new ClientboundSetSubtitleTextPacket(subtext != null ? subtext : Component.empty()); ClientboundSetTitlesAnimationPacket timePacket = new ClientboundSetTitlesAnimationPacket( (int) (ConfigManager.PREFERENCES.notificationDelay * 0.1f / 50), // 10 (int) (ConfigManager.PREFERENCES.notificationDelay * 0.7f / 50), // 70 @@ -239,9 +251,8 @@ protected void notifyPlayer(ServerPlayer player, String title, String subtitle) } if (ConfigManager.PREFERENCES.messageDisplay == PreferencesConfig.MessageDisplay.CHAT) { - UUID uuid = player.getUUID(); - if (text != null) player.sendMessage(MCPHelpers.merge(new TextComponent(">> "), text), uuid); - if (subtext != null) player.sendMessage(MCPHelpers.merge(new TextComponent(">> "), subtext), uuid); + if (text != null) player.sendSystemMessage(MCPHelpers.merge(Component.translatable(">> "), text)); + if (subtext != null) player.sendSystemMessage(MCPHelpers.merge(Component.translatable(">> "), subtext)); } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java similarity index 96% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java index a9b84f6..9adfd09 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/ThrowAction.java @@ -1,5 +1,8 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; + +import java.util.List; + import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -8,8 +11,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import java.util.List; - public class ThrowAction extends ItemSelectiveAction { public ThrowAction(List words) throws TSLSyntaxError { @@ -73,9 +74,9 @@ protected void performAction(ServerPlayer player, EventArguments args) { if (server != null) { CommandSourceStack commandSource = player.createCommandSourceStack() .withPermission(9999).withSuppressedOutput(); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/playsound minecraft:entity.ender_pearl.throw master @s"); - server.getCommands().performCommand(commandSource, + server.getCommands().performPrefixedCommand(commandSource, "/particle minecraft:witch ~ ~ ~ 2 2 2 0.1 400"); } } diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java index 0990642..35f0156 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/action/WaitAction.java @@ -1,11 +1,5 @@ package net.programmer.igoodie.twitchspawn.tslanguage.action; -import net.minecraft.server.level.ServerPlayer; -import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; -import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue; -import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import java.util.AbstractMap; import java.util.List; @@ -13,6 +7,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import net.minecraft.server.level.ServerPlayer; +import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; +import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue; +import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; + public class WaitAction extends TSLAction { public static final Map UNIT_COEF = Stream.of( diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java index 8c5de7b..9fa243f 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/EventArguments.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event; -import com.google.common.base.Defaults; -import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLEventKeyword; +import com.google.common.base.Defaults; import java.lang.reflect.Field; import java.util.HashSet; import java.util.Random; import java.util.Set; +import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLEventKeyword; + public class EventArguments { public static EventArguments createRandom(String streamerNickname) { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java index 38bad40..f9e2c13 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEvent.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event; -import net.programmer.igoodie.twitchspawn.tslanguage.TSLFlowNode; -import net.programmer.igoodie.twitchspawn.tslanguage.action.TSLAction; -import net.programmer.igoodie.twitchspawn.tslanguage.predicate.TSLPredicate; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import net.programmer.igoodie.twitchspawn.tslanguage.TSLFlowNode; +import net.programmer.igoodie.twitchspawn.tslanguage.action.TSLAction; +import net.programmer.igoodie.twitchspawn.tslanguage.predicate.TSLPredicate; + public class TSLEvent implements TSLFlowNode { protected String name; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEventPair.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEventPair.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEventPair.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/TSLEventPair.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java index 85ded63..b4262eb 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonationBuilder.java @@ -1,11 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; public class DonationBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java index e1a1dcb..7d310bd 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/DonorDriveDonationBuilder.java @@ -1,11 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; public class DonorDriveDonationBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java index 21325c1..c216951 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/EventBuilder.java @@ -1,12 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; import net.programmer.igoodie.twitchspawn.util.TSHelper; -import org.json.JSONObject; public abstract class EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java index 915ec3f..d2f9e65 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/ExtraLifeBuilder.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; -import java.awt.*; public class ExtraLifeBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java index 00660ff..a01f94e 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/PatreonBuilder.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; -import java.awt.*; public class PatreonBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java index f97e928..3279e33 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TiltifyBuilder.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; -import java.awt.*; public class TiltifyBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java index 8f11ebb..3ce8310 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TreatStreamBuilder.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; -import java.awt.*; public class TreatStreamBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java similarity index 98% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java index 036e088..778813d 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/event/builder/TwitchFollowBuilder.java @@ -1,13 +1,14 @@ package net.programmer.igoodie.twitchspawn.tslanguage.event.builder; + +import org.json.JSONObject; + import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; import net.programmer.igoodie.twitchspawn.tracer.Platform; import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; import net.programmer.igoodie.twitchspawn.util.JSONUtils; -import org.json.JSONObject; -import java.awt.*; public class TwitchFollowBuilder extends EventBuilder { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLActionKeyword.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLActionKeyword.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLActionKeyword.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLActionKeyword.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLComparatorSymbol.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLComparatorSymbol.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLComparatorSymbol.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLComparatorSymbol.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java similarity index 96% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java index 96f0f15..a5cd5ea 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLEventKeyword.java @@ -1,15 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.keyword; -import net.programmer.igoodie.twitchspawn.configuration.CredentialsConfig; -import net.programmer.igoodie.twitchspawn.tracer.Platform; -import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; -import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; -import net.programmer.igoodie.twitchspawn.tslanguage.event.builder.*; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEventPair; +import net.programmer.igoodie.twitchspawn.tslanguage.event.builder.*; + public enum TSLEventKeyword { DONATION( diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java index ed71b21..714228d 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/keyword/TSLPredicateProperty.java @@ -1,12 +1,13 @@ package net.programmer.igoodie.twitchspawn.tslanguage.keyword; -import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; + public enum TSLPredicateProperty { ACTOR( diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java index 8475dc3..d93a27b 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLParser.java @@ -1,8 +1,17 @@ package net.programmer.igoodie.twitchspawn.tslanguage.parser; + import com.google.gson.JsonArray; import com.google.gson.JsonParseException; import com.google.gson.JsonParser; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import net.programmer.igoodie.twitchspawn.tslanguage.TSLFlowNode; import net.programmer.igoodie.twitchspawn.tslanguage.action.TSLAction; import net.programmer.igoodie.twitchspawn.tslanguage.event.TSLEvent; @@ -13,14 +22,6 @@ import net.programmer.igoodie.twitchspawn.tslanguage.predicate.TSLPredicate; import net.programmer.igoodie.twitchspawn.util.GsonUtils; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class TSLParser { private static Pattern PERCENTAGE_PATTERN = Pattern.compile("(?\\d{1,3})(\\.(?\\d{1,2}))?"); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLRuleTokenizer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLRuleTokenizer.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLRuleTokenizer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLRuleTokenizer.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxError.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxError.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxError.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxError.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxErrors.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxErrors.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxErrors.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLSyntaxErrors.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLTokenizer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLTokenizer.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLTokenizer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/parser/TSLTokenizer.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/BasicComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/BasicComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/BasicComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/BasicComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/ContainsComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/ContainsComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/ContainsComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/ContainsComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/EqualsComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/EqualsComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/EqualsComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/EqualsComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanOrEqComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanOrEqComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanOrEqComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/GreaterThanOrEqComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java index 2483064..5246b24 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/InRangeComparator.java @@ -1,10 +1,11 @@ package net.programmer.igoodie.twitchspawn.tslanguage.predicate; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; + public class InRangeComparator extends TSLComparator { public static Pattern RANGE_PATTERN = Pattern.compile("^\\[(?.+),(?.+)\\]$"); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/IsComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/IsComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/IsComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/IsComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanOrEqComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanOrEqComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanOrEqComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/LessThanOrEqComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PostfixComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PostfixComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PostfixComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PostfixComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PrefixComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PrefixComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PrefixComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/PrefixComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLComparator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLComparator.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLComparator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLComparator.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java index f757e29..7148ac4 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/tslanguage/predicate/TSLPredicate.java @@ -1,8 +1,9 @@ package net.programmer.igoodie.twitchspawn.tslanguage.predicate; + import net.programmer.igoodie.twitchspawn.TwitchSpawn; -import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.TSLFlowNode; +import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLPredicateProperty; import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java index a35b94c..e765cb7 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/udl/NotepadUDLUpdater.java @@ -1,9 +1,8 @@ package net.programmer.igoodie.twitchspawn.udl; + import com.google.common.io.Resources; -import net.programmer.igoodie.twitchspawn.TwitchSpawn; import org.apache.commons.io.FileUtils; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -16,6 +15,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; + public class NotepadUDLUpdater { private static Set PROCESSES_TO_TERMINATE = new HashSet<>(Arrays.asList( diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/CooldownBucket.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/CooldownBucket.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/CooldownBucket.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/CooldownBucket.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java index ba90d1a..a6d61bb 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/ExpressionEvaluator.java @@ -1,6 +1,5 @@ package net.programmer.igoodie.twitchspawn.util; -import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -11,6 +10,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.programmer.igoodie.twitchspawn.tslanguage.event.EventArguments; + public class ExpressionEvaluator { public static final Pattern EXPRESSION_PATTERN = Pattern.compile("\\$\\{(.*?)\\}"); diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java index 00a6445..de8970e 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/GsonUtils.java @@ -1,10 +1,10 @@ package net.programmer.igoodie.twitchspawn.util; + import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; - import java.util.LinkedList; import java.util.List; import java.util.Map; diff --git a/common/src/main/java/net/programmer/igoodie/twitchspawn/util/ItemProcessingHelper.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/ItemProcessingHelper.java new file mode 100644 index 0000000..a8e2f1b --- /dev/null +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/ItemProcessingHelper.java @@ -0,0 +1,40 @@ +package net.programmer.igoodie.twitchspawn.util; + + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.datafixers.util.Either; + +import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.ItemStack; + + +/** + * This class provides helper methods for item processing. + */ +public class ItemProcessingHelper +{ + /** + * Creates an item stack from given item input and item amount. + * @param itemInput Item input. + * @param itemAmount Item amount. + * @return Created item stack. + * @throws CommandSyntaxException If something goes wrong during parsing. + */ + public static ItemStack createItemStack(String itemInput, int itemAmount) throws CommandSyntaxException + { + Either itemResult = + ItemParser.parseForTesting(BuiltInRegistries.ITEM.asLookup(), new StringReader(itemInput)); + + if (itemResult.left().isPresent()) + { + ItemStack itemStack = new ItemStack(itemResult.left().get().item(), itemAmount); + itemResult.ifRight(tagResult -> itemStack.setTag(tagResult.nbt())); + + return itemStack; + } + + throw new InternalError("Invalid item format occurred after validation... Something fishy here.."); + } +} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java index 345ba0c..f3f002b 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/JSONUtils.java @@ -1,9 +1,9 @@ package net.programmer.igoodie.twitchspawn.util; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; - import java.util.function.Consumer; public class JSONUtils { diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/MCPHelpers.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/MCPHelpers.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/MCPHelpers.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/MCPHelpers.java diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java similarity index 99% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java index 9d3bead..cd53e9d 100644 --- a/src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java +++ b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/PercentageRandomizer.java @@ -1,6 +1,5 @@ package net.programmer.igoodie.twitchspawn.util; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; import java.util.Collections; import java.util.LinkedList; @@ -9,6 +8,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; + public class PercentageRandomizer { private static final int MAX_PERCENTAGE = 100_00; diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/util/TSHelper.java b/common/src/main/java/net/programmer/igoodie/twitchspawn/util/TSHelper.java similarity index 100% rename from src/main/java/net/programmer/igoodie/twitchspawn/util/TSHelper.java rename to common/src/main/java/net/programmer/igoodie/twitchspawn/util/TSHelper.java diff --git a/src/main/resources/assets/twitchspawn/default/preferences.toml b/common/src/main/resources/assets/twitchspawn/default/preferences.toml similarity index 100% rename from src/main/resources/assets/twitchspawn/default/preferences.toml rename to common/src/main/resources/assets/twitchspawn/default/preferences.toml diff --git a/src/main/resources/assets/twitchspawn/default/rules.default.tsl b/common/src/main/resources/assets/twitchspawn/default/rules.default.tsl similarity index 100% rename from src/main/resources/assets/twitchspawn/default/rules.default.tsl rename to common/src/main/resources/assets/twitchspawn/default/rules.default.tsl diff --git a/src/main/resources/assets/twitchspawn/default/subtitles.default.json b/common/src/main/resources/assets/twitchspawn/default/subtitles.default.json similarity index 100% rename from src/main/resources/assets/twitchspawn/default/subtitles.default.json rename to common/src/main/resources/assets/twitchspawn/default/subtitles.default.json diff --git a/src/main/resources/assets/twitchspawn/default/titles.default.json b/common/src/main/resources/assets/twitchspawn/default/titles.default.json similarity index 100% rename from src/main/resources/assets/twitchspawn/default/titles.default.json rename to common/src/main/resources/assets/twitchspawn/default/titles.default.json diff --git a/src/main/resources/assets/twitchspawn/lang/de_de.json b/common/src/main/resources/assets/twitchspawn/lang/de_de.json similarity index 68% rename from src/main/resources/assets/twitchspawn/lang/de_de.json rename to common/src/main/resources/assets/twitchspawn/lang/de_de.json index 2a08bf1..b11a6b9 100644 --- a/src/main/resources/assets/twitchspawn/lang/de_de.json +++ b/common/src/main/resources/assets/twitchspawn/lang/de_de.json @@ -1,11 +1,16 @@ { - "modloader.twitchspawn.error.tsl": "TSL Error: §4{2}", - "modloader.twitchspawn.error.json": "JSON Error: §4{2}", - "modloader.twitchspawn.error.toml": "TOML Error: §4{2}", - "modloader.twitchspawn.error.unknown": "Unbekannter Fehler: §4{2} ({3})", + "modloader.twitchspawn.error.title": "TwitchSpawn Errors", + "modloader.twitchspawn.error.continue": "Proceed to main menu", + "modloader.twitchspawn.error.folder": "Open Config Folder", + "modloader.twitchspawn.error.reload": "Reload Configs", + + "modloader.twitchspawn.error.tsl": "TSL Error: §4%s", + "modloader.twitchspawn.error.json": "JSON Error: §4%s", + "modloader.twitchspawn.error.toml": "TOML Error: §4%s", + "modloader.twitchspawn.error.unknown": "Unbekannter Fehler: §4%s (%s)", "commands.twitchspawn.reloadcfg.success": "§3>> Alle Konfigurationen erfolgreich neu geladen", - "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Neu laden gescheitert. Syntax Fehler: \n{0}", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Neu laden gescheitert. Syntax Fehler: \n%s", "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn sollte angehalten werden, damit die Konfigurationen neu geladen werden können. ", "commands.twitchspawn.reloadcfg.no_perm": "§4>> Du hast keine Berechtigung die TwitchSpawn Konfigurationen neu zu laden.", @@ -16,22 +21,22 @@ "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn läuft bereits.", "commands.twitchspawn.start.no_perm": "§4>> Du hast keine Berechtigung TwitchSpawn zu starten.", - "commands.twitchspawn.stop.success": "§6>> TwitchSpawn wurde von {0} angehalten (Ursache: {1})", + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn wurde von %s angehalten (Ursache: %2$s)", "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn wurde bereits angehalten.", "commands.twitchspawn.stop.no_perm": "§4>> Du hast keine Berechtigung TwitchSpawn anzuhalten.", - "commands.twitchspawn.rules.list": "§3>> Regelset ist geladen für: {0}", - "commands.twitchspawn.rules.default": "§3>> Das geladene Standard-Regelset enthält folgendes:\n{1}", - "commands.twitchspawn.rules.one": "§3>> Das für {0} geladene Regelset enthält folgendes:\n{1}", - "commands.twitchspawn.rules.one.fail": "§4>> Für {0} wurde kein Regelset geladen", + "commands.twitchspawn.rules.list": "§3>> Regelset ist geladen für: %s", + "commands.twitchspawn.rules.default": "§3>> Das geladene Standard-Regelset enthält folgendes:\n%2$s", + "commands.twitchspawn.rules.one": "§3>> Das für %s geladene Regelset enthält folgendes:\n%2$s", + "commands.twitchspawn.rules.one.fail": "§4>> Für %s wurde kein Regelset geladen", "commands.twitchspawn.simulate.missing": "§4>> Im Simulationsobjekt fehlt ein Event-Name. Erwartet \"event\" Feld.", - "commands.twitchspawn.simulate.invalid_event": "§4>> Ungültiger Event-Name -> {0}", - "commands.twitchspawn.simulate.success": "§a>> Simulation erfolgreich ausgeführt {0}", + "commands.twitchspawn.simulate.invalid_event": "§4>> Ungültiger Event-Name -> %s", + "commands.twitchspawn.simulate.success": "§a>> Simulation erfolgreich ausgeführt %s", "commands.twitchspawn.simulate.no_perm": "§4>> Du hast keine Berechtigung ein Event zu simulieren.", - "commands.twitchspawn.test.not_found": "§4>> Kein Regelwerk mit {0} verbunden", - "commands.twitchspawn.test.success": "§a>> Erfolgreich Regeln für {0} in die Warteschlange gestellt", - + "commands.twitchspawn.test.not_found": "§4>> Kein Regelwerk mit %s verbunden", + "commands.twitchspawn.test.success": "§a>> Erfolgreich Regeln für %s in die Warteschlange gestellt", + "errors.twitchspawn.loading": "Kann TwitchSpawn nicht laden." } diff --git a/src/main/resources/assets/twitchspawn/lang/en_us.json b/common/src/main/resources/assets/twitchspawn/lang/en_us.json similarity index 69% rename from src/main/resources/assets/twitchspawn/lang/en_us.json rename to common/src/main/resources/assets/twitchspawn/lang/en_us.json index c0e3b6c..6739fb9 100644 --- a/src/main/resources/assets/twitchspawn/lang/en_us.json +++ b/common/src/main/resources/assets/twitchspawn/lang/en_us.json @@ -1,11 +1,16 @@ { - "modloader.twitchspawn.error.tsl": "TSL Error: §4{2}", - "modloader.twitchspawn.error.json": "JSON Error: §4{2}", - "modloader.twitchspawn.error.toml": "TOML Error: §4{2}", - "modloader.twitchspawn.error.unknown": "Unknown Error: §4{2} ({3})", + "modloader.twitchspawn.error.title": "TwitchSpawn Errors", + "modloader.twitchspawn.error.continue": "Proceed to main menu", + "modloader.twitchspawn.error.folder": "Open Config Folder", + "modloader.twitchspawn.error.reload": "Reload Configs", + + "modloader.twitchspawn.error.tsl": "§4TSL Error: §4%s", + "modloader.twitchspawn.error.json": "§4JSON Error: §4%s", + "modloader.twitchspawn.error.toml": "§4TOML Error: §4%s", + "modloader.twitchspawn.error.unknown": "§4Unknown Error: §4%s (%s)", "commands.twitchspawn.reloadcfg.success": "§3>> Successfully reloaded all the configs", - "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Failed to reload. Syntax errors:\n{0}", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Failed to reload. Syntax errors:\n%s", "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn should be stopped in order to be able to reload configs.", "commands.twitchspawn.reloadcfg.no_perm": "§4>> You do not have permission to reload TwitchSpawn configs.", @@ -16,22 +21,22 @@ "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn is already running.", "commands.twitchspawn.start.no_perm": "§4>> You do not have permission to start TwitchSpawn.", - "commands.twitchspawn.stop.success": "§6>> TwitchSpawn stopped by {0} (Reason: {1})", + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn stopped by %1$s (Reason: %2$s)", "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn is already stopped.", "commands.twitchspawn.stop.no_perm": "§4>> You do not have permission to stop TwitchSpawn.", - "commands.twitchspawn.rules.list": "§3>> Rulesets loaded for: {0}", - "commands.twitchspawn.rules.default": "§3>> Default ruleset loaded includes following:\n{1}", - "commands.twitchspawn.rules.one": "§3>> Ruleset loaded for {0} includes following:\n{1}", - "commands.twitchspawn.rules.one.fail": "§4>> No ruleset was loaded for {0}", + "commands.twitchspawn.rules.list": "§3>> Rulesets loaded for: %s", + "commands.twitchspawn.rules.default": "§3>> Default ruleset loaded includes following:\n%2$s", + "commands.twitchspawn.rules.one": "§3>> Ruleset loaded for %1$s includes following:\n%2$s", + "commands.twitchspawn.rules.one.fail": "§4>> No ruleset was loaded for %s", "commands.twitchspawn.simulate.missing": "§4>> Missing event name in simulation object. Expected \"event\" field.", - "commands.twitchspawn.simulate.invalid_event": "§4>> Invalid event name -> {0}", - "commands.twitchspawn.simulate.success": "§a>> Simulation fired off successfully {0}", + "commands.twitchspawn.simulate.invalid_event": "§4>> Invalid event name -> %s", + "commands.twitchspawn.simulate.success": "§a>> Simulation fired off successfully %s", "commands.twitchspawn.simulate.no_perm": "§4>> You do not have permission to simulate an event.", - "commands.twitchspawn.test.not_found": "§4>> No ruleset associated with {0}", - "commands.twitchspawn.test.success": "§a>> Successfully queued rules for {0}", + "commands.twitchspawn.test.not_found": "§4>> No ruleset associated with %s", + "commands.twitchspawn.test.success": "§a>> Successfully queued rules for %s", "errors.twitchspawn.loading": "Cannot load TwitchSpawn" } diff --git a/src/main/resources/assets/twitchspawn/lang/es_es.json b/common/src/main/resources/assets/twitchspawn/lang/es_es.json similarity index 73% rename from src/main/resources/assets/twitchspawn/lang/es_es.json rename to common/src/main/resources/assets/twitchspawn/lang/es_es.json index 656940c..ed1d547 100644 --- a/src/main/resources/assets/twitchspawn/lang/es_es.json +++ b/common/src/main/resources/assets/twitchspawn/lang/es_es.json @@ -1,38 +1,43 @@ - -{ - "modloader.twitchspawn.error.tsl": "Error de TSL: §4{2}", - "modloader.twitchspawn.error.json": "Error de JSON: §4{2}", - "modloader.twitchspawn.error.toml": "Error de TOML: §4{2}", - "modloader.twitchspawn.error.unknown": "Error Desconocido: §4{2} ({3})", - - "commands.twitchspawn.reloadcfg.success": "§3>> ¡Se han recargado exitosamente todas las configuraciones!", - "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Recarga Fallida. Errores de Sintaxis:\n{0}", - "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn debe ser detenido para poder recargar las configuraciones.", - "commands.twitchspawn.reloadcfg.no_perm": "§4>> No tienes permiso para recargar las configuraciones de TwitchSpawn.", - - "commands.twitchspawn.status.on": "§3>> TwitchSpawn se esta ejecutando. [ON]", - "commands.twitchspawn.status.off": "§3>> TwitchSpawn no se esta ejecutando [OFF]", - - "commands.twitchspawn.start.success": "§a>> ¡TwitchSpawn ha iniciado en este servidor!", - "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn ya se esta ejecutando.", - "commands.twitchspawn.start.no_perm": "§4>> No tienes permiso para iniciar TwitchSpawn.", - - "commands.twitchspawn.stop.success": "§6>> TwitchSpawn se ha detenido por {0} (Razon: {1})", - "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn ya esta apagado.", - "commands.twitchspawn.stop.no_perm": "§4>> No tienes permiso para detener TwitchSpawn.", - - "commands.twitchspawn.rules.list": "§3>> Lista de Reglas cargadas para: {0}", - "commands.twitchspawn.rules.default": "§3>> La Lista de Reglas por defecto incluye:\n{1}", - "commands.twitchspawn.rules.one": "§3>> Lista de Recarga caragada para {0} e incluye:\n{1}", - "commands.twitchspawn.rules.one.fail": "§4>> Ninguna Lista de Reglas ha sido cargada para {0}", - - "commands.twitchspawn.simulate.missing": "§4>> Falta el nombre del evento en el objeto de simulación. Esperado: \"event\" field.", - "commands.twitchspawn.simulate.invalid_event": "§4>> Nombre de evento invalido -> {0}", - "commands.twitchspawn.simulate.success": "§a>> Simulacion ejecutada {0}", - "commands.twitchspawn.simulate.no_perm": "§4>> No tienes permiso para simular un evento.", - - "commands.twitchspawn.test.not_found": "§4>> Ninguna Lista de Reglas asociada con {0}", - "commands.twitchspawn.test.success": "§a>> Se han puesto en cola las reglas para {0}", - - "errors.twitchspawn.loading": "No se puede cargar TwitchSpawn." -} \ No newline at end of file + +{ + "modloader.twitchspawn.error.title": "TwitchSpawn Errors", + "modloader.twitchspawn.error.continue": "Proceed to main menu", + "modloader.twitchspawn.error.folder": "Open Config Folder", + "modloader.twitchspawn.error.reload": "Reload Configs", + + "modloader.twitchspawn.error.tsl": "Error de TSL: §4%s", + "modloader.twitchspawn.error.json": "Error de JSON: §4%s", + "modloader.twitchspawn.error.toml": "Error de TOML: §4%s", + "modloader.twitchspawn.error.unknown": "Error Desconocido: §4%s (%s)", + + "commands.twitchspawn.reloadcfg.success": "§3>> ¡Se han recargado exitosamente todas las configuraciones!", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Recarga Fallida. Errores de Sintaxis:\n%s", + "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn debe ser detenido para poder recargar las configuraciones.", + "commands.twitchspawn.reloadcfg.no_perm": "§4>> No tienes permiso para recargar las configuraciones de TwitchSpawn.", + + "commands.twitchspawn.status.on": "§3>> TwitchSpawn se esta ejecutando. [ON]", + "commands.twitchspawn.status.off": "§3>> TwitchSpawn no se esta ejecutando [OFF]", + + "commands.twitchspawn.start.success": "§a>> ¡TwitchSpawn ha iniciado en este servidor!", + "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn ya se esta ejecutando.", + "commands.twitchspawn.start.no_perm": "§4>> No tienes permiso para iniciar TwitchSpawn.", + + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn se ha detenido por %s (Razon: %2$s)", + "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn ya esta apagado.", + "commands.twitchspawn.stop.no_perm": "§4>> No tienes permiso para detener TwitchSpawn.", + + "commands.twitchspawn.rules.list": "§3>> Lista de Reglas cargadas para: %s", + "commands.twitchspawn.rules.default": "§3>> La Lista de Reglas por defecto incluye:\n%2$s", + "commands.twitchspawn.rules.one": "§3>> Lista de Recarga caragada para %s e incluye:\n%2$s", + "commands.twitchspawn.rules.one.fail": "§4>> Ninguna Lista de Reglas ha sido cargada para %s", + + "commands.twitchspawn.simulate.missing": "§4>> Falta el nombre del evento en el objeto de simulación. Esperado: \"event\" field.", + "commands.twitchspawn.simulate.invalid_event": "§4>> Nombre de evento invalido -> %s", + "commands.twitchspawn.simulate.success": "§a>> Simulacion ejecutada %s", + "commands.twitchspawn.simulate.no_perm": "§4>> No tienes permiso para simular un evento.", + + "commands.twitchspawn.test.not_found": "§4>> Ninguna Lista de Reglas asociada con %s", + "commands.twitchspawn.test.success": "§a>> Se han puesto en cola las reglas para %s", + + "errors.twitchspawn.loading": "No se puede cargar TwitchSpawn." +} diff --git a/src/main/resources/assets/twitchspawn/lang/fr_fr.json b/common/src/main/resources/assets/twitchspawn/lang/fr_fr.json similarity index 71% rename from src/main/resources/assets/twitchspawn/lang/fr_fr.json rename to common/src/main/resources/assets/twitchspawn/lang/fr_fr.json index afbedb2..1ba4dad 100644 --- a/src/main/resources/assets/twitchspawn/lang/fr_fr.json +++ b/common/src/main/resources/assets/twitchspawn/lang/fr_fr.json @@ -1,11 +1,16 @@ { - "modloader.twitchspawn.error.tsl": "Erreur TSL: §4{2}", - "modloader.twitchspawn.error.json": "Erreur JSON: §4{2}", - "modloader.twitchspawn.error.toml": "Erreur TOML: §4{2}", - "modloader.twitchspawn.error.unknown": "Erreur inconnue: §4{2} ({3})", + "modloader.twitchspawn.error.title": "TwitchSpawn Errors", + "modloader.twitchspawn.error.continue": "Proceed to main menu", + "modloader.twitchspawn.error.folder": "Open Config Folder", + "modloader.twitchspawn.error.reload": "Reload Configs", + + "modloader.twitchspawn.error.tsl": "Erreur TSL: §4%s", + "modloader.twitchspawn.error.json": "Erreur JSON: §4%s", + "modloader.twitchspawn.error.toml": "Erreur TOML: §4%s", + "modloader.twitchspawn.error.unknown": "Erreur inconnue: §4%s (%s)", "commands.twitchspawn.reloadcfg.success": "§3>> Chargement des configurations réussi.", - "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Echec du chargement. Erreur de syntaxe:\n{0}", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Echec du chargement. Erreur de syntaxe:\n%s", "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn doit être arrêté pour charger les configurations.", "commands.twitchspawn.reloadcfg.no_perm": "§4>> Vous n'avez pas de l'autorisation nécessaire pour charger les configurations de TwitchSpawn.", @@ -16,22 +21,22 @@ "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn est déjà en cours d'utilisation.", "commands.twitchspawn.start.no_perm": "§4>> Vous n'avez l'autorisation nécessaire pour démarrer TwitchSpawn.", - "commands.twitchspawn.stop.success": "§6>> TwitchSpawn a été arrêté par {0} (Motif: {1})", + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn a été arrêté par %s (Motif: %2$s)", "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn est déjà arrêté.", "commands.twitchspawn.stop.no_perm": "§4>> Vous n'avez l'autorisation nécessaire pour arrêter TwitchSpawn.", - "commands.twitchspawn.rules.list": "§3>> Rulesets chargé pour: {0}", - "commands.twitchspawn.rules.default": "§3>> Le ruleset par défaut chargé inclut les éléments suivants:\n{1}", - "commands.twitchspawn.rules.one": "§3>> Le ruleset chargé pour {0} inclut les éléments suivants:\n{1}", - "commands.twitchspawn.rules.one.fail": "§4>> Pas de ruleset chargé pour {0}", + "commands.twitchspawn.rules.list": "§3>> Rulesets chargé pour: %s", + "commands.twitchspawn.rules.default": "§3>> Le ruleset par défaut chargé inclut les éléments suivants:\n%2$s", + "commands.twitchspawn.rules.one": "§3>> Le ruleset chargé pour %s inclut les éléments suivants:\n%2$s", + "commands.twitchspawn.rules.one.fail": "§4>> Pas de ruleset chargé pour %s", "commands.twitchspawn.simulate.missing": "§4>> Évènement manquant dans la simulation de l'objet. Syntaxe attendue \"évènement\" champ.", - "commands.twitchspawn.simulate.invalid_event": "§4>> Non d'évènement invalide -> {0}", - "commands.twitchspawn.simulate.success": "§a>> Exécution de la simulation réussie {0}", + "commands.twitchspawn.simulate.invalid_event": "§4>> Non d'évènement invalide -> %s", + "commands.twitchspawn.simulate.success": "§a>> Exécution de la simulation réussie %s", "commands.twitchspawn.simulate.no_perm": "§4>> Vous n'avez pas l'autorisation de simuler un évènement.", - "commands.twitchspawn.test.not_found": "§4>> Aucun ruleset associé à {0}", - "commands.twitchspawn.test.success": "§a>> Ajout des règles à la file d'attente réussi pour {0}", + "commands.twitchspawn.test.not_found": "§4>> Aucun ruleset associé à %s", + "commands.twitchspawn.test.success": "§a>> Ajout des règles à la file d'attente réussi pour %s", "errors.twitchspawn.loading": "Impossible de charger TwitchSpawn" } diff --git a/src/main/resources/assets/twitchspawn/lang/it_it.json b/common/src/main/resources/assets/twitchspawn/lang/it_it.json similarity index 72% rename from src/main/resources/assets/twitchspawn/lang/it_it.json rename to common/src/main/resources/assets/twitchspawn/lang/it_it.json index fe64440..7d6ff82 100644 --- a/src/main/resources/assets/twitchspawn/lang/it_it.json +++ b/common/src/main/resources/assets/twitchspawn/lang/it_it.json @@ -1,11 +1,16 @@ { - "modloader.twitchspawn.error.tsl": "TSL Error: §4{2}", - "modloader.twitchspawn.error.json": "JSON Error: §4{2}", - "modloader.twitchspawn.error.toml": "TOML Error: §4{2}", - "modloader.twitchspawn.error.unknown": "Errore Sconosciuto: §4{2} ({3})", + "modloader.twitchspawn.error.title": "TwitchSpawn Errors", + "modloader.twitchspawn.error.continue": "Proceed to main menu", + "modloader.twitchspawn.error.folder": "Open Config Folder", + "modloader.twitchspawn.error.reload": "Reload Configs", + + "modloader.twitchspawn.error.tsl": "TSL Error: §4%s", + "modloader.twitchspawn.error.json": "JSON Error: §4%s", + "modloader.twitchspawn.error.toml": "TOML Error: §4%s", + "modloader.twitchspawn.error.unknown": "Errore Sconosciuto: §4%s (%s)", "commands.twitchspawn.reloadcfg.success": "§3>> Configurazioni ricaricate con successo", - "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Ricaricamento fallito. Errori di sintassi:\n{0}", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Ricaricamento fallito. Errori di sintassi:\n%s", "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn deve essere fermata per essere in grado fi ricaricare le configurazioni.", "commands.twitchspawn.reloadcfg.no_perm": "§4>> Non hai il permesso di ricaricare le configurazioni di TwitchSpawn.", @@ -16,22 +21,22 @@ "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn è già in esecuzione.", "commands.twitchspawn.start.no_perm": "§4>> Non hai il permesso di avviare TwitchSpawn.", - "commands.twitchspawn.stop.success": "§6>> TwitchSpawn è stata fermata da {0} (Reason: {1})", + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn è stata fermata da %s (Reason: %2$s)", "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn è già stata fermata.", "commands.twitchspawn.stop.no_perm": "§4>> Non hai il permesso di fermare TwitchSpawn.", - "commands.twitchspawn.rules.list": "§3>> Insieme di regole caricato per: {0}", - "commands.twitchspawn.rules.default": "§3>> L'insieme di regole default loaded include le seguenti regole:\n{1}", - "commands.twitchspawn.rules.one": "§3>> L'insieme di regole per {0} include le seguenti regole:\n{1}", - "commands.twitchspawn.rules.one.fail": "§4>> Nessun insieme di regole è caricato per {0}", + "commands.twitchspawn.rules.list": "§3>> Insieme di regole caricato per: %s", + "commands.twitchspawn.rules.default": "§3>> L'insieme di regole default loaded include le seguenti regole:\n%2$s", + "commands.twitchspawn.rules.one": "§3>> L'insieme di regole per %s include le seguenti regole:\n%2$s", + "commands.twitchspawn.rules.one.fail": "§4>> Nessun insieme di regole è caricato per %s", "commands.twitchspawn.simulate.missing": "§4>> Mancante il nome dell'evvento nella simulazione dell'oggetto. Ci si aspettava un campo \"event\".", - "commands.twitchspawn.simulate.invalid_event": "§4>> Nome dell'evento non valido -> {0}", - "commands.twitchspawn.simulate.success": "§a>> Simulazione terminata con successo {0}", + "commands.twitchspawn.simulate.invalid_event": "§4>> Nome dell'evento non valido -> %s", + "commands.twitchspawn.simulate.success": "§a>> Simulazione terminata con successo %s", "commands.twitchspawn.simulate.no_perm": "§4>> Non hai il permesso di simulare un evento.", - "commands.twitchspawn.test.not_found": "§4>> Nessun insieme di regole associato a {0}", - "commands.twitchspawn.test.success": "§a>> Iserimento della regola avvenuto con successo per {0}", + "commands.twitchspawn.test.not_found": "§4>> Nessun insieme di regole associato a %s", + "commands.twitchspawn.test.success": "§a>> Iserimento della regola avvenuto con successo per %s", "errors.twitchspawn.loading": "Impossibile caricare TwitchSpawn" } diff --git a/common/src/main/resources/assets/twitchspawn/lang/lv_lv.json b/common/src/main/resources/assets/twitchspawn/lang/lv_lv.json new file mode 100644 index 0000000..2378154 --- /dev/null +++ b/common/src/main/resources/assets/twitchspawn/lang/lv_lv.json @@ -0,0 +1,42 @@ +{ + "modloader.twitchspawn.error.title": "TwitchSpawn Kļūdas", + "modloader.twitchspawn.error.continue": "Turpināt uz galveno izvēlni", + "modloader.twitchspawn.error.folder": "Atvērt konfigurācijas mapi", + "modloader.twitchspawn.error.reload": "Pārlādēd konfigurācijas", + + "modloader.twitchspawn.error.tsl": "TSL Kļūda: §4%s", + "modloader.twitchspawn.error.json": "JSON Kļūda: §4%s", + "modloader.twitchspawn.error.toml": "TOML Kļūda: §4%s", + "modloader.twitchspawn.error.unknown": "Nezināma Kļūda: §4%s (%s)", + + "commands.twitchspawn.reloadcfg.success": "§3>> Konfigurācijas faili pārlādēti!", + "commands.twitchspawn.reloadcfg.invalid_syntax": "§4>> Kļūda pārlādējot. Sintakses kļūda:\n%s", + "commands.twitchspawn.reloadcfg.already_started": "§4>> TwitchSpawn nepieciešams apturēt, lai pārlādētu konfigurācijas failus.", + "commands.twitchspawn.reloadcfg.no_perm": "§4>> Tev nav atļaujas pārlādēt TwitchSpawn konfigurāciju.", + + "commands.twitchspawn.status.on": "§3>> TwitchSpawn šobrīd strādā. [ON]", + "commands.twitchspawn.status.off": "§3>> TwitchSpawn šobrīd ir izslēgts. [OFF]", + + "commands.twitchspawn.start.success": "§A>> TwitchSpawn tagad ir startēts šajā serverī!", + "commands.twitchspawn.start.illegal_state": "§4>> TwitchSpawn jau darbojas.", + "commands.twitchspawn.start.no_perm": "§4>> Jums nav atļaujas startēt TwitchSpawn.", + + "commands.twitchspawn.stop.success": "§6>> TwitchSpawn apturēja %s (iemesls: %2$s)", + "commands.twitchspawn.stop.illegal_state": "§4>> TwitchSpawn jau ir apturēts.", + "commands.twitchspawn.stop.no_perm": "§4>> Jums nav atļaujas apturēt TwitchSpawn.", + + "commands.twitchspawn.rules.list": "§3>> Noteikumu kopas priekš: %s", + "commands.twitchspawn.rules.default": "§3>> ielādētā noklusējuma noteikumu kopa ietver:\n %2$s", + "commands.twitchspawn.rules.one": "§3>> %s ielādētā noteikumu kopa ietver:\n %2$s", + "commands.twitchspawn.rules.one.fail": "§4>> %s netika ielādēta noteikumu kopa", + + "commands.twitchspawn.simulate.missing": "§4 >> simulācijas objektā trūkst notikuma nosaukuma. Paredzēts notikums lauks.", + "commands.twitchspawn.simulate.invalid_event": "§4 >> Nederīgs notikuma nosaukums - > %s", + "commands.twitchspawn.simulate.success": "§A >> simulācija sekmīgi izslēgta %s", + "commands.twitchspawn.simulate.no_perm": "§4 >> Jums nav atļaujas simulēt notikumu.", + + "commands.twitchspawn.test.not_found": "§4 >> ar %s nav saistīta noteikumu kopa", + "commands.twitchspawn.test.success": "§A >> %s noteikumus ir sekmīgi ievietotas rindā", + + "errors.twitchspawn.loading": "Nevarēja ielādēt TwitchSpawn" +} diff --git a/src/main/resources/assets/twitchspawn/sounds.json b/common/src/main/resources/assets/twitchspawn/sounds.json similarity index 100% rename from src/main/resources/assets/twitchspawn/sounds.json rename to common/src/main/resources/assets/twitchspawn/sounds.json diff --git a/src/main/resources/assets/twitchspawn/sounds/pop_in.ogg b/common/src/main/resources/assets/twitchspawn/sounds/pop_in.ogg similarity index 100% rename from src/main/resources/assets/twitchspawn/sounds/pop_in.ogg rename to common/src/main/resources/assets/twitchspawn/sounds/pop_in.ogg diff --git a/src/main/resources/assets/twitchspawn/sounds/pop_out.ogg b/common/src/main/resources/assets/twitchspawn/sounds/pop_out.ogg similarity index 100% rename from src/main/resources/assets/twitchspawn/sounds/pop_out.ogg rename to common/src/main/resources/assets/twitchspawn/sounds/pop_out.ogg diff --git a/src/main/resources/assets/twitchspawn/textures/cooldown.png b/common/src/main/resources/assets/twitchspawn/textures/cooldown.png similarity index 100% rename from src/main/resources/assets/twitchspawn/textures/cooldown.png rename to common/src/main/resources/assets/twitchspawn/textures/cooldown.png diff --git a/src/main/resources/assets/twitchspawn/textures/indicators.png b/common/src/main/resources/assets/twitchspawn/textures/indicators.png similarity index 100% rename from src/main/resources/assets/twitchspawn/textures/indicators.png rename to common/src/main/resources/assets/twitchspawn/textures/indicators.png diff --git a/src/main/resources/assets/twitchspawn/udl/tsl_udl.xml b/common/src/main/resources/assets/twitchspawn/udl/tsl_udl.xml similarity index 100% rename from src/main/resources/assets/twitchspawn/udl/tsl_udl.xml rename to common/src/main/resources/assets/twitchspawn/udl/tsl_udl.xml diff --git a/src/main/resources/pack.mcmeta b/common/src/main/resources/pack.mcmeta similarity index 100% rename from src/main/resources/pack.mcmeta rename to common/src/main/resources/pack.mcmeta diff --git a/src/main/resources/pack.png b/common/src/main/resources/pack.png similarity index 100% rename from src/main/resources/pack.png rename to common/src/main/resources/pack.png diff --git a/common/src/main/resources/twitchspawn-common.mixins.json b/common/src/main/resources/twitchspawn-common.mixins.json new file mode 100644 index 0000000..a6b2724 --- /dev/null +++ b/common/src/main/resources/twitchspawn-common.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.programmer.igoodie.twitchspawn.mixin.fabric", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/test/resources/comment_expected.tsl b/common/src/test/resources/comment_expected.tsl similarity index 100% rename from src/test/resources/comment_expected.tsl rename to common/src/test/resources/comment_expected.tsl diff --git a/src/test/resources/comment_test.tsl b/common/src/test/resources/comment_test.tsl similarity index 100% rename from src/test/resources/comment_test.tsl rename to common/src/test/resources/comment_test.tsl diff --git a/src/test/resources/test.toml b/common/src/test/resources/test.toml similarity index 100% rename from src/test/resources/test.toml rename to common/src/test/resources/test.toml diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..6be5b6a --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,87 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" +} + +architectury { + platformSetupLoomIde() + fabric() +} + +configurations { + common + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentFabric.extendsFrom common +// +// shade +// implementation.extendsFrom shade +} + + +dependencies { + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" + // Remove the next line if you don't want to depend on the API + modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } + + implementation "com.electronwill.night-config:core:3.6.4" + implementation "com.electronwill.night-config:toml:3.6.4" + + shadowCommon "com.electronwill.night-config:core:3.6.4" + shadowCommon "com.electronwill.night-config:toml:3.6.4" + shadowCommon "com.squareup.okhttp3:okhttp:3.8.1" + shadowCommon "io.socket:socket.io-client:1.0.2" +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + archiveClassifier.set("dev-shadow") +} + +remapJar { + inputFile.set shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} + +jar { + archiveClassifier.set("dev") +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +publishing { + publications { + mavenFabric(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } +} diff --git a/fabric/src/main/java/net/programmer/igoodie/twitchspawn/events/fabric/TwitchSpawnEventHandlerImpl.java b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/events/fabric/TwitchSpawnEventHandlerImpl.java new file mode 100644 index 0000000..f7f964a --- /dev/null +++ b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/events/fabric/TwitchSpawnEventHandlerImpl.java @@ -0,0 +1,22 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.events.fabric; + + +/** + * This class manages the registration of events. + */ +public class TwitchSpawnEventHandlerImpl +{ + /** + * Register client events. + */ + public static void registerClient() + { + // Fabric events are registered via mixins. + } +} diff --git a/fabric/src/main/java/net/programmer/igoodie/twitchspawn/fabric/TwitchSpawnFabric.java b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/fabric/TwitchSpawnFabric.java new file mode 100644 index 0000000..cea148b --- /dev/null +++ b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/fabric/TwitchSpawnFabric.java @@ -0,0 +1,13 @@ +package net.programmer.igoodie.twitchspawn.fabric; + +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.fabricmc.api.ModInitializer; + + +public class TwitchSpawnFabric implements ModInitializer { + @Override + public void onInitialize() { + TwitchSpawn.init(); + TwitchSpawn.LOGGER.info("TwitchSpawn Fabric initialized!"); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinGui.java b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinGui.java new file mode 100644 index 0000000..b7e6417 --- /dev/null +++ b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinGui.java @@ -0,0 +1,72 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.mixin.fabric; + + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.resources.ResourceLocation; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; + + +/** + * This mixin injects into render method to simulate similar entry points as in forge. + */ +@Mixin(value = Gui.class) +public class MixinGui +{ + @Inject(method = "render", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/Gui;renderHotbar(FLnet/minecraft/client/gui/GuiGraphics;)V")) + private void preRenderHotbar(GuiGraphics guiGraphics, float f, CallbackInfo ci) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.invoker().renderHud( + guiGraphics, + ResourceLocation.of("hotbar", ':')); + } + + @Inject(method = "render", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/components/spectator/SpectatorGui;renderHotbar(Lnet/minecraft/client/gui/GuiGraphics;)V")) + private void preRenderHotbarSpectator(GuiGraphics guiGraphics, float f, CallbackInfo ci) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.invoker().renderHud( + guiGraphics, + ResourceLocation.of("hotbar", ':')); + } + + @Inject(method = "render", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/Gui;renderHotbar(FLnet/minecraft/client/gui/GuiGraphics;)V", + shift = At.Shift.AFTER)) + private void postRenderHotbar(GuiGraphics guiGraphics, float f, CallbackInfo ci) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_POST.invoker().renderHud( + guiGraphics, + ResourceLocation.of("hotbar", ':')); + } + + @Inject(method = "render", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/components/spectator/SpectatorGui;renderHotbar(Lnet/minecraft/client/gui/GuiGraphics;)V", + shift = At.Shift.AFTER)) + private void postRenderHotbarSpectator(GuiGraphics guiGraphics, float f, CallbackInfo ci) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_POST.invoker().renderHud( + guiGraphics, + ResourceLocation.of("hotbar", ':')); + } + + @Inject(method = "render", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/gui/Gui;renderEffects(Lnet/minecraft/client/gui/GuiGraphics;)V", + shift = At.Shift.AFTER)) + private void renderDebugText(GuiGraphics guiGraphics, float f, CallbackInfo ci) + { + TwitchSpawnClientGuiEvent.DEBUG_TEXT.invoker().renderHud(guiGraphics); + } +} diff --git a/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinLoadingOverlay.java b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinLoadingOverlay.java new file mode 100644 index 0000000..7c7467c --- /dev/null +++ b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/mixin/fabric/MixinLoadingOverlay.java @@ -0,0 +1,41 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.mixin.fabric; + + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.LoadingOverlay; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; + + +/** + * This mixin is used to trigger the {@link TwitchSpawnClientGuiEvent#FINISH_LOADING_OVERLAY} event. + */ +@Mixin(value = LoadingOverlay.class, remap = false) +public class MixinLoadingOverlay +{ + @Shadow + @Final + private Minecraft minecraft; + + + @Inject(method = "render", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/Minecraft;setOverlay(Lnet/minecraft/client/gui/screens/Overlay;)V", + shift = At.Shift.AFTER)) + private void overlayRemoveEvent(CallbackInfo callbackInfo) + { + TwitchSpawnClientGuiEvent.FINISH_LOADING_OVERLAY.invoker().removeOverlay(this.minecraft, this.minecraft.screen); + } +} diff --git a/fabric/src/main/java/net/programmer/igoodie/twitchspawn/registries/fabric/TwitchSpawnArgumentTypesImpl.java b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/registries/fabric/TwitchSpawnArgumentTypesImpl.java new file mode 100644 index 0000000..b9d3cb8 --- /dev/null +++ b/fabric/src/main/java/net/programmer/igoodie/twitchspawn/registries/fabric/TwitchSpawnArgumentTypesImpl.java @@ -0,0 +1,44 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.registries.fabric; + + +import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry; +import net.minecraft.commands.synchronization.SingletonArgumentInfo; +import net.minecraft.resources.ResourceLocation; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.command.RulesetNameArgumentType; +import net.programmer.igoodie.twitchspawn.command.StreamerArgumentType; +import net.programmer.igoodie.twitchspawn.command.TSLWordsArgumentType; + + +/** + * This class manages the registration of command argument types. + */ +public class TwitchSpawnArgumentTypesImpl +{ + /** + * Fabric has very simple command argument type registration. + */ + public static void registerArgumentType() + { + ArgumentTypeRegistry.registerArgumentType( + new ResourceLocation(TwitchSpawn.MOD_ID, "ruleset"), + RulesetNameArgumentType.class, + SingletonArgumentInfo.contextFree(RulesetNameArgumentType::rulesetName)); + + ArgumentTypeRegistry.registerArgumentType( + new ResourceLocation(TwitchSpawn.MOD_ID, "streamer"), + StreamerArgumentType.class, + SingletonArgumentInfo.contextFree(StreamerArgumentType::streamerNick)); + + ArgumentTypeRegistry.registerArgumentType( + new ResourceLocation(TwitchSpawn.MOD_ID, "tslwords"), + TSLWordsArgumentType.class, + SingletonArgumentInfo.contextFree(TSLWordsArgumentType::tslWords)); + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..e72e678 --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,27 @@ +{ + "schemaVersion": 1, + "id": "twitchspawn", + "version": "${version}", + + "name": "TwitchSpawn", + "description": "TwitchSpawn listens for live events related to your Twitch channel using various Socket APIs.\nThen it handles those events with the rules handcrafted by you!", + "authors": [], + "contact": {}, + + "license": "GNU LGPL 3.0", + "icon": "icon.png", + + "environment": "*", + "entrypoints": { + "main": [ + "net.programmer.igoodie.twitchspawn.fabric.TwitchSpawnFabric" + ] + }, + "mixins": [ + "twitchspawn.mixins.json" + ], + "depends": { + "fabricloader": ">=0.15.3", + "minecraft": ">=1.20.2" + } +} diff --git a/fabric/src/main/resources/twitchspawn.mixins.json b/fabric/src/main/resources/twitchspawn.mixins.json new file mode 100644 index 0000000..edaef3d --- /dev/null +++ b/fabric/src/main/resources/twitchspawn.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.programmer.igoodie.twitchspawn.mixin.fabric", + "compatibilityLevel": "JAVA_17", + "client": [ + "MixinGui", + "MixinLoadingOverlay" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..ad406ce --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,97 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" +} +architectury { + platformSetupLoomIde() + forge() +} + +loom { +// accessWidenerPath = project(":common").loom.accessWidenerPath + + forge { +// convertAccessWideners = true +// extraAccessWideners.add loom.accessWidenerPath.get().asFile.name + + mixinConfig "twitchspawn-common.mixins.json" + mixinConfig "twitchspawn.mixins.json" + } +} + +configurations { + common + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentForge.extendsFrom common +} + +dependencies { + forge "net.minecraftforge:forge:${rootProject.forge_version}" + // Remove the next line if you don't want to depend on the API + modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}" + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } + + implementation 'com.squareup.okhttp3:okhttp:3.8.1' + implementation 'io.socket:socket.io-client:1.0.2' + + forgeRuntimeLibrary 'com.squareup.okhttp3:okhttp:3.8.1' + forgeRuntimeLibrary 'io.socket:socket.io-client:1.0.2' + + shadowCommon 'com.squareup.okhttp3:okhttp:3.8.1' + shadowCommon 'io.socket:socket.io-client:1.0.2' +} + +processResources { + inputs.property "version", project.version + + filesMatching("META-INF/mods.toml") { + expand "version": project.version + } +} + +shadowJar { + exclude "fabric.mod.json" + exclude "architectury.common.json" + + configurations = [project.configurations.shadowCommon] + archiveClassifier.set("dev-shadow") +} + +remapJar { + inputFile.set shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} + +jar { + archiveClassifier.set("dev") +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +publishing { + publications { + mavenForge(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } +} diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 0000000..32f842a --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.platform=forge \ No newline at end of file diff --git a/forge/src/main/java/net/programmer/igoodie/twitchspawn/events/forge/TwitchSpawnEventHandlerImpl.java b/forge/src/main/java/net/programmer/igoodie/twitchspawn/events/forge/TwitchSpawnEventHandlerImpl.java new file mode 100644 index 0000000..f745fff --- /dev/null +++ b/forge/src/main/java/net/programmer/igoodie/twitchspawn/events/forge/TwitchSpawnEventHandlerImpl.java @@ -0,0 +1,48 @@ + +package net.programmer.igoodie.twitchspawn.events.forge; + + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; +import net.minecraftforge.client.event.RenderGuiOverlayEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; + + +/** + * This class handles the registration of events. + */ +public class TwitchSpawnEventHandlerImpl +{ + @OnlyIn(Dist.CLIENT) + public static void registerClient() + { + // Register client events. + MinecraftForge.EVENT_BUS.register(TwitchSpawnEventHandlerImpl.class); + } + + + @SubscribeEvent + public static void onScreenGuiOverlayEvent(CustomizeGuiOverlayEvent.DebugText event) + { + TwitchSpawnClientGuiEvent.DEBUG_TEXT.invoker().renderHud(event.getGuiGraphics()); + } + + + @SubscribeEvent + public static void onRenderGuiOverlayPre(RenderGuiOverlayEvent.Pre event) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_PRE.invoker().renderHud(event.getGuiGraphics(), + event.getOverlay().id()); + } + + + @SubscribeEvent + public static void onRenderGuiOverlayPost(RenderGuiOverlayEvent.Post event) + { + TwitchSpawnClientGuiEvent.OVERLAY_RENDER_POST.invoker().renderHud(event.getGuiGraphics(), + event.getOverlay().id()); + } +} diff --git a/forge/src/main/java/net/programmer/igoodie/twitchspawn/forge/TwitchSpawnForge.java b/forge/src/main/java/net/programmer/igoodie/twitchspawn/forge/TwitchSpawnForge.java new file mode 100644 index 0000000..6d7c5da --- /dev/null +++ b/forge/src/main/java/net/programmer/igoodie/twitchspawn/forge/TwitchSpawnForge.java @@ -0,0 +1,21 @@ +package net.programmer.igoodie.twitchspawn.forge; + + +import dev.architectury.platform.forge.EventBuses; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.registries.forge.TwitchSpawnArgumentTypesImpl; + + +@Mod(TwitchSpawn.MOD_ID) +public class TwitchSpawnForge { + public TwitchSpawnForge() { + // Submit our event bus to let architectury register our content on the right time + EventBuses.registerModEventBus(TwitchSpawn.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); + TwitchSpawn.init(); + + // Register Registry + TwitchSpawnArgumentTypesImpl.REGISTRY.register(FMLJavaModLoadingContext.get().getModEventBus()); + } +} diff --git a/forge/src/main/java/net/programmer/igoodie/twitchspawn/mixin/forge/MixinForgeLoadingOverlay.java b/forge/src/main/java/net/programmer/igoodie/twitchspawn/mixin/forge/MixinForgeLoadingOverlay.java new file mode 100644 index 0000000..9c3dd8a --- /dev/null +++ b/forge/src/main/java/net/programmer/igoodie/twitchspawn/mixin/forge/MixinForgeLoadingOverlay.java @@ -0,0 +1,41 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package net.programmer.igoodie.twitchspawn.mixin.forge; + + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.loading.ForgeLoadingOverlay; +import net.programmer.igoodie.twitchspawn.events.TwitchSpawnClientGuiEvent; + + +/** + * This mixin is used to trigger the {@link TwitchSpawnClientGuiEvent#FINISH_LOADING_OVERLAY} event. + */ +@Mixin(value = ForgeLoadingOverlay.class, remap = false) +public class MixinForgeLoadingOverlay +{ + @Shadow + @Final + private Minecraft minecraft; + + + @Inject(method = "render", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/Minecraft;setOverlay(Lnet/minecraft/client/gui/screens/Overlay;)V", + shift = At.Shift.AFTER)) + private void overlayRemoveEvent(CallbackInfo callbackInfo) + { + TwitchSpawnClientGuiEvent.FINISH_LOADING_OVERLAY.invoker().removeOverlay(this.minecraft, this.minecraft.screen); + } +} diff --git a/forge/src/main/java/net/programmer/igoodie/twitchspawn/registries/forge/TwitchSpawnArgumentTypesImpl.java b/forge/src/main/java/net/programmer/igoodie/twitchspawn/registries/forge/TwitchSpawnArgumentTypesImpl.java new file mode 100644 index 0000000..18e25a0 --- /dev/null +++ b/forge/src/main/java/net/programmer/igoodie/twitchspawn/registries/forge/TwitchSpawnArgumentTypesImpl.java @@ -0,0 +1,41 @@ +package net.programmer.igoodie.twitchspawn.registries.forge; + + +import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.commands.synchronization.ArgumentTypeInfos; +import net.minecraft.commands.synchronization.SingletonArgumentInfo; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.programmer.igoodie.twitchspawn.TwitchSpawn; +import net.programmer.igoodie.twitchspawn.command.RulesetNameArgumentType; +import net.programmer.igoodie.twitchspawn.command.StreamerArgumentType; +import net.programmer.igoodie.twitchspawn.command.TSLWordsArgumentType; + + +public class TwitchSpawnArgumentTypesImpl +{ + /** + * Registry for argument types. + */ + public static final net.minecraftforge.registries.DeferredRegister> REGISTRY = + DeferredRegister.create(ForgeRegistries.COMMAND_ARGUMENT_TYPES, TwitchSpawn.MOD_ID); + + public static void registerArgumentType() + { + // Do nothing. Forge is registred on startup. + } + + static { + // Argument type for ruleset names. + REGISTRY.register("ruleset", () -> ArgumentTypeInfos.registerByClass(RulesetNameArgumentType.class, + SingletonArgumentInfo.contextFree(RulesetNameArgumentType::rulesetName))); + + // Argument type for streamer names. + REGISTRY.register("streamer", () -> ArgumentTypeInfos.registerByClass(StreamerArgumentType.class, + SingletonArgumentInfo.contextFree(StreamerArgumentType::streamerNick))); + + // Argument type for TSL words. + REGISTRY.register("tslwords", () -> ArgumentTypeInfos.registerByClass(TSLWordsArgumentType.class, + SingletonArgumentInfo.contextFree(TSLWordsArgumentType::tslWords))); + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..8170bfc --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,73 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="javafml" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the forge version +loaderVersion="[48,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. +# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. +license="GNU LGPL 3.0" +# A URL to refer people to when problems occur with this mod +issueTrackerURL="https://github.com/iGoodie/TwitchSpawn/issues" +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="twitchspawn" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +# ${version} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata +# see the associated build.gradle script for how to populate this completely automatically during a build +version="${version}" #mandatory +# A display name for the mod +displayName="TwitchSpawn" #mandatory +# A URL to query for updates for this mod. See the JSON update specification +#updateJSONURL="http://myurl.me/" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +#displayURL="http://example.com/" #optional +# A file name (in the root of the mod JAR) containing a logo for display +logoFile="icon.png" #optional +# A text field displayed in the mod UI +#credits="Thanks for this example mod goes to Java" #optional +# A text field displayed in the mod UI +authors="iGoodie, BONNe1704" #optional +# Display Test controls the display for your mod in the server connection screen +# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. +# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. +# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. +# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. +# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. +#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) + +# The description text for the mod (multi line!) (#mandatory) +description=''' + TwitchSpawn listens for live events related to your Twitch channel using various Socket APIs. + Then it handles those events with the rules handcrafted by you! +''' +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.twitchspawn]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[48,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.twitchspawn]] + modId="minecraft" + mandatory=true + # This version range declares a minimum of the current minecraft version up to but not including the next major version + versionRange="[1.20.2,1.21)" + ordering="NONE" + side="BOTH" +[[dependencies.twitchspawn]] + modId = "architectury" + mandatory = true + versionRange = "[9.1.12,)" + ordering = "AFTER" + side = "BOTH" diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..9936dbb --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,7 @@ +{ + "pack": { + "description": "TwitchSpawn resources", + "pack_format": 18, + "forge:server_data_pack_format": 12 + } +} diff --git a/forge/src/main/resources/twitchspawn.mixins.json b/forge/src/main/resources/twitchspawn.mixins.json new file mode 100644 index 0000000..2b470a3 --- /dev/null +++ b/forge/src/main/resources/twitchspawn.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.programmer.igoodie.twitchspawn.mixin.forge", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "MixinForgeLoadingOverlay" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/gradle.properties b/gradle.properties index 9c090b9..1648d2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,14 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. -org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false +org.gradle.jvmargs=-Xmx1G -mod_id=twitchspawn -mod_group=net.programmer.igoodie -mod_version=1.9.4 +minecraft_version=1.20.2 -minecraft_version=1.18.2 -forge_version=40.0.52 +archives_base_name=TwitchSpawn +mod_version=2.0.0 +maven_group=net.programmer.igoodie -mcpMappings_channel=official -mcpMappings_version=1.18.2 +architectury_version=10.0.17 + +fabric_loader_version=0.15.3 +fabric_api_version=0.91.2+1.20.2 + +forge_version=1.20.2-48.1.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..ccebba7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 774fae8..3499ded 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 744e882..79a61d4 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..7feba6a --- /dev/null +++ b/settings.gradle @@ -0,0 +1,14 @@ +pluginManagement { + repositories { + maven { url "https://maven.fabricmc.net/" } + maven { url "https://maven.architectury.dev/" } + maven { url "https://maven.minecraftforge.net/" } + gradlePluginPortal() + } +} + +include("common") +include("fabric") +include("forge") + +rootProject.name = "architectury-twitchspawn" \ No newline at end of file diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java b/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java deleted file mode 100644 index 84c4d79..0000000 --- a/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawn.java +++ /dev/null @@ -1,145 +0,0 @@ -package net.programmer.igoodie.twitchspawn; - -import net.minecraft.commands.synchronization.ArgumentTypes; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.RegisterCommandsEvent; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.server.ServerAboutToStartEvent; -import net.minecraftforge.event.server.ServerStartingEvent; -import net.minecraftforge.event.server.ServerStoppingEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingStage; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.network.NetworkDirection; -import net.programmer.igoodie.twitchspawn.client.gui.GlobalChatCooldownOverlay; -import net.programmer.igoodie.twitchspawn.client.gui.StatusIndicatorOverlay; -import net.programmer.igoodie.twitchspawn.command.RulesetNameArgumentType; -import net.programmer.igoodie.twitchspawn.command.StreamerArgumentType; -import net.programmer.igoodie.twitchspawn.command.TwitchSpawnCommand; -import net.programmer.igoodie.twitchspawn.command.serializer.RulesetNameArgumentSerializer; -import net.programmer.igoodie.twitchspawn.command.serializer.StreamerArgumentSerializer; -import net.programmer.igoodie.twitchspawn.configuration.ConfigManager; -import net.programmer.igoodie.twitchspawn.configuration.PreferencesConfig; -import net.programmer.igoodie.twitchspawn.network.NetworkManager; -import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket; -import net.programmer.igoodie.twitchspawn.tracer.TraceManager; -import net.programmer.igoodie.twitchspawn.udl.NotepadUDLUpdater; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -@Mod(TwitchSpawn.MOD_ID) -public class TwitchSpawn { - - public static final String MOD_ID = "twitchspawn"; - public static final Logger LOGGER = LogManager.getLogger(TwitchSpawn.class); - - public static MinecraftServer SERVER; - public static TraceManager TRACE_MANAGER; - - public TwitchSpawn() { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::dedicatedServerSetup); - - MinecraftForge.EVENT_BUS.register(this); - } - - private void commonSetup(final FMLCommonSetupEvent event) { - try { - ConfigManager.loadConfigs(); - NetworkManager.initialize(); - - ArgumentTypes.register("twitchspawn:streamer", StreamerArgumentType.class, - new StreamerArgumentSerializer()); - ArgumentTypes.register("twitchspawn:ruleset", RulesetNameArgumentType.class, - new RulesetNameArgumentSerializer()); - - } catch (TwitchSpawnLoadingErrors e) { - e.bindFMLWarnings(ModLoadingStage.COMMON_SETUP); - if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { - throw new RuntimeException("TwitchSpawn loading errors occurred"); - } - } - } - - private void clientSetup(final FMLClientSetupEvent event) { - NotepadUDLUpdater.attemptUpdate(); - MinecraftForge.EVENT_BUS.register(StatusIndicatorOverlay.class); - MinecraftForge.EVENT_BUS.register(GlobalChatCooldownOverlay.class); - } - - private void dedicatedServerSetup(final FMLDedicatedServerSetupEvent event) {} - - @SubscribeEvent - public void registerSounds(RegistryEvent.Register event) { - event.getRegistry().register(new SoundEvent(new ResourceLocation(TwitchSpawn.MOD_ID, "pop_in"))); - event.getRegistry().register(new SoundEvent(new ResourceLocation(TwitchSpawn.MOD_ID, "pop_out"))); - } - - @SubscribeEvent - public void onRegisterCommands(RegisterCommandsEvent event) { - TwitchSpawnCommand.register(event.getDispatcher()); - } - - @SubscribeEvent - public void onServerAboutToStart(ServerAboutToStartEvent event) { - SERVER = event.getServer(); - TRACE_MANAGER = new TraceManager(); - } - - @SubscribeEvent - public void onServerStarting(ServerStartingEvent event) { - if (ConfigManager.PREFERENCES.autoStart == PreferencesConfig.AutoStartEnum.ENABLED) { - LOGGER.info("Auto-start is enabled. Attempting to start tracers."); - TRACE_MANAGER.start(); - } - } - - @SubscribeEvent - public void onServerStopping(ServerStoppingEvent event) { - SERVER = null; - - if (TRACE_MANAGER.isRunning()) - TRACE_MANAGER.stop(null, "Server stopping"); - - ConfigManager.RULESET_COLLECTION.clearQueue(); - } - - @SubscribeEvent - public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { - ServerPlayer entity = (ServerPlayer) event.getPlayer(); - - String translationKey = TRACE_MANAGER.isRunning() ? - "commands.twitchspawn.status.on" : "commands.twitchspawn.status.off"; - - entity.sendMessage(new TranslatableComponent(translationKey), entity.getUUID()); - - if (TRACE_MANAGER.isRunning()) - TRACE_MANAGER.connectStreamer(entity.getName().getString()); - - NetworkManager.CHANNEL.sendTo(new StatusChangedPacket(TRACE_MANAGER.isRunning()), - entity.connection.connection, - NetworkDirection.PLAY_TO_CLIENT); - } - - @SubscribeEvent - public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { - ServerPlayer entity = (ServerPlayer) event.getPlayer(); - - if (TRACE_MANAGER.isRunning()) - TRACE_MANAGER.disconnectStreamer(entity.getName().getString()); - } - -} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java b/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java deleted file mode 100644 index 418c50e..0000000 --- a/src/main/java/net/programmer/igoodie/twitchspawn/TwitchSpawnLoadingErrors.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.programmer.igoodie.twitchspawn; - -import com.electronwill.nightconfig.core.io.ParsingException; -import com.google.gson.JsonSyntaxException; -import net.minecraftforge.fml.*; -import net.minecraftforge.forgespi.language.IModInfo; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; -import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxErrors; - -import java.util.LinkedList; -import java.util.List; - -public class TwitchSpawnLoadingErrors extends Exception { - - List exceptions; - - public TwitchSpawnLoadingErrors() { - this.exceptions = new LinkedList<>(); - } - - public void addException(Exception exception) { - if (exception instanceof TSLSyntaxErrors) - this.exceptions.addAll(((TSLSyntaxErrors) exception).getErrors()); - else - this.exceptions.add(exception); - } - - public boolean isEmpty() { - return exceptions.size() == 0; - } - - public void bindFMLWarnings(ModLoadingStage stage) { - ModContainer modContainer = ModList.get() - .getModContainerById(TwitchSpawn.MOD_ID).get(); - - IModInfo modInfo = modContainer.getModInfo(); - - for (Exception exception : exceptions) { - String i18nMessage; - - if (exception instanceof TSLSyntaxError) - i18nMessage = "modloader.twitchspawn.error.tsl"; - else if (exception instanceof ParsingException) - i18nMessage = "modloader.twitchspawn.error.toml"; - else if (exception instanceof JsonSyntaxException) - i18nMessage = "modloader.twitchspawn.error.json"; - else - i18nMessage = "modloader.twitchspawn.error.unknown"; - - ModLoadingWarning warning = new ModLoadingWarning( - modInfo, stage, i18nMessage, - exception.getMessage(), - exception.getClass().getSimpleName() - ); - - ModLoader.get().addWarning(warning); - - TwitchSpawn.LOGGER.error(exception.getMessage()); - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - String delimiter = ""; - for (Exception exception : exceptions) { - sb.append(delimiter); - sb.append(exception.getMessage()); - delimiter = "\n"; - } - return sb.toString(); - } - -} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/RulesetNameArgumentSerializer.java b/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/RulesetNameArgumentSerializer.java deleted file mode 100644 index ef68dcf..0000000 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/RulesetNameArgumentSerializer.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.programmer.igoodie.twitchspawn.command.serializer; - -import com.google.gson.JsonObject; -import net.minecraft.commands.synchronization.ArgumentSerializer; -import net.minecraft.network.FriendlyByteBuf; -import net.programmer.igoodie.twitchspawn.command.RulesetNameArgumentType; - -public class RulesetNameArgumentSerializer implements ArgumentSerializer { - - @Override - public void serializeToNetwork(RulesetNameArgumentType p_121579_, FriendlyByteBuf p_121580_) { - - } - - @Override - public RulesetNameArgumentType deserializeFromNetwork(FriendlyByteBuf p_121581_) { - return RulesetNameArgumentType.rulesetName(); - } - - @Override - public void serializeToJson(RulesetNameArgumentType p_121577_, JsonObject p_121578_) { - - } - -} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/StreamerArgumentSerializer.java b/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/StreamerArgumentSerializer.java deleted file mode 100644 index a6b2103..0000000 --- a/src/main/java/net/programmer/igoodie/twitchspawn/command/serializer/StreamerArgumentSerializer.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.programmer.igoodie.twitchspawn.command.serializer; - -import com.google.gson.JsonObject; -import net.minecraft.commands.synchronization.ArgumentSerializer; -import net.minecraft.network.FriendlyByteBuf; -import net.programmer.igoodie.twitchspawn.command.StreamerArgumentType; - -public class StreamerArgumentSerializer implements ArgumentSerializer { - - @Override - public void serializeToNetwork(StreamerArgumentType argumentType, FriendlyByteBuf buffer) { - - } - - @Override - public StreamerArgumentType deserializeFromNetwork(FriendlyByteBuf buffer) { - return StreamerArgumentType.streamerNick(); - } - - @Override - public void serializeToJson(StreamerArgumentType argumentType, JsonObject jsonObject) { - - } - -} diff --git a/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java b/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java deleted file mode 100644 index 2f09198..0000000 --- a/src/main/java/net/programmer/igoodie/twitchspawn/network/NetworkManager.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.programmer.igoodie.twitchspawn.network; - -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.simple.SimpleChannel; -import net.programmer.igoodie.twitchspawn.TwitchSpawn; -import net.programmer.igoodie.twitchspawn.network.packet.GlobalChatCooldownPacket; -import net.programmer.igoodie.twitchspawn.network.packet.OsRunPacket; -import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket; - -public class NetworkManager { - - private static final String PROTOCOL_VERSION = "0.0.4"; - - public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder - .named(new ResourceLocation(TwitchSpawn.MOD_ID, "network")) - .clientAcceptedVersions(v -> v.equals(PROTOCOL_VERSION)) - .serverAcceptedVersions(v -> v.equals(PROTOCOL_VERSION)) - .networkProtocolVersion(() -> PROTOCOL_VERSION) - .simpleChannel(); - - public static void initialize() { - CHANNEL.registerMessage(0, StatusChangedPacket.class, - StatusChangedPacket::encode, - StatusChangedPacket::decode, - StatusChangedPacket::handle); - - CHANNEL.registerMessage(1, OsRunPacket.class, - OsRunPacket::encode, - OsRunPacket::decode, - OsRunPacket::handle); - - CHANNEL.registerMessage(2, GlobalChatCooldownPacket.class, - GlobalChatCooldownPacket::encode, - GlobalChatCooldownPacket::decode, - GlobalChatCooldownPacket::handle - ); - } - -} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml deleted file mode 100644 index 7b9b57a..0000000 --- a/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,29 +0,0 @@ -modLoader="javafml" -loaderVersion="[37,)" -license="EPL-1.0" -issueTrackerURL="https://github.com/iGoodie/TwitchSpawn/issues" - -[[mods]] -modId="twitchspawn" -version="${file.jarVersion}" -displayName="TwitchSpawn" -authors="iGoodie" -logoFile="pack.png" -description=''' - TwitchSpawn listens for live events related to your Twitch channel using various Socket APIs. - Then it handles those events with the rules handcrafted by you! -''' - -[[dependencies.twitchspawn]] - modId="forge" - mandatory=true - versionRange="[37.0.1,)" - ordering="NONE" - side="BOTH" - -[[dependencies.twitchspawn]] - modId="minecraft" - mandatory=true - versionRange="[1.17.1,)" - ordering="NONE" - side="BOTH"