Giter VIP home page Giter VIP logo

vaultapi's Introduction

VaultAPI - Abstraction Library API for Bukkit Plugins -

How to include the API with Maven:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.github.MilkBowl</groupId>
        <artifactId>VaultAPI</artifactId>
        <version>1.7</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

How to include the API with Gradle:

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compileOnly "com.github.MilkBowl:VaultAPI:1.7"
}

Note: The VaultAPI version has 2 numbers (major.minor), unlike Vault, which has 3. The 2 numbers in the VaultAPI will always correspond to the 2 beginning numbers in a Vault version to make it clear what versions your plugin will for sure work with.

Why Vault?

I have no preference which library suits your plugin and development efforts best. Really, I thought a central suite (rather...Vault) of solutions was the the proper avenue than focusing on a single category of plugin. That's where the idea for Vault came into play.

So, what features do I think you'll like the most?

  • No need to include my source code in your plugin
  • Broad range of supported plugins
  • Choice!

License

Copyright (C) 2011-2018 Morgan Humes [email protected]

Vault is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Vault is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Vault. If not, see http://www.gnu.org/licenses/.

Building

VaultAPI comes with all libraries needed to build from the current branch.

Implementing Vault

Implementing Vault is quite simple. It requires getting the Economy, Permission, or Chat service from the Bukkit ServiceManager. See the example below:

package com.example.plugin;

import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.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<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }
    
    private boolean setupChat() {
        RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
        chat = rsp.getProvider();
        return chat != null;
    }
    
    private boolean setupPermissions() {
        RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
        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.getName()))));
            EconomyResponse r = econ.depositPlayer(player, 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;
    }
}

vaultapi's People

Contributors

2008choco avatar creatorfromhell avatar dependabot[bot] avatar donotspampls avatar geolykt avatar hintss avatar mung3r avatar rubyhale avatar sleaker avatar stuntguy3000 avatar sxtanna avatar sycholic avatar yannicklamprecht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vaultapi's Issues

1.11 support

Hello.
Would be nice if you updated this plugin to 1.11.
Thanks.

My plugin won't find Vault

I've added the depend value in plugin.yml, i've added all the methods and fields needed. But my plugin still does not find Vault. I can see my plugin loading after Vault is loaded and working. What could be wrong?

Unable to hook into vault at all.

I'm using the maven repo on the front page, and the exact code you're using. I keep getting:

[15:34:44 INFO]: [PlugMan] Metrics started: http://mcstats.org/plugin/PlugMan
[15:34:44 INFO]: [Vault] Checking for Updates ...
[15:34:44 INFO]: [PlugMan] No update was found.
[15:34:44 INFO]: [Vault] Stable Version: 1.5.6 | Current Version: 1.6.6
[15:34:44 ERROR]: [FiberChat] [FiberChat] - Disabled due to no Vault dependency found!
[15:34:44 INFO]: [FiberChat] Disabling FiberChat v0.0.1

[Vault] Stable Version: 1.5.6 | Current Version: 1.6.6.

set money?

I couldnt find a method to set the money of a player. Am I blind?

Add methods that support BigDecimals

Changing the current ones would likely break some plugins, so instead, could it be that new methods are added to the API that support BigDecimals?

API Version in readme

Hi,

I noticed the latest version of the plugin is 1.7.1 and the latest API version in the Maven repository is 1.7.

In the readme, the version is listed as 1.6. Is 1.7 not supported yet, or has this just been overlooked in updating?

Thanks. :)

Maven issues?

"The import net.milkbowl cannot be resolved"

I have switched to the maven repo below, while previously using @TheE repo. I see that VaultAPI-1.6.jar is in my Maven Dependencies folder inside Eclipse, but I am unable to import anything from it.

    <repositories>
        <repository>
            <id>vault-repo</id>
            <url>http://nexus.hc.to/content/repositories/pub_releases</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>net.milkbowl.vault</groupId>
            <artifactId>VaultAPI</artifactId>
            <version>1.6</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Execute code when a player pays?

