TeleportComponent - ParzivalExe/guiapi GitHub Wiki
From Overview
The TeleportComponent teleports the Player to a specified Location of type TeleportLocation which is also given by the GuiAPI. This custom Location-Object supports to not only a static Location but also Locations relative to the player who clicked on the Component and even a mix of both. When clicked, this Component also closes the Gui.
Implementation
The creation of the TeleportComponent itself is pretty easy and mostly the same as most other components:
ComponentMeta teleportMeta= new ComponentMeta("Teleport", new ItemStack(Material.ENDER_PEARL));
//manipulate teleportMeta here
TeleportLocation location = new TeleportLocation(null, 0, 0, 0);
StaticComponent teleportComponent= new StaticComponent(teleportMeta, location);
//manipulate teleportComponent here
gui.addComponent(teleportComponent);
As you can see, for the TeleportComponent we need the final Position to teleport to as a TeleportPosition-Object and because of this, it adds a bit more complexity to this component than the first once we had so far. The TeleportLocation is generally made out of the exact same variables as a normal Location in Bukkit, meaning: World world, double x, double y, double z, float yaw and float pitch.
The special part of this custom object is, that everyone of these variables can also be used relative to the position of the player who gets teleported to this position. Therefore almost every variable has an accompanying boolean with the prefix relative... so: boolean relativeX, boolean relativeY... The only exception to this is the world. Here you simply have to give null and the relative world the player is in right now will be used.
Even if you set one of these values to relative (again excluding the world), you can still give values over the variables (x, y...) which would then act as an offset to the relative position of the player.
As an example, here is a TeleportLocation which would teleport a player 10 blocks up:
TeleportLocation location = new TeleportLocation(null, 0, true, 10, true, 0, true);
The constructor used has the following syntax: TeleportLocation(World world, double x, boolean relativeX, double y, boolean relativeY, double z, boolean relativeZ) {...}
Events
ComponentClickedEvent = fired, when the TeleportComponent (or any other Component) is clicked
TeleportComponentClickedEvent = fired, when the TeleportComponent is clicked
XML-Attributes
title="{Component-Title}" = sets the Title of this Component (example: title="Hello World")
look="{AMOUNT}xID:{DATA}{[DURABILITY]}" = sets the Look of this Component (example: look="3x322:1" or look="3xGOLDEN_APPLE")
description="[{line1}, {line2}...]" = sets the description of this Component (example: description="[This is a Description, with a \,]")
place="{PLACE}" = sets the place this Component should be placed at in the Gui (example: place="4")
location="{world_name}|*=(*){x}:(*){y}:(*){z}[:(*){yaw}:(*){pitch}]" = this one is pretty complicated. Generally, a position of x=1, y=2, z=-3, yaw=1.8, pitch=4.6 in world="world" would look like this: location="world=1:2:-3:1.8:4.6". Seems much simpler, right. If we want to signal, that some position should now be relative to the player (which was already described in Implementation, we would write an * as a prefix to that location. So let's say we want to reproduce the same position as in Implementation where the player is simply teleported 10 blocks upwards (y-axis): location="*=*0:*10:*0:*0:*0". We can also get rid of the 0 as it will have an offset of 0 automatically when no value is given: location=*=*:*10:*:*:* and lastly we could even get rid of the yaw and pitch as long as these should be relative to the player without offset (like they are right now): location="*=*:*10:*". Much easier, right. By the way, 10 blocks down (y-axis) would be: location="*=*:*-10:*" just to reinforce how this system works :wink:
Resources
Component-Code: io.github.parzivalExe.guiApi.components.TeleportComponent
TeleportLocation-Code: io.github.parzivalExe.guiApi.objects.TeleportLocation
Great, now you know how to implement a TeleportComponent with a few lines. Next Component on the List is the GetItemComponent