player points + vault economy support

This commit is contained in:
Kiran Hart 2021-06-25 00:19:46 -04:00
parent ede7afccc4
commit c2c1846511
14 changed files with 269 additions and 30 deletions

View File

@ -31,7 +31,6 @@ jobs:
run: mvn verify -B --file pom.xml
transfer:
needs: build
runs-on: ubuntu-latest
steps:
- name: Transfer main branch to Tweetzy

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.16.1</version>
<version>2.17.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -145,6 +145,13 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.black_ixx</groupId>
<artifactId>PlayerPoints</artifactId>
<version>3.0.3</version>
<scope>system</scope>
<systemPath>${user.home}/Documents/Development/Minecraft/External Jars/PlayerPoints.jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -6,6 +6,7 @@ import ca.tweetzy.auctionhouse.commands.*;
import ca.tweetzy.auctionhouse.database.DataManager;
import ca.tweetzy.auctionhouse.database.migrations._1_InitialMigration;
import ca.tweetzy.auctionhouse.database.migrations._2_FilterWhitelistMigration;
import ca.tweetzy.auctionhouse.economy.EconomyManager;
import ca.tweetzy.auctionhouse.listeners.AuctionListeners;
import ca.tweetzy.auctionhouse.listeners.PlayerListeners;
import ca.tweetzy.auctionhouse.managers.AuctionItemManager;
@ -31,9 +32,7 @@ import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChain;
import co.aikar.taskchain.TaskChainFactory;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.List;
@ -52,7 +51,7 @@ public class AuctionHouse extends TweetyPlugin {
private static AuctionHouse instance;
@Getter
private Economy economy;
private EconomyManager economyManager;
@Getter
private final GuiManager guiManager = new GuiManager(this);
@ -101,17 +100,14 @@ public class AuctionHouse extends TweetyPlugin {
return;
}
// Check for vault
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null) this.economy = rsp.getProvider();
}
taskChainFactory = BukkitTaskChainFactory.create(this);
// Settings
Settings.setup();
// Check the economy right after the settings setup
this.economyManager = new EconomyManager(this);
// local
setLocale(Settings.LANG.getString());
LocaleSettings.setup();

View File

