Support for reserve and playerpoints.

This commit is contained in:
Brianna 2019-07-21 20:23:33 -04:00
parent 98324ede9a
commit ae3c6eb00f
9 changed files with 154 additions and 13 deletions

View File

@ -84,5 +84,11 @@
<artifactId>holographicdisplays-api</artifactId>
<version>2.3.2</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,10 @@ package com.songoda.epicanchors;
import com.songoda.epicanchors.anchor.Anchor;
import com.songoda.epicanchors.anchor.AnchorManager;
import com.songoda.epicanchors.command.CommandManager;
import com.songoda.epicanchors.economy.Economy;
import com.songoda.epicanchors.economy.PlayerPointsEconomy;
import com.songoda.epicanchors.economy.ReserveEconomy;
import com.songoda.epicanchors.economy.VaultEconomy;
import com.songoda.epicanchors.hologram.Hologram;
import com.songoda.epicanchors.hologram.HologramHolographicDisplays;
import com.songoda.epicanchors.tasks.AnchorTask;
@ -36,6 +40,8 @@ public class EpicAnchors extends JavaPlugin {
private static EpicAnchors INSTANCE;
private Economy economy;
private SettingsManager settingsManager;
private AnchorManager anchorManager;
@ -68,6 +74,16 @@ public class EpicAnchors extends JavaPlugin {
plugin.addModule(new LocaleModule());
SongodaUpdate.load(plugin);
PluginManager pluginManager = Bukkit.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();
dataFile.createNewFile("Loading Data File", "EpicAnchors Data File");
this.anchorManager = new AnchorManager();
@ -81,8 +97,6 @@ public class EpicAnchors extends JavaPlugin {
// Command registration
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
PluginManager pluginManager = Bukkit.getPluginManager();
// Event registration
pluginManager.registerEvents(new BlockListeners(this), this);
pluginManager.registerEvents(new InteractListeners(this), this);
@ -200,4 +214,8 @@ public class EpicAnchors extends JavaPlugin {
public AnchorManager getAnchorManager() {
return anchorManager;
}
public Economy getEconomy() {
return economy;
}
}

View File

@ -27,20 +27,15 @@ public class Anchor {
EpicAnchors instance = EpicAnchors.getInstance();
if (type.equals("ECO")) {
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
if (instance.getEconomy() == null)
return;
double cost = instance.getConfig().getDouble("Main.Economy Cost");
if (econ.has(player, cost)) {
econ.withdrawPlayer(player, cost);
if (instance.getEconomy().hasBalance(player, cost)) {
instance.getEconomy().withdrawBalance(player, cost);
} else {
instance.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
return;
}
} else {
player.sendMessage("Vault is not installed.");
return;
}
} else if (type.equals("XP")) {
int cost = instance.getConfig().getInt("Main.XP Cost");
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {

View File

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

View File

@ -0,0 +1,38 @@
package com.songoda.epicanchors.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.epicanchors.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

@ -0,0 +1,28 @@
package com.songoda.epicanchors.economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class VaultEconomy implements Economy {
private final net.milkbowl.vault.economy.Economy vault;
public VaultEconomy() {
this.vault = Bukkit.getServicesManager().
getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return vault.has(player, cost);
}
@Override
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

@ -3,6 +3,9 @@ package com.songoda.epicanchors.utils.settings;
public enum Category {
MAIN("General settings and options."),
ECONOMY("Settings regarding economy.",
"Only one economy option can be used at a time. If you enable more than",
"one of these the first one will be used."),
INTERFACES("These settings allow you to alter the way interfaces look.",
"They are used in GUI's to make patterns, change them up then open up a",
"GUI to see how it works."),

View File

@ -38,6 +38,15 @@ public enum Setting {
HOLOGRAMS("Main.Holograms", true,
"Toggle holograms showing above anchors."),
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?"),
ECO_ICON("Interfaces.Economy Icon", EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "SUNFLOWER" : "DOUBLE_PLANT",
"Item to be displayed as the icon for economy upgrades."),