mirror of
https://github.com/songoda/EpicHeads.git
synced 2025-02-18 04:21:20 +01:00
Added compatibility for reserve.
This commit is contained in:
parent
5059f4859f
commit
78f56a1354
10
pom.xml
10
pom.xml
@ -56,6 +56,10 @@
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>reserve-repo</id>
|
||||
<url>https://dl.bintray.com/theneweconomy/java/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -79,5 +83,11 @@
|
||||
<artifactId>playerpoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.tnemc</groupId>
|
||||
<artifactId>Reserve</artifactId>
|
||||
<version>0.1.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,10 +1,7 @@
|
||||
package com.songoda.epicheads;
|
||||
|
||||
import com.songoda.epicheads.command.CommandManager;
|
||||
import com.songoda.epicheads.economy.Economy;
|
||||
import com.songoda.epicheads.economy.ItemEconomy;
|
||||
import com.songoda.epicheads.economy.PlayerPointsEconomy;
|
||||
import com.songoda.epicheads.economy.VaultEconomy;
|
||||
import com.songoda.epicheads.economy.*;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.head.HeadManager;
|
||||
@ -29,6 +26,7 @@ import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@ -88,21 +86,23 @@ public class EpicHeads extends JavaPlugin {
|
||||
this.playerManager = new PlayerManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Register Listeners
|
||||
AbstractGUI.initializeListeners(this);
|
||||
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LoginListeners(this), this);
|
||||
pluginManager.registerEvents(new DeathListeners(this), this);
|
||||
pluginManager.registerEvents(new ItemListeners(this), this);
|
||||
pluginManager.registerEvents(new LoginListeners(this), this);
|
||||
|
||||
// Setup Economy
|
||||
if (Setting.VAULT_ECONOMY.getBoolean()
|
||||
&& getServer().getPluginManager().getPlugin("Vault") != null)
|
||||
this.economy = new VaultEconomy(this);
|
||||
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean()
|
||||
&& getServer().getPluginManager().getPlugin("PlayerPoints") != null)
|
||||
this.economy = new PlayerPointsEconomy(this);
|
||||
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();
|
||||
else if (Setting.ITEM_ECONOMY.getBoolean())
|
||||
this.economy = new ItemEconomy(this);
|
||||
this.economy = new ItemEconomy();
|
||||
|
||||
// Download Heads
|
||||
downloadHeads();
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface Economy {
|
||||
|
||||
boolean hasBalance(Player player, double cost);
|
||||
boolean hasBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean withdrawBalance(Player player, double cost);
|
||||
boolean withdrawBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean deposit(OfflinePlayer player, double amount);
|
||||
}
|
||||
|
@ -1,18 +1,11 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
public ItemEconomy(EpicHeads plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public boolean isItem(ItemStack itemStack) {
|
||||
if (itemStack == null)
|
||||
|
@ -1,19 +1,15 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import org.black_ixx.playerpoints.PlayerPoints;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PlayerPointsEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
private final PlayerPoints playerPoints;
|
||||
|
||||
public PlayerPointsEconomy(EpicHeads plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.playerPoints = (PlayerPoints) plugin.getServer().getPluginManager().getPlugin("PlayerPoints");
|
||||
public PlayerPointsEconomy() {
|
||||
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
|
||||
}
|
||||
|
||||
private int convertAmount(double amount) {
|
||||
@ -21,16 +17,22 @@ public class PlayerPointsEconomy implements Economy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(Player player, double cost) {
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
return playerPoints.getAPI().look(player.getUniqueId()) >= amount;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(Player player, double cost) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.songoda.epicheads.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));
|
||||
}
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
package com.songoda.epicheads.economy;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class VaultEconomy implements Economy {
|
||||
|
||||
private final EpicHeads plugin;
|
||||
|
||||
private final net.milkbowl.vault.economy.Economy vault;
|
||||
|
||||
public VaultEconomy(EpicHeads 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 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();
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,9 @@ public enum Setting {
|
||||
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?"),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user