From 2199f36d74e00838309460638a020b7aa04832e5 Mon Sep 17 00:00:00 2001 From: Alice Isabel Date: Sat, 30 Dec 2023 17:00:00 -0300 Subject: [PATCH] Add SharePosCommand.java --- .../blocovermelho/bvextension/Extension.java | 2 ++ .../bvextension/commands/SharePosCommand.java | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/org/blocovermelho/bvextension/commands/SharePosCommand.java diff --git a/src/main/java/org/blocovermelho/bvextension/Extension.java b/src/main/java/org/blocovermelho/bvextension/Extension.java index 96f0308..c0e811a 100644 --- a/src/main/java/org/blocovermelho/bvextension/Extension.java +++ b/src/main/java/org/blocovermelho/bvextension/Extension.java @@ -15,6 +15,7 @@ import net.minecraft.server.command.ServerCommandSource; import org.apache.commons.io.IOUtils; import org.blocovermelho.bvextension.commands.GamemodeSwitchCommand; +import org.blocovermelho.bvextension.commands.SharePosCommand; import org.blocovermelho.bvextension.events.RestorePositionLogoff; import java.io.IOException; @@ -54,6 +55,7 @@ public void onInitialize() { @Override public void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess commandBuildContext) { GamemodeSwitchCommand.register(dispatcher); + SharePosCommand.register(dispatcher); } @Override diff --git a/src/main/java/org/blocovermelho/bvextension/commands/SharePosCommand.java b/src/main/java/org/blocovermelho/bvextension/commands/SharePosCommand.java new file mode 100644 index 0000000..4215f54 --- /dev/null +++ b/src/main/java/org/blocovermelho/bvextension/commands/SharePosCommand.java @@ -0,0 +1,36 @@ +package org.blocovermelho.bvextension.commands; + +import com.mojang.brigadier.CommandDispatcher; +import net.minecraft.server.command.ServerCommandSource; +import org.blocovermelho.bvextension.Extension; +import org.blocovermelho.bvextension.utils.Waypoint; + +import java.util.Objects; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class SharePosCommand { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(literal("pos") + .requires(ServerCommandSource::isExecutedByPlayer) + .then(argument("nome", string()) + .executes(s -> { + var player = Objects.requireNonNull(s.getSource().getPlayer()); + var name = getString(s, "nome"); + + var text = Waypoint.intoChatMessage(player, name); + Extension.audiences.players().sendMessage(text); + return 1; + }) + + ).executes(s -> { + var player = Objects.requireNonNull(s.getSource().getPlayer()); + var text = Waypoint.intoChatMessage(player, null); + Extension.audiences.players().sendMessage(text); + return 1; + })); + } +}