Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.20.4 #65

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.github.quiltservertools.blockbotapi;

import io.github.quiltservertools.blockbotapi.event.ChatMessageEvent;
import io.github.quiltservertools.blockbotapi.event.PlayerAdvancementGrantEvent;
import io.github.quiltservertools.blockbotapi.event.PlayerDeathEvent;
import io.github.quiltservertools.blockbotapi.event.*;
import io.github.quiltservertools.blockbotapi.sender.MessageSender;
import io.github.quiltservertools.blockbotapi.sender.PlayerMessageSender;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -38,8 +35,8 @@ public static void registerBot(Bot bot) {
BlockBotApi.bots.add(bot);

ChatMessageEvent.EVENT.register(bot::onChatMessage);
ServerPlayConnectionEvents.JOIN.register(bot::onPlayerConnect);
ServerPlayConnectionEvents.DISCONNECT.register(bot::onPlayerDisconnect);
PlayerJoinMessageEvent.EVENT.register(bot::onPlayerJoinMessage);
PlayerLeaveMessageEvent.EVENT.register(bot::onPlayerLeaveMessage);
PlayerDeathEvent.EVENT.register(bot::onPlayerDeath);
PlayerAdvancementGrantEvent.EVENT.register(bot::onAdvancementGrant);
ServerLifecycleEvents.SERVER_STARTED.register(bot::onServerStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public interface Bot {
void onChatMessage(MessageSender sender, Text message);
void onPlayerConnect(ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server);
void onPlayerDisconnect(ServerPlayNetworkHandler handler, MinecraftServer server);
void onPlayerJoinMessage(ServerPlayerEntity player);
void onPlayerLeaveMessage(ServerPlayerEntity player);
void onPlayerDeath(ServerPlayerEntity player, Text message);
void onAdvancementGrant(ServerPlayerEntity player, Advancement advancement);
void onServerStart(MinecraftServer server);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.quiltservertools.blockbotapi.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;

public interface PlayerJoinMessageEvent {
Event<PlayerJoinMessageEvent> EVENT = EventFactory.createArrayBacked(PlayerJoinMessageEvent.class, (listeners) -> (player) -> {
for (PlayerJoinMessageEvent listener : listeners) {
listener.onPlayerJoinMessage(player);
}
});

void onPlayerJoinMessage(ServerPlayerEntity player);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.quiltservertools.blockbotapi.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;

public interface PlayerLeaveMessageEvent {
Event<PlayerLeaveMessageEvent> EVENT = EventFactory.createArrayBacked(PlayerLeaveMessageEvent.class, (listeners) -> (player) -> {
for (PlayerLeaveMessageEvent listener : listeners) {
listener.onPlayerLeaveMessage(player);
}
});

void onPlayerLeaveMessage(ServerPlayerEntity player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import com.mojang.brigadier.context.CommandContext;
import io.github.quiltservertools.blockbotapi.event.ChatMessageEvent;
import io.github.quiltservertools.blockbotapi.sender.MessageSender;
import io.github.quiltservertools.blockbotapi.sender.PlayerMessageSender;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.MeCommand;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -22,21 +18,7 @@ public abstract class MeCommandMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/command/ServerCommandSource;Lnet/minecraft/network/message/MessageType$Parameters;)V")
)
private static void relayPlayerMeToDiscord(CommandContext<ServerCommandSource> ctx, SignedMessage message, CallbackInfo ci) {
var entity = ctx.getSource().getEntity();
MessageSender sender;
if (entity instanceof ServerPlayerEntity player) {
sender = new PlayerMessageSender(
player,
MessageSender.MessageType.EMOTE
);
} else {
sender = new MessageSender(
Text.literal(ctx.getSource().getName()),
ctx.getSource().getDisplayName(),
MessageSender.MessageType.EMOTE
);
}

MessageSender sender = MessageSender.of(ctx.getSource(), MessageSender.MessageType.EMOTE);
ChatMessageEvent.EVENT.invoker().message(
sender,
message.getContent()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.quiltservertools.blockbotapi.mixin;

import io.github.quiltservertools.blockbotapi.event.PlayerJoinMessageEvent;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
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;

@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin {
@Inject(
method = "onPlayerConnect",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"
)
)
private void relayJoinMessageToDiscord(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
PlayerJoinMessageEvent.EVENT.invoker().onPlayerJoinMessage(player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.quiltservertools.blockbotapi.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import io.github.quiltservertools.blockbotapi.event.ChatMessageEvent;
import io.github.quiltservertools.blockbotapi.sender.MessageSender;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.RandomCommand;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(RandomCommand.class)
public abstract class RandomCommandMixin {

@WrapOperation(
method = "execute",
at = @At(
value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"
)
)
private static void relayRandomRollToDiscord(PlayerManager instance, Text message, boolean overlay, Operation<Void> original, ServerCommandSource source) {
original.call(instance, message, overlay);
MessageSender sender = MessageSender.of(source, MessageSender.MessageType.ANNOUNCEMENT);
ChatMessageEvent.EVENT.invoker().message(
sender,
// Change translation to literal
Text.literal(message.getString())
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import com.mojang.brigadier.context.CommandContext;
import io.github.quiltservertools.blockbotapi.event.ChatMessageEvent;
import io.github.quiltservertools.blockbotapi.sender.MessageSender;
import io.github.quiltservertools.blockbotapi.sender.PlayerMessageSender;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.SayCommand;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -22,21 +18,7 @@ public abstract class SayCommandMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/command/ServerCommandSource;Lnet/minecraft/network/message/MessageType$Parameters;)V")
)
private static void relayPlayerSayToDiscord(CommandContext<ServerCommandSource> ctx, SignedMessage message, CallbackInfo ci) {
var entity = ctx.getSource().getEntity();
MessageSender sender;
if (entity instanceof ServerPlayerEntity player) {
sender = new PlayerMessageSender(
player,
MessageSender.MessageType.ANNOUNCEMENT
);
} else {
sender = new MessageSender(
Text.literal(ctx.getSource().getName()),
ctx.getSource().getDisplayName(),
MessageSender.MessageType.ANNOUNCEMENT
);
}

MessageSender sender = MessageSender.of(ctx.getSource(), MessageSender.MessageType.ANNOUNCEMENT);
ChatMessageEvent.EVENT.invoker().message(
sender,
message.getContent()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.quiltservertools.blockbotapi.mixin;

import io.github.quiltservertools.blockbotapi.event.PlayerLeaveMessageEvent;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
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 abstract class ServerPlayNetworkHandlerMixin {
@Shadow
public ServerPlayerEntity player;

@Inject(
method = "cleanUp",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"
)
)
private void relayLeaveMessageToDiscord(CallbackInfo ci) {
PlayerLeaveMessageEvent.EVENT.invoker().onPlayerLeaveMessage(this.player);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.github.quiltservertools.blockbotapi.mixin;

import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.ParsedCommandNode;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.github.quiltservertools.blockbotapi.event.ChatMessageEvent;
import io.github.quiltservertools.blockbotapi.sender.MessageSender;
import io.github.quiltservertools.blockbotapi.sender.PlayerMessageSender;
import net.minecraft.command.EntitySelector;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.TextArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.command.TellRawCommand;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.Texts;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -24,24 +20,14 @@ public abstract class TellRawCommandMixin {
method = "method_13777",
at = @At(value = "HEAD")
)
private static void relayMeToDiscord(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir) throws CommandSyntaxException {
// Check if tellraw is sent to every online player
if (context.getArgument("targets", EntitySelector.class).getLimit() > 1 && EntityArgumentType.getPlayers(context, "targets").size() == context.getSource().getPlayerNames().size()) {
private static void relayTellrawToDiscord(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir) throws CommandSyntaxException {
// We are checking for "@a" to make sure only messages intended for the public are relayed.
// Messages with a selector like @a[distance=..100] should not be relayed.
String input = context.getInput();
ParsedCommandNode<ServerCommandSource> parsedCommandNode = context.getNodes().get(context.getNodes().size() - 2);
if (parsedCommandNode.getRange().get(input).equals("@a")) {
var entity = context.getSource().getEntity();
MessageSender sender;
if (entity instanceof ServerPlayerEntity player) {
sender = new PlayerMessageSender(
player,
MessageSender.MessageType.REGULAR
);
} else {
sender = new MessageSender(
Text.literal(context.getSource().getName()),
context.getSource().getDisplayName(),
MessageSender.MessageType.REGULAR
);
}

MessageSender sender = MessageSender.of(context.getSource(), MessageSender.MessageType.EMOTE);
ChatMessageEvent.EVENT.invoker().message(
sender,
Texts.parse(context.getSource(), TextArgumentType.getTextArgument(context, "message"), entity, 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.quiltservertools.blockbotapi.sender;

import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

Expand All @@ -14,6 +16,24 @@ public MessageSender(Text name, Text displayName, @NotNull MessageType type) {
this.type = type;
}

public static MessageSender of(ServerCommandSource commandSource, MessageType type) {
var entity = commandSource.getEntity();
MessageSender sender;
if (entity instanceof ServerPlayerEntity player) {
sender = new PlayerMessageSender(
player,
type
);
} else {
sender = new MessageSender(
Text.literal(commandSource.getName()),
commandSource.getDisplayName(),
type
);
}
return sender;
}

public Text getName() {
return name;
}
Expand Down
3 changes: 3 additions & 0 deletions blockbot-api/src/main/resources/blockbot-api.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"MeCommandMixin",
"MixinPlayerAdvancementTracker",
"MixinServerPlayerEntity",
"PlayerManagerMixin",
"RandomCommandMixin",
"SayCommandMixin",
"ServerPlayNetworkHandlerMixin",
"TellRawCommandMixin"
],
"server": [],
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("maven-publish")
id("fabric-loom") version "1.2.+"
id("fabric-loom") version "1.6.+"
kotlin("jvm") version "1.7.10"
id("com.github.johnrengelman.shadow") version "7.1.2"
kotlin("plugin.serialization") version "1.7.10"
Expand Down Expand Up @@ -38,6 +38,8 @@ allprojects {
}
maven("https://api.modrinth.com/maven")
maven("https://oss.sonatype.org/content/repositories/snapshots")
// net.kyori:adventure-text-serializer-gson dev builds
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

// Declare dependencies
Expand Down
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-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 8 additions & 8 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
minecraft = "1.20.2"
fabric-loader = "0.14.23"
yarn-mappings = "1.20.2+build.1"
minecraft = "1.20.4"
fabric-loader = "0.15.10"
yarn-mappings = "1.20.4+build.3"

fabric-api = "0.90.0+1.20.2"
fabric-api = "0.97.0+1.20.4"

# Kotlin
fabric-kotlin = "1.9.4+kotlin.1.8.21"
Expand All @@ -12,11 +12,11 @@ fabric-kotlin = "1.9.4+kotlin.1.8.21"
kord-extensions = "1.5.6"
mc-discord-reserializer = "4.3.0"
emoji-java = "5.1.1"
adventure-gson = "4.11.0"
adventure-gson = "4.15.0-SNAPSHOT"

placeholder-api = "2.2.0+1.20.2"
permission-api = "0.3-SNAPSHOT"
vanish-api = "1.4.3+1.20.2"
placeholder-api = "2.3.0+1.20.3"
permission-api = "0.3.1"
vanish-api = "1.5.0+1.20.3-rc1"
konf = "1.1.2"

[libraries]
Expand Down
Loading
Loading