From dd8cf78b93483cf75c0891fdfd733e7feeb3c651 Mon Sep 17 00:00:00 2001 From: lukasabbe <67807954+lukasabbe@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:37:13 +0200 Subject: [PATCH] Fixed up the code a bit --- .github/workflows/build.yml | 19 ++++-- build.gradle | 31 +-------- gradle.properties | 4 +- .../lukasabbe/voicechatgroupmsg/Commands.java | 56 ---------------- .../voicechatgroupmsg/VoiceChatGroupMsg.java | 53 ++------------- .../command/MsgVcCommand.java | 64 +++++++++++++++++++ .../voicechatgroupmsg/util/VoiceChatUtil.java | 56 ++++++++++++++++ src/main/resources/fabric.mod.json | 2 +- 8 files changed, 145 insertions(+), 140 deletions(-) delete mode 100644 src/main/java/me/lukasabbe/voicechatgroupmsg/Commands.java create mode 100644 src/main/java/me/lukasabbe/voicechatgroupmsg/command/MsgVcCommand.java create mode 100644 src/main/java/me/lukasabbe/voicechatgroupmsg/util/VoiceChatUtil.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b01da52..e85f85d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,8 +1,3 @@ -# Automatically build the project and run any configured tests for every push -# and submitted pull request. This can help catch issues that only occur on -# certain platforms or Java versions, and provides a first line of defence -# against bad commits. - name: build on: [pull_request, push] @@ -34,4 +29,16 @@ jobs: uses: actions/upload-artifact@v4 with: name: Artifacts - path: build/libs/ \ No newline at end of file + path: build/libs/ + - name: Read values from gradle properties file + id: read_property + uses: christian-draeger/read-properties@1.1.1 + with: + path: "./gradle.properties" + properties: "mod_version minecraft_version archives_base_name" + - name: Upload artifacts to discord + uses: tsickert/discord-webhook@v6.0.0 + with: + webhook-url: ${{ secrets.WEBHOOK_URL }} + content: "Git hub action build. **THIS MAY NOT BE A FUNCTIONAL BUILD**\nMod: ${{steps.read_property.outputs.archives_base_name}}\nMCVersion: ${{steps.read_property.outputs.minecraft_version}}\nMod version: ${{steps.read_property.outputs.mod_version}}" + filename: build/libs/${{ steps.read_property.outputs.archives_base_name }}-${{steps.read_property.outputs.mod_version}}.jar \ No newline at end of file diff --git a/build.gradle b/build.gradle index ab20f6c..d814a3b 100644 --- a/build.gradle +++ b/build.gradle @@ -26,11 +26,11 @@ dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modRuntimeOnly "maven.modrinth:simple-voice-chat:fabric-${voicechat_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // Simple Voice chat implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_version}" + modRuntimeOnly "maven.modrinth:simple-voice-chat:fabric-${voicechat_version}" } processResources { @@ -50,10 +50,6 @@ processResources { def targetJavaVersion = 21 tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { it.options.release.set(targetJavaVersion) @@ -65,9 +61,6 @@ java { if (JavaVersion.current() < javaVersion) { toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) } - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. withSourcesJar() } @@ -76,21 +69,3 @@ jar { rename { "${it}_${project.archivesBaseName}"} } } - -// configure the maven publication -publishing { - publications { - create("mavenJava", MavenPublication) { - artifactId = project.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. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } -} diff --git a/gradle.properties b/gradle.properties index 713ac23..29fb5c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,10 +5,10 @@ org.gradle.jvmargs=-Xmx1G # check these on https://modmuss50.me/fabric.html minecraft_version=1.21.5 yarn_mappings=1.21.5+build.1 - loader_version=0.16.10 + loader_version=0.16.13 # Mod Properties - mod_version = 1.0.1+1.21.5 + mod_version = 1.1+1.21.5 maven_group = me.lukasabbe archives_base_name = VoiceChatGroupMsg diff --git a/src/main/java/me/lukasabbe/voicechatgroupmsg/Commands.java b/src/main/java/me/lukasabbe/voicechatgroupmsg/Commands.java deleted file mode 100644 index 6512bb1..0000000 --- a/src/main/java/me/lukasabbe/voicechatgroupmsg/Commands.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.lukasabbe.voicechatgroupmsg; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import de.maxhenkel.voicechat.api.Group; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.MessageArgumentType; -import net.minecraft.network.message.MessageType; -import net.minecraft.network.message.SentMessage; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; - -import java.util.List; - -public class Commands { - public static void CreateGroupMsgCommand(CommandDispatcher dispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager - .literal("msgvc") - .then(CommandManager - .argument("message", MessageArgumentType.message()) - .executes(Commands::runCommand))); - } - - private static int runCommand(CommandContext ctx) throws CommandSyntaxException { - final ServerCommandSource source = ctx.getSource(); - if(!source.isExecutedByPlayer()) { - source.sendError(Text.literal("You can't send msgvc as the console")); - return 0; - } - final ServerPlayerEntity player = source.getPlayer(); - if(!VoiceChatGroupMsg.isPlayerInGroup(player)){ - source.sendError(Text.literal("You need to be in a voice chat group to use this command")); - return 0; - } - Group group = VoiceChatGroupMsg.getPlayerGroup(player); - List players = VoiceChatGroupMsg.GroupPlayers(group.getId(), source.getWorld()); - MessageArgumentType.getSignedMessage(ctx, "message", signedMessage -> { - player.sendChatMessage( - SentMessage.of(signedMessage), - true, - MessageType.params(MessageType.TEAM_MSG_COMMAND_OUTGOING,source).withTargetName(Text.of(group.getName()))); - players.forEach(player1 -> { - if(!player1.getUuid().equals(player.getUuid())){ - player1.sendChatMessage( - SentMessage.of(signedMessage), - true, - MessageType.params(MessageType.TEAM_MSG_COMMAND_INCOMING,source).withTargetName(Text.of(group.getName()))); - } - }); - }); - return 1; - } -} diff --git a/src/main/java/me/lukasabbe/voicechatgroupmsg/VoiceChatGroupMsg.java b/src/main/java/me/lukasabbe/voicechatgroupmsg/VoiceChatGroupMsg.java index 5ef1751..65f8588 100644 --- a/src/main/java/me/lukasabbe/voicechatgroupmsg/VoiceChatGroupMsg.java +++ b/src/main/java/me/lukasabbe/voicechatgroupmsg/VoiceChatGroupMsg.java @@ -1,60 +1,19 @@ package me.lukasabbe.voicechatgroupmsg; -import de.maxhenkel.voicechat.api.Group; -import de.maxhenkel.voicechat.api.VoicechatPlugin; -import de.maxhenkel.voicechat.api.VoicechatServerApi; -import de.maxhenkel.voicechat.api.events.EventRegistration; -import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent; +import me.lukasabbe.voicechatgroupmsg.command.MsgVcCommand; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import java.util.List; -import java.util.UUID; +public class VoiceChatGroupMsg implements DedicatedServerModInitializer { -public class VoiceChatGroupMsg implements DedicatedServerModInitializer, VoicechatPlugin { public final static String MOD_ID = "voicechatgroupmsg"; - private static VoicechatServerApi API = null; + @Override public void onInitializeServer() { - CommandRegistrationCallback.EVENT.register(Commands::CreateGroupMsgCommand); + registerCommands(); } - @Override - public String getPluginId() { - return MOD_ID; - } - - @Override - public void registerEvents(EventRegistration registration) { - registration.registerEvent(VoicechatServerStartedEvent.class, this::onServerStarted); - } - - public void onServerStarted(VoicechatServerStartedEvent event) { - API = event.getVoicechat(); - } - - public static boolean isPlayerInGroup(ServerPlayerEntity player){ - try{ - return API.getConnectionOf(player.getUuid()).isInGroup(); - }catch (NullPointerException ignore){ - return false; - } - } - public static boolean isPlayerInGroup(ServerPlayerEntity player, UUID groupID){ - try{ - if(!API.getConnectionOf(player.getUuid()).isInGroup()) return false; - return API.getConnectionOf(player.getUuid()).getGroup().getId().equals(groupID); - - }catch (NullPointerException ignore){ - return false; - } - } - public static Group getPlayerGroup(ServerPlayerEntity player){ - return API.getConnectionOf(player.getUuid()).getGroup(); - } - public static List GroupPlayers(UUID groupUUID, ServerWorld serverWorld){ - return serverWorld.getPlayers(player -> isPlayerInGroup(player, groupUUID)); + private static void registerCommands() { + CommandRegistrationCallback.EVENT.register(MsgVcCommand::CreateGroupMsgCommand); } } diff --git a/src/main/java/me/lukasabbe/voicechatgroupmsg/command/MsgVcCommand.java b/src/main/java/me/lukasabbe/voicechatgroupmsg/command/MsgVcCommand.java new file mode 100644 index 0000000..fb367f5 --- /dev/null +++ b/src/main/java/me/lukasabbe/voicechatgroupmsg/command/MsgVcCommand.java @@ -0,0 +1,64 @@ +package me.lukasabbe.voicechatgroupmsg.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import de.maxhenkel.voicechat.api.Group; +import me.lukasabbe.voicechatgroupmsg.util.VoiceChatUtil; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.command.argument.MessageArgumentType; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.registry.RegistryKey; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +import java.util.List; + +public class MsgVcCommand { + public static void CreateGroupMsgCommand(CommandDispatcher dispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { + dispatcher.register( + CommandManager + .literal("msgvc") + .requires(ServerCommandSource::isExecutedByPlayer) + .then( + CommandManager + .argument("message", MessageArgumentType.message()) + .executes(MsgVcCommand::runCommand))); + } + + private static int runCommand(CommandContext ctx) throws CommandSyntaxException { + final ServerCommandSource source = ctx.getSource(); + + final ServerPlayerEntity player = source.getPlayer(); + if(!VoiceChatUtil.isPlayerInGroup(player)){ + source.sendError(Text.literal("You need to be in a voice chat group to use this command")); + return 0; + } + + Group group = VoiceChatUtil.getPlayerGroup(player); + + List players = VoiceChatUtil.GroupPlayers(group.getId(), source.getWorld()); + + MessageArgumentType.getSignedMessage(ctx, "message", signedMessage -> { + sendMessage(player, signedMessage, MessageType.TEAM_MSG_COMMAND_OUTGOING, source, group); + players.forEach(voiceChatMember -> { + if(voiceChatMember.getUuid().equals(player.getUuid())) return; + sendMessage(voiceChatMember, signedMessage, MessageType.TEAM_MSG_COMMAND_INCOMING, source, group); + }); + }); + return 1; + } + + private static void sendMessage(ServerPlayerEntity player, SignedMessage signedMessage, RegistryKey teamMsgCommandOutgoing, ServerCommandSource source, Group group) { + player.sendChatMessage( + SentMessage.of(signedMessage), + true, + MessageType.params(teamMsgCommandOutgoing, source) + .withTargetName(Text.of(group.getName())) + ); + } +} diff --git a/src/main/java/me/lukasabbe/voicechatgroupmsg/util/VoiceChatUtil.java b/src/main/java/me/lukasabbe/voicechatgroupmsg/util/VoiceChatUtil.java new file mode 100644 index 0000000..28603b0 --- /dev/null +++ b/src/main/java/me/lukasabbe/voicechatgroupmsg/util/VoiceChatUtil.java @@ -0,0 +1,56 @@ +package me.lukasabbe.voicechatgroupmsg.util; + +import de.maxhenkel.voicechat.api.Group; +import de.maxhenkel.voicechat.api.VoicechatPlugin; +import de.maxhenkel.voicechat.api.VoicechatServerApi; +import de.maxhenkel.voicechat.api.events.EventRegistration; +import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; + +import java.util.List; +import java.util.UUID; + +import static me.lukasabbe.voicechatgroupmsg.VoiceChatGroupMsg.MOD_ID; + +public class VoiceChatUtil implements VoicechatPlugin { + + private static VoicechatServerApi API = null; + + @Override + public String getPluginId() { + return MOD_ID; + } + + @Override + public void registerEvents(EventRegistration registration) { + registration.registerEvent(VoicechatServerStartedEvent.class, this::onServerStarted); + } + + public void onServerStarted(VoicechatServerStartedEvent event) { + API = event.getVoicechat(); + } + + public static boolean isPlayerInGroup(ServerPlayerEntity player){ + try{ + return API.getConnectionOf(player.getUuid()).isInGroup(); + }catch (NullPointerException ignore){ + return false; + } + } + public static boolean isPlayerInGroup(ServerPlayerEntity player, UUID groupID){ + try{ + if(!API.getConnectionOf(player.getUuid()).isInGroup()) return false; + return API.getConnectionOf(player.getUuid()).getGroup().getId().equals(groupID); + + }catch (NullPointerException ignore){ + return false; + } + } + public static Group getPlayerGroup(ServerPlayerEntity player){ + return API.getConnectionOf(player.getUuid()).getGroup(); + } + public static List GroupPlayers(UUID groupUUID, ServerWorld serverWorld){ + return serverWorld.getPlayers(player -> isPlayerInGroup(player, groupUUID)); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0d7357e..a14178c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,7 +16,7 @@ "me.lukasabbe.voicechatgroupmsg.VoiceChatGroupMsg" ], "voicechat": [ - "me.lukasabbe.voicechatgroupmsg.VoiceChatGroupMsg" + "me.lukasabbe.voicechatgroupmsg.util.VoiceChatUtil" ] }, "depends": {