Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Update README.md

Update README.md

Update README.md

Update README.md

Update README.md
  • Loading branch information
Owen3H committed Jun 24, 2024
1 parent 19c9691 commit 48a19cd
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [**EarthMC-NPM**](https://www.npmjs.com/package/earthmc)
An **unofficial** wrapper library for interacting with the [EarthMC Dynmap](https://earthmc.net/map/aurora/) API.<br>
An **unofficial** wrapper library for interacting with the **EarthMC** map APIs.<br>
This package is part of the [EarthMC Toolkit](https://emctoolkit.vercel.app) and provides extensive info on people, places and more.

## Install
Expand All @@ -13,13 +13,62 @@ PNPM ➜ `pnpm add earthmc`\
Yarn ➜ `yarn add earthmc`\
NPM (ew) ➜ `npm i earthmc`

## Basic Usage
View the full documentation [here](https://emctoolkit.vercel.app/docs/npm).

## Import
By default, the available maps are exported and can be used like so:
```ts
import { Aurora } from 'earthmc' // ESM
const { Aurora } = require('earthmc') // CJS
```

However, you may want to create your own map instance to customize the expiry time of the cache.
```ts
import { Squaremap, Dynmap } from 'earthmc'

const Aurora = new Squaremap('aurora', 10) // Default Squaremap TTL is 30s.
const Nova = new Dynmap('nova', 90) // Default Dynmap TTL is 120s.
```

## Basic Usage
Visit the [documentation](https://emctoolkit.vercel.app/docs/npm) to use this library to its full potential.

```ts
const towns = await Aurora.Towns.all().catch(console.error)
console.log(towns.length)
```

// These calls are instant since the previous call to `all()` populated the cache.
const single = await Aurora.Towns.get('exampleName')
const many = await Aurora.Towns.get('town1', 'town2', 'town3', ...)
```

### GPS
In addition to the four main classes (Towns, Nations, Residents, Players), both maps also provide a GPS.
Here is an example of how you could use it.
```ts
// To avoid PVP, call `safestRoute` instead.
const route = await Aurora.GPS.fastestRoute({ x: town.x, z: town.z })
const desc = `Type **/n spawn ${route.nation.name}** and head **${route.direction}** for **${route.distance}** blocks.`
```

To continously track a player, you can use the `track` method.
- First parameter (player name) is **required**, but case insensitive.
- Second parameter (interval) is optional. Defaults to `3000` milliseconds.
- Third parameter (route) is optional. Defaults to `FASTEST`.
```ts
// Start tracking a player, with 5s delay, outputting the safest route.
const tracker = await Aurora.GPS.track("PlayerName", 5000, Routes.SAFEST).catch(e => {
console.error("Error fetching player: " + e)
})

// Listen for any errors that may occur.
tracker.on('error', e => {
console.error("An error occurred: " + e)
})

tracker.on('underground', (playerInfo) => {
console.log("Player went underground - " + playerInfo)
})

tracker.on('locationUpdate', (routeInfo) => {
console.log("Player's location updated - " + routeInfo)
})
```

0 comments on commit 48a19cd

Please sign in to comment.