API Bridge
Last updated
Last updated
Our goal is to make every method in the Spigot API available through our scripting language, allowing you to leverage the full power of Spigot while scripting. You can access the Spigot API documentation (1.21.1) for comprehensive details on the available classes and methods, including main classes such as Player, Location, Block, ItemStack, Entity and World.
Familiarizing yourself with these classes will help you effectively utilize the Spigot API to create dynamic and engaging experiences in your scripts.
Some links for the main classes are:
Weβve designed our scripting language to provide a way to access Spigot API methods easily. Each method from the Spigot API is translated into a format that fits the syntax of our language, making it intuitive for developers to use.
For example, consider the Player class, which contains methods like getDisplayName()
and setDisplayName()
.
In our scripting language, you can access these methods as follows:
To retrieve a player's display name, you can use:
or simply:
To set a player's display name, you can use:
or simply:
For methods that start with "is" or "has" in the Spigot API, such as isSneaking
or hasPermission
, the prefix is dropped, and a ?
is added at the end to indicate it returns a Boolean value. For example:
isSneaking()
in Spigot becomes:
hasPermission("some.permission")
becomes:
This example demonstrates how to send a personalized message to a player when they join the game.
Sending a Message: The send_message
method is used to display a message to the player. The text inside the parentheses is the content of the message.
Formatted Message: In this message, we use color codes for formatting:
&a
sets the text color to light green.
&e
sets the text color to yellow.
Personalization: The part {{player.name}}
dynamically includes the playerβs name in the message, making it more personal. When the message is sent, it will replace {{player.name}}
with the actual name of the player, so they see something like "Welcome to the server, Steve!" when they join.
Adding an Item: The add_item
method is called on the player's inventory to add a specific item.
Item Specification: In this case, we are adding :STONE
, which represents a stone block in the game. The colon (:
) indicates that it is an enumeration (enum) value for item types. You can check all the materials available at Material Spigot API.
Result: When this line of code executes, a stone item is added to the player's inventory, allowing them to use it in the game.
In this example, weβll show how to teleport a player 10 blocks upwards and then place a block at the new location.
This line retrieves the player's current position in the game world. The player.location
property gives us an object that contains the player's coordinates (X, Y, Z) along with the world they are in. We store this information in a variable called current_location
for later use.
Next, we increase the Y coordinate of current_location
by 10. The Y coordinate represents the vertical position in the game world. By adding 10, we are moving the player 10 blocks higher into the air. The line current_location.y += 10
is shorthand for saying "take the current Y coordinate and add 10 to it."
This line of code moves the player to the newly calculated location. The player.teleport(current_location)
method is called, which takes the new coordinates and updates the player's position in the game world to that point. After this line, the player will be standing 10 blocks above where they were initially.
Here, we adjust the Y coordinate of new_location
by subtracting 1. This changes the position to be directly below the new teleport location (which is now 10 blocks up). This step is necessary because we want to place a block just underneath where the player is now standing, not at their new height.
This line is meant to set the type of block at the updated current_location
. By accessing current_location.block
, we are referring to the block that is currently at the coordinates specified by current_location
. Then, we set its type to :STONE
, which means we want to place a stone block at that location. You can check all the block types available on Material Spigot API.
To truly harness the full potential of our scripting language, it's essential to familiarize yourself with the Spigot API. This knowledge will empower you to perform a wide range of actions within the game. However, many functionalities require you to access other components first. For instance, if you wish to add an item to a player's inventory, you must first access that inventory. Similarly, to set a material for a block, you'll need to retrieve the block's reference, often starting from its location.
By understanding how to navigate the Spigot API, youβll be able to create more complex and interactive scripts, enhancing your experience and enabling you to customize your gameplay to suit your needs.