mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 22:05:11 +00:00
重写完成至玩家死亡
This commit is contained in:
parent
8a13d0a72b
commit
f5fc7ba31e
4 changed files with 38 additions and 4 deletions
|
|
@ -19,7 +19,7 @@ public class MixinPlayerAdvancementTracker {
|
|||
@Shadow
|
||||
private ServerPlayerEntity owner;
|
||||
|
||||
@Inject(method = "grantCriterion", at = @At("RETURN"))
|
||||
@Inject(method = "grantCriterion", at = @At("HEAD"))
|
||||
private void grantCriterion(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (advancement.getDisplay() != null && advancement.getDisplay().shouldAnnounceToChat()) {
|
||||
switch (advancement.getDisplay().getFrame()) {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ import static top.xujiayao.mcdiscordchat.Main.TEXTS;
|
|||
@Mixin(PlayerManager.class)
|
||||
public class MixinPlayerManager {
|
||||
|
||||
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
||||
@Inject(method = "onPlayerConnect", at = @At("HEAD"))
|
||||
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"))
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void remove(ServerPlayerEntity player, CallbackInfo ci) {
|
||||
CHANNEL.sendMessage(TEXTS.leftServer()
|
||||
.replace("%playerName%", MarkdownSanitizer.escape(player.getEntityName()))).queue();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package top.xujiayao.mcdiscordchat.minecraft.mixins;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.dv8tion.jda.api.utils.MarkdownSanitizer;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
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(ServerPlayerEntity.class)
|
||||
public abstract class MixinServerPlayerEntity extends PlayerEntity {
|
||||
|
||||
private MixinServerPlayerEntity(World world, BlockPos pos, float yaw, GameProfile profile) {
|
||||
super(world, pos, yaw, profile);
|
||||
}
|
||||
|
||||
@Inject(method = "onDeath", at = @At("HEAD"))
|
||||
private void onDeath(DamageSource source, CallbackInfo ci) {
|
||||
CHANNEL.sendMessage(TEXTS.deathMessage()
|
||||
.replace("%deathMessage%", MarkdownSanitizer.escape(getDamageTracker().getDeathMessage().getString()))).queue();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"MixinPlayerManager",
|
||||
"MixinPlayerAdvancementTracker"
|
||||
"MixinPlayerAdvancementTracker",
|
||||
"MixinServerPlayerEntity"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue