Code Monkey home page Code Monkey logo

hologram-lib's Introduction

Note

New update: 3.1.0: Reactive holograms. Scroll down for more information.

HoloEasy is a simple, modern and high-performant Java and Kotlin Minecraft Hologram library for 1.8-1.20.4 servers.

holoeasy video

Quickstart

Requirements

  • ProtocolLib installed on your server

Add dependency

Maven

<dependency>
    <groupId>com.github.unldenis</groupId>
    <artifactId>holoeasy</artifactId>
    <version>3.1.1</version>
</dependency>

Gradle

implementation("com.github.unldenis:holoeasy:3.1.1")

Make sure you include the repository as well.

Start programming

Java

import static org.holoeasy.builder.HologramBuilder.*;

// you can use a Pool or a org.bukkit.Plugin for HologramKey
IHologramPool pool = HoloEasy.startInteractivePool(plugin, 60, 0.5f, 5f);

public void addHologram(Location location) {
    hologram(new HologramKey(pool, "unique-id-holo"), location, () -> {
        textline("Hello");
        textline("Score {} - {}", 0, 1);
        clickable("Click me").onClick(p -> {
            p.sendTitle(ChatColor.AQUA + "Hi", ChatColor.BOLD + "by HoloEasy",
                    20, 20, 20);
        });
        item(new ItemStack(Material.ENCHANTED_GOLDEN_APPLE));
    });
}

Kotlin

import org.holoeasy.builder.HologramBuilder.*

// you can use a Pool or a org.bukkit.Plugin for HologramKey
val pool = startInteractivePool(plugin, 60.0, 0.5f, 5f)

fun addHologram(location: Location) {
    hologram(HologramKey(pool, "unique-id-holo"), location) {
        textline("Hello")
        textline("Score {} - {}", 0, 1)
        clickable("Click me").onClick {
            it.sendTitle(ChatColor.AQUA + "Hi", ChatColor.BOLD + "by HoloEasy",
                20, 20, 20)
        }
        item(ItemStack(Material.ENCHANTED_GOLDEN_APPLE))
    }
}

Reactive Holograms

From 3.1.0 version, the parameters of text lines and item lines can also be reactive. This means that you can update the line by simply calling the 'set' method to these.

holoeasy state video

Warning

Mutable states have no player information at this time. If you need to create a hologram for a specific player, it is recommended that you do not add it to a Pool.

Java

var clickCount = mutableStateOf(0); // can be any type

var holo = hologram(new HologramKey(plugin, "unique-id-holo"), location, () -> {
    textline("{}!", "Static");
    textline("Count: {}", clickCount);
    clickable("Click me", 0.5f, 5f).onClick($ -> clickCount.set(clickCount.get() + 1));
});

// It hasn't been added to a pool, so it's up to us to make it visible and hide it from players. It's better to use a pool because it's automatic and performs asynchronous operations.
// HologramKey decides whether to add it to a pool or not.
holo.show(player);

Kotlin

val clickCount = mutableStateOf(0) // can be any type

val holo = hologram(HologramKey(plugin, "unique-id-holo"), location) {
    textline("{}!", "Static")
    textline("Count: {}", clickCount)
    clickable("Click me", 0.5f, 5f).onClick { clickCount.set(clickCount.get() + 1)}
}

// It hasn't been added to a pool, so it's up to us to make it visible and hide it from players. It's better to use a pool because it's automatic and performs asynchronous operations.
// HologramKey decides whether to add it to a pool or not.
holo.show(player)

Ex (Hologram-Lib)

Are you using a version older than 3.0.0? You can find the documentation here.

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.