3.0.4 • Published 4 years ago

minehut.js v3.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Minehut.js

IMPORTANT

This package wouldn't have been possible without the help of my friend DeltaRays#0054.

About

Minehut.js is a TypeScript and JavaScript library that allows you to interact with the Minehut API.

Release 3.0.0

This release is focused on the FileManager, bringing some features I had forgotten about + the .watch() method:

Created by Kiko#6282

Collections

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.

Example

// 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)

Main Object

The Minehut object contains some methods and properties:

.Session

See Session

.getServers()

Returns: Promise<Collection<string, Server>>

.getServer()

ParameterTypeDescription
namestring?The ID or name of the server.

Returns: Promise\<Server>

.getPlugins()

Returns: Promise<Collection<string, Plugin>>

.getPlugin()

ParameterTypeDescription
namestring?The ID or name of the plugin.

Returns: Promise\<Plugin>

.getIcons()

Returns: Promise<Collection<string, Icon>>

.getIcon()

ParameterTypeDescription
namestring?The ID or name of the icon.

Returns: Promise\<Icon>

.getStats()

Returns: Promise<MinehutStats>

.getPromotion()

Returns: Promise<Object { text: string, link: string }>

.signup()

ParameterTypeDescription
emailstringThe email to sign up with.
birthdaystringA date string indicating the birthday.

Returns: Promise\

.checkCode()

ParameterTypeDescription
codestringThe code sent to the email from Minehut.signup().

Returns: Promise\ 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()

.confirmEmail()

ParameterTypeDescription
codestringThe code sent to the email from Minehut.signup().
passwordstringThe password to set for the account.

Returns: Promise\

MinehutStats

Represents an object containing network statistics.

PropertyType
serverCountObject { online: number, total: number }
playerCountObject { total: number, lobbies: number, servers: number}
userCountnumber
maxServerCountnumber
ramCountnumber
maxRamnumber

Server

The Server class represents a Minehut server accessible with no authorization required. The structure is as follows:

PropertyType
idstring
ownerIdstring
namestring
nameLowerstring
creationnumber
platformstring
storageNodestring
vnumber
portnumber
lastOnlinenumber
motdstring
creditsPerDaynumber
visibilityboolean
offerstring
propertiesServerProperties
suspendedboolean
iconsCollection<string, Icon>?
iconIdsstring?
iconIcon?
iconIdstring?
iconNamestring?
onlineboolean
maxPlayersnumber
playerCountnumber
pluginsCollection<string, Plugin>?
pluginIdsstring

There are also 2 methods:

.fetchPlugins()

