Skip to content

Commit

Permalink
Merge pull request #104 from Tweetzy/dev
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
kiranhart authored Oct 11, 2024
2 parents eb10d91 + 90907d2 commit f45bf1b
Show file tree
Hide file tree
Showing 34 changed files with 685 additions and 154 deletions.
29 changes: 27 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

<name>Markets</name>
<description>A new take on traditional player owned shops</description>
<version>2.19.0</version>
<version>2.22.0</version>
<packaging>jar</packaging>

<properties>
<author>Kiran Hart</author>
<jarName>${project.name}</jarName>
<main.class>${project.groupId}.${project.artifactId}.${project.name}</main.class>
<java.version>16</java.version>
<flight.version>3.24.1</flight.version>
<flight.version>3.27.0</flight.version>
<flight.path>ca.tweetzy</flight.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -47,6 +47,14 @@
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository>
<repository>
<id>auxilor-plugins</id>
<url>https://repo.auxilor.io/repository/maven-public/</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand Down Expand Up @@ -84,12 +92,23 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.willfp</groupId>
<artifactId>EcoBits</artifactId>
<version>1.8.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.TechsCode</groupId>
<artifactId>UltraEconomyAPI</artifactId>
<version>2.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>taskchain-bukkit</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
Expand Down Expand Up @@ -164,6 +183,8 @@
<includes>
<include>${flight.path}:flight*</include>
<include>com.google.code.gson:gson</include>
<include>co.aikar:taskchain-bukkit</include>
<include>co.aikar:taskchain-core</include>
</includes>
</artifactSet>
<filters>
Expand All @@ -187,6 +208,10 @@
<pattern>com.google.gson</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.gson</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.taskchain</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.lib.taskchain</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/ca/tweetzy/markets/Markets.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
import ca.tweetzy.markets.model.manager.*;
import ca.tweetzy.markets.settings.Settings;
import ca.tweetzy.markets.settings.Translations;
import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChain;
import co.aikar.taskchain.TaskChainFactory;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;

