#/hub command

1 messages · Page 1 of 1 (latest)

vague ruin
#

Can anyone make a BP Script that when you type /hub in chat you tp tp 0 23 -4 ?

forest elbow
#

dude

vague ruin
#

why does this not work?

#

import { CommandPermissionLevel, CustomCommandStatus, system, world, CustomCommandOrigin } from "@minecraft/server";

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerCommand(
{
name: "hub",
description: "Teleports you to the hub (0,23,-4)",
permissionLevel: CommandPermissionLevel.Any,
cheatsRequired: true
},
(origin: CustomCommandOrigin) => {
if (!origin.sourceEntity) {
return { status: CustomCommandStatus.Failure };
}

        const player = origin.sourceEntity;

        try {
            system.run(() => {
                player.teleport(
                    { x: 0, y: 23, z: -4 },
                    { dimension: world.getDimension(player.dimension) }
                );
                player.sendMessage("§aTeleported to the hub!");
            });
        } catch (e) {
            console.error("[HubPack] Teleport failed:", e);
            return { status: CustomCommandStatus.Failure };
        }

        return { status: CustomCommandStatus.Success };
    }
);

console.warn("[HubPack] Registered /hub command (cheats required)");

});

vague ruin
forest elbow
#

the problem was world.getDimension(player.dimension), that function only accepts strings

vivid void
#

i use this ```javascript
import { world, system, CommandPermissionLevel } from "@minecraft/server";

const qtp_coords = {
hub: [0, 200, 0],
playzome: [10, 200, 10],
market: [20, 200, 20],
};

function qtp(player, location) {
let coords = qtp_coords[location.toLowerCase()];
if (!coords) { player.sendMessage(Failed to Tp to ${location}); return; }
let [x, y, z] = coords;
player.teleport({ x, y, z });
player.sendMessage(Teleported to ${location});
}

const commands = {
hub: {
name: "axil:hub",
description: "Tp to Hub",
permissionLevel: CommandPermissionLevel.Any,
optionalParameters: []
}
}

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerCommand(commands.hub,
(origin) => {
var player = origin.sourceEntity;
try {
if (!player) return;
system.run(() => {
qtp(player, "hub");
});
} catch (err) {
console.error([Axil COM] ${err});
}
}
);
});

tight matrix
graceful verge
tight matrix
tight matrix
#

Is the error

#

About world.getDimension(player.dimension), you can just type player.dimension since you only need to return the dimension function, and using player.dimension automatically says what dimension does the player currently in

vague ruin
#

will this work?

#

import {
system,
world,
CommandPermissionLevel,
CustomCommandStatus
} from "@minecraft/server";

// Hub location
const HUB_COORDS = { x: 0, y: 200, z: 0 };

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
const hubCommand = {
name: "server:hub",
description: "Teleport to the Hub",
permissionLevel: CommandPermissionLevel.Any,
cheatsRequired: true
};

customCommandRegistry.registerCommand(hubCommand, (origin) => {
try {
const player = origin.sourceEntity;
if (!player) {
return { status: CustomCommandStatus.Error, message: "Command can only be run by a player." };
}

  system.run(() => {
    player.teleport(HUB_COORDS, { dimension: player.dimension });
    player.sendMessage("§aTeleported to the Hub!");
  });

  return { status: CustomCommandStatus.Success };
} catch (err) {
  console.error(`[server:hub] ${err}`);
  return { status: CustomCommandStatus.Error, message: "Teleport failed." };
}

});
});

maiden stone
vague ruin
#

does it work?

maiden stone
# vivid void i use this ```javascript import { world, system, CommandPermissionLevel } from "...

I modified your code a bit, this is way to overcomplicated

import { CustomCommandParamType, system, CommandPermissionLevel, Player, world } from "@minecraft/server";

const warps = {
    hub: { location: { x: 0, y: 23, z: -4 }, dimension: world.getDimension("overworld") },
    playzome: { location: { x: 10, y: 200, z: 10 }, dimension: world.getDimension("overworld") },
    market: { location: { x: 20, y: 200, z: 20 }, dimension: world.getDimension("overworld") },
};

/**
 * @param {Player} player
 * @param {typeof warps[keyof typeof warps]} target
 */
const warp = (player, target) => player.teleport(target.location, { dimension: target.dimension });

