mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-10-31 23:59:35 +01:00
Support for reserve and playerpoints.
This commit is contained in:
parent
98324ede9a
commit
ae3c6eb00f
6
pom.xml
6
pom.xml
@ -84,5 +84,11 @@
|
|||||||
<artifactId>holographicdisplays-api</artifactId>
|
<artifactId>holographicdisplays-api</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.tnemc</groupId>
|
||||||
|
<artifactId>Reserve</artifactId>
|
||||||
|
<version>0.1.3.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -3,6 +3,10 @@ package com.songoda.epicanchors;
|
|||||||
import com.songoda.epicanchors.anchor.Anchor;
|
import com.songoda.epicanchors.anchor.Anchor;
|
||||||
import com.songoda.epicanchors.anchor.AnchorManager;
|
import com.songoda.epicanchors.anchor.AnchorManager;
|
||||||
import com.songoda.epicanchors.command.CommandManager;
|
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.Hologram;
|
||||||
import com.songoda.epicanchors.hologram.HologramHolographicDisplays;
|
import com.songoda.epicanchors.hologram.HologramHolographicDisplays;
|
||||||
import com.songoda.epicanchors.tasks.AnchorTask;
|
import com.songoda.epicanchors.tasks.AnchorTask;
|
||||||
@ -36,6 +40,8 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
|
|
||||||
private static EpicAnchors INSTANCE;
|
private static EpicAnchors INSTANCE;
|
||||||
|
|
||||||
|
private Economy economy;
|
||||||
|
|
||||||
private SettingsManager settingsManager;
|
private SettingsManager settingsManager;
|
||||||
private AnchorManager anchorManager;
|
private AnchorManager anchorManager;
|
||||||
|
|
||||||
@ -68,6 +74,16 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
plugin.addModule(new LocaleModule());
|
plugin.addModule(new LocaleModule());
|
||||||
SongodaUpdate.load(plugin);
|
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");
|
dataFile.createNewFile("Loading Data File", "EpicAnchors Data File");
|
||||||
|
|
||||||
this.anchorManager = new AnchorManager();
|
this.anchorManager = new AnchorManager();
|
||||||
@ -81,8 +97,6 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
// Command registration
|
// Command registration
|
||||||
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
||||||
|
|
||||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
|
||||||
|
|
||||||
// Event registration
|
// Event registration
|
||||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||||
@ -200,4 +214,8 @@ public class EpicAnchors extends JavaPlugin {
|
|||||||
public AnchorManager getAnchorManager() {
|
public AnchorManager getAnchorManager() {
|
||||||
return anchorManager;
|
return anchorManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Economy getEconomy() {
|
||||||
|
return economy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,20 +27,15 @@ public class Anchor {
|
|||||||
EpicAnchors instance = EpicAnchors.getInstance();
|
EpicAnchors instance = EpicAnchors.getInstance();
|
||||||
|
|
||||||
if (type.equals("ECO")) {
|
if (type.equals("ECO")) {
|
||||||
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
|
if (instance.getEconomy() == null)
|
||||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
return;
|
||||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
|
||||||
double cost = instance.getConfig().getDouble("Main.Economy Cost");
|
double cost = instance.getConfig().getDouble("Main.Economy Cost");
|
||||||
if (econ.has(player, cost)) {
|
if (instance.getEconomy().hasBalance(player, cost)) {
|
||||||
econ.withdrawPlayer(player, cost);
|
instance.getEconomy().withdrawBalance(player, cost);
|
||||||
} else {
|
} else {
|
||||||
instance.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
instance.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
player.sendMessage("Vault is not installed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (type.equals("XP")) {
|
} else if (type.equals("XP")) {
|
||||||
int cost = instance.getConfig().getInt("Main.XP Cost");
|
int cost = instance.getConfig().getInt("Main.XP Cost");
|
||||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||||
|
12
src/main/java/com/songoda/epicanchors/economy/Economy.java
Normal file
12
src/main/java/com/songoda/epicanchors/economy/Economy.java
Normal 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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,9 @@ package com.songoda.epicanchors.utils.settings;
|
|||||||
public enum Category {
|
public enum Category {
|
||||||
|
|
||||||
MAIN("General settings and options."),
|
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.",
|
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",
|
"They are used in GUI's to make patterns, change them up then open up a",
|
||||||
"GUI to see how it works."),
|
"GUI to see how it works."),
|
||||||
|
@ -38,6 +38,15 @@ public enum Setting {
|
|||||||
HOLOGRAMS("Main.Holograms", true,
|
HOLOGRAMS("Main.Holograms", true,
|
||||||
"Toggle holograms showing above anchors."),
|
"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",
|
ECO_ICON("Interfaces.Economy Icon", EpicAnchors.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "SUNFLOWER" : "DOUBLE_PLANT",
|
||||||
"Item to be displayed as the icon for economy upgrades."),
|
"Item to be displayed as the icon for economy upgrades."),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user