@ -0,0 +1,70 @@
package ca.tweetzy.auctionhouse.economy;
import ca.tweetzy.auctionhouse.settings.Settings;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
/**
* The current file has been created by Kiran Hart
* Date Created: June 24 2021
* Time Created: 11:26 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class EconomyManager {
private final JavaPlugin plugin;
private IEconomy selectedEconomy;
enum SupportedEconomy {
VAULT("Vault"),
PLAYER_POINTS("PlayerPoints");
@Getter
final String economyName;
SupportedEconomy(String economyName) {
this.economyName = economyName;
}
}
public EconomyManager(JavaPlugin plugin) {
this.plugin = plugin;
String preferredEconomy = Settings.ECONOMY_MODE.getString();
if (preferredEconomy.equalsIgnoreCase(SupportedEconomy.VAULT.getEconomyName())) {
this.selectedEconomy = new VaultEconomy();
if (!this.selectedEconomy.isEnabled()) {
Bukkit.getPluginManager().disablePlugin(this.plugin);
plugin.getLogger().severe("Something went wrong while trying to load the " + selectedEconomy.getHookName() + " economy!");
}
}
if (preferredEconomy.equalsIgnoreCase(SupportedEconomy.PLAYER_POINTS.getEconomyName())) {
this.selectedEconomy = new PlayerPointsEconomy();
if (!this.selectedEconomy.isEnabled()) {
Bukkit.getPluginManager().disablePlugin(this.plugin);
plugin.getLogger().severe("Something went wrong while trying to load the " + selectedEconomy.getHookName() + " economy!");
}
}
this.plugin.getLogger().info("Using " + selectedEconomy.getHookName() + " as the economy provider!");
}
public double getBalance(OfflinePlayer offlinePlayer) {
return this.selectedEconomy.getBalance(offlinePlayer);
}
public boolean has(OfflinePlayer offlinePlayer, double cost) {
return this.selectedEconomy.has(offlinePlayer, cost);
}
public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double cost) {
return this.selectedEconomy.withdraw(offlinePlayer, cost);
}
public boolean depositPlayer(OfflinePlayer offlinePlayer, double cost) {
return this.selectedEconomy.deposit(offlinePlayer, cost);
}
}

View File

@ -0,0 +1,24 @@
package ca.tweetzy.auctionhouse.economy;
import org.bukkit.OfflinePlayer;
/**
* The current file has been created by Kiran Hart
* Date Created: June 24 2021
* Time Created: 11:21 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public interface IEconomy {
String getHookName();
boolean isEnabled();
double getBalance(OfflinePlayer player);
boolean has(OfflinePlayer player, double cost);
boolean withdraw(OfflinePlayer player, double cost);
boolean deposit(OfflinePlayer player, double cost);
}

View File

@ -0,0 +1,77 @@
package ca.tweetzy.auctionhouse.economy;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The current file has been created by Kiran Hart
* Date Created: June 24 2021
* Time Created: 11:39 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class PlayerPointsEconomy implements IEconomy {
private final PlayerPoints playerPoints;
public PlayerPointsEconomy() {
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
}
@Override
public String getHookName() {
return "PlayerPoints";
}
@Override
public boolean isEnabled() {
return playerPoints.isEnabled();
}
@Override
public double getBalance(OfflinePlayer player) {
AtomicInteger value = new AtomicInteger(0);
playerPoints.getAPI().lookAsync(player.getUniqueId()).thenAccept(value::set);
return value.get();
}
@Override
public boolean has(OfflinePlayer player, double cost) {
int total = 0;
try {
total = playerPoints.getAPI().lookAsync(player.getUniqueId()).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return total >= convert(cost);
}
@Override
public boolean withdraw(OfflinePlayer player, double cost) {
boolean success = false;
try {
success = playerPoints.getAPI().takeAsync(player.getUniqueId(), convert(cost)).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return success;
}
@Override
public boolean deposit(OfflinePlayer player, double cost) {
boolean success = false;
try {
success = playerPoints.getAPI().giveAsync(player.getUniqueId(), convert(cost)).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return success;
}
private int convert(double amount) {
return (int) Math.ceil(amount);
}
}

View File

@ -0,0 +1,58 @@
package ca.tweetzy.auctionhouse.economy;
import ca.tweetzy.auctionhouse.exception.EconomyProviderNotFoundException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
/**
* The current file has been created by Kiran Hart
* Date Created: June 24 2021
* Time Created: 11:23 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class VaultEconomy implements IEconomy {
private final net.milkbowl.vault.economy.Economy vault;
public VaultEconomy() {
RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> v = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (v != null) {
this.vault = v.getProvider();
} else {
this.vault = null;
throw new EconomyProviderNotFoundException("Could not find any plugin to hook into: " + getHookName());
}
}
@Override
public String getHookName() {
return "Vault";
}
@Override
public boolean isEnabled() {
return vault != null;
}
@Override
public double getBalance(OfflinePlayer player) {
if (vault == null) return 0D;
return vault.getBalance(player);
}
@Override
public boolean has(OfflinePlayer player, double cost) {
return vault != null && vault.has(player, cost);
}
@Override
public boolean withdraw(OfflinePlayer player, double cost) {
return vault != null && vault.withdrawPlayer(player, cost).transactionSuccess();
}
@Override
public boolean deposit(OfflinePlayer player, double cost) {
return vault != null && vault.depositPlayer(player, cost).transactionSuccess();
}
}

View File

@ -0,0 +1,14 @@
package ca.tweetzy.auctionhouse.exception;
/**
* The current file has been created by Kiran Hart
* Date Created: June 24 2021
* Time Created: 11:17 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class EconomyProviderNotFoundException extends NullPointerException {
public EconomyProviderNotFoundException(String errorMessage) {
super(errorMessage);
}
}

View File

@ -128,7 +128,7 @@ public class GUIAuctionHouse extends Gui {
return;
}
if (!AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getBasePrice())) {
if (!AuctionHouse.getInstance().getEconomyManager().has(e.player, auctionItem.getBasePrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
@ -164,7 +164,7 @@ public class GUIAuctionHouse extends Gui {
return;
}
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomyManager().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}
@ -281,7 +281,7 @@ public class GUIAuctionHouse extends Gui {
private void drawFixedButtons() {
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%active_player_auctions%", auctionPlayer.getItems(false).size());
put("%player_balance%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getEconomy().getBalance(auctionPlayer.getPlayer())));
put("%player_balance%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getEconomyManager().getBalance(auctionPlayer.getPlayer())));
}}), e -> {
cleanup();
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));

View File

@ -46,7 +46,7 @@ public class GUIConfirmBid extends Gui {
return;
}
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomyManager().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
return;
}

View File

@ -93,7 +93,7 @@ public class GUIConfirmPurchase extends Gui {
}
// Check economy
if (!AuctionHouse.getInstance().getEconomy().has(e.player, this.buyingSpecificQuantity ? this.purchaseQuantity * this.pricePerItem : located.getBasePrice())) {
if (!AuctionHouse.getInstance().getEconomyManager().has(e.player, this.buyingSpecificQuantity ? this.purchaseQuantity * this.pricePerItem : located.getBasePrice())) {
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_NOT_ENOUGH_MONEY.getString(), 1.0F, 1.0F);
e.gui.close();
@ -162,8 +162,8 @@ public class GUIConfirmPurchase extends Gui {
}
private void transferFunds(Player from, double amount) {
AuctionHouse.getInstance().getEconomy().withdrawPlayer(from, amount);
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), amount);
AuctionHouse.getInstance().getEconomyManager().withdrawPlayer(from, amount);
AuctionHouse.getInstance().getEconomyManager().depositPlayer(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), amount);
}
private void sendMessages(GuiClickEvent e, AuctionItem located, boolean overwritePrice, double price) {

View File

@ -23,11 +23,6 @@ public class AuctionListeners implements Listener {
@EventHandler
public void onAuctionStart(AuctionStartEvent e) {
// TODO THIS IS GONNA BE SCUFFED
if (Settings.DATABASE_USE.getBoolean() && Settings.DATABASE_UPDATE_ON_EVENT.getBoolean()) {
}
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean()) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> {

View File

@ -20,6 +20,7 @@ public class Settings {
static final Config config = AuctionHouse.getInstance().getCoreConfig();
public static final ConfigSetting LANG = new ConfigSetting(config, "lang", "en_US", "Default language file");
public static final ConfigSetting ECONOMY_MODE = new ConfigSetting(config, "economy provider", "Vault", "Supported Economies:", "Vault", "PlayerPoints");
/* ===============================
* BASIC SETTINGS
* ===============================*/
@ -95,6 +96,7 @@ public class Settings {
"",
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
);
public static final ConfigSetting CLICKS_NON_BID_ITEM_QTY_PURCHASE = new ConfigSetting(config, "auction setting.clicks.non bid item qty purchase", "RIGHT",
"Valid Click Types",
"LEFT",
@ -116,6 +118,7 @@ public class Settings {
"",
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
);
public static final ConfigSetting CLICKS_BID_ITEM_BUY_NOW = new ConfigSetting(config, "auction setting.clicks.bid item buy now", "RIGHT",
"Valid Click Types",
"LEFT",
@ -127,7 +130,6 @@ public class Settings {
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
);
public static final ConfigSetting CLICKS_INSPECT_CONTAINER = new ConfigSetting(config, "auction setting.clicks.inspect container", "SHIFT_RIGHT",
"Valid Click Types",
"LEFT",
@ -161,9 +163,6 @@ public class Settings {
public static final ConfigSetting DATABASE_PASSWORD = new ConfigSetting(config, "database.password", "Password1.", "What is the password to the user connecting?");
public static final ConfigSetting DATABASE_USE_SSL = new ConfigSetting(config, "database.use ssl", true, "Should the database connection use ssl?");
public static final ConfigSetting DATABASE_UPDATE_ON_EVENT = new ConfigSetting(config, "database.update on event", true, "When an item is listed/bought/expired/cancelled should auction house update the database immediately?");
/* ===============================
* DISCORD WEBHOOK
* ===============================*/

View File

@ -60,7 +60,7 @@ public class TickAuctionsTask extends BukkitRunnable {
OfflinePlayer auctionWinner = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());
if (!AuctionHouse.getInstance().getEconomy().has(auctionWinner, auctionItem.getCurrentPrice())) {
if (!AuctionHouse.getInstance().getEconomyManager().has(auctionWinner, auctionItem.getCurrentPrice())) {
auctionItem.setExpired(true);
continue;
}
@ -69,8 +69,8 @@ public class TickAuctionsTask extends BukkitRunnable {
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
if (!auctionEndEvent.isCancelled()) continue;
AuctionHouse.getInstance().getEconomy().withdrawPlayer(auctionWinner, auctionItem.getCurrentPrice());
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(auctionItem.getOwner()), auctionItem.getCurrentPrice());
AuctionHouse.getInstance().getEconomyManager().withdrawPlayer(auctionWinner, auctionItem.getCurrentPrice());
AuctionHouse.getInstance().getEconomyManager().depositPlayer(Bukkit.getOfflinePlayer(auctionItem.getOwner()), auctionItem.getCurrentPrice());
if (Bukkit.getOfflinePlayer(auctionItem.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")