diff --git a/build.gradle b/build.gradle index 6ffade9..cee3421 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '0.4-SNAPSHOT' + id 'fabric-loom' version '0.8-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = project.name version = project.mod + "+" + project.mc @@ -16,8 +16,8 @@ minecraft { repositories { maven { - url = "http://maven.fabricmc.net/" - name = "Fabric" + name = "dv8tion" + url = "https://m2.dv8tion.net/releases/" } } @@ -28,15 +28,14 @@ dependencies { modImplementation(fabricApi.module("fabric-api-base", project.fabric)) modImplementation(fabricApi.module("fabric-command-api-v1", project.fabric)) + modImplementation(fabricApi.module("fabric-lifecycle-events-v1", project.fabric)) // bot stuff - include modApi("net.dv8tion:JDA:4.2.0_175") { + include implementation("net.dv8tion:JDA:4.3.0_296") { exclude module: 'opus-java' } // needed for jda to run - include("org.slf4j:slf4j-api:1.7.25") - include("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") include("net.sf.trove4j:trove4j:3.0.3") include("org.apache.commons:commons-collections4:4.1") include("com.fasterxml.jackson.core:jackson-databind:2.10.1") @@ -44,34 +43,34 @@ dependencies { include("com.fasterxml.jackson.core:jackson-core:2.10.1") include("com.squareup.okhttp3:okhttp:3.13.0") include("com.squareup.okio:okio:2.6.0") - include("com.neovisionaries:nv-websocket-client:2.9") - modRuntimeMapped("net.fabricmc:fabric-language-kotlin:1.3.72+build.1") // includes kotlin for squareup libs + include("com.neovisionaries:nv-websocket-client:2.14") + modRuntimeMapped("net.fabricmc:fabric-language-kotlin:1.6.2+kotlin.1.5.20") { // includes kotlin for squareup libs + exclude module: "fabric-loader" + } } processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" - expand "version": project.version - } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" + filesMatching("fabric.mod.json") { + expand "version": project.version } } tasks.withType(JavaCompile) { options.encoding = "UTF-8" + + options.release = 16 } -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier = "sources" - from sourceSets.main.allSource +java { + withSourcesJar() } jar { - from "LICENSE" + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}" } + } } // configure the maven publication diff --git a/gradle.properties b/gradle.properties index 96e3e3d..e26a169 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx3G +org.gradle.jvmargs=-Xmx1G # Fabric Properties -mc=1.16.1 -yarn=21 -loader=0.8.9+build.203 +mc=1.17 +yarn=13 +loader=0.11.6 # Mod Properties -mod=1.0.5 +mod=1.1.0 group=net.modfest name=ModFestUtilities # Dependencies -fabric=0.14.1+build.372-1.16 +fabric=0.36.1+1.17 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4b7e1f3..0f80bbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/settings.gradle b/settings.gradle index 5b60df3..f91a4fe 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' diff --git a/src/main/java/net/modfest/utilities/ModFestUtilities.java b/src/main/java/net/modfest/utilities/ModFestUtilities.java index 7b5c6a8..9b48121 100644 --- a/src/main/java/net/modfest/utilities/ModFestUtilities.java +++ b/src/main/java/net/modfest/utilities/ModFestUtilities.java @@ -7,6 +7,7 @@ import net.dv8tion.jda.api.requests.GatewayIntent; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.command.CommandManager; import net.minecraft.text.LiteralText; import net.modfest.utilities.config.Config; @@ -45,6 +46,18 @@ public void onInitialize() { })) ) ); + + ServerLifecycleEvents.SERVER_STARTED.register(server -> { + WebHookUtil.send(WebHookJson.createSystem("The server has started.")); + }); + + ServerLifecycleEvents.SERVER_STARTING.register(server -> { + WebHookUtil.send(WebHookJson.createSystem("The server is starting...")); + }); + ServerLifecycleEvents.SERVER_STOPPING.register(server -> { + ModFestUtilities.shutdown(); + WebHookUtil.send(WebHookJson.createSystem("The server has shutdown.")); + }); } public static void restart() { diff --git a/src/main/java/net/modfest/utilities/config/Config.java b/src/main/java/net/modfest/utilities/config/Config.java index 95533ce..ee351aa 100644 --- a/src/main/java/net/modfest/utilities/config/Config.java +++ b/src/main/java/net/modfest/utilities/config/Config.java @@ -15,7 +15,7 @@ public class Config { private static Config instance; - private final File file = new File(FabricLoader.getInstance().getConfigDirectory(), "modfest.json"); + private final File file = FabricLoader.getInstance().getConfigDir().resolve("modfest.json").toFile(); private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private ConfigData data; diff --git a/src/main/java/net/modfest/utilities/data/WebHookJson.java b/src/main/java/net/modfest/utilities/data/WebHookJson.java index 9efc0df..1775ebe 100644 --- a/src/main/java/net/modfest/utilities/data/WebHookJson.java +++ b/src/main/java/net/modfest/utilities/data/WebHookJson.java @@ -3,7 +3,6 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Formatting; import net.modfest.utilities.config.Config; public class WebHookJson { @@ -24,7 +23,7 @@ public WebHookJson(String content, String username, String avatar) { } public static WebHookJson create(ServerPlayerEntity player, String content) { - return new WebHookJson(content, player.getName().asString(), "https://crafatar.com/avatars/" + player.getUuidAsString() + "?overlay&size=512"); + return new WebHookJson(content, player.getName().asString(), "https://api.nucleoid.xyz/skin/face/256/" + player.getUuidAsString()); } public static WebHookJson createSystem(String content) { diff --git a/src/main/java/net/modfest/utilities/discord/ChannelListener.java b/src/main/java/net/modfest/utilities/discord/ChannelListener.java index f61825c..5cc0cdf 100644 --- a/src/main/java/net/modfest/utilities/discord/ChannelListener.java +++ b/src/main/java/net/modfest/utilities/discord/ChannelListener.java @@ -48,7 +48,7 @@ public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) { } LiteralText text = (LiteralText) new LiteralText("<" + event.getAuthor().getName() + ">") - .setStyle(Style.EMPTY.setHoverEvent( + .setStyle(Style.EMPTY.withHoverEvent( new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText) ).withColor(Formatting.BLUE)).append(new LiteralText(" " + event.getMessage().getContentStripped()).formatted(Formatting.GRAY)); diff --git a/src/main/java/net/modfest/utilities/mixin/MinecraftDedicatedServerMixin.java b/src/main/java/net/modfest/utilities/mixin/MinecraftDedicatedServerMixin.java deleted file mode 100644 index 841a1bb..0000000 --- a/src/main/java/net/modfest/utilities/mixin/MinecraftDedicatedServerMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.modfest.utilities.mixin; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.server.dedicated.MinecraftDedicatedServer; -import net.modfest.utilities.data.WebHookJson; -import net.modfest.utilities.discord.WebHookUtil; -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.CallbackInfoReturnable; - -@Environment(EnvType.SERVER) -@Mixin(MinecraftDedicatedServer.class) -public class MinecraftDedicatedServerMixin { - - @Inject(method = "setupServer()Z", at = @At(value = "INVOKE", target = "Ljava/lang/String;format(Ljava/util/Locale;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", ordinal = 0)) - private void serverReady(CallbackInfoReturnable info) { - WebHookUtil.send(WebHookJson.createSystem("The server has started.")); - } - - @Inject(method = "setupServer()Z", at = @At("HEAD")) - private void setupServer(CallbackInfoReturnable info) { - WebHookUtil.send(WebHookJson.createSystem("The server is starting...")); - } -} diff --git a/src/main/java/net/modfest/utilities/mixin/MinecraftServerMixin.java b/src/main/java/net/modfest/utilities/mixin/MinecraftServerMixin.java deleted file mode 100644 index b4e4bff..0000000 --- a/src/main/java/net/modfest/utilities/mixin/MinecraftServerMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.modfest.utilities.mixin; - -import net.minecraft.server.MinecraftServer; -import net.modfest.utilities.ModFestUtilities; -import net.modfest.utilities.data.WebHookJson; -import net.modfest.utilities.discord.WebHookUtil; -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; - -@Mixin(MinecraftServer.class) -public class MinecraftServerMixin { - - @Inject(method = "shutdown", at = @At("HEAD")) - private void shutdown(CallbackInfo info) { - ModFestUtilities.shutdown(); - WebHookUtil.send(WebHookJson.createSystem("The server has shutdown.")); - } -} diff --git a/src/main/java/net/modfest/utilities/mixin/PlayerManagerMixin.java b/src/main/java/net/modfest/utilities/mixin/PlayerManagerMixin.java index b47edf3..e0a2c89 100644 --- a/src/main/java/net/modfest/utilities/mixin/PlayerManagerMixin.java +++ b/src/main/java/net/modfest/utilities/mixin/PlayerManagerMixin.java @@ -1,5 +1,6 @@ package net.modfest.utilities.mixin; +import net.minecraft.network.ClientConnection; import net.minecraft.network.MessageType; import net.minecraft.network.listener.ServerPlayPacketListener; import net.minecraft.server.MinecraftServer; @@ -20,35 +21,13 @@ @Mixin(PlayerManager.class) public abstract class PlayerManagerMixin implements ServerPlayPacketListener { + @Inject(method = "onPlayerConnect", at = @At("RETURN")) + private void playerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + WebHookUtil.send(WebHookJson.createSystem("**" + player.getDisplayName().getString() + "** joined!")); + } - @Shadow public abstract ServerPlayerEntity getPlayer(UUID uuid); - @Shadow public abstract MinecraftServer getServer(); - - @Shadow @Final private MinecraftServer server; - - @Inject(method = "broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At("HEAD")) - private void broadcastChatMessage(Text message, MessageType type, UUID sender, CallbackInfo info) { - if(this.server.playerManager != null) { - this.server.playerManager = this.getServer().getPlayerManager(); - } - if (Config.getInstance().getWebhook().isEmpty()) return; - if(message instanceof TranslatableText) { - String key = ((TranslatableText) message).getKey(); - - if(key.equals("chat.type.text")) { // chat - String msg = (String) ((TranslatableText) message).getArgs()[1]; - ServerPlayerEntity player = this.server.playerManager.getPlayer(sender); - if(player != null) - WebHookUtil.send(WebHookJson.create(player, msg)); - - } else if (key.equals("multiplayer.player.joined")) { // join - String name = ((Text)((TranslatableText) message).getArgs()[0]).getString(); - WebHookUtil.send(WebHookJson.createSystem("**" + name + "** Joined.")); - - } else if (key.equals("multiplayer.player.left")) { // leave - String name = ((Text)((TranslatableText) message).getArgs()[0]).getString(); - WebHookUtil.send(WebHookJson.createSystem("**" + name + "** Left.")); - } - } + @Inject(method = "remove", at = @At("HEAD")) + private void playerDisconnected(ServerPlayerEntity player, CallbackInfo ci) { + WebHookUtil.send(WebHookJson.createSystem("**" + player.getDisplayName().getString() + "** left!")); } } diff --git a/src/main/java/net/modfest/utilities/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/net/modfest/utilities/mixin/ServerPlayNetworkHandlerMixin.java new file mode 100644 index 0000000..1e96687 --- /dev/null +++ b/src/main/java/net/modfest/utilities/mixin/ServerPlayNetworkHandlerMixin.java @@ -0,0 +1,23 @@ +package net.modfest.utilities.mixin; + +import net.minecraft.server.filter.TextStream; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import net.modfest.utilities.data.WebHookJson; +import net.modfest.utilities.discord.WebHookUtil; +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; + +@Mixin(ServerPlayNetworkHandler.class) +public class ServerPlayNetworkHandlerMixin { + @Shadow public ServerPlayerEntity player; + + @Inject(method = "handleMessage", cancellable = true, at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + private void onChat(TextStream.Message message, CallbackInfo ci) { + WebHookUtil.send(WebHookJson.create(this.player, message.getFiltered())); + } +} diff --git a/src/main/java/net/modfest/utilities/mixin/ServerPlayerEntityMixin.java b/src/main/java/net/modfest/utilities/mixin/ServerPlayerEntityMixin.java index 22a3ee1..b374c8f 100644 --- a/src/main/java/net/modfest/utilities/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/net/modfest/utilities/mixin/ServerPlayerEntityMixin.java @@ -12,20 +12,14 @@ import net.modfest.utilities.config.Config; import net.modfest.utilities.data.WebHookJson; import net.modfest.utilities.discord.WebHookUtil; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(ServerPlayerEntity.class) public class ServerPlayerEntityMixin { - @Inject(method = "onDeath", at = @At("TAIL")) - private void sendDeathMessage(DamageSource source, CallbackInfo info) { + @Inject(method = "onDeath", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V")) + private void hook_deathMessage(DamageSource source, CallbackInfo ci, boolean bl, Text text) { if (!Config.getInstance().shouldMirrorDeath()) return; - if (Config.getInstance().getWebhook().isEmpty()) return; - - Text displayName = ((PlayerEntity) (Object) this).getDisplayName(); - if (source.getAttacker() instanceof PlayerEntity) { - Text attackerDisplayName = ((PlayerEntity) source.getAttacker()).getDisplayName(); - WebHookUtil.send(WebHookJson.createSystem("**" + displayName.getString() + "** Died To **" + attackerDisplayName.getString() + "**.")); - } else { - WebHookUtil.send(WebHookJson.createSystem("**" + displayName.getString() + "** Died.")); - } + WebHookUtil.send(WebHookJson.create((ServerPlayerEntity) (Object) this, text.getString())); } } diff --git a/src/main/resources/modfestutilities.mixins.json b/src/main/resources/modfestutilities.mixins.json index 1394c74..61bda4f 100644 --- a/src/main/resources/modfestutilities.mixins.json +++ b/src/main/resources/modfestutilities.mixins.json @@ -4,13 +4,11 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "CrashReportMixin", - "MinecraftServerMixin", - "PlayerManagerMixin" - ], - "server": [ - "MinecraftDedicatedServerMixin", + "PlayerManagerMixin", + "ServerPlayNetworkHandlerMixin", "ServerPlayerEntityMixin" ], + "server": [], "injectors": { "defaultRequire": 1 }