Created
October 6, 2019 21:58
-
-
Save jwulf/40bcbdc0def68a7349a65aafb9de230a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const magik = magikcraft.io; | |
const Collectors = java.util.stream.Collectors; | |
import * as utils from 'utils' | |
console.log('Loaded track') | |
function main(name, period = 5000) { | |
const world = utils.world(magik.aspecto().world) | |
const target = world.getLivingEntities() | |
.stream() | |
.filter(entity => entity.getName() == name) | |
.collect(Collectors.toList()) | |
if (target.length > 0) { | |
cancelTracker() | |
track(target[0], period) | |
} else { | |
echo(self, `${name} not found`) | |
} | |
} | |
function cancelTracker() { | |
const tracker = magik.memento.getItem('tracker') | |
if (tracker) { | |
echo(self, `Cancelling ${tracker}`) | |
clearInterval(tracker); | |
} | |
} | |
function track(target, period) { | |
magik.memento.setItem('tracker', | |
setInterval(() => { | |
self.setCompassTarget(target.location) | |
echo(self, `Tracking ${target.getName()}`) | |
}, period)) | |
echo(self, `Tracking ${target.getName()}`) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment