Merge branch 'dev/rewrite' of https://github.com/Altitude-Devs/PlayerShops into dev/rewrite
This commit is contained in:
commit
b07bf2a92b
|
|
@ -6,6 +6,7 @@ import com.alttd.playershops.handler.ShopHandler;
|
|||
import com.alttd.playershops.hook.WorldGuardHook;
|
||||
import com.alttd.playershops.shop.PlayerShop;
|
||||
import com.alttd.playershops.shop.TransactionError;
|
||||
import com.alttd.playershops.storage.database.DatabaseHelper;
|
||||
import com.alttd.playershops.utils.Logger;
|
||||
import com.alttd.playershops.utils.ShopUtil;
|
||||
import com.alttd.playershops.utils.Util;
|
||||
|
|
@ -134,6 +135,7 @@ public class TransactionListener extends EventListener {
|
|||
return;
|
||||
}
|
||||
player.sendActionBar(Util.parseMiniMessage(shop.getType().getShopTypeConfig().playerBought, placeholders));
|
||||
plugin.getDatabaseHelper().logTransaction(player, shop, orders);
|
||||
}
|
||||
|
||||
private boolean notifyOwner(PlayerShop playerShop) {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import com.alttd.playershops.utils.ShopUtil;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -54,6 +56,20 @@ public record DatabaseHelper(PlayerShops plugin, DatabaseManager databaseManager
|
|||
|
||||
void createTransactionsTable() {
|
||||
Logger.info("Creating transactions table");
|
||||
String sql = "CREATE TABLE IF NOT EXISTS transactions(" +
|
||||
"id INT NOT NULL AUTO INCREMENT, " +
|
||||
"shop_id VARCHAR(36) NOT NULL, " +
|
||||
"actor_name VARCHAR(16) NOT NULL, " +
|
||||
"actor_uuid VARCHAR(36) NOT NULL, " +
|
||||
"server VARCHAR(16) NOT NULL, " +
|
||||
"action VARCHAR(36) NOT NULL, " +
|
||||
"time BIGINT NOT NULL, " +
|
||||
"price DOUBLE, " +
|
||||
"amount INT, " +
|
||||
"item BLOB, " +
|
||||
"PRIMARY KEY (id)" +
|
||||
")";
|
||||
databaseManager().addDatabaseQuery(new DatabaseQuery(sql), false);
|
||||
}
|
||||
|
||||
ResultSet selectTable(String tableName) throws SQLException {
|
||||
|
|
@ -175,4 +191,38 @@ public record DatabaseHelper(PlayerShops plugin, DatabaseManager databaseManager
|
|||
}), queue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a transaction with a shop
|
||||
*/
|
||||
public void logTransaction(Player player, PlayerShop shop, int orders) {
|
||||
String query = "INSERT INTO transaction (shop_id, actor_name, actor_uuid, server, action, time, price, amount, item) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
databaseManager().addDatabaseQuery(
|
||||
new DatabaseQuery(query, new DatabaseQuery.DatabaseTask() {
|
||||
@Override
|
||||
public void edit(PreparedStatement ps) throws SQLException {
|
||||
ps.setString(1, shop.getShopID().toString());
|
||||
ps.setString(2, player.getName());
|
||||
ps.setString(3, player.getUniqueId().toString());
|
||||
ps.setString(4, shop.getServer());
|
||||
ps.setString(5, shop.getType().toString());
|
||||
ps.setLong(6, new Date().getTime());
|
||||
ps.setDouble(7, shop.getPrice());
|
||||
ps.setInt(8, orders);
|
||||
ItemStack itemStack = shop.getItemStack();
|
||||
if (itemStack != null && !itemStack.getType().equals(Material.AIR)) {
|
||||
ps.setBytes(9, shop.getItemStack().serializeAsBytes());
|
||||
} else {
|
||||
ps.setBytes(9, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(SQLException e) {
|
||||
Logger.error("Could not log transaction by " + player.getName() + " at " + shop.getShopLocation() + " to the database.\n" + e);
|
||||
}
|
||||
}), true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user