Hello.
How can I handle a pay event, for example, let's say than a players pays for something, how can I detect that the player has paid something? And for winning money?

Java 8 problem with Vault as dependency

Hi, we were making one plugin which would take forge mod (items + accounts) and connect them to the Vault Economy system, which is working,but only in Java 7, not in Java 8. With Java 8 there are unresolved compilation errors with Vault.
Can you look, if you won't get any idea WHY or WHAT can do it?

Java 7:

  • Plugin loads, and other plugins can use its economy thingies via Vault (used latest Vault and it worked well)

Java 8:
Same error with Vault 1.4.1 and Vault 1.5.6 (we use Minecraft 1.7.10 for this, so that's why we tried 1.4 version of Vault, but then other plugins do not work with Economy support via Vault)
http://pastebin.com/2QYNh7TP

We used to compile the plugin with Java 8 in all scenarios, and everytime succesfully, it only refuses to work on server with Java 8.

Is there anything that would break Vault usage on Java 8? Because other things (and vault itself) is running regardless if Java 7 or 8 ....

Thanks for any help or hint.

Vault krincraft repository gone

The krincraft repository (whatever it is) is all gone, could you do everyone a favor and remove it from your repositories in pom?

Repository is offline

As of writing the repository (http://nexus.theyeticave.net/content/repositories/pub_releases) is offline; could you fix this?

Also, have you thought about deploying VaultAPI to Bintray or any other official MavenNexus? This way we would not need to depend on any privately hosted repository.

Banner ItemStack name

Hey,

Seems that when I have an ItemStack of the banneritem and I try to get the name of it, it errors.

Code:
public String getItemname(ItemStack auctionitem){
String s = null;
Bukkit.broadcastMessage("0");
Bukkit.broadcastMessage(Items.itemByStack(auctionitem).getName());

Seems to only be messaging the 0, and stops afterwards. Other items do work, so I think the list is just missing the item banner.

Thanks in advance,

Darthmineboy

VaultAPI not removing permissions.

Hello, I am developing plugin in which part is function which removes or adds permissions based on gamemode switching. The problem is with removing, because permissions which were set before for example in PermissionsEx are not being removed. Code which I use:
public static void removePermission(Player player, String permissionnode) { permission.playerRemove(player,permissionnode); }

Of course I have previously initialized the VaultAPI using the setup etc.

Event System

At first glance at the API, there does not appear to be a means to trigger an event when something happens via Vault, such as a permission change, or an economy balance transfer. Would it be possible for something like this to be added in? I've a plugin that displays a player's balance to them, via polling, and it would be a lot more efficient to only run calls on actual data changes.

Waring using double !

Hello,

I just tried to do a economy plugin based on the VaultAPI but I saw that the operations done on accounts are with doubles. That's not good !
For example (in Java) this code :

double d = 0;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
d += 0.1;
System.out.println(d);

Shows : 0.9999999999999999
As we know, it should be 1.0 !

I don't think it's good in any economy plugin to lose some money just because of that.

To avoid those "loses" we need to change the interface Economy to use BigDecimal instead of double. Here's the same example but with BigDecimal :

BigDecimal bg = BigDecimal.ZERO;
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
bg = bg.add(new BigDecimal("0.1"));
System.out.println(bg.toString());

And it shows : 1.0

I hope someone will change that.

Best regards, Zayceur

Not all brewable potions IDs have valid ItemInfo

I discovered this when a Vault API call ( Items.itemByStack(ItemStack itemStack) ) was failing to recognise some splash potions of slowness but not others.

The issue is that sometimes potions with the exact same effect can have different IDs. This includes both brewable and non-brewable potions.

This information taken from the minecraft wiki helps explain the issue:

Bits 13 and 14 (8192 and 16384) determines whether the potion is a drinkable potion or a splash potion. If bit 13 is true, it's drinkable. If 14 is true, it's a splash potion.
Bits 7-12 and 15 are ignored, so many potions with distinct data values will have the same properties.

Any potion that has bits 7-12 or bit 15 of the potion's damage value set as 1 will not be recognised by the api (I am not sure if this is possible to brew) . In addition, it seems that when brewing any splash potion, the potion will only have the ID that you recognise if the gunpowder was added last. If any other ingredient (usually a fermented spider eye) is added after the gunpowder then both bits 13 and 14 will be set to true. Since the API's hardcoded values assume that bit 13 is false for splash potions (and it isn't always true with vanilla mechanics), the API fails to recognise some valid potions.

An example:
water bottle + netherwart + sugar + fermented spider eye + gunpowder yields a Splash Potion of Slowness (potion:16394)

However

water bottle + netherwart + sugar + gunpowder + fermented spider eye yields a functionally identical Splash Potion of Slowness but with a different damage value (potion:24586)

I can kind of understand why non-brewable (but obtainable via commands) items like potion of saturation aren't on your list. However, it seems that if potion's ItemInfo was generated by reading the data value to determine the potion type rather than hardcoding the data value for every possible potion type, you could support all brewable potions and as side effect also support non-brewable ones.

How TF you get maven to work

I am using maven to build my plugins and I want my core plugin to hook to my Nexus OSS. However I cannot find any guide and you clearly have it working. How did you achieve this???

[Feature Request] Choosing Hooks

Hello,

Would it be possible to add a feature where we would be able to choose which plugin takes priority to hook into Vault? For example, let's say I have 2 economy plugins installed which both support Vault, PlayerPoints and EssentialsEco. With a command (e.x /vault priority economy {Plugin}), I am able to choose which plugin will hook into Vault first, which pretty much means which plugin will be used for economy through Vault.

Thanks for your time,
John

Why ignore intangible materials?

In reference to: https://github.com/MilkBowl/VaultAPI/blob/master/src/test/java/net/milkbowl/vault/test/ItemTest.java#L19

Why does the API even bother ignoring these? This seems like unnecessary overhead and has created a problem for one of my users, PikaMug/Quests#282, which I will now describe:

A quest to break a few blocks of REDSTONE_ORE is made. However, hitting REDSTONE_ORE turns it into GLOWING_REDSTONE_ORE. When the ore finally breaks, the GLOWING_REDSTONE_ORE is ignored and results in a NullPointerException via itemByType()

Recaptcha netbeans and maven

Looks like your maven repo is behind recaptcha "protection". So i (and others) can't reach it from IDE.
Can you please do something with it?

Failed to read artifact descriptor for net.milkbowl.vault:VaultAPI:jar:1.6: Could not transfer artifact net.milkbowl.vault:VaultAPI:pom:1.6 from/to vault-repo (http://nexus.hc.to/content/repositories/pub_releases): Access denied to: http://nexus.hc.to/content/repositories/pub_releases/net/milkbowl/vault/VaultAPI/1.6/VaultAPI-1.6.pom , ReasonPhrase:Forbidden. -> [Help 1]

Crashes Plot2

i couldn't figure out what was breaking plot2 and the dev's insisted it wasn't them so i one by one added back every plugin having EssentialsX, Luck Perms, World Edit beta5, and Plot2 as the base doing a server start after each and watching if plot2 enabled. When i went and added vault (I NEED THIS) plot2 enabled but crashed and stopped working. It seems there's some compatibility issue.

Im using spigot1.13.2 the latest version of P2 and Vault

Thank you i appreciate you taking the time to read this and hope its fixed soon! <3

Everything deprecated??

Everything that I have tried (depositing) are all deprecated. Is there something else i should use?

Accessing vault methods doesn't work?

This worked in vault 1.4 and now won't work in vault 1.5. The tutorial states that this way should work too, but for some reason it doesn't.
This is my main class:
http://pastie.org/private/xkhxm9zn7mgstsggispa
As you can see all setup for vault has been done, as I only need the permissions part.
Now writing permission.[any vault method] just gives me an error.
Doing it in the main class or any other class has the same effect.

Aternos

I am needing help with my aternos server, I downloaded vault for my aternos server, but when I go in game, I cannot do anything with vault, can you please help me!

Enhancement: Add a getPlayerPermissions

Would it be possible for someone to add a getPlayerPermissions(Player, World)/getPlayerPermissions(Player) method. ie. when called it returns a Set containing all of a players permissions.

Bad Gateway

It seems like Vault can't be used as dependency at the moment, because http://nexus.hc.to/ reponds with a 502. Is this a temporary problem?

Vault returning no ranks when using Group Manager

So it would appear that Vault is not working with Group Manager. After some quick debug I quickly discovered that no ranks were being returned by Vault when trying to fetch a user's ranks. If I use the the whois command in Group Manager it does show that the user has a rank. Would really appreciate it if you could fix this because a lot of Enjin user's still rely on Group Manager (as much as I dislike) and it's causing a lot of users to think Enjin plugin is broken.

Add Bungeecord support

In this day and age a lot of general management plugins run on Bungeecord too. Especially permissions plugins, chat plugins and ban plugins are often seen running on BungeeCord networks with no common API for use of other plugins. Vault managed to provide this for Bukkit in the past, it would just feel right to also have a familiar for Bungee too.

Mark the commits of released versions with git tags

Could you mark the commits of each released API version with a git tag equal to that version, e.g. commit 5b8dc3a with the tag v1.7?

This would allow usage of tools such as JitPack to build against VaultAPI without having to build against a commit hash. You could even replace your currently offline repository (#69) with JitPack this way without having to setup and configure any infrastructure by yourself.

I would submit a PR, but unfortunately, git tags cannot be parts of PRs.

Repo offline?

Hi,

I am receiving a connection issue. Is this a server issue?

nexus.hc.to is offline.

Maven can't connect to nexus.hc.to due to server refusing connection.

Downloading: http://nexus.hc.to/content/repositories/pub_releases/org/spigotmc/spigot-api/1.13-R0.1-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT/maven-metadata.xml from/to vault-repo (http://nexus.hc.to/content/repositories/pub_releases): Connect to nexus.hc.to:80 [nexus.hc.to/142.44.143.127] failed: Connection refused: connect
...
[WARNING] Failure to transfer com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT/maven-metadata.xml from http://nexus.hc.to/content/repositories/pub_releases was cached in the local repository, resolution will not be reattempted until the update interval of vault-repo has elapsed or updates are forced. Original error: Could not transfer metadata com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT/maven-metadata.xml from/to vault-repo (http://nexus.hc.to/content/repositories/pub_releases): Connect to nexus.hc.to:80 [nexus.hc.to/142.44.143.127] failed: Connection refused: connect

Browser can't connect to the server too. What happened, @Sleaker?

Strict interfaces

Hello again, I'm rewriting my rscPermissions and going to add 100% Vault support thought your new API.
I have a problem that it is hard to check which methods of Chat / Permission are deprecated and I should not implement them.
Can you extract other interface, for example StrictChat / StrictPermission containing only abstract non-deprecated method definitions (which are really implemented in Chat/Permission)?
This will be helpful for developers: inheriting their implementations from Strict* interfaces, implementing abstract methods, and after that just reinheric normal interface.

Add UUID support

Currently methods only take in the player's name or an OfflinePlayer object. They should also support direct player UUIDs so that the plugin itself can decide what to do with it. This is important as getting an OfflinePlayer might be more time consuming than passing in the UUID (or even the player's name which shouldn't be deprecated in the first place) as the plugin itself probably already maps names/uuids.

Add UUID-playername storage/mapping API

Currently most plugins (e.g. all economy, logging, permissions and ban plugins) keep their own mapping of playernames to UUIDs. The VaultAPI would be the perfect place to provide a unified interface to access this information from plugins that already provide that.

Additionally this could be expanded to also provide a player name history and last seen API (which should probably be separate from the sole lookup API as most plugins that store the UUID-name mapping will probably not store the other information too)

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.