Jycraft / jycraft

Extend Minecraft servers with Python using Jython.
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

Registering event handlers #1

Closed pauleveritt closed 9 years ago

pauleveritt commented 9 years ago

I see that mcapi.registerhook has the start of what appears to be event handlers. I'd like to try and accomplish what ScriptCraft has in:

https://github.com/walterhiggins/ScriptCraft/blob/master/docs/API-Reference.md#eventsplayermove

...which uses this hook:

https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/hook/player/PlayerMoveHook.html

...but it seems I'm a bit far off.

Macuyiko commented 9 years ago

This is indeed possible, see below:

hooks

from mcapi import *
from net.canarymod.hook.player import PlayerMoveHook

def hookfunc(listener, hook):
  yell(str(hook.getPlayer().getName())+" is moving!")

registerhook(PlayerMoveHook, hookfunc)