use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.
the class BankCommand method register.
public void register(CommandDispatcher<ServerCommandSource> dispatcher, ShopExtension extension) {
dispatcher.register(literal("bank").requires(server -> extension.extensionSettings().isEnabled()).then(literal("balance").executes(context -> {
context.getSource().sendFeedback(new LiteralText("Balance: ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(extension.getBalance(context.getSource().getPlayer())))), false);
return 1;
})).then(literal("transfer").then(argument("player", StringArgumentType.string()).suggests((c, b) -> suggestMatching(extension.getPlayers(), b)).then(argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
String playerName = StringArgumentType.getString(context, "player");
String playerUUID = extension.getPlayerUUID(playerName);
int amount = IntegerArgumentType.getInteger(context, "amount");
if (playerUUID == null) {
context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("Este jugador no existe!"), false);
return 1;
}
if (extension.getAccounts().get(context.getSource().getPlayer()).getCoins() < amount) {
context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("No tienes balance suficiente!"), false);
return 1;
}
extension.updateFounds(playerUUID, amount);
extension.updateFounds(context.getSource().getPlayer(), amount * -1);
extension.logTransfer(context.getSource().getPlayer(), playerUUID, playerName, amount);
context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Transferencia de ").append(MarkEnum.OTAKU_COIN.appendMessage(String.format("%d a %s completada!", amount, playerName))), false);
ServerPlayerEntity destPlayer = context.getSource().getServer().getPlayerManager().getPlayer(UUID.fromString(playerUUID));
if (destPlayer != null) {
destPlayer.networkHandler.sendPacket(new OverlayMessageS2CPacket(new LiteralText(context.getSource().getPlayer().getName().getString() + " te ha transferido ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(amount)))));
}
return 1;
})))));
}
use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.
the class DiscordExtension method settingsCommand.
@Override
public void settingsCommand(LiteralArgumentBuilder<ServerCommandSource> builder) {
builder.then(literal("setBot").then(argument("token", StringArgumentType.string()).then(argument("chatChannelID", LongArgumentType.longArg()).executes(context -> {
if (DiscordListener.chatbridge) {
context.getSource().sendFeedback(new LiteralText("Stop the bot before you make any changes..."), false);
} else {
extensionSettings().setToken(StringArgumentType.getString(context, "token"));
extensionSettings().setChatChannelID(LongArgumentType.getLong(context, "chatChannelID"));
context.getSource().sendFeedback(new LiteralText("Done!"), false);
ExtensionManager.saveSettings();
}
return 1;
})))).then(literal("stop").executes(context -> {
if (DiscordListener.chatbridge) {
DiscordListener.stop();
this.extensionSettings().setRunning(false);
context.getSource().sendFeedback(new LiteralText("Bot stopped!"), false);
ExtensionManager.saveSettings();
} else {
context.getSource().sendFeedback(new LiteralText("Bot already stopped."), false);
}
return 1;
})).then(literal("start").executes(context -> {
if (!DiscordListener.chatbridge) {
DiscordListener.start(KahzerxServer.minecraftServer, extensionSettings().getToken(), String.valueOf(extensionSettings().getChatChannelID()), this);
if (DiscordListener.chatbridge) {
context.getSource().sendFeedback(new LiteralText("Started!"), false);
} else {
context.getSource().sendFeedback(new LiteralText("Failed to start."), false);
}
ExtensionManager.saveSettings();
} else {
context.getSource().sendFeedback(new LiteralText("But is already running."), false);
}
return 1;
})).then(literal("shouldFeedback").then(argument("feedback", BoolArgumentType.bool()).executes(context -> {
extensionSettings().setShouldFeedback(BoolArgumentType.getBool(context, "feedback"));
context.getSource().sendFeedback(new LiteralText("[shouldFeedback] > " + extensionSettings().isShouldFeedback() + "."), false);
ExtensionManager.saveSettings();
return 1;
})).executes(context -> {
context.getSource().sendFeedback(new LiteralText("[shouldFeedback] > " + extensionSettings().isShouldFeedback() + "."), false);
return 1;
})).then(literal("chatBridgePrefix").then(argument("prefix", StringArgumentType.string()).executes(context -> {
extensionSettings().setPrefix(StringArgumentType.getString(context, "prefix"));
context.getSource().sendFeedback(new LiteralText("[Prefix] > " + extensionSettings().getPrefix() + "."), false);
ExtensionManager.saveSettings();
return 1;
})).executes(context -> {
String help = "Server prefix.";
context.getSource().sendFeedback(new LiteralText(help), false);
String prefix = extensionSettings().getPrefix();
context.getSource().sendFeedback(new LiteralText(prefix.equals("") ? "There is no prefix." : "[Prefix] > " + extensionSettings().getPrefix() + "."), false);
return 1;
})).then(literal("crossServerChat").then(argument("enabled", BoolArgumentType.bool()).executes(context -> {
extensionSettings().setCrossServerChat(BoolArgumentType.getBool(context, "enabled"));
context.getSource().sendFeedback(new LiteralText("[CrossServerChat] > " + extensionSettings().isCrossServerChat() + "."), false);
ExtensionManager.saveSettings();
return 1;
})).executes(context -> {
String help = "Same bot(same token) on same chatID and different prefix on many servers will connect their chats.";
context.getSource().sendFeedback(new LiteralText(help), false);
context.getSource().sendFeedback(new LiteralText("[CrossServerChat] > " + extensionSettings().isCrossServerChat() + "."), false);
return 1;
})).then(literal("allowedChats").then(literal("add").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
if (extensionSettings().getAllowedChats().contains(LongArgumentType.getLong(context, "chatID"))) {
context.getSource().sendFeedback(new LiteralText("ID already added."), false);
} else {
extensionSettings().addAllowedChatID(LongArgumentType.getLong(context, "chatID"));
context.getSource().sendFeedback(new LiteralText("ID added."), false);
ExtensionManager.saveSettings();
}
return 1;
}))).then(literal("remove").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
if (extensionSettings().getAllowedChats().contains(LongArgumentType.getLong(context, "chatID"))) {
extensionSettings().removeAllowedChatID(LongArgumentType.getLong(context, "chatID"));
context.getSource().sendFeedback(new LiteralText("ID removed."), false);
ExtensionManager.saveSettings();
} else {
context.getSource().sendFeedback(new LiteralText("This ID doesn't exist."), false);
}
return 1;
}))).then(literal("list").executes(context -> {
context.getSource().sendFeedback(new LiteralText(extensionSettings().getAllowedChats().toString()), false);
return 1;
})).executes(context -> {
String help = "ChatIDs where !online work.";
context.getSource().sendFeedback(new LiteralText(help), false);
return 1;
}));
}
use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.
the class HomeExtension method tpHome.
public int tpHome(ServerCommandSource src) throws CommandSyntaxException {
ServerPlayerEntity player = src.getPlayer();
if (player == null) {
return 1;
}
String playerUUID = player.getUuidAsString();
HomePos homePos = playerHomes.get(playerUUID);
if (homePos.isValid()) {
player.teleport(DimUtils.getWorld(homePos.getDim(), player), homePos.getX(), homePos.getY(), homePos.getZ(), player.getYaw(), player.getPitch());
// xp resets when you tp from other dimension and needs to update smh, mojang pls.
player.addExperience(0);
} else {
player.sendMessage(MarkEnum.INFO.appendText(new LiteralText("You don't have a home yet, use ").styled(style -> style.withColor(Formatting.WHITE)).append(getClickableSetHomeCommand())), false);
}
return 1;
}
use of net.minecraft.server.command.ServerCommandSource in project Geyser-Fabric by GeyserMC.
the class GeyserFabricMod method startGeyser.
/**
* Initialize core Geyser.
* A function, as it needs to be called in different places depending on if Geyser is being reloaded or not.
*
* @param server The minecraft server.
*/
public void startGeyser(MinecraftServer server) {
this.server = server;
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true);
String ip = server.getServerIp();
int port = ((GeyserServerPortGetter) server).geyser$getServerPort();
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
this.geyserConfig.getRemote().setAddress(ip);
}
this.geyserConfig.getRemote().setPort(port);
}
if (geyserConfig.getBedrock().isCloneRemotePort()) {
geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort());
}
Optional<ModContainer> floodgate = FabricLoader.getInstance().getModContainer("floodgate");
boolean floodgatePresent = floodgate.isPresent();
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && !floodgatePresent) {
geyserLogger.severe(GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + GeyserLocale.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
return;
} else if (geyserConfig.isAutoconfiguredRemote() && floodgatePresent) {
// Floodgate installed means that the user wants Floodgate authentication
geyserLogger.debug("Auto-setting to Floodgate authentication.");
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
}
geyserConfig.loadFloodgate(this, floodgate.orElse(null));
this.connector = GeyserImpl.start(PlatformType.FABRIC, this);
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
this.geyserCommandManager = new GeyserFabricCommandManager(connector);
this.geyserWorldManager = new GeyserFabricWorldManager(server);
// Start command building
// Set just "geyser" as the help command
GeyserFabricCommandExecutor helpExecutor = new GeyserFabricCommandExecutor(connector, connector.getCommandManager().getCommands().get("help"), !playerCommands.contains("help"));
commandExecutors.add(helpExecutor);
LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser").executes(helpExecutor);
// Register all subcommands as valid
for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) {
GeyserFabricCommandExecutor executor = new GeyserFabricCommandExecutor(connector, command.getValue(), !playerCommands.contains(command.getKey()));
commandExecutors.add(executor);
builder.then(net.minecraft.server.command.CommandManager.literal(command.getKey()).executes(executor));
}
server.getCommandManager().getDispatcher().register(builder);
}
use of net.minecraft.server.command.ServerCommandSource in project ImmersivePortalsMod by qouteall.
the class MyCommandServer method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("portal").requires(commandSource -> commandSource.hasPermissionLevel(2));
builder.then(CommandManager.literal("border_set").then(CommandManager.argument("x1", IntegerArgumentType.integer()).then(CommandManager.argument("y1", IntegerArgumentType.integer()).then(CommandManager.argument("x2", IntegerArgumentType.integer()).then(CommandManager.argument("y2", IntegerArgumentType.integer()).executes(context -> {
BorderPortal.setBorderPortal(context.getSource().getWorld(), IntegerArgumentType.getInteger(context, "x1"), IntegerArgumentType.getInteger(context, "y1"), IntegerArgumentType.getInteger(context, "x2"), IntegerArgumentType.getInteger(context, "y2"));
return 0;
}))))));
builder.then(CommandManager.literal("border_remove").executes(context -> {
BorderPortal.removeBorderPortal(context.getSource().getWorld());
return 0;
}));
builder.then(CommandManager.literal("view_portal_data").executes(context -> {
return processPortalTargetedCommand(context, (portal) -> {
sendPortalInfo(context, portal);
});
}));
builder.then(CommandManager.literal("set_portal_custom_name").then(CommandManager.argument("name", TextArgumentType.text()).executes(context -> {
return processPortalTargetedCommand(context, portal -> {
Text name = TextArgumentType.getTextArgument(context, "name");
portal.setCustomName(name);
});
})));
builder.then(CommandManager.literal("delete_portal").executes(context -> processPortalTargetedCommand(context, portal -> {
sendMessage(context, "deleted " + portal);
portal.remove();
})));
builder.then(CommandManager.literal("set_portal_nbt").then(CommandManager.argument("nbt", NbtCompoundTagArgumentType.nbtCompound()).executes(context -> processPortalTargetedCommand(context, portal -> {
CompoundTag newNbt = NbtCompoundTagArgumentType.getCompoundTag(context, "nbt");
CompoundTag portalNbt = portal.toTag(new CompoundTag());
newNbt.getKeys().forEach(key -> portalNbt.put(key, newNbt.getTag(key)));
// portalNbt.copyFrom(newNbt);
UUID uuid = portal.getUuid();
portal.fromTag(portalNbt);
portal.setUuid(uuid);
reloadPortal(portal);
sendPortalInfo(context, portal);
}))));
builder.then(CommandManager.literal("set_portal_destination").then(CommandManager.argument("dim", DimensionArgumentType.dimension()).then(CommandManager.argument("dest", Vec3ArgumentType.vec3()).executes(context -> processPortalTargetedCommand(context, portal -> {
try {
portal.dimensionTo = DimensionArgumentType.getDimensionArgument(context, "dim");
portal.destination = Vec3ArgumentType.getVec3(context, "dest");
reloadPortal(portal);
sendMessage(context, portal.toString());
} catch (CommandSyntaxException ignored) {
ignored.printStackTrace();
}
})))));
builder.then(CommandManager.literal("tpme").then(CommandManager.argument("dim", DimensionArgumentType.dimension()).then(CommandManager.argument("dest", Vec3ArgumentType.vec3()).executes(context -> {
DimensionType dimension = DimensionArgumentType.getDimensionArgument(context, "dim");
Vec3d pos = Vec3ArgumentType.getVec3(context, "dest");
ServerPlayerEntity player = context.getSource().getPlayer();
SGlobal.serverTeleportationManager.invokeTpmeCommand(player, dimension, pos);
return 0;
}))));
builder.then(CommandManager.literal("complete_bi_way_portal").executes(context -> processPortalTargetedCommand(context, portal -> {
Portal result = completeBiWayPortal(portal, p -> sendMessage(context, "Removed " + p));
sendMessage(context, "Added " + result);
})));
builder.then(CommandManager.literal("complete_bi_faced_portal").executes(context -> processPortalTargetedCommand(context, portal -> {
Portal result = completeBiFacedPortal(portal, p -> sendMessage(context, "Removed " + p));
sendMessage(context, "Added " + result);
})));
builder.then(CommandManager.literal("complete_bi_way_bi_faced_portal").executes(context -> processPortalTargetedCommand(context, portal -> completeBiWayBiFacedPortal(portal, p -> sendMessage(context, "Removed " + p), p -> sendMessage(context, "Added " + p)))));
builder.then(CommandManager.literal("remove_connected_portals").executes(context -> processPortalTargetedCommand(context, portal -> {
Consumer<Portal> removalInformer = p -> sendMessage(context, "Removed " + p);
removeOverlappedPortals(portal.world, portal.getPos(), portal.getNormal().multiply(-1), removalInformer);
ServerWorld toWorld = McHelper.getServer().getWorld(portal.dimensionTo);
removeOverlappedPortals(toWorld, portal.destination, portal.getNormal().multiply(-1), removalInformer);
removeOverlappedPortals(toWorld, portal.destination, portal.getNormal(), removalInformer);
})));
builder.then(CommandManager.literal("connect_floor").then(CommandManager.argument("from", DimensionArgumentType.dimension()).then(CommandManager.argument("to", DimensionArgumentType.dimension()).executes(context -> {
DimensionType from = DimensionArgumentType.getDimensionArgument(context, "from");
DimensionType to = DimensionArgumentType.getDimensionArgument(context, "to");
VerticalConnectingPortal.connect(from, VerticalConnectingPortal.ConnectorType.floor, to);
return 0;
}))));
builder.then(CommandManager.literal("connect_ceil").then(CommandManager.argument("from", DimensionArgumentType.dimension()).then(CommandManager.argument("to", DimensionArgumentType.dimension()).executes(context -> {
DimensionType from = DimensionArgumentType.getDimensionArgument(context, "from");
DimensionType to = DimensionArgumentType.getDimensionArgument(context, "to");
VerticalConnectingPortal.connect(from, VerticalConnectingPortal.ConnectorType.ceil, to);
return 0;
}))));
builder.then(CommandManager.literal("connection_floor_remove").then(CommandManager.argument("dim", DimensionArgumentType.dimension()).executes(context -> {
DimensionType dim = DimensionArgumentType.getDimensionArgument(context, "dim");
VerticalConnectingPortal.removeConnectingPortal(VerticalConnectingPortal.ConnectorType.floor, dim);
return 0;
})));
builder.then(CommandManager.literal("connection_ceil_remove").then(CommandManager.argument("dim", DimensionArgumentType.dimension()).executes(context -> {
DimensionType dim = DimensionArgumentType.getDimensionArgument(context, "dim");
VerticalConnectingPortal.removeConnectingPortal(VerticalConnectingPortal.ConnectorType.ceil, dim);
return 0;
})));
dispatcher.register(builder);
}
Aggregations