Add the draft of the transaction structure

This commit is contained in:
Flowsqy 2022-08-27 11:51:11 +02:00
parent 1d136933a7
commit a91e9c1661
6 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package de.epiceric.shopchest.shop;
import org.bukkit.inventory.ItemStack;
public class Product {
private final ItemStack itemStack;
private final ProductValue productValue;
public Product(ItemStack itemStack, ProductValue productValue) {
this.itemStack = itemStack;
this.productValue = productValue;
}
}

View File

@ -0,0 +1,8 @@
package de.epiceric.shopchest.shop;
public class ProductValue {
private final int amount;
private final double price;
}

View File

@ -0,0 +1,18 @@
package de.epiceric.shopchest.shop;
import org.bukkit.inventory.ItemStack;
public class Shop_ {
private final ItemStack itemStack;
private final ProductValue buyValue, sellValue;
public Product getBuyProduct() {
return new Product(itemStack, buyValue);
}
public Product getSellProduct() {
return new Product(itemStack, sellValue);
}
}

View File

@ -0,0 +1,4 @@
package de.epiceric.shopchest.transaction;
public interface Actor {
}

View File

@ -0,0 +1,52 @@
package de.epiceric.shopchest.transaction;
import org.bukkit.inventory.ItemStack;
public class Transaction {
private final Actor buyer, seller;
private final ItemStack itemStack;
private int amount;
private final double buyPrice, sellPrice;
public void apply() {
if(!check()) {
return;
}
transferItems();
transferMoney();
inform();
// log
}
private boolean check() {
// Check buyer money
// Check seller item quantity
// Check buyer inventory space
}
private void transferItems() {
// Remove items from seller inventory
// Add items in buyer inventory
}
private void transferMoney() {
// Remove buyer money
// Add seller money
}
private void inform() {
// Inform buyer
// Inform seller
}
}

View File

@ -0,0 +1,18 @@
package de.epiceric.shopchest.transaction;
import de.epiceric.shopchest.shop.Product;
public class TransactionRequest {
private final Actor buyer, seller;
private final Product product;
private final int amount;
public Transaction prepare() {
// Calculate price
// Apply taxes
}
}