#/hub command
1 messages · Page 1 of 1 (latest)
dude
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)");
});
?
Is there an error message?
the problem was world.getDimension(player.dimension), that function only accepts strings
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});
}
}
);
});
Does this even exist, genuine question because I always want to know how to make a real custom commands than using chatSend before events that doesn't work always for non-beta
Yes that does exist mojang have been working on a full command system for awhile, and while the system has many "advanced command" flaws it is a great system for any basic command, it got released to stable an update or to ago. So chatSend which always needs beta-apis is no longer needed.
Thankss, I'm excited to try this out
It says line 11
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
The command doesn’t show in chat
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." };
}
});
});
yea it came out of beta in the latest update
does it work?
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]));
},
);
});
just need hub warp though
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 };
}
);
});
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") }));
},
);
});
pls make your code a codeblock, this isn't readable
how bro?
```js
Your Code
```
IDK how to do that
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 };
}
);
});
done
I modified it a bit bc I had unnecessary stuff in it
Btw just use status 1, that's what failure means
Also success is optionl
You don't need it
so is there updated code?
have you tested it?
Because it doesn’t work so I have to go pls make it work
I'm not at home and this looked fine in vscode and still looks fine to me