Page tree
Skip to end of metadata
Go to start of metadata

ViaVersion provides an API for developers, this page will show you some basic usage.

Javadocs: https://jd.viaversion.com

French Tutorial: https://www.youtube.com/watch?v=rbVPZewRmbY

Deprecated!

The old API is deprecated from 1.0.0, please use the new API.

 

What changed?

We focused for the 1.0.0 release at making ViaVersion multiplatform compatible. This also meant we had to change the way ViaVersion and the api worked,

 

The class ViaVersion is deprecated, by usages like ViaVersion.getInstance() use Via.getAPI() intead.

Maven

ViaVersion provides a Maven repository that you can use to implement the ViaVersion API inside your project.

Repository:
ViaVersion Maven repository
<repository>
    <id>viaversion-repo</id>
    <url>https://repo.viaversion.com</url>
</repository>

 

Dependency:
ViaVersion Maven dependency
<dependency>
    <groupId>us.myles</groupId>
    <artifactId>viaversion</artifactId>
    <version>LATEST</version>
</dependency>

Get the players protocol version

You can get the protocol version from a player, List with all the Minecraft versions + protocol numbers (http://wiki.vg/Protocol_version_numbers)

ViaAPI api = Via.getAPI(); // Get the API
int version = api.getPlayerVersion(player); // Get the protocol version

BossBar API

Mojang introduced new bossbars in Minecraft 1.9

ViaVersion provides an API for developers to use the new BossBar for 1.9 players and higher.

 

Example BossBar usage:

BossBarExample.java
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.ViaVersionAPI;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;

public class BossBarExample extends JavaPlugin implements Listener {
    private BossBar bossBar;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this); // Register Bukkit events

        ViaAPI api = Via.getAPI(); // Get the API
        bossBar = api.createBossBar(
                "Hi! This BossBar is created using the ViaVersion API!", // BossBar title
                1F, // Boss health (Float between 0 and 1)
                BossColor.BLUE,  // BossBar color
                BossStyle.SOLID); // BossBar Style
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
		// When we added the BossBar, we supported addPlayer with a Player object, that is deprecated since 1.0.0. 
		// Get the player UUID instead.
        bossBar.addPlayer(e.getPlayer().getUniqueId()); // Show the BossBar when a player joins 
    }
}
Preview:

 

Side note

Our API will not give 1.8 players a BossBar for the people that use 1.8-1.8.8.

Spigot provides an API for everyone that uses Spigot 1.9 and higher. We recommend you to use that one if you are using Spigot 1.9 or higher.