### Implement VaultUnlocked Services in Java Source: https://github.com/theneweconomy/vaultunlockedapi/blob/master/README.md This Java code demonstrates how to obtain and use VaultUnlocked services like Economy, Permission, and Chat within a Bukkit plugin. It shows the setup process in `onEnable` and command handling for economy and permission checks. ```java package com.example.plugin; import java.math.BigDecimal; import java.util.logging.Logger; import net.milkbowl.vault2.chat.Chat; import net.milkbowl.vault2.economy.Economy; import net.milkbowl.vault2.economy.EconomyResponse; import net.milkbowl.vault2.permission.Permission; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; public class ExamplePlugin extends JavaPlugin { private static Economy econ = null; private static Permission perms = null; private static Chat chat = null; @Override public void onDisable() { getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion())); } @Override public void onEnable() { if (!setupEconomy()) { getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName())); getServer().getPluginManager().disablePlugin(this); return; } setupPermissions(); setupChat(); } private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) { return false; } RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } econ = rsp.getProvider(); return econ != null; } private boolean setupChat() { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Chat.class); if (rsp == null) { return false; } chat = rsp.getProvider(); return chat != null; } private boolean setupPermissions() { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Permission.class); if (rsp == null) { return false; } perms = rsp.getProvider(); return perms != null; } public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { if(!(sender instanceof Player)) { getLogger().info("Only players are supported for this Example Plugin, but you should not do this!!!"); return true; } Player player = (Player) sender; if(command.getLabel().equals("test-economy")) { // Lets give the player 1.05 currency (note that SOME economic plugins require rounding!) sender.sendMessage(String.format("You have %s", econ.format(econ.getBalance(player.getUniqueId())))); EconomyResponse r = econ.depositPlayer(player.getUniqueId(), new BigDecimal("1.05")); if(r.transactionSuccess()) { sender.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance))); } else { sender.sendMessage(String.format("An error occured: %s", r.errorMessage)); } return true; } else if(command.getLabel().equals("test-permission")) { // Lets test if user has the node "example.plugin.awesome" to determine if they are awesome or just suck if(perms.has(player, "example.plugin.awesome")) { sender.sendMessage("You are awesome!"); } else { sender.sendMessage("You suck!"); } return true; } else { return false; } } public static Economy getEconomy() { return econ; } public static Permission getPermissions() { return perms; } public static Chat getChat() { return chat; } } ``` -------------------------------- ### Include VaultUnlockedAPI with Gradle Source: https://github.com/theneweconomy/vaultunlockedapi/blob/master/README.md This snippet demonstrates how to include the VaultUnlockedAPI in your Gradle project. It configures the required Maven repository and adds the API as a compileOnly dependency. ```groovy repositories { maven { url 'https://repo.codemc.org/repository/maven-public' } } dependencies { compileOnly "net.milkbowl.vault:VaultUnlockedAPI:2.11" } ``` -------------------------------- ### Include VaultUnlockedAPI with Maven Source: https://github.com/theneweconomy/vaultunlockedapi/blob/master/README.md This snippet shows how to add the VaultUnlockedAPI as a dependency in your Maven project. It includes the necessary repository configuration and the dependency declaration, specifying the artifact and version. ```xml codemc-repo https://repo.codemc.org/repository/maven-public net.milkbowl.vault VaultUnlockedAPI 2.11 provided ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.