Giter Club home page Giter Club logo

adventure's Introduction

adventure License build

A serverside user interface library for Minecraft.

Artifacts

There are various artifacts:

  • adventure-api is the core project - you will always want to import this.
  • adventure-text-serializer-gson is a GSON-based JSON serializer.
  • adventure-text-serializer-legacy is a legacy character text serializer.
  • adventure-text-serializer-plain is a plain text serializer.

Importing text into your project

  • Maven
<dependency>
  <groupId>net.kyori</groupId>
  <artifactId>adventure-api</artifactId>
  <version>4.0.0-SNAPSHOT</version>
</dependency>
  • Gradle
repositories {
  mavenCentral()
}

dependencies {
  compile 'net.kyori:adventure-api:4.0.0-SNAPSHOT'
}

Example usage

Creating components

// Creates a line of text saying "You're a Bunny! Press <key> to jump!", with some colouring and styling.
final TextComponent textComponent = TextComponent.of("You're a ")
  .color(NamedTextColor.GRAY)
  .append(TextComponent.of("Bunny").color(NamedTextColor.LIGHT_PURPLE))
  .append(TextComponent.of("! Press "))
  .append(
    KeybindComponent.of("key.jump")
      .color(NamedTextColor.LIGHT_PURPLE)
      .decoration(TextDecoration.BOLD, true)
  )
  .append(TextComponent.of(" to jump!"));
// now you can send `textComponent` to something, such as a client

You can also use a builder, which is mutable, and creates one final component with the children.

// Creates a line of text saying "You're a Bunny! Press <key> to jump!", with some colouring and styling.
final TextComponent textComponent2 = TextComponent.builder().content("You're a ")
  .color(NamedTextColor.GRAY)
  .append(TextComponent.builder("Bunny").color(NamedTextColor.LIGHT_PURPLE).build())
  .append(TextComponent.of("! Press "))
  .append(
    KeybindComponent.builder("key.jump")
      .color(NamedTextColor.LIGHT_PURPLE)
      .decoration(TextDecoration.BOLD, true)
      .build()
  )
  .append(TextComponent.of(" to jump!"))
  .build();
// now you can send `textComponent2` to something, such as a client

Serializing and deserializing components

Serialization to JSON, legacy and plain representations is also supported.

// Creates a text component
final TextComponent textComponent = TextComponent.of("Hello ")
  .color(NamedTextColor.GOLD)
  .append(
    TextComponent.of("world")
      .color(NamedTextColor.AQUA).
      decoration(TextDecoration.BOLD, true)
  )
  .append(TextComponent.of("!").color(NamedTextColor.RED));

// Converts textComponent to the JSON form used for serialization by Minecraft.
String json = GsonComponentSerializer.INSTANCE.serialize(textComponent);

// Converts textComponent to a legacy string - "&6Hello &b&lworld&c!"
String legacy = LegacyComponentSerializer.legacy().serialize(textComponent, '&');

// Converts textComponent to a plain string - "Hello world!"
String plain = PlainComponentSerializer.INSTANCE.serialize(textComponent);

The same is of course also possible in reverse for deserialization.

// Converts JSON in the form used for serialization by Minecraft to a Component
Component component = GsonComponentSerializer.INSTANCE.deserialize(json);

// Converts a legacy string (using formatting codes) to a TextComponent
TextComponent component = LegacyComponentSerializer.legacy().deserialize("&6Hello &b&lworld&c!", '&');

// Converts a plain string to a TextComponent
TextComponent component = PlainComponentSerializer.INSTANCE.deserialize("Hello world!");

Using components within your application

The way you use components within your application will of course vary depending on what you're aiming to achieve.

However, the most common task is likely to be sending a component to some sort of Minecraft client. The method for doing this will depend on the platform your program is running on, however it is likely to involve serializing the component to Minecraft's JSON format, and then sending the JSON through another method provided by the platform.

The text library is platform agnostic and therefore doesn't provide any way to send components to clients. However, some platform adapters (which make this easy!) can be found in the adventure-platform project.

adventure's People

Contributors

andre601 avatar astei avatar dependabot[bot] avatar draycia avatar electroid avatar itsaphel avatar kashike avatar kennytv avatar liach avatar lucko avatar zml2008 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.