Added support for playerpoints and reserve

This commit is contained in:
Brianna 2019-07-20 22:47:52 -04:00
parent 729040556c
commit b4414c0a6b
7 changed files with 111 additions and 23 deletions

View File

@ -211,5 +211,11 @@
<artifactId>ultimatecore</artifactId>
<version>2.1.25</version>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Reserve</artifactId>
<version>0.1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -3,6 +3,8 @@ package com.songoda.ultimatekits;
import com.songoda.ultimatekits.command.CommandManager;
import com.songoda.ultimatekits.conversion.Convert;
import com.songoda.ultimatekits.economy.Economy;
import com.songoda.ultimatekits.economy.PlayerPointsEconomy;
import com.songoda.ultimatekits.economy.ReserveEconomy;
import com.songoda.ultimatekits.economy.VaultEconomy;
import com.songoda.ultimatekits.handlers.DisplayItemHandler;
import com.songoda.ultimatekits.handlers.ParticleHandler;
@ -17,6 +19,7 @@ import com.songoda.ultimatekits.listeners.EntityListeners;
import com.songoda.ultimatekits.listeners.InteractListeners;
import com.songoda.ultimatekits.utils.*;
import com.songoda.ultimatekits.utils.locale.Locale;
import com.songoda.ultimatekits.utils.settings.Setting;
import com.songoda.ultimatekits.utils.settings.SettingsManager;
import com.songoda.ultimatekits.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
@ -104,11 +107,16 @@ public class UltimateKits extends JavaPlugin {
this.keyManager = new KeyManager();
this.commandManager = new CommandManager(this);
if (getServer().getPluginManager().getPlugin("Vault") != null)
this.economy = new VaultEconomy(this);
PluginManager pluginManager = getServer().getPluginManager();
// Setup Economy
if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault"))
this.economy = new VaultEconomy();
else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve"))
this.economy = new ReserveEconomy();
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints"))
this.economy = new PlayerPointsEconomy();
// Register Hologram Plugin
if (pluginManager.isPluginEnabled("HolographicDisplays"))
hologram = new HologramHolographicDisplays(this);

View File

@ -1,12 +1,12 @@
package com.songoda.ultimatekits.economy;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;
public interface Economy {
boolean AddToBalance(Player player, double amount);
boolean hasBalance(OfflinePlayer player, double cost);
boolean hasBalance(Player player, double cost);
boolean withdrawBalance(OfflinePlayer player, double cost);
boolean withdrawBalance(Player player, double cost);
boolean deposit(OfflinePlayer player, double amount);
}

View File

@ -0,0 +1,38 @@
package com.songoda.ultimatekits.economy;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class PlayerPointsEconomy implements Economy {
private final PlayerPoints playerPoints;
public PlayerPointsEconomy() {
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
}
private int convertAmount(double amount) {
return (int) Math.ceil(amount);
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);
return playerPoints.getAPI().look(player.getUniqueId()) >= amount;
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);
return playerPoints.getAPI().take(player.getUniqueId(), amount);
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
int amt = convertAmount(amount);
return playerPoints.getAPI().give(player.getUniqueId(), amt);
}
}

View File

@ -0,0 +1,32 @@
package com.songoda.ultimatekits.economy;
import net.tnemc.core.Reserve;
import net.tnemc.core.economy.EconomyAPI;
import org.bukkit.OfflinePlayer;
import java.math.BigDecimal;
public class ReserveEconomy implements Economy {
EconomyAPI economyAPI;
public ReserveEconomy() {
if (Reserve.instance().economyProvided())
economyAPI = Reserve.instance().economy();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost));
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
return economyAPI.removeHoldings(player.getUniqueId(), new BigDecimal(cost));
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
return economyAPI.addHoldings(player.getUniqueId(), new BigDecimal(amount));
}
}

View File

@ -1,33 +1,28 @@
package com.songoda.ultimatekits.economy;
import com.songoda.ultimatekits.UltimateKits;
import org.bukkit.entity.Player;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class VaultEconomy implements Economy {
private final UltimateKits plugin;
private final net.milkbowl.vault.economy.Economy vault;
public VaultEconomy(UltimateKits plugin) {
this.plugin = plugin;
this.vault = plugin.getServer().getServicesManager().
public VaultEconomy() {
this.vault = Bukkit.getServicesManager().
getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
}
@Override
public boolean AddToBalance(Player player, double amount) {
return vault.depositPlayer(player, amount).transactionSuccess();
}
@Override
public boolean hasBalance(Player player, double cost) {
public boolean hasBalance(OfflinePlayer player, double cost) {
return vault.has(player, cost);
}
@Override
public boolean withdrawBalance(Player player, double cost) {
public boolean withdrawBalance(OfflinePlayer player, double cost) {
return vault.withdrawPlayer(player, cost).transactionSuccess();
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
return vault.depositPlayer(player, amount).transactionSuccess();
}
}

View File

@ -18,6 +18,15 @@ public enum Setting {
CHANCE_IN_PREVIEW("Main.Display Chance In Preview", true),
CURRENCY_SYMBOL("Main.Currency Symbol", "$"),
VAULT_ECONOMY("Economy.Use Vault Economy", true,
"Should Vault be used?"),
RESERVE_ECONOMY("Economy.Use Reserve Economy", true,
"Should Reserve be used?"),
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false,
"Should PlayerPoints be used?"),
EXIT_ICON("Interfaces.Exit Icon", UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR"),
BUY_ICON("Interfaces.Buy Icon", "EMERALD"),
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),