Description: Fetches plugins (doesn't return them, only assigns) Returns: Promise\

.fetchIcons()

Description: Fetches icons (doesn't return them, only assigns) Returns: Promise\

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.

Plugin

The Plugin class is one that doesn't have many uses. Instead, it exists just for the sake of having it.

PropertyType
idstring
namestring
creditsnumber
platformstring
descriptionstring
detailsstring
versionstring
disabledboolean
fileNamestring
configFileNamestring
vnumber
creatednumber
lastUpdatednumber

Icon

Like the Plugin class, the icon class also exists just for the sake of it.

PropertyType
idstring
displayNamestring
iconNamestring
pricenumber
rankstring
availableboolean
vnumber
disabledboolean
creatednumber
lastUpdatednumber

Session

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:

.login()

ParameterTypeDescription
credentialsObject { 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:

PropertyType
userUser
idstring
tokenstring
loggedInboolean

There's also a .fetch() method, but I don't recommend using it:

.fetch()

ParameterTypeDefaultDescription
urlstringThe URL to send the request to.
methodstring"GET"The request method.
bodyObject | stringThe request body.

Description: Fetches with authorization. Returns: Promise\<Response>

User

The User class represents a logged in Minehut user.

PropertyType
sessionSession
idstring
emailstring
emailVerifiedboolean
emailSentAtnumber
vnumber
emailCodestring
creditsnumber
lastLoginnumber
lastPasswordChangenumber
minecraftMinecraft
maxServersnumber
serverIdsstring
serversCollection<string, SessionServer>
transactionsCollection<string, Transaction>
paymentsCollection<string, Payment>

.changePassword()

ParameterType
oldPasswordstring
newPasswordstring

Description: Changes the password for the logged in user. Returns: Promise\

.purchaseSlots()

ParameterType
slotsnumber

Description: Purchases a server slot. 400 credits are required for each slot. Returns: Promise\

.createServer()

Description: Creates a new server using a free slot. Returns: Promise\

.refresh()

Description: Re-fetches properties (doesn't return them, only assigns). Returns: Promise\

SessionServer

SessionServer represents a server belonging to the logged in user. It extends Server and has

PropertyType
ownerUser
sessionSession
fileManagerFileManager
maxRamnumber
serviceOnlineboolean
serverIpstring
serverPortnumber
timeNoPlayersnumber
startedAtnumber
stoppedAtnumber
startingboolean
stoppingboolean
exitedboolean
statusstring
metricsObject
transferScheduledboolean

.start()

Description: Starts the server up. Returns: Promise\

.restart()

Description: Restarts the server. Returns: Promise\

.stop()

ParameterTypeDefaultDescription
serviceboolean?trueWhether to stop the service or not.

Description: Starts the server up. Returns: Promise\

.setName()

ParameterTypeDescription
namestringThe new server name.

Description: Changes the server name. Returns: Promise\

.setMOTD()

ParameterTypeDescription
motdstringThe new server MOTD.

Description: Changes the server MOTD. Returns: Promise\

.setVisibility()

ParameterTypeDescription
isVisiblebooleanWhether the server is visible or not.

Description: Changes the server visibility. Returns: Promise\

.sendCommand()

ParameterTypeDescription
commandstringThe command to execute.

Description: Sends a command to the server. Returns: Promise\

.editProperties()

ParameterTypeDescription
propertiesPartial<ServerProperties>The properties to edit.

Description: Edits the server properties. Returns: Promise\

.purchaseIcon()

ParameterTypeDescription
identifierstring | IconThe icon to purchase.

Description: Purchases an icon. Returns: Promise\

.setIcon()

ParameterTypeDescription
identifierstring | Icon | nullThe icon to set. Don't specify anything or specify null to set the default icon.

Description: Changes the server's icon. Returns: Promise\

.installPlugin()

ParameterTypeDescription
identifierstring | PluginThe plugin to install

Description: Installs a plugin. Returns: Promise\

.resetPlugin()

ParameterTypeDescription
identifierstring | PluginThe plugin to reset.

Description: Resets plugin data. Returns: Promise\

.uninstallPlugin()

ParameterTypeDescription
identifierstring | PluginThe plugin to uninstall

Description: Uninstalls a plugin. Returns: Promise\

.refresh()

Description: Re-fetches the server properties. Returns: Promise\

FileManager

The FileManager class is used to manage everything that's file-related, such as world uploading, file creation and resets.

PropertyType
userUser
serverSessionServer
sessionSession

.createFile()

ParameterTypeDescription
pathstring?The path to the file without its name. Specify an empty string if you're targeting the root directory.
namestringThe file name.

Description: Creates a file. Returns: Promise\

.createDir()

ParameterTypeDescription
pathstringThe path to the directory.

Description: Creates a directory. Returns: Promise\

.editFile()

ParameterTypeDescription
pathstringThe path to the file with its name.
contentstringThe new content.

Description: Edits a file. Returns: Promise\

.readFile()

ParameterTypeDescription
pathstringThe path to the file with its name.

Description: Reads a file, returning its content. Returns: Promise\<string>

.watch()

ParameterTypeDescription
watchPathstringThe local path to watch.
uploadPathstring?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\

.readDir()

ParameterTypeDescription
pathstring?The path to the directory. Specify an empty string for the root directory.

Description: Reads a directory, returning its children. Returns: Promise\

.deleteFile()

ParameterTypeDescription
pathstring?The path to the file.

Description: Deletes a file. Returns: Promise\

.deleteDir()

ParameterTypeDescription
pathstring?The path to the directory.

Description: Deletes a directory. Returns: Promise\

.uploadWorld()

ParameterTypeDescription
fullPathstringThe path to the zip file.

Description: Uploads a world. Returns: Promise\

.saveWorld()

Description: Saves the world. Returns: Promise\

.resetWorld()

Description: Resets the world. Use with caution! Returns: Promise\

.repairFiles()

Description: Repairs the server's files. Returns: Promise\

.resetServer()

Description: Resets the server. Use with caution! Returns: Promise\

DirChild

An object with information about a directory's child element (file or folder).

PropertyType
namestring
directoryboolean
blockedboolean

ServerProperties

The ServerProperties type contains all of the properties that servers can have.

PropertyType
viewDistancenumber
resourcePackSha1string
resourcePackstring
generatorSettingsstring
levelNamestring
levelTypestring
announcePlayerAchievementsboolean
enableCommandBlockboolean
generateStructuresboolean
allowNetherboolean
levelSeedstring
difficultynumber
pvpboolean
hardcoreboolean
forceGamemodeboolean
spawnMobsboolean
spawnAnimalsboolean
allowFlightboolean
gamemodenumber
maxPlayersnumber
spawnProtectionnumber

Minecraft

Object containing information of a user's linked minecraft account.

PropertyType
linkCodestring
lastLinkTimenumber
usernamestring
uuidstring

Transaction

Object containing information about a credit transaction.

PropertyType
idstring
userstring
userEmailstring
ipstring
descstring
typestring
pluginIdstring
serverIdstring
pricenumber
timenumber
vnumber

Payment

Object containing information about a payment.

PropertyType
idstring
userstring
gatewaystring
paymentIdstring
pricenumber
timenumber
vnumber
emailnumber
3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.0

4 years ago

1.0.2

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago