Update broadcast message
This commit is contained in:
parent
65bc83ed60
commit
a8a29aaefe
@ -4,12 +4,16 @@ import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
@ -18,14 +22,13 @@ public class SaveCoordinates implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
dispatcher.register(
|
||||
literal("sc")
|
||||
.then(CommandManager.argument("desc", StringArgumentType.string())
|
||||
.executes(context -> printCoordinates(context, getDescription(context)))));
|
||||
dispatcher.register(literal("sc").then(CommandManager.argument("desc", StringArgumentType.string())
|
||||
.executes(SaveCoordinates::printCoordinates)));
|
||||
});
|
||||
}
|
||||
|
||||
private static String getDimensionTypeString(ServerCommandSource source) {
|
||||
// Does not work with modded dimensions
|
||||
|
||||
DimensionType dimensionType = source.getEntity().world.getDimension();
|
||||
|
||||
@ -44,15 +47,19 @@ public class SaveCoordinates implements ModInitializer {
|
||||
return StringArgumentType.getString(context, "desc");
|
||||
}
|
||||
|
||||
private static int printCoordinates(CommandContext<ServerCommandSource> context, String description) {
|
||||
private static int printCoordinates(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerCommandSource source = context.getSource();
|
||||
String dimensionTypeString = getDimensionTypeString(source);
|
||||
String description = getDescription(context);
|
||||
Vec3d pos = source.getEntity().getPos();
|
||||
long x = Math.round(pos.x);
|
||||
long y = Math.round(pos.y);
|
||||
long z = Math.round(pos.z);
|
||||
Text text = new LiteralText( "<Coordinates> " +
|
||||
description + " at " + dimensionTypeString + " [ " + x + " , " + y + " , " + z + " ]");
|
||||
PlayerManager playerManager = source.getMinecraftServer().getPlayerManager();
|
||||
|
||||
source.sendFeedback(new LiteralText(description + " at " + dimensionTypeString + " [ " + x + " , " + y + " , " + z + " ]"), false);
|
||||
playerManager.broadcastChatMessage(text, MessageType.CHAT,source.getPlayer().getUuid());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user