mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2025-01-08 07:57:41 +01:00
Move message for a successful transaction in dedicated informer class
This commit is contained in:
parent
355572f7f3
commit
5a6b338172
@ -2,8 +2,26 @@ package de.epiceric.shopchest.transaction;
|
|||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public interface Actor {
|
public interface Actor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this {@link Actor} is represented by an entity
|
||||||
|
* <br>
|
||||||
|
* (e.g. An admin shop is not represented; A player shop is represented (by a player owner))
|
||||||
|
*
|
||||||
|
* @return Whether this {@link Actor} is represented
|
||||||
|
*/
|
||||||
|
boolean isRepresented();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of this {@link Actor}
|
||||||
|
*
|
||||||
|
* @return The name of this {@link Actor}
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this {@link Actor} have a specified amount of money
|
* Check if this {@link Actor} have a specified amount of money
|
||||||
*
|
*
|
||||||
@ -33,7 +51,7 @@ public interface Actor {
|
|||||||
/**
|
/**
|
||||||
* Send a message to this {@link Actor}
|
* Send a message to this {@link Actor}
|
||||||
*
|
*
|
||||||
* @param message The message to send
|
* @param messageSupplier The message supplier that provide the message to send
|
||||||
*/
|
*/
|
||||||
void sendMessage(String message);
|
void sendMessage(Supplier<String> messageSupplier);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package de.epiceric.shopchest.transaction;
|
package de.epiceric.shopchest.transaction;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.config.Config;
|
||||||
|
import de.epiceric.shopchest.config.Placeholder;
|
||||||
import de.epiceric.shopchest.language.LanguageUtils;
|
import de.epiceric.shopchest.language.LanguageUtils;
|
||||||
import de.epiceric.shopchest.language.Message;
|
import de.epiceric.shopchest.language.Message;
|
||||||
|
import de.epiceric.shopchest.language.Replacement;
|
||||||
|
|
||||||
public class BuyInformer implements TransactionInformer {
|
public class BuyInformer implements TransactionInformer {
|
||||||
|
|
||||||
@ -9,17 +12,58 @@ public class BuyInformer implements TransactionInformer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughMoney() {
|
public void sendNotEnoughMoney() {
|
||||||
buyer.sendMessage(LanguageUtils.getMessage(Message.NOT_ENOUGH_MONEY));
|
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.NOT_ENOUGH_MONEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughItem() {
|
public void sendNotEnoughItem() {
|
||||||
buyer.sendMessage(LanguageUtils.getMessage(Message.OUT_OF_STOCK));
|
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.OUT_OF_STOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughSpace() {
|
public void sendNotEnoughSpace() {
|
||||||
buyer.sendMessage(LanguageUtils.getMessage(Message.NOT_ENOUGH_INVENTORY_SPACE));
|
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.NOT_ENOUGH_INVENTORY_SPACE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendInitiatorSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired) {
|
||||||
|
if (seller.isRepresented()) {
|
||||||
|
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.BUY_SUCCESS,
|
||||||
|
new Replacement(Placeholder.AMOUNT, amount),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, productName),
|
||||||
|
new Replacement(Placeholder.BUY_PRICE, String.valueOf(moneyAmountRequired)),
|
||||||
|
new Replacement(Placeholder.VENDOR, seller.getName())
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.BUY_SUCCESS_ADMIN,
|
||||||
|
new Replacement(Placeholder.AMOUNT, amount),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, productName),
|
||||||
|
new Replacement(Placeholder.BUY_PRICE, String.valueOf(moneyAmountRequired))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTargetSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired) {
|
||||||
|
if (sellerPlayer.isOnline()) {
|
||||||
|
if (Config.enableVendorMessages) {
|
||||||
|
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_BOUGHT,
|
||||||
|
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
||||||
|
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
|
||||||
|
new Replacement(Placeholder.PLAYER, executor.getName())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (Config.enableVendorBungeeMessages) {
|
||||||
|
String message = LanguageUtils.getMessage(Message.SOMEONE_BOUGHT,
|
||||||
|
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
||||||
|
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
|
||||||
|
new Replacement(Placeholder.PLAYER, executor.getName())
|
||||||
|
);
|
||||||
|
sendBungeeMessage(shop.getVendor().getName(), message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package de.epiceric.shopchest.transaction;
|
package de.epiceric.shopchest.transaction;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.config.Config;
|
||||||
|
import de.epiceric.shopchest.config.Placeholder;
|
||||||
import de.epiceric.shopchest.language.LanguageUtils;
|
import de.epiceric.shopchest.language.LanguageUtils;
|
||||||
import de.epiceric.shopchest.language.Message;
|
import de.epiceric.shopchest.language.Message;
|
||||||
|
import de.epiceric.shopchest.language.Replacement;
|
||||||
|
|
||||||
public class SellInformer implements TransactionInformer {
|
public class SellInformer implements TransactionInformer {
|
||||||
|
|
||||||
@ -9,17 +12,59 @@ public class SellInformer implements TransactionInformer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughMoney() {
|
public void sendNotEnoughMoney() {
|
||||||
seller.sendMessage(LanguageUtils.getMessage(Message.VENDOR_NOT_ENOUGH_MONEY));
|
seller.sendMessage(() -> LanguageUtils.getMessage(Message.VENDOR_NOT_ENOUGH_MONEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughItem() {
|
public void sendNotEnoughItem() {
|
||||||
seller.sendMessage(LanguageUtils.getMessage(Message.NOT_ENOUGH_ITEMS));
|
seller.sendMessage(() -> LanguageUtils.getMessage(Message.NOT_ENOUGH_ITEMS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendNotEnoughSpace() {
|
public void sendNotEnoughSpace() {
|
||||||
seller.sendMessage(LanguageUtils.getMessage(Message.CHEST_NOT_ENOUGH_INVENTORY_SPACE));
|
seller.sendMessage(() -> LanguageUtils.getMessage(Message.CHEST_NOT_ENOUGH_INVENTORY_SPACE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendInitiatorSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired) {
|
||||||
|
if (buyer.isRepresented()) {
|
||||||
|
seller.sendMessage(() -> LanguageUtils.getMessage(Message.SELL_SUCCESS,
|
||||||
|
new Replacement(Placeholder.AMOUNT, amount),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, productName),
|
||||||
|
new Replacement(Placeholder.SELL_PRICE, String.valueOf(moneyAmountGiven)),
|
||||||
|
new Replacement(Placeholder.VENDOR, buyer.getName())
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IF ADMIN SHOP
|
||||||
|
seller.sendMessage(() -> LanguageUtils.getMessage(Message.SELL_SUCCESS_ADMIN,
|
||||||
|
new Replacement(Placeholder.AMOUNT, amount),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, productName),
|
||||||
|
new Replacement(Placeholder.SELL_PRICE, String.valueOf(moneyAmountGiven))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTargetSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired) {
|
||||||
|
if (buyerPlayer.isOnline()) {
|
||||||
|
if (Config.enableVendorMessages) {
|
||||||
|
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_SOLD,
|
||||||
|
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
||||||
|
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
|
||||||
|
new Replacement(Placeholder.PLAYER, executor.getName())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (Config.enableVendorBungeeMessages) {
|
||||||
|
String message = LanguageUtils.getMessage(Message.SOMEONE_SOLD,
|
||||||
|
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
||||||
|
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
||||||
|
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
|
||||||
|
new Replacement(Placeholder.PLAYER, executor.getName())
|
||||||
|
);
|
||||||
|
sendBungeeMessage(shop.getVendor().getName(), message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package de.epiceric.shopchest.transaction;
|
package de.epiceric.shopchest.transaction;
|
||||||
|
|
||||||
import de.epiceric.shopchest.config.Config;
|
|
||||||
import de.epiceric.shopchest.config.Placeholder;
|
|
||||||
import de.epiceric.shopchest.event.ShopBuySellEvent;
|
import de.epiceric.shopchest.event.ShopBuySellEvent;
|
||||||
import de.epiceric.shopchest.language.LanguageUtils;
|
|
||||||
import de.epiceric.shopchest.language.Message;
|
|
||||||
import de.epiceric.shopchest.language.Replacement;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
// TODO Moved outclass :
|
// TODO Moved outclass :
|
||||||
@ -125,85 +120,10 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void inform() {
|
private void inform() {
|
||||||
|
String amountStr;
|
||||||
// DIRECT
|
String productName;
|
||||||
|
informer.sendInitiatorSuccess(amountStr, productName, moneyAmountGiven, moneyAmountRequired);
|
||||||
// TO BUYER
|
informer.sendTargetSuccess(amountStr, productName, moneyAmountGiven, moneyAmountRequired);
|
||||||
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
|
|
||||||
executor.sendMessage(LanguageUtils.getMessage(Message.BUY_SUCCESS,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.VENDOR, vendorName)
|
|
||||||
));
|
|
||||||
|
|
||||||
// IF ADMIN SHOP
|
|
||||||
executor.sendMessage(LanguageUtils.getMessage(Message.BUY_SUCCESS_ADMIN,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount1)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice))
|
|
||||||
));
|
|
||||||
|
|
||||||
// TO SELLER
|
|
||||||
if(sellerPlayer.isOnline()) {
|
|
||||||
if(Config.enableVendorMessages) {
|
|
||||||
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_BOUGHT,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.PLAYER, executor.getName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(Config.enableVendorBungeeMessages) {
|
|
||||||
String message = LanguageUtils.getMessage(Message.SOMEONE_BOUGHT,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.PLAYER, executor.getName())
|
|
||||||
);
|
|
||||||
sendBungeeMessage(shop.getVendor().getName(), message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// INDIRECT
|
|
||||||
|
|
||||||
// TO BUYER
|
|
||||||
if(buyerPlayer.isOnline()) {
|
|
||||||
if(Config.enableVendorMessages) {
|
|
||||||
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_SOLD,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.PLAYER, executor.getName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(Config.enableVendorBungeeMessages) {
|
|
||||||
String message = LanguageUtils.getMessage(Message.SOMEONE_SOLD,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.PLAYER, executor.getName())
|
|
||||||
);
|
|
||||||
sendBungeeMessage(shop.getVendor().getName(), message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TO SELLER
|
|
||||||
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
|
|
||||||
executor.sendMessage(LanguageUtils.getMessage(Message.SELL_SUCCESS,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
|
|
||||||
new Replacement(Placeholder.VENDOR, vendorName)
|
|
||||||
));
|
|
||||||
|
|
||||||
// IF ADMIN SHOP
|
|
||||||
executor.sendMessage(LanguageUtils.getMessage(Message.SELL_SUCCESS_ADMIN,
|
|
||||||
new Replacement(Placeholder.AMOUNT, String.valueOf(finalNewAmount)),
|
|
||||||
new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()),
|
|
||||||
new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice))
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,8 @@ public interface TransactionInformer {
|
|||||||
|
|
||||||
void sendNotEnoughSpace();
|
void sendNotEnoughSpace();
|
||||||
|
|
||||||
|
void sendInitiatorSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired);
|
||||||
|
|
||||||
|
void sendTargetSuccess(String amount, String productName, double moneyAmountGiven, double moneyAmountRequired);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user