2.38.0 - UltraEconomy Support

This commit is contained in:
Kiran Hart 2021-10-05 22:38:08 -04:00
parent bf7ffac0da
commit aaed974ae2
8 changed files with 121 additions and 23 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId> <groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId> <artifactId>auctionhouse</artifactId>
<version>2.37.0</version> <version>2.38.0</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -192,6 +192,12 @@
<version>2.10.10</version> <version>2.10.10</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>me.TechsCode</groupId>
<artifactId>UltraEconomy</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,9 +1,9 @@
package ca.tweetzy.auctionhouse; package ca.tweetzy.auctionhouse;
import ca.tweetzy.auctionhouse.api.UpdateChecker; import ca.tweetzy.auctionhouse.api.UpdateChecker;
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPI; import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPIHook;
import ca.tweetzy.auctionhouse.api.hook.UltraEconomyHook;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionStat;
import ca.tweetzy.auctionhouse.commands.*; import ca.tweetzy.auctionhouse.commands.*;
import ca.tweetzy.auctionhouse.database.DataManager; import ca.tweetzy.auctionhouse.database.DataManager;
import ca.tweetzy.auctionhouse.database.migrations.*; import ca.tweetzy.auctionhouse.database.migrations.*;
@ -26,6 +26,8 @@ import ca.tweetzy.core.database.MySQLConnector;
import ca.tweetzy.core.database.SQLiteConnector; import ca.tweetzy.core.database.SQLiteConnector;
import ca.tweetzy.core.gui.GuiManager; import ca.tweetzy.core.gui.GuiManager;
import ca.tweetzy.core.hooks.EconomyManager; import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.hooks.PluginHook;
import ca.tweetzy.core.hooks.economies.Economy;
import ca.tweetzy.core.utils.Metrics; import ca.tweetzy.core.utils.Metrics;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.TextUtils;
import co.aikar.taskchain.BukkitTaskChainFactory; import co.aikar.taskchain.BukkitTaskChainFactory;
@ -50,6 +52,7 @@ public class AuctionHouse extends TweetyPlugin {
private static TaskChainFactory taskChainFactory; private static TaskChainFactory taskChainFactory;
private static AuctionHouse instance; private static AuctionHouse instance;
private PluginHook ultraEconomyHook;
@Getter @Getter
@Setter @Setter
@ -110,18 +113,26 @@ public class AuctionHouse extends TweetyPlugin {
taskChainFactory = BukkitTaskChainFactory.create(this); taskChainFactory = BukkitTaskChainFactory.create(this);
// Load Economy
EconomyManager.load();
// Settings // Settings
Settings.setup(); Settings.setup();
this.ultraEconomyHook = PluginHook.addHook(Economy.class, "UltraEconomy", UltraEconomyHook.class);
// Load Economy
EconomyManager.load();
// local // local
setLocale(Settings.LANG.getString()); setLocale(Settings.LANG.getString());
LocaleSettings.setup(); LocaleSettings.setup();
// Setup Economy // Setup Economy
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString()); final String ECO_PLUGIN =Settings.ECONOMY_PLUGIN.getString();
if (ECO_PLUGIN.startsWith("UltraEconomy")) {
EconomyManager.getManager().setPreferredHook(this.ultraEconomyHook);
} else {
EconomyManager.getManager().setPreferredHook(ECO_PLUGIN);
}
if (!EconomyManager.getManager().isEnabled()) { if (!EconomyManager.getManager().isEnabled()) {
getLogger().severe("Could not find a valid economy provider for Auction House"); getLogger().severe("Could not find a valid economy provider for Auction House");
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
@ -200,8 +211,8 @@ public class AuctionHouse extends TweetyPlugin {
); );
// Placeholder API // Placeholder API
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPIHook") != null) {
new PlaceholderAPI(this).register(); new PlaceholderAPIHook(this).register();
} }
// start the auction tick task // start the auction tick task

View File

