mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-13 23:05:21 +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 java.util.function.Supplier;
|
||||
|
||||
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
|
||||
*
|
||||
@ -33,7 +51,7 @@ public interface 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;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.config.Placeholder;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.Message;
|
||||
import de.epiceric.shopchest.language.Replacement;
|
||||
|
||||
public class BuyInformer implements TransactionInformer {
|
||||
|
||||
@ -9,17 +12,58 @@ public class BuyInformer implements TransactionInformer {
|
||||
|
||||
@Override
|
||||
public void sendNotEnoughMoney() {
|
||||
buyer.sendMessage(LanguageUtils.getMessage(Message.NOT_ENOUGH_MONEY));
|
||||
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.NOT_ENOUGH_MONEY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNotEnoughItem() {
|
||||
buyer.sendMessage(LanguageUtils.getMessage(Message.OUT_OF_STOCK));
|
||||
buyer.sendMessage(() -> LanguageUtils.getMessage(Message.OUT_OF_STOCK));
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.config.Placeholder;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.Message;
|
||||
import de.epiceric.shopchest.language.Replacement;
|
||||
|
||||
public class SellInformer implements TransactionInformer {
|
||||
|
||||
@ -9,17 +12,59 @@ public class SellInformer implements TransactionInformer {
|
||||
|
||||
@Override
|
||||
public void sendNotEnoughMoney() {
|
||||
seller.sendMessage(LanguageUtils.getMessage(Message.VENDOR_NOT_ENOUGH_MONEY));
|
||||
seller.sendMessage(() -> LanguageUtils.getMessage(Message.VENDOR_NOT_ENOUGH_MONEY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNotEnoughItem() {
|
||||
seller.sendMessage(LanguageUtils.getMessage(Message.NOT_ENOUGH_ITEMS));
|
||||
seller.sendMessage(() -> LanguageUtils.getMessage(Message.NOT_ENOUGH_ITEMS));
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.config.Placeholder;
|
||||
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;
|
||||
|
||||
// TODO Moved outclass :
|
||||
@ -125,85 +120,10 @@ public class Transaction {
|
||||
}
|
||||
|
||||
private void inform() {
|
||||
|
||||
// DIRECT
|
||||
|
||||
// TO BUYER
|
||||
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))
|
||||
));
|
||||
String amountStr;
|
||||
String productName;
|
||||
informer.sendInitiatorSuccess(amountStr, productName, moneyAmountGiven, moneyAmountRequired);
|
||||
informer.sendTargetSuccess(amountStr, productName, moneyAmountGiven, moneyAmountRequired);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,4 +8,8 @@ public interface TransactionInformer {
|
||||
|
||||
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