Skip to main content

Migrating To V2

Overview​

When transferring BeAPI to utilize NPM's create app features we realized how awkward BeAPI's API was in general. It was kinda hard to understand and even furthermore hard to document. With this in mind, we decided to completely refactor BeAPI to be object-oriented rather than well... a mess.

Create App​

Before you do anything, it is recommended to follow the installing guide located here in a new project.

BeAPI is an NPM module now therefore you will not be importing files locally anymore.

import { ... } from 'beapi-core';

Client​

Everything has been changed to an object-oriented style. The main class where everything is located is now exported as Client.

import { client } from 'beapi-core';

Database​

We have added a new memory-based persistent database with better performance and more reliability. It is breaking and very different from before.

see databasing for more info.

Intervals and Timeouts​

The Interval and Timeout methods now are added to globalThis therefore they do not need to be imported anymore. You can use them as if it is vanilla Javascript.

const interval = setInterval(() => {
console.log('Interval!');
}, 100);

clearInterval(interval);

const timeout = setTimeout(() => {
console.log('Timeout!');
}, 100);

clearTimeout(timeout);

Console​

We once again targeted globalThis to polyfill most common console methods.

console.log('Log');
console.warn('Warn');
console.error('Error');
console.info('Info');
console.debug('Debug');

Utils​

Some useful utils are exported as normal methods through the main export.

import {
between,
binToString,
stringToBin,
deprecated, // Used by BeAPI event checker, serves no other purpose.
getAll,
runCommand,
genUuid,
verifyUuid,
} from 'beapi-core';

Classes​

All classes are exported and accessible. Most classes do not need to be constructed by you as a client.

import { Player } from 'beapi-core';

Types​

All types are exported and also accessible.

import type { Awaitable } from 'beapi-core';

Common Things That Changed​

executeCommand​

❌

import { executeCommand } from '...';
executeCommand(...);

✔️

import { client } from 'beapi-core';
client.executeCommand(...);

✔️

import { runCommand } from 'beapi-core';
runCommand(...);

Commands​

❌

import { commands } from '...';
commands.registerCommand(...);

✔️

import { client } from 'beapi-core';
client.commands.register(...);

Events​

❌

import { events } from '...';
events.on(...);

✔️

import { client } from 'beapi-core';
client.on(...);

World​

❌

import { world } from '...';
world.sendMessage(...);

✔️

import { client } from 'beapi-core';
client.world.sendMessage(...);

Entities​

❌

import { entities } from '...';
entities.getEntityList(...);

✔️

import { client } from 'beapi-core';
client.entities.getAll(...);

Players​

❌

import { players } from '...';
players.getEntityList(...);

✔️

import { client } from 'beapi-core';
client.players.getAll(...);

Socket​

Removed...