@ -2,8 +2,7 @@ package ca.tweetzy.auctionhouse.api;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent; import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.api.hook.MMOItems; import ca.tweetzy.auctionhouse.api.hook.MMOItemsHook;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType; import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.AuctionedItem;
@ -18,21 +17,17 @@ import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.ItemUtils; import ca.tweetzy.core.utils.items.ItemUtils;
import ca.tweetzy.core.utils.nms.NBTEditor; import ca.tweetzy.core.utils.nms.NBTEditor;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BundleMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -262,7 +257,7 @@ public class AuctionAPI {
: Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100); : Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
ItemStack itemStack = auctionItem.getItem(); ItemStack itemStack = auctionItem.getItem();
String itemName = MMOItems.isEnabled() ? MMOItems.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack));
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject();
embedObject.setTitle(isNew ? Settings.DISCORD_MSG_START_TITLE.getString() : Settings.DISCORD_MSG_FINISH_TITLE.getString()); embedObject.setTitle(isNew ? Settings.DISCORD_MSG_START_TITLE.getString() : Settings.DISCORD_MSG_FINISH_TITLE.getString());
@ -304,7 +299,7 @@ public class AuctionAPI {
: Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100); : Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100);
ItemStack itemStack = auctionItem.getItem(); ItemStack itemStack = auctionItem.getItem();
String itemName = MMOItems.isEnabled() ? MMOItems.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack));
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject();
embedObject.setTitle(Settings.DISCORD_MSG_BID_TITLE.getString()); embedObject.setTitle(Settings.DISCORD_MSG_BID_TITLE.getString());

View File

@ -17,10 +17,10 @@ import org.bukkit.inventory.ItemStack;
*/ */
@UtilityClass @UtilityClass
public class MMOItems { public class MMOItemsHook {
public boolean isEnabled() { public boolean isEnabled() {
return Bukkit.getPluginManager().getPlugin("MMOItems") != null; return Bukkit.getPluginManager().getPlugin("MMOItemsHook") != null;
} }
private boolean hasType(@NonNull final NBTItem itemStack) { private boolean hasType(@NonNull final NBTItem itemStack) {

View File

@ -2,7 +2,6 @@ package ca.tweetzy.auctionhouse.api.hook;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import io.lumine.mythic.lib.comp.PlaceholderAPIHook;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -13,11 +12,11 @@ import org.jetbrains.annotations.NotNull;
* Time Created: 6:36 p.m. * Time Created: 6:36 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise * Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/ */
public class PlaceholderAPI extends PlaceholderExpansion { public class PlaceholderAPIHook extends PlaceholderExpansion {
private final AuctionHouse plugin; private final AuctionHouse plugin;
public PlaceholderAPI(AuctionHouse plugin) { public PlaceholderAPIHook(AuctionHouse plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -0,0 +1,73 @@
package ca.tweetzy.auctionhouse.api.hook;
import ca.tweetzy.auctionhouse.exception.UltraEconomyCurrencyException;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.hooks.economies.Economy;
import me.TechsCode.UltraEconomy.UltraEconomy;
import me.TechsCode.UltraEconomy.objects.Account;
import me.TechsCode.UltraEconomy.objects.Currency;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
/**
* The current file has been created by Kiran Hart
* Date Created: October 05 2021
* Time Created: 9:18 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public final class UltraEconomyHook extends Economy {
private final Currency currency;
public UltraEconomyHook() {
final String[] ultraEconomyCurrencyName = Settings.ECONOMY_PLUGIN.getString().split(":");
this.currency = UltraEconomy.getAPI().getCurrencies().name(ultraEconomyCurrencyName[1]).orElse(null);
if (this.currency == null) {
throw new UltraEconomyCurrencyException("AuctionHouse could not find the currency: " + ultraEconomyCurrencyName[0]);
}
}
@Override
public double getBalance(OfflinePlayer player) {
final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null);
return account == null ? 0 : account.getBalance(this.currency).getOnBank();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null);
return account != null && account.getBalance(this.currency).getOnBank() >= cost;
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null);
if (account == null) return false;
final float oldAmount = account.getBalance(this.currency).getOnBank();
account.getBalance(this.currency).setBank(oldAmount - (float) cost);
return true;
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null);
if (account == null) return false;
final float oldAmount = account.getBalance(this.currency).getOnBank();
account.getBalance(this.currency).setBank(oldAmount + (float) amount);
return true;
}
@Override
public String getName() {
return "UltraEconomy";
}
@Override
public boolean isEnabled() {
return Bukkit.getPluginManager().getPlugin("UltraEconomy") != null;
}
}

View File

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

View File

@ -5,7 +5,7 @@ main: ca.tweetzy.auctionhouse.AuctionHouse
description: Auction House is a premium auction solution for your server. description: Auction House is a premium auction solution for your server.
website: https://tweetzy.ca/ website: https://tweetzy.ca/
authors: [Kiran Hart] authors: [Kiran Hart]
softdepend: [Vault, PlayerPoints, PlaceholderAPI, MMOItems] softdepend: [Vault, PlayerPoints, PlaceholderAPIHook, MMOItemsHook, UltraEconomy]
commands: commands:
auctionhouse: auctionhouse: