Java Reference
In-Depth Information
locs.push(event.getDestination());
playerTeleports.put(player.getName(), locs);
}
}
@Command(aliases = {
"back"
},
description =
"Go back to previous places that you teleported to."
,
permissions = {
""
},
toolTip =
"/back"
)
public void
backCommand(MessageReceiver caller,
String[]
args) {
if
(caller
instanceof
Player) {
Player me = (Player)caller;
Stack
<Location> locs = playerTeleports.get(me.getName());
if
(locs != null && !locs.empty()) {
Location loc = locs.peek();
while
(equalsIsh(loc, me.getLocation()) && locs.size() > 1) {
locs.pop();
loc = locs.peek();
}
isTeleporting.add(me);
me.teleportTo(loc);
}
else
{
me.chat(
"You have not teleported yet."
);
}
}
}
}
As this plugin is using event listening, here are the special things you need
to do:
•At
❶
, declare that this plugin
implementsListener
.
•At
❸
, register the plugin for events.
•At
❺
add the
@HookHandler
annotation and declare that this event listener
will listen for
TeleportHook
events.
Every time a player teleports, the
onTeleport
function will be called. The first
thing we do is get the correct
Player
object, which is stored in the
event
that
was passed in to us. Now we know who we're dealing with.
Next we're looking in the list named
isTeleporting
to find out whether this player
is someone we are in the middle of teleporting. What's
isTeleporting
, you ask?
Ah, take a look up at the top of the plugin around
❷
, and you'll see two
variables declared to be
private static
. That means no one else can see them,
and the values will stick around in between this command being run. So here