system.beforeEvents.startup.subscribe(({ customCommandRegistry: commandReg }) => {
    commandReg.registerCommand(
        {
            name: "custom:hub",
            description: "Teleports you to the hub (0,23,-4)",
            permissionLevel: CommandPermissionLevel.Any,
        },
        ({ sourceEntity: player }) => {
            if (!(player instanceof Player)) return { status: 1, message: "Only players can use this Command" };
            system.run(() => warp(warps["hub"]));
        },
    );

    commandReg.registerEnum("custom:warps", Object.keys(warps));
    commandReg.registerCommand(
        {
            name: "custom:warps",
            description: "Teleport to a warp Location",
            permissionLevel: CommandPermissionLevel.Any,
            mandatoryParameters: [{ type: CustomCommandParamType.Enum, name: "custom:warps" }],
        },
        /** @param {keyof typeof warps} target  */
        ({ sourceEntity: player }, target) => {
            if (!(player instanceof Player)) return { status: 1, message: "Only players can use this Command" };
            system.run(() => warp(warps[target]));
        },
    );
});
vague ruin
#

just need hub warp though

maiden stone
#

then delete the warp stuff

#

like the command and enum I declared

vague ruin
#

this good?

#

import { system, CommandPermissionLevel, CustomCommandStatus, Player, world } from "@minecraft/server";

const hub = {
location: { x: 0, y: 23, z: -4 },
dimension: world.getDimension("overworld"),
};

/**

  • @param {Player} player
    */
    const warpToHub = (player) => {
    player.teleport(hub.location, { dimension: hub.dimension });
    player.sendMessage("§aTeleported to the hub!");
    };

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerCommand(
{
name: "server:hub",
description: "Teleports you to the hub (0,23,-4)",
permissionLevel: CommandPermissionLevel.Any,
cheatsRequired: true,
},
({ sourceEntity: player }) => {
if (!(player instanceof Player)) {
return { status: CustomCommandStatus.Failure, message: "Only players can use this command" };
}

  system.run(() => warpToHub(player));

  return { status: CustomCommandStatus.Success };
}

);
});

maiden stone
#
import { system, CommandPermissionLevel, Player, world } from "@minecraft/server";

system.beforeEvents.startup.subscribe(({ customCommandRegistry: commandReg }) => {
    commandReg.registerCommand(
        {
            name: "custom:hub",
            description: "Teleports you to the hub (0,23,-4)",
            permissionLevel: CommandPermissionLevel.Any,
        },
        ({ sourceEntity: player }) => {
            if (!(player instanceof Player)) return { status: 1, message: "Only players can use this Command" };
            system.run(() => player.teleport({ x: 0, y: 23, z: -4 }, { dimension: world.getDimension("overworld") }));
        },
    );
});
maiden stone
vague ruin
#

how bro?

maiden stone
#

```js
Your Code
```

vague ruin
#

IDK how to do that

maiden stone
#

just copy it

#

but if you have an en keyboard layout you should have it

vague ruin
#
import { system, CommandPermissionLevel, CustomCommandStatus, Player, world } from "@minecraft/server";

const hub = {
  location: { x: 0, y: 23, z: -4 },
  dimension: world.getDimension("overworld"),
};

/**
 * @param {Player} player
 */
const warpToHub = (player) => {
  player.teleport(hub.location, { dimension: hub.dimension });
  player.sendMessage("§aTeleported to the hub!");
};

system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
  customCommandRegistry.registerCommand(
    {
      name: "server:hub",
      description: "Teleports you to the hub (0,23,-4)",
      permissionLevel: CommandPermissionLevel.Any,
      cheatsRequired: true,
    },
    ({ sourceEntity: player }) => {
      if (!(player instanceof Player)) {
        return { status: CustomCommandStatus.Failure, message: "Only players can use this command" };
      }

      system.run(() => warpToHub(player));

      return { status: CustomCommandStatus.Success };
    }
  );
});
vague ruin
maiden stone
maiden stone
#

Also success is optionl

#

You don't need it

vague ruin
#

so is there updated code?

vague ruin
#

bro?

maiden stone
#

I edited the message

#

Just copy that and paste it and test if it works

vague ruin
#

have you tested it?

vague ruin
maiden stone