### Create DebugArrow - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Example of creating a DebugArrow, which includes start and end positions, color, and properties for the arrowhead like length, radius, segments, and scale. ```java DebugArrow debugArrow = new DebugArrow( new Vector3f(100, 64, 100), Color.YELLOW, new Vector3f(110, 64, 110), 1.0f, // Arrowhead length 0.5f, // Arrowhead radius 4, // Arrowhead segments 1.0f // Arrowhead scale ); ``` -------------------------------- ### Create BlockState from Property Values (Java) Source: https://docs.allaymc.org/tutorials/block Demonstrates creating a BlockState for an Oak Door by specifying its properties directly. It also shows how to start with a default state and immutably set properties. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.state.BlockState; import org.allaymc.api.block.property.BlockPropertyType; import org.allaymc.api.block.property.BlockPropertyTypes; import org.allaymc.api.block.property.enums.*; public class Example { public void getWithProperties() { // Create from property values BlockState door = BlockTypes.OAK_DOOR.ofState( BlockPropertyTypes.DOOR_HINGE_BIT.createValue(false), BlockPropertyTypes.MINECRAFT_CARDINAL_DIRECTION.createValue(MinecraftCardinalDirection.NORTH), BlockPropertyTypes.OPEN_BIT.createValue(false), BlockPropertyTypes.UPPER_BLOCK_BIT.createValue(false) ); // Or start from default and set properties immutably BlockState closedNorthDoor = BlockTypes.OAK_DOOR .getDefaultState() .setPropertyValue(BlockPropertyTypes.OPEN_BIT, false) .setPropertyValue(BlockPropertyTypes.MINECRAFT_CARDINAL_DIRECTION, MinecraftCardinalDirection.NORTH); } } ``` -------------------------------- ### Clone Project Repository (Shell) Source: https://docs.allaymc.org/tutorials/create-your-first-plugin Clone the newly created GitHub repository to your local machine and navigate into the project directory. Requires Git installed. No inputs or outputs beyond local files; ensures project is local for editing. ```shell git clone https://github.com/yourusername/MyPlugin.git cd MyPlugin ``` -------------------------------- ### Create DebugBox - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Example of instantiating a DebugBox with specified position, color, scale, and dimensions. This shape is a simple rectangular prism. ```java DebugBox debugBox = new DebugBox( new Vector3f(100, 64, 100), Color.BLUE, 1.5f, new Vector3f(3, 3, 3) ); ``` -------------------------------- ### Create DebugLine - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Shows how to create a DebugLine object, defining its start and end points, and color. This shape visualizes a straight line segment. ```java DebugLine debugLine = new DebugLine( new Vector3f(100, 64, 100), Color.GREEN, new Vector3f(110, 64, 110) ); ``` -------------------------------- ### Update scoreboard with player count on join/quit (Java) Source: https://docs.allaymc.org/tutorials/use-scoreboards Extends the previous example by updating the scoreboard lines to include the current online player count each time a player joins or leaves. Calls the update() method within the event handlers to refresh the displayed information. Shows how to retrieve online player count via Server.getInstance(). ```Java import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.eventbus.event.player.PlayerQuitEvent; import org.allaymc.api.scoreboard.Scoreboard; import org.allaymc.api.scoreboard.data.DisplaySlot; import org.allaymc.api.server.Server; import java.util.List; public class MyScoreboard { protected static final Scoreboard info = new Scoreboard("INFO"); protected static void update() { var networkSettings = Server.SETTINGS.networkSettings(); info.setLines(List.of( "Welcome to the server!", "Online: " + Server.getInstance().getOnlinePlayerCount(), networkSettings.ip() + ":" + networkSettings.port() )); } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { info.addViewer(event.getPlayer(), DisplaySlot.SIDEBAR); update(); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { info.removeViewer(event.getPlayer(), DisplaySlot.SIDEBAR); update(); } } ``` -------------------------------- ### Create DebugText - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Example of creating a DebugText object, which allows displaying text at a specific position with a given color, scale, and content. Useful for labels and annotations. ```java DebugText debugText = new DebugText( new Vector3f(100, 64, 100), Color.WHITE, "Hello, Debug!", 1.0f // Scale ); ``` -------------------------------- ### Create a basic scoreboard in AllayMC (Java) Source: https://docs.allaymc.org/tutorials/use-scoreboards Defines a new Scoreboard instance named INFO using the AllayMC API. This snippet shows the minimal code required to declare a static scoreboard field for later use. No event handling or line updates are performed. ```Java import org.allaymc.api.scoreboard.Scoreboard; public class MyScoreboard { protected static final Scoreboard info = new Scoreboard("INFO"); } ``` -------------------------------- ### Handle Form Response with Modal Form - Java Source: https://docs.allaymc.org/tutorials/use-forms This example shows how to create a modal form to ask a player a question and handle their 'Yes' or 'No' response. It sends different messages based on the player's choice. Requires the AllayMC API library. ```java import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.form.Forms; import org.allaymc.api.utils.TextFormat; public class MyEventListener { @EventHandler private void onPlayerJoin(PlayerJoinEvent event) { var player = event.getPlayer(); Forms.modal() .title(TextFormat.YELLOW + "Do You Like Allay?") .content(TextFormat.GREEN + "Please tell us if you like allay-chan!") .trueButton(TextFormat.GREEN + "Yes", () -> player.sendText("Thank you!")) .falseButton(TextFormat.RED + "No", () -> player.sendText("Sorry to hear that!")) .sendTo(player); } } ``` -------------------------------- ### Get Default BlockState Source: https://docs.allaymc.org/tutorials/block Obtains the default BlockState for a given BlockType. This is commonly used to get a base representation of a block before applying any specific properties or states. It requires importing `BlockTypes` and `BlockState`. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.state.BlockState; public class Example { public void getDefaultState() { BlockState stone = BlockTypes.STONE.getDefaultState(); } } ``` -------------------------------- ### Update a Single Block Property In-place (Java) Source: https://docs.allaymc.org/tutorials/block Demonstrates how to modify a specific property of an existing block without replacing the entire BlockState. This example toggles the 'OPEN_BIT' property of a door. ```java import org.allaymc.api.block.Block; import org.allaymc.api.block.property.BlockPropertyTypes; import org.allaymc.api.world.Dimension; import org.joml.Vector3i; public class Example { public void toggleOpen(Dimension dimension, Vector3i doorPos) { Block door = new Block(dimension, doorPos); boolean open = door.getPropertyValue(BlockPropertyTypes.OPEN_BIT); door.updateBlockProperty(BlockPropertyTypes.OPEN_BIT, !open); } } ``` -------------------------------- ### Set or Update BlockState at a Location (Java) Source: https://docs.allaymc.org/tutorials/block Provides an example of how to place a specific BlockState (in this case, Stone) at given coordinates within a Dimension. This method overwrites any existing block at that location. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.state.BlockState; import org.allaymc.api.world.Dimension; public class Example { public void placeStone(Dimension dimension, int x, int y, int z) { BlockState stone = BlockTypes.STONE.getDefaultState(); dimension.setBlockState(x, y, z, stone); } } ``` -------------------------------- ### Display scoreboard on player join/quit (Java) Source: https://docs.allaymc.org/tutorials/use-scoreboards Registers event handlers for PlayerJoinEvent and PlayerQuitEvent to add and remove the INFO scoreboard from the SIDEBAR display slot. It also initializes the scoreboard lines with server IP and port. Demonstrates use of the EventHandler annotation and Scoreboard#setLines. ```Java import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.eventbus.event.player.PlayerQuitEvent; import org.allaymc.api.scoreboard.Scoreboard; import org.allaymc.api.scoreboard.data.DisplaySlot; import org.allaymc.api.server.Server; import java.util.List; public class MyScoreboard { protected static final Scoreboard info = new Scoreboard("INFO"); static { update(); } protected static void update() { var networkSettings = Server.SETTINGS.networkSettings(); info.setLines(List.of( "Welcome to the server!", networkSettings.ip() + ":" + networkSettings.port() )); } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { info.addViewer(event.getPlayer(), DisplaySlot.SIDEBAR); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { info.removeViewer(event.getPlayer(), DisplaySlot.SIDEBAR); } } ``` -------------------------------- ### Getting data from PDC in Java Source: https://docs.allaymc.org/tutorials/persistent-data-container Shows how to retrieve stored data from a Persistent Data Container using an Identifier and PersistentDataType. Includes checking if data exists before accessing it to avoid errors. ```java import org.allaymc.api.item.type.ItemTypes; import org.allaymc.api.pdc.PersistentDataType; import org.allaymc.api.utils.identifier.Identifier; public class Example { public void example() { // Create an Identifier var key = new Identifier("allaymc", "example-key"); var itemStack = ...// Retrieve the item from before // Get the data from the PDC var pdc = itemStack.getPersistentDataContainer(); if (pdc.has(key, PersistentDataType.STRING)) { var value = pdc.get(key, PersistentDataType.STRING); // Do something with the value player.sendMessage(value); } } } ``` -------------------------------- ### Get BlockType from Registry Source: https://docs.allaymc.org/tutorials/block Fetches a BlockType by its Identifier from the central registries. This method is useful for dynamic keys or custom content where block types are not directly available as static fields. It requires importing `BlockType`, `Registries`, and `Identifier`. ```java import org.allaymc.api.block.type.BlockType; import org.allaymc.api.registry.Registries; import org.allaymc.api.utils.identifier.Identifier; public class Example { public void getFromRegistry() { Identifier id = new Identifier("minecraft:stone"); // stone may be null if not found BlockType stone = Registries.BLOCK_TYPE.get(id); } } ``` -------------------------------- ### Get BlockType from BlockTypes Class Source: https://docs.allaymc.org/tutorials/block Retrieves BlockType instances using static fields from the BlockTypes class. This is a convenient way to access common block types like AIR or STONE without manual identifier lookup. It requires importing `BlockTypes` and `BlockType` from the Allay API. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.type.BlockType; import org.allaymc.api.block.behavior.BlockBehavior; public class Example { public void getFromBlockTypes() { BlockType air = BlockTypes.AIR; BlockType stone = BlockTypes.STONE; } } ``` -------------------------------- ### Configure Plugin Metadata (JSON) Source: https://docs.allaymc.org/tutorials/create-your-first-plugin Define the plugin's metadata in plugin.json, including name, entrance point, authors, version, API version, description, website, and dependencies. Fields like api_version and dependencies are optional. Version must follow semantic versioning; API and dependency versions support expressions like >=0.1.0. Outputs a valid config file for plugin loading. ```json { "name": "MyPlugin", "entrance": "your.group.name.myplugin.MyPlugin", "authors": ["yourname"], "version": "0.1.0", "api_version": ">=0.1.0", "description": "The description of your plugin", "website": "The website of your plugin", "dependencies": [ { "name": "AnotherPlugin1" }, { "name": "AnotherPlugin2", "version": ">=0.1.0", "optional": true } ] } ``` -------------------------------- ### Run Allay Server with Plugin (Shell) Source: https://docs.allaymc.org/tutorials/create-your-first-plugin Execute the Gradle task to run the Allay server directly from the project, loading the plugin. Requires AllayGradle plugin in build.gradle. No specific inputs; outputs a running server instance. Limitation: Only works if using JavaPluginTemplate or equivalent. ```shell ./gradlew runServer ``` -------------------------------- ### Build Plugin JAR (Shell) Source: https://docs.allaymc.org/tutorials/create-your-first-plugin Use Gradle to build a shadowed JAR file for the plugin. Depends on AllayGradle plugin. Outputs the JAR at build/libs/MyPlugin-1.0.0-shaded.jar, ready for copying to server's plugins directory. Version in filename matches plugin.json. ```shell ./gradlew shadowJar ``` -------------------------------- ### Create and Send a Simple Form - Java Source: https://docs.allaymc.org/tutorials/use-forms This snippet demonstrates how to create and send a simple form to a player when they join the server. It uses the AllayMC API to define the form's title and content. Requires the AllayMC API library. ```java import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.form.Forms; import org.allaymc.api.utils.TextFormat; public class MyEventListener { @EventHandler private void onPlayerJoin(PlayerJoinEvent event) { Forms.simple() .title(TextFormat.BLUE + "allay-chan") .content(TextFormat.GREEN + "Welcome to the server!") .sendTo(event.getPlayer()); } } ``` -------------------------------- ### Handle Command Execution in AllayMC Source: https://docs.allaymc.org/tutorials/register-commands Implements the command execution logic for the '/hello' command, sending a 'Hello World!' message to the sender. This involves overriding the prepareCommandTree method and defining an executor for the root command. ```java import org.allaymc.api.command.Command; import org.allaymc.api.command.tree.CommandTree; import org.allaymc.api.server.Server; public class HelloCommand extends Command { public HelloCommand() { super("hello", "Greets the command sender."); } @Override public void prepareCommandTree(CommandTree tree) { tree.getRoot() .exec(context -> { context.getSender().sendText("Hello World!"); return context.success(); }); } } ``` -------------------------------- ### Create BlockState from Legacy Format (Java) Source: https://docs.allaymc.org/tutorials/block Shows how to create BlockStates using the legacy format with BlockStateGetter. This method supports old ID and property names, converting them to the latest state representation. ```java import org.allaymc.api.block.state.BlockState; import org.allaymc.api.block.type.BlockStateGetter; public class Example { public void fromGetter() { // Legacy id+val format is supported since it will be updated to the latest state BlockState stone = BlockStateGetter.name("minecraft:stone").val(1).blockState(); // Similarly, old properties are supported BlockState anvil = BlockStateGetter.name("minecraft:anvil").property("damage", "very_damaged").blockState(); // This would return the default state of the block type BlockState pinkPetals = BlockStateGetter.name("minecraft:pink_petals").blockState(); } } ``` -------------------------------- ### Registering Components for Items in AllayMC (Java) Source: https://docs.allaymc.org/development/component-injection-system This code demonstrates how to register components for different item types using the AllayItemType builder. It shows how to add a main component and multiple additional components to an item, influencing its behavior. Dependencies include AllayItemType, ItemId, and specific component implementation classes. ```java ItemTypes.STICK = AllayItemType .builder(ItemStickStackImpl.class) .vanillaItem(ItemId.STICK) .addComponent(ItemStickBaseComponentImpl::new, ItemStickBaseComponentImpl.class) .addComponent(ItemSayHiComponentImpl::new, ItemSayHiComponentImpl.class) .build(); ItemTypes.CARROT_ON_A_STICK = AllayItemType .builder(ItemCarrotOnAStickStackImpl.class) .vanillaItem(ItemId.CARROT_ON_A_STICK) .addComponent(ItemSayHiComponentImpl::new, ItemSayHiComponentImpl.class) .build(); ``` -------------------------------- ### Create Block Instance at a Location (Java) Source: https://docs.allaymc.org/tutorials/block Explains how to create a Block instance, which encapsulates both the BlockState and its position within a Dimension. This is a prerequisite for modifying a block. ```java import org.allaymc.api.block.Block; import org.allaymc.api.world.Dimension; import org.joml.Vector3i; public class Example { public Block createBlockInstance(Dimension dimension, Vector3i pos) { // Captures state + position return new Block(dimension, pos); } } ``` -------------------------------- ### Create DebugSphere - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Shows how to instantiate a DebugSphere, defining its center, color, scale, and the number of segments for its approximation. This shape is a 3D spherical object. ```java DebugSphere debugSphere = new DebugSphere( new Vector3f(100, 64, 100), Color.CYAN, 1.0f, // Scale 20 // Segments ); ``` -------------------------------- ### Read BlockState at a Location (Java) Source: https://docs.allaymc.org/tutorials/block Demonstrates how to retrieve the BlockState of a block at specific coordinates (x, y, z) within a Dimension. It also shows how to specify a layer for reading. ```java import org.allaymc.api.world.Dimension; import org.joml.Vector3i; public class Example { public BlockState readAt(Dimension dimension, int x, int y, int z) { return dimension.getBlockState(x, y, z); } public BlockState readAtLayer1(Dimension dimension, Vector3i pos) { return dimension.getBlockState(pos, 1); } } ``` -------------------------------- ### Java Player Join Event Listener Source: https://docs.allaymc.org/tutorials/register-event-listeners Listens for player join events and broadcasts a welcome message. Requires AllayMC API imports for events and server communication. The annotated method must accept a single event parameter and return void. ```java import org.allaymc.api.entity.interfaces.EntityPlayer; import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.eventbus.event.player.PlayerJoinEvent; import org.allaymc.api.server.Server; import org.allaymc.api.utils.TextFormat; public class MyEventListener { @EventHandler private void onPlayerJoin(PlayerJoinEvent event) { Server.getInstance().getMessageChannel().broadcastText(TextFormat.YELLOW + "Welcome " + event.getPlayer().getDisplayName() + " to the server!"); } } ``` -------------------------------- ### Using List data types in PDC Java Source: https://docs.allaymc.org/tutorials/persistent-data-container Shows how to store and retrieve lists of data in a Persistent Data Container. Demonstrates both verbose and simplified methods for creating list data types. ```java // Storing a list of strings in a container by verbosely creating // a list data type wrapping the string data type. container.set( key, PersistentDataType.LIST.listTypeFrom(PersistentDataType.STRING), List.of("a", "list", "of", "strings") ); // Storing a list of strings in a container by using the api // provided pre-definitions of commonly used list types. container.set(key, PersistentDataType.LIST.strings(), List.of("a", "list", "of", "strings")); // Retrieving a list of strings from the container. List strings = container.get(key, PersistentDataType.LIST.strings()); ``` -------------------------------- ### Define a Basic AllayMC Command in Java Source: https://docs.allaymc.org/tutorials/register-commands Creates a simple command class that extends the AllayMC Command class. This defines the command's name and description. It's a fundamental step for any custom command. ```java import org.allaymc.api.command.Command; import org.allaymc.api.server.Server; public class HelloCommand extends Command { public HelloCommand() { super("hello", "Greets the command sender."); } } ``` -------------------------------- ### Extend ItemBaseComponentImpl for Item Functionality in Java Source: https://docs.allaymc.org/development/component-injection-system This Java code demonstrates extending the ItemBaseComponentImpl class to add custom functionality to an item. The constructor calls the superclass constructor, and the rightClickItemOn method is overridden to send a message to the player and then call the superclass's implementation, showcasing method overriding and interaction with player-related information. ```java import org.allaymc.api.block.dto.PlayerInteractInfo; import org.allaymc.api.item.ItemStackInitInfo; import org.allaymc.api.world.Dimension; import org.joml.Vector3ic; public class ItemStickBaseComponentImpl extends ItemBaseComponentImpl { public ItemStickBaseComponentImpl(ItemStackInitInfo initInfo) { super(initInfo); } @Override public void rightClickItemOn(Dimension dimension, Vector3ic placeBlockPos, PlayerInteractInfo interactInfo) { interactInfo.player().sendText("Hi from base component!"); super.rightClickItemOn(dimension, placeBlockPos, interactInfo); } } ``` -------------------------------- ### Copy BlockState Property Values (Java) Source: https://docs.allaymc.org/tutorials/block Illustrates how to copy property values from one BlockState to another of a similar type. This is useful when you want to maintain the same properties across different but related block types. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.state.BlockState; public class Example { public void copy() { BlockState door = BlockTypes.OAK_DOOR.getDefaultState(); // Copy property values from another similar block state (if they have the same property types) BlockState darkDoor = BlockTypes.DARK_OAK_DOOR.copyPropertyValuesFrom(door); } } ``` -------------------------------- ### Add Optional Parameter to AllayMC Command Source: https://docs.allaymc.org/tutorials/register-commands Enhances the '/hello' command to accept an optional message parameter. If a message is provided, it's sent to the sender; otherwise, the default 'Hello World!' message is used. This demonstrates using the 'msg' parameter type and .optional() modifier. ```java import org.allaymc.api.command.Command; import org.allaymc.api.command.tree.CommandTree; import org.allaymc.api.server.Server; public class HelloCommand extends Command { public HelloCommand() { super("hello", "Greets the command sender."); } @Override public void prepareCommandTree(CommandTree tree) { tree.getRoot() .msg("message") .optional() .exec(context -> { String message = context.getResult(0); if (message.isBlank()) { context.getSender().sendText("Hello World!"); } else { context.getSender().sendText(message); } return context.success(); }); } } ``` -------------------------------- ### Creating nested PDC in Java Source: https://docs.allaymc.org/tutorials/persistent-data-container Illustrates how to create and use nested PersistentDataContainers. Useful for organizing complex data structures within a single container. ```java // Get the existing container PersistentDataContainer container = ...; // Create a new container PersistentDataContainer newContainer = container.getAdapterContext().newPersistentDataContainer(); ``` -------------------------------- ### Apply Color Codes using Allay TextFormat API in Java Source: https://docs.allaymc.org/advanced/use-color-codes This snippet shows how to create colored text by importing the TextFormat utility and concatenating its constants. It requires the Allay API library and ensures the text reset constant is appended to avoid lingering formatting. The output is a string that can be displayed in-game with the specified color. ```Java import org.allaymc.api.utils.TextFormat; var myBeautifulText = "This is " + TextFormat.DARK_GREEN + "dark green." + TextFormat.RESET; ``` -------------------------------- ### Adding data to PDC in Java Source: https://docs.allaymc.org/tutorials/persistent-data-container Demonstrates how to store custom data in a Persistent Data Container using an Identifier and PersistentDataType. Requires an ItemStack implementing PersistentDataHolder and a key-value pair to store. ```java import org.allaymc.api.item.type.ItemTypes; import org.allaymc.api.pdc.PersistentDataType; import org.allaymc.api.utils.identifier.Identifier; public class Example { public void example() { // Create an Identifier var key = new Identifier("allaymc", "example-key"); // ItemStack implements PersistentDataHolder, so we can get the PDC from it var itemStack = ItemTypes.DIAMOND.createItemStack(); itemStack.getPersistentDataContainer().set(key, PersistentDataType.STRING, "I love AllayMC"); } } ``` -------------------------------- ### Create DebugCircle - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Demonstrates the creation of a DebugCircle, specifying its center position, color, scale, and the number of segments used to render it. This shape is a flat circle in 3D space. ```java DebugCircle debugCircle = new DebugCircle( new Vector3f(100, 64, 100), Color.MAGENTA, 2.0f, // Scale 30 // Segments ); ``` -------------------------------- ### Schedule Repeating Popup Message for Online Players (Java) Source: https://docs.allaymc.org/tutorials/schedule-tasks Schedules a recurring task to send a 'Hi!' popup message to all online players every second. This uses the server scheduler for global execution. It requires the AllayMC API and assumes a basic plugin structure. ```java import org.allaymc.api.plugin.Plugin; import org.allaymc.api.server.Server; public class MyPlugin extends Plugin { @Override public void onEnable() { Server.getInstance().getScheduler().scheduleRepeating(this, () -> { Server.getInstance().getOnlinePlayers().values().forEach(player -> player.sendPopup("Hi!")); return true; }, 20); } } ``` -------------------------------- ### Add Member Permissions to an AllayMC Command Source: https://docs.allaymc.org/tutorials/register-commands Modifies the HelloCommand to grant 'MEMBER' permissions, allowing all players to use it by default. This is done within the command's constructor by iterating through default permissions and adding them to the MEMBER group. ```java import org.allaymc.api.command.Command; import org.allaymc.api.command.tree.CommandTree; import org.allaymc.api.permission.PermissionGroups; import org.allaymc.api.server.Server; public class HelloCommand extends Command { public HelloCommand() { super("hello", "Greets the command sender."); getPermissions().forEach(PermissionGroups.MEMBER::addPermission); } } ``` -------------------------------- ### Modify BlockState Property: Set Facing to North (Java) Source: https://docs.allaymc.org/tutorials/block This Java code snippet demonstrates how to read a BlockState, check its type, modify a specific property (facing direction), and then write the updated BlockState back to the world. It utilizes the AllayMC API for block and world interactions. Dependencies include necessary AllayMC API imports. ```java import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.state.BlockState; import org.allaymc.api.block.property.BlockPropertyTypes; import org.allaymc.api.world.Dimension; import org.allaymc.api.block.property.MinecraftCardinalDirection; public class Example { public void setFacingToNorth(Dimension dimension, int x, int y, int z) { BlockState current = dimension.getBlockState(x, y, z, 0); if (current.getBlockType() == BlockTypes.OAK_DOOR) { BlockState updated = current.setPropertyValue(BlockPropertyTypes.MINECRAFT_CARDINAL_DIRECTION, MinecraftCardinalDirection.NORTH); dimension.setBlockState(x, y, z, updated); } } } ``` -------------------------------- ### Register an AllayMC Command in a Plugin Source: https://docs.allaymc.org/tutorials/register-commands Registers a custom command with the AllayMC server during the plugin's enable phase. This involves extending the Plugin class and using the Registries.COMMANDS.register() method. Ensure the HelloCommand class is accessible. ```java import org.allaymc.api.plugin.Plugin; import org.allaymc.api.registry.Registries; public class MyPlugin extends Plugin { @Override public void onEnable() { Registries.COMMANDS.register(new HelloCommand()); } } ``` -------------------------------- ### Define ItemComponent with @Identifier and @EventHandler in Java Source: https://docs.allaymc.org/development/component-injection-system This Java code defines a custom item component implementing the ItemComponent interface. It uses an @Identifier.Component annotation to define a unique identifier and an @EventHandler to listen for CItemBreakBlockEvent, demonstrating basic event handling and dependency injection of the owning ItemStack via @ComponentObject. ```java import org.allaymc.api.eventbus.EventHandler; import org.allaymc.api.item.ItemStack; import org.allaymc.api.item.component.ItemComponent; import org.allaymc.api.utils.identifier.Identifier; import org.allaymc.server.component.annotation.ComponentObject; import org.allaymc.server.item.component.event.CItemBreakBlockEvent; public class ItemSayHiComponentImpl implements ItemComponent { @Identifier.Component public static final Identifier IDENTIFIER = new Identifier("my:say_hi_component"); @ComponentObject private ItemStack thisItem; @EventHandler public void onItemSayHi(CItemBreakBlockEvent event) { System.out.println("Hi from ItemSayHiComponent(" + thisItem.getItemType().getIdentifier() + ")!"); } } ``` -------------------------------- ### Schedule Repeating Block Information Popup Per World (Java) Source: https://docs.allaymc.org/tutorials/schedule-tasks Schedules a recurring task for each world to send players a popup displaying the identifier of the block they are standing on. This utilizes the world scheduler for performance optimization in world-specific operations. It depends on the AllayMC API. ```java import org.allaymc.api.plugin.Plugin; import org.allaymc.api.server.Server; public class MyPlugin extends Plugin { @Override public void onEnable() { Server.getInstance().getWorldPool().getWorlds().values().forEach(world -> { world.getScheduler().scheduleRepeating(this, () -> { world.getPlayers().forEach(player -> player.sendPopup(player.getBlockStateStandingOn().getBlockType().getIdentifier().toString())); return true; }, 20); }); } } ``` -------------------------------- ### Default Identifier for ItemBaseComponentImpl in Java Source: https://docs.allaymc.org/development/component-injection-system This Java code snippet shows the definition of the ItemBaseComponentImpl class, which implements the ItemBaseComponent interface. It highlights the use of the @Identifier.Component annotation to define a static final Identifier for the base component, which is automatically provided when extending this class. ```java import org.allaymc.api.item.component.ItemBaseComponent; import org.allaymc.api.utils.identifier.Identifier; public class ItemBaseComponentImpl implements ItemBaseComponent { @Identifier.Component public static final Identifier IDENTIFIER = new Identifier("minecraft:item_base_component"); } ``` -------------------------------- ### Add Viewer to Debug Shape - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Illustrates how to make a debug shape visible to a specific player by adding them as a viewer. This controls who can see the debug visualization. ```java // Add a viewer to the debug shape debugBox.addViewer(player); ``` -------------------------------- ### Add Debug Box Shape - Java Source: https://docs.allaymc.org/tutorials/use-debug-shapes Demonstrates how to create and add a DebugBox to a dimension using the Dimension interface. Requires Vector3f and Color. The shape is sent to players joining the dimension and removed upon departure. ```java DebugBox debugBox = new DebugBox( new Vector3f(100, 64, 100), // Position Color.RED, // Color 1.0f, // Scale new Vector3f(2, 2, 2) // Box bounds ); // Add the debug shape to the dimension dimension.addDebugShape(debugBox); ```