This package is no longer being maintained, any bug support will not be given.
This package wouldn't have been possible without the help of my friend DeltaRays#0054.
Minehut.js is a TypeScript and JavaScript library that allows you to interact with the Minehut API.
This release is focused on the FileManager
, bringing some features I had forgotten about + the .watch()
method:
- Added
FileManager.watch()
; - Added
FileManager.createDir()
; - Added
FileManager.deleteFile()
; - Added
FileManager.deleteDir()
; FileManager.uploadWorld()
now supports relative paths.
Created by Kiko#6282
The library uses the Collection
class from Discord.js due to its useful methods such as .find()
, .filter()
and .first()
. For more information, check the Discord.js Documentation.
// Start server
import { Session } from "minehut.js"
const session = new Session()
session.login({
email: "hello@testmail.com",
password: "codingisawesome"
}).then(async session => {
const server = session.servers.first()
await server.start()
}, console.error)
The Minehut
object contains some methods and properties:
.Session
.getServers()
.getServer(name: string)
.getPlugins()
.getPlugin(name: string)
.getIcons()
.getIcon(name: string)
.getStats()
.getPromotion()
.signup()
.checkCode()
.confirmEmail()
See Session
Returns: Promise<Collection<string, Server>>
Parameter | Type | Description |
---|---|---|
name |
string? | The ID or name of the server. |
Returns: Promise<Collection<string, Plugin>>
Parameter | Type | Description |
---|---|---|
name |
string? | The ID or name of the plugin. |
Returns: Promise<Plugin> |
Returns: Promise<Collection<string, Icon>>
Parameter | Type | Description |
---|---|---|
name |
string? | The ID or name of the icon. |
Returns: Promise<MinehutStats>
Returns: Promise<Object { text: string, link: string }>
Parameter | Type | Description |
---|---|---|
email |
string | The email to sign up with. |
birthday |
string | A date string indicating the birthday. |
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
code |
string | The code sent to the email from Minehut.signup() . |
Returns: Promise<void>
NOTE: While this method exists, I'm (still) not sure if it is necessary for signing up. Anyways, just to be sure, you should always use .signup()
, .checkCode()
and .confirmEmail()
Parameter | Type | Description |
---|---|---|
code |
string | The code sent to the email from Minehut.signup() . |
password |
string | The password to set for the account. |
Returns: Promise<void>
Represents an object containing network statistics.
Property | Type |
---|---|
serverCount |
Object { online: number, total: number } |
playerCount |
Object { total: number, lobbies: number, servers: number} |
userCount |
number |
maxServerCount |
number |
ramCount |
number |
maxRam |
number |
The Server
class represents a Minehut server accessible with no authorization required. The structure is as follows:
Property | Type |
---|---|
id |
string |
ownerId |
string |
name |
string |
nameLower |
string |
creation |
number |
platform |
string |
storageNode |
string |
v |
number |
port |
number |
lastOnline |
number |
motd |
string |
creditsPerDay |
number |
visibility |
boolean |
offer |
string |
properties |
ServerProperties |
suspended |
boolean |
icons |
Collection<string, Icon>? |
iconIds |
string? |
icon |
Icon? |
iconId |
string? |
iconName |
string? |
online |
boolean |
maxPlayers |
number |
playerCount |
number |
plugins |
Collection<string, Plugin>? |
pluginIds |
string |
There are also 2 methods:
Description: Fetches plugins (doesn't return them, only assigns)
Returns: Promise<void>
Description: Fetches icons (doesn't return them, only assigns)
Returns: Promise<void>
The reason these exist is because Minehut.js doesn't store the plugins and icons as their respective class instances right away, which also explains why some plugin and icon properties are marked as partial.
The Plugin
class is one that doesn't have many uses. Instead, it exists just for the sake of having it.
Property | Type |
---|---|
id |
string |
name |
string |
credits |
number |
platform |
string |
description |
string |
details |
string |
version |
string |
disabled |
boolean |
fileName |
string |
configFileName |
string |
v |
number |
created |
number |
lastUpdated |
number |
Like the Plugin
class, the icon class also exists just for the sake of it.
Property | Type |
---|---|
id |
string |
displayName |
string |
iconName |
string |
price |
number |
rank |
string |
available |
boolean |
v |
number |
disabled |
boolean |
created |
number |
lastUpdated |
number |
Session
is the class that manages a user's session. The constructor takes no parameters. Instead, after instanciating the class, you should use the .login()
method to log in:
Parameter | Type | Description |
---|---|---|
credentials |
Object { email: string, password: string } | Minehut email and password. |
Description: Logs in to Minehut using specified credentials.
Returns: Promise<Session>
When successfully logged in, you can either use the original variable or the variable resolved by the promise to access the complete Session object:
Property | Type |
---|---|
user |
User |
id |
string |
token |
string |
loggedIn |
boolean |
There's also a .fetch()
method, but I don't recommend using it:
Parameter | Type | Default | Description |
---|---|---|---|
url |
string | The URL to send the request to. | |
method |
string | "GET" |
The request method. |
body |
Object | string | The request body. |
Description: Fetches with authorization.
Returns: Promise<Response>
The User
class represents a logged in Minehut user.
Property | Type |
---|---|
session |
Session |
id |
string |
email |
string |
emailVerified |
boolean |
emailSentAt |
number |
v |
number |
emailCode |
string |
credits |
number |
lastLogin |
number |
lastPasswordChange |
number |
minecraft |
Minecraft |
maxServers |
number |
serverIds |
string |
servers |
Collection<string, SessionServer> |
transactions |
Collection<string, Transaction> |
payments |
Collection<string, Payment> |
Parameter | Type |
---|---|
oldPassword |
string |
newPassword |
string |
Description: Changes the password for the logged in user.
Returns: Promise<void>
Parameter | Type |
---|---|
slots |
number |
Description: Purchases a server slot. 400 credits are required for each slot.
Returns: Promise<void>
Description: Creates a new server using a free slot.
Returns: Promise<void>
Description: Re-fetches properties (doesn't return them, only assigns).
Returns: Promise<void>
SessionServer
represents a server belonging to the logged in user. It extends Server
and has
Property | Type |
---|---|
owner |
User |
session |
Session |
fileManager |
FileManager |
maxRam |
number |
serviceOnline |
boolean |
serverIp |
string |
serverPort |
number |
timeNoPlayers |
number |
startedAt |
number |
stoppedAt |
number |
starting |
boolean |
stopping |
boolean |
exited |
boolean |
status |
string |
metrics |
Object |
transferScheduled |
boolean |
Description: Starts the server up.
Returns: Promise<void>
Description: Restarts the server.
Returns: Promise<void>
Parameter | Type | Default | Description |
---|---|---|---|
service |
boolean? | true |
Whether to stop the service or not. |
Description: Starts the server up.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
name |
string | The new server name. |
Description: Changes the server name.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
motd |
string | The new server MOTD. |
Description: Changes the server MOTD.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
isVisible |
boolean | Whether the server is visible or not. |
Description: Changes the server visibility.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
command |
string | The command to execute. |
Description: Sends a command to the server.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
properties |
Partial<ServerProperties> | The properties to edit. |
Description: Edits the server properties.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
identifier |
string | Icon | The icon to purchase. |
Description: Purchases an icon.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
identifier |
string | Icon | null | The icon to set. Don't specify anything or specify null to set the default icon. |
Description: Changes the server's icon.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
identifier |
string | Plugin | The plugin to install |
Description: Installs a plugin.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
identifier |
string | Plugin | The plugin to reset. |
Description: Resets plugin data.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
identifier |
string | Plugin | The plugin to uninstall |
Description: Uninstalls a plugin.
Returns: Promise<void>
Description: Re-fetches the server properties.
Returns: Promise<void>
The FileManager
class is used to manage everything that's file-related, such as world uploading, file creation and resets.
Property | Type |
---|---|
user |
User |
server |
SessionServer |
session |
Session |
Parameter | Type | Description |
---|---|---|
path |
string? | The path to the file without its name. Specify an empty string if you're targeting the root directory. |
name |
string | The file name. |
Description: Creates a file.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string | The path to the directory. |
Description: Creates a directory.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string | The path to the file with its name. |
content |
string | The new content. |
Description: Edits a file.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string | The path to the file with its name. |
Description: Reads a file, returning its content.
Returns: Promise<string>
Parameter | Type | Description |
---|---|---|
watchPath |
string | The local path to watch. |
uploadPath |
string? | The path to upload to. Specify an empty string for the root directory. |
Description: Watches a directory/file and uploads it to Minehut on changes/delete. Warning: Deleted files will not sync to Minehut if they're deleted while this method isn't running.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string? | The path to the directory. Specify an empty string for the root directory. |
Description: Reads a directory, returning its children.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string? | The path to the file. |
Description: Deletes a file.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
path |
string? | The path to the directory. |
Description: Deletes a directory.
Returns: Promise<void>
Parameter | Type | Description |
---|---|---|
fullPath |
string | The path to the zip file. |
Description: Uploads a world.
Returns: Promise<void>
Description: Saves the world.
Returns: Promise<void>
Description: Resets the world. Use with caution!
Returns: Promise<void>
Description: Repairs the server's files.
Returns: Promise<void>
Description: Resets the server. Use with caution!
Returns: Promise<void>
An object with information about a directory's child element (file or folder).
Property | Type |
---|---|
name |
string |
directory |
boolean |
blocked |
boolean |
The ServerProperties
type contains all of the properties that servers can have.
Property | Type |
---|---|
viewDistance |
number |
resourcePackSha1 |
string |
resourcePack |
string |
generatorSettings |
string |
levelName |
string |
levelType |
string |
announcePlayerAchievements |
boolean |
enableCommandBlock |
boolean |
generateStructures |
boolean |
allowNether |
boolean |
levelSeed |
string |
difficulty |
number |
pvp |
boolean |
hardcore |
boolean |
forceGamemode |
boolean |
spawnMobs |
boolean |
spawnAnimals |
boolean |
allowFlight |
boolean |
gamemode |
number |
maxPlayers |
number |
spawnProtection |
number |
Object containing information of a user's linked minecraft account.
Property | Type |
---|---|
linkCode |
string |
lastLinkTime |
number |
username |
string |
uuid |
string |
Object containing information about a credit transaction.
Property | Type |
---|---|
id |
string |
user |
string |
userEmail |
string |
ip |
string |
desc |
string |
type |
string |
pluginId |
string |
serverId |
string |
price |
number |
time |
number |
v |
number |
Object containing information about a payment.
Property | Type |
---|---|
id |
string |
user |
string |
gateway |
string |
paymentId |
string |
price |
number |
time |
number |
v |
number |
email |
number |