重写完成至玩家加入离开服务器

This commit is contained in:
Xujiayao 2022-03-21 21:07:43 +08:00
parent d2858dd14b
commit 7337d13cd0
5 changed files with 36 additions and 26 deletions

View file

@ -76,7 +76,5 @@ public class Main implements DedicatedServerModInitializer {
JDA.shutdown();
});
//MinecraftEventListener.init();
}
}

View file

@ -1,22 +0,0 @@
package top.xujiayao.mcdiscordchat.minecraft.mixins;
import net.minecraft.client.gui.screen.TitleScreen;
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 static top.xujiayao.mcdiscordchat.Main.LOGGER;
/**
* @author Xujiayao
*/
@Mixin({TitleScreen.class})
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
LOGGER.info("This line is printed by an example mod mixin!");
}
}

View file

@ -0,0 +1,31 @@
package top.xujiayao.mcdiscordchat.minecraft.mixins;
import net.dv8tion.jda.api.utils.MarkdownSanitizer;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
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 static top.xujiayao.mcdiscordchat.Main.CHANNEL;
import static top.xujiayao.mcdiscordchat.Main.TEXTS;
/**
* @author Xujiayao
*/
@Mixin(PlayerManager.class)
public class MixinPlayerManager {
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
CHANNEL.sendMessage(TEXTS.joinServer().replace("%playerName%", MarkdownSanitizer.escape(player.getEntityName()))).queue();
}
@Inject(method = "remove", at = @At("RETURN"))
private void remove(ServerPlayerEntity player, CallbackInfo ci) {
CHANNEL.sendMessage(TEXTS.leftServer().replace("%playerName%", MarkdownSanitizer.escape(player.getEntityName()))).queue();
}
}

View file

@ -20,6 +20,9 @@
"top.xujiayao.mcdiscordchat.Main"
]
},
"mixins": [
"mcdiscordchat.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3",
"fabric": "*",

View file

@ -1,9 +1,9 @@
{
"required": true,
"package": "top.xujiayao.mcdiscordchat.mixins",
"package": "top.xujiayao.mcdiscordchat.minecraft.mixins",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ExampleMixin"
"MixinPlayerManager"
],
"injectors": {
"defaultRequire": 1