Skip to content

Commit

Permalink
Merge pull request #4 from Tom-The-Geek/update/1.17
Browse files Browse the repository at this point in the history
Update to 1.17
  • Loading branch information
Meredith Espinosa authored Jul 12, 2021
2 parents 33e5d02 + 6542c40 commit 585b6b1
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 124 deletions.
41 changes: 20 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,8 +16,8 @@ minecraft {

repositories {
maven {
url = "http://maven.fabricmc.net/"
name = "Fabric"
name = "dv8tion"
url = "https://m2.dv8tion.net/releases/"
}
}

Expand All @@ -28,50 +28,49 @@ 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")
include("com.fasterxml.jackson.core:jackson-annotations:2.10.1")
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
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Empty file modified gradlew
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/modfest/utilities/ModFestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/modfest/utilities/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/modfest/utilities/data/WebHookJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

This file was deleted.

This file was deleted.

37 changes: 8 additions & 29 deletions src/main/java/net/modfest/utilities/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!"));
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
8 changes: 3 additions & 5 deletions src/main/resources/modfestutilities.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"CrashReportMixin",
"MinecraftServerMixin",
"PlayerManagerMixin"
],
"server": [
"MinecraftDedicatedServerMixin",
"PlayerManagerMixin",
"ServerPlayNetworkHandlerMixin",
"ServerPlayerEntityMixin"
],
"server": [],
"injectors": {
"defaultRequire": 1
}
Expand Down

0 comments on commit 585b6b1

Please sign in to comment.