Skip to content

Commit

Permalink
Add SharePosCommand.java
Browse files Browse the repository at this point in the history
  • Loading branch information
alikindsys committed Dec 30, 2023
1 parent 34d1828 commit 2199f36
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/blocovermelho/bvextension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,7 @@ public void onInitialize() {
@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
GamemodeSwitchCommand.register(dispatcher);
SharePosCommand.register(dispatcher);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServerCommandSource> 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;
}));
}
}

0 comments on commit 2199f36

Please sign in to comment.