Using multipliers - AlonsoAliaga/VaultMultipliers GitHub Wiki
Using multipliers in your plugin
If you are a developer and want to use multiplierd provided by other plugins follow this guide.
Using multipliers is really simple.
First, make sure the plugin is installed.
package com.alonsoaliaga.exampleplugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.alonsoaliaga.vaultmultipliers.multipliers.Multiplier;
public class ExamplePlugin extends JavaPlugin {
public Multipliers multipliers = null;
@Override
public void onEnable() {
if(getServer().getPluginManager().getPlugin("VaultMultiplier") != null) {
//Code here
}
}
}
Second, we get API instance and assign it.
package com.alonsoaliaga.exampleplugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.alonsoaliaga.vaultmultipliers.VaultMultipliers;
import com.alonsoaliaga.vaultmultipliers.multipliers.Multiplier;
public class ExamplePlugin extends JavaPlugin {
public Multipliers multipliers = null;
@Override
public void onEnable() {
if(getServer().getPluginManager().getPlugin("VaultMultiplier") != null) {
multipliers = VaultMultipliers.getAPI();
getServer().getConsoleSender().sendMessage("VaultMultiplier hooked successfully!");
}else{
getServer().getConsoleSender().sendMessage("VaultMultiplier couldn't be hooked successfully!");
}
}
}
Third, multipliers are ready to use for our minigame or any other system we want.
Remember you should NOT use multipliers in commands a normal user is able to use to move currency
If you do that, players can send money to each others and multiply the amount of money.
Forth, to use them you simply need to do the following.
public double getAdditionalCoins(Player player, double amount) {
//This will return the multiplied amount of additional coins.
//Example: If the amount the player is supposed to earn is 20.
//The method will return the amount of coins the player should earn additional to the original amount based on multipliers registered.
//For example, AlonsoLevels provides an additional multiplier of 2.5x for reaching level 25.
//It means that method should return 20 * 2.5 = 50. This value is the amount of coins the player will earn additional
//to the original one and that's what you should add to your currency (custom or using vault).
return multipliers.getAdditionalMultiplier(player.getUniqueId(), amount);
}
The whole command will look like this:
package com.alonsoaliaga.exampleplugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.entity.Player;
import com.alonsoaliaga.vaultmultipliers.VaultMultipliers;
import com.alonsoaliaga.vaultmultipliers.multipliers.Multiplier;
public class ExamplePlugin extends JavaPlugin {
public Multipliers multipliers = null;
@Override
public void onEnable() {
if(getServer().getPluginManager().getPlugin("VaultMultiplier") != null) {
multipliers = VaultMultipliers.getAPI();
getServer().getConsoleSender().sendMessage("VaultMultiplier hooked successfully!");
}else{
getServer().getConsoleSender().sendMessage("VaultMultiplier couldn't be hooked successfully!");
}
}
//This method will
public void addCoinsToPlayer(Player player, double amount) {
double additionalCoins = getAdditionalCoins(player, amount);
double totalCoins = amount + additionalCoins;
//You can use vault here or your own economy system to add the total coins. (original + additional)
//Additionally you can send the message to the player including the amount of additional earned coins.
player.sendMessage(String.format("You earned %s (+%s additional)",String.valueOf(amount),String.valueOf(additionalCoins)));
}
private double getAdditionalCoins(Player player, double amount) {
return multipliers.getAdditionalMultiplier(player.getUniqueId(), amount);
}
}
That's it! Your plugin now uses multipliers!
Remember to not use multipliers in commands/events the player can use/call otherwise they will be able to multiply coins by sending money to other players with /money give command or similar.