public final class Markets extends FlightPlugin {

private static TaskChainFactory taskChainFactory;

@SuppressWarnings("FieldCanBeLocal")
private DatabaseConnector databaseConnector;
private DataManager dataManager;
Expand Down Expand Up @@ -52,6 +57,7 @@ protected void onFlight() {
Translations.init();

Common.setPrefix(Settings.PREFIX.getStringOr("&8[&EMarkets&8]"));
taskChainFactory = BukkitTaskChainFactory.create(this);

// Set up the database if enabled
this.databaseConnector = new SQLiteConnector(this);
Expand All @@ -73,7 +79,8 @@ protected void onFlight() {
new _13_MarketReviewMigration(),
new _14_MarketRequestMigration(),
new _15_TransactionsMigration(),
new _16_InfiniteItemsMigration()
new _16_InfiniteItemsMigration(),
new _17_BankEntryPriceMigration()
);

// run migrations for tables
Expand Down Expand Up @@ -188,6 +195,10 @@ public static Economy getEconomy() {
return getInstance().economy;
}

public static <T> TaskChain<T> newChain() {
return taskChainFactory.newChain();
}

// helpers
private void setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public abstract class AbstractCurrency implements Chargeable {
@Setter
protected String displayName;

@Setter
@Getter
protected boolean isVault;

public String getStoreableName() {
return this.owningPlugin + "/" + this.currencyName + "/" + this.displayName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class IconableCurrency extends AbstractCurrency {
protected ItemStack icon;

public IconableCurrency(String owningPlugin, String currencyName, String displayName, ItemStack icon) {
super(owningPlugin, currencyName, displayName);
super(owningPlugin, currencyName, displayName, false);
this.icon = icon;
}
}
35 changes: 35 additions & 0 deletions src/main/java/ca/tweetzy/markets/api/market/BankEntry.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ca.tweetzy.markets.api.market;

import ca.tweetzy.flight.utils.ItemUtil;
import ca.tweetzy.markets.Markets;
import ca.tweetzy.markets.api.Identifiable;
import ca.tweetzy.markets.api.Storeable;
import ca.tweetzy.markets.api.Synchronize;
import ca.tweetzy.markets.api.currency.AbstractCurrency;
import ca.tweetzy.markets.settings.Settings;
import lombok.NonNull;
import org.bukkit.inventory.ItemStack;

Expand All @@ -17,4 +21,35 @@ public interface BankEntry extends Identifiable, Synchronize, Storeable<BankEntr
int getQuantity();

void setQuantity(final int amount);

String getCurrency();

void setCurrency(String string);

ItemStack getCurrencyItem();

void setCurrencyItem(ItemStack currencyItem);

double getPrice();

void setPrice(double price);

default boolean isCurrencyOfItem() {
final String[] split = getCurrency().split("/");
return split[1].equalsIgnoreCase("item");
}

default String getCurrencyDisplayName() {
if (isCurrencyOfItem())
return ItemUtil.getItemName(this.getCurrencyItem());

final String[] split = getCurrency().split("/");

final AbstractCurrency abstractCurrency = Markets.getCurrencyManager().locateCurrency(split[0], split[1]);

if (!split[0].equalsIgnoreCase("vault") && !split[1].equalsIgnoreCase("vault") && abstractCurrency != null)
return abstractCurrency.getDisplayName();

return Settings.CURRENCY_VAULT_SYMBOL.getString();
}
}
11 changes: 11 additions & 0 deletions src/main/java/ca/tweetzy/markets/commands/CommandAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ca.tweetzy.flight.settings.TranslationManager;
import ca.tweetzy.markets.Markets;
import ca.tweetzy.markets.gui.shared.MarketsMainGUI;
import ca.tweetzy.markets.gui.user.BankGUI;
import ca.tweetzy.markets.settings.Settings;
import ca.tweetzy.markets.settings.Translations;
import org.bukkit.Bukkit;
Expand All @@ -29,6 +30,16 @@ protected ReturnType execute(CommandSender sender, String... args) {
}// 0 1 2


if (args.length == 1) {
if (!(sender instanceof final Player player)) return ReturnType.FAIL;

switch(args[0].toLowerCase()) {
case "collecttax":
Markets.getGuiManager().showGUI(player, new BankGUI(null, player, true));
}
return ReturnType.SUCCESS;
}

if (args.length >= 2) {
final Player target = Bukkit.getPlayerExact(args[0]);

Expand Down
33 changes: 16 additions & 17 deletions src/main/java/ca/tweetzy/markets/commands/CommandView.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,33 @@ protected ReturnType execute(CommandSender sender, String... args) {
return ReturnType.FAIL;
}

if (args.length == 1){
if (market.getOwnerUUID().equals(player.getUniqueId())) {
Markets.getGuiManager().showGUI(player, new MarketOverviewGUI(player, market));
} else {
Markets.getGuiManager().showGUI(player, new MarketViewGUI(player, market));
}
return ReturnType.SUCCESS;
}

if (args.length == 2) {
final Category locatedCategory = market.getCategories().stream().filter(category -> category.getName().equalsIgnoreCase(args[1])).findFirst().orElse(null);
if (locatedCategory == null) {
handle(market, player, target);
} else {
if (market.getOwnerUUID().equals(target.getUniqueId())) {
Markets.getGuiManager().showGUI(player, new MarketCategoryViewGUI(player, market, locatedCategory));
} else {
Markets.getGuiManager().showGUI(player, new MarketCategoryEditGUI(player, market, locatedCategory));
}
return ReturnType.FAIL;
}

} else {
handle(market, player, target);
if (market.getOwnerUUID().equals(player.getUniqueId())) {
Markets.getGuiManager().showGUI(player, new MarketCategoryEditGUI(player, market, locatedCategory));
} else {
Markets.getGuiManager().showGUI(player, new MarketCategoryViewGUI(player, market, locatedCategory, false));

}
}
}

return ReturnType.SUCCESS;
}

private void handle(Market market, Player player, OfflinePlayer target) {
if (market.getOwnerUUID().equals(target.getUniqueId())) {
Markets.getGuiManager().showGUI(player, new MarketOverviewGUI(player, market));
} else {
Markets.getGuiManager().showGUI(player, new MarketViewGUI(player, market));
}
}

@Override
protected List<String> tab(CommandSender sender, String... args) {
return null;
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/ca/tweetzy/markets/database/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ca.tweetzy.markets.impl.*;
import ca.tweetzy.markets.impl.layout.HomeLayout;
import lombok.NonNull;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -578,7 +579,7 @@ public void deleteOffer(@NonNull final Offer offer, Callback<Boolean> callback)
public void createBankEntry(@NonNull final BankEntry bankEntry, final Callback<BankEntry> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> {

final String query = "INSERT INTO " + this.getTablePrefix() + "bank_entry (id, owner, item, quantity) VALUES (?, ?, ?, ?)";
final String query = "INSERT INTO " + this.getTablePrefix() + "bank_entry (id, owner, item, quantity, price, currency, currency_item) VALUES (?, ?, ?, ?, ?, ?, ?)";
final String fetchQuery = "SELECT * FROM " + this.getTablePrefix() + "bank_entry WHERE id = ?";

try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
Expand All @@ -591,6 +592,10 @@ public void createBankEntry(@NonNull final BankEntry bankEntry, final Callback<B
preparedStatement.setString(3, SerializeUtil.encodeItem(bankEntry.getItem()));
preparedStatement.setInt(4, bankEntry.getQuantity());

preparedStatement.setDouble(5, bankEntry.getPrice());
preparedStatement.setString(6, bankEntry.getCurrency());
preparedStatement.setString(7, SerializeUtil.encodeItem( bankEntry.getCurrencyItem()));

preparedStatement.executeUpdate();

if (callback != null) {
Expand Down Expand Up @@ -627,12 +632,14 @@ public void getBankEntries(@NonNull final Callback<List<BankEntry>> callback) {
public void updateBankEntry(@NonNull final BankEntry entry, final Callback<Boolean> callback) {
this.runAsync(() -> this.databaseConnector.connect(connection -> {
//id, owning_market, name, icon, display_name, description, created_at, updated_at
final String query = "UPDATE " + this.getTablePrefix() + "bank_entry SET quantity = ? WHERE id = ?";
final String query = "UPDATE " + this.getTablePrefix() + "bank_entry SET quantity = ?, price = ? WHERE id = ?";

try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {

preparedStatement.setInt(1, entry.getQuantity());
preparedStatement.setString(2, entry.getId().toString());
preparedStatement.setDouble(2, entry.getPrice());

preparedStatement.setString(3, entry.getId().toString());

int result = preparedStatement.executeUpdate();

Expand Down Expand Up @@ -887,11 +894,17 @@ private Rating extractMarketRating(@NonNull final ResultSet resultSet) throws SQ
}

private BankEntry extractBankEntry(@NonNull final ResultSet resultSet) throws SQLException {

final ItemStack currencyItem = resultSet.getString("currency_item") == null ? CompMaterial.AIR.parseItem() : SerializeUtil.decodeItem(resultSet.getString("currency_item"));

return new MarketBankEntry(
UUID.fromString(resultSet.getString("id")),
UUID.fromString(resultSet.getString("owner")),
SerializeUtil.decodeItem(resultSet.getString("item")),
resultSet.getInt("quantity")
resultSet.getInt("quantity"),
resultSet.getString("currency"),
currencyItem,
resultSet.getDouble("price")
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ca.tweetzy.markets.database.migrations;

import ca.tweetzy.flight.database.DataMigration;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public final class _17_BankEntryPriceMigration extends DataMigration {

public _17_BankEntryPriceMigration() {
super(17);
}

@Override
public void migrate(Connection connection, String tablePrefix) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute("ALTER TABLE " + tablePrefix + "bank_entry ADD price DOUBLE NOT NULL default 0;");
statement.execute("ALTER TABLE " + tablePrefix + "bank_entry ADD currency VARCHAR(72) NOT NULL DEFAULT 'Vault/Vault'");
statement.execute("ALTER TABLE " + tablePrefix + "bank_entry ADD currency_item TEXT NULL");

}
}
}
Loading

0 comments on commit f45bf1b

Please sign in to comment.