2012-08-10 21:44:32 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2012-08-10 22:25:08 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
2014-05-20 23:13:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Commands.Toggle;
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
|
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Economy.Economy;
|
|
|
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
|
|
|
import org.bukkit.Bukkit;
|
2018-08-23 23:10:24 +02:00
|
|
|
import org.bukkit.Location;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2014-04-12 14:22:34 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class TransactionMessageSender implements Listener {
|
2018-08-22 01:21:34 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
2012-06-08 15:28:36 +02:00
|
|
|
public static void onTransaction(TransactionEvent event) {
|
2012-08-10 18:56:16 +02:00
|
|
|
if (event.getTransactionType() == TransactionEvent.TransactionType.BUY) {
|
2012-06-08 15:28:36 +02:00
|
|
|
sendBuyMessage(event);
|
|
|
|
} else {
|
|
|
|
sendSellMessage(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void sendBuyMessage(TransactionEvent event) {
|
|
|
|
Player player = event.getClient();
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
2019-09-15 00:49:40 +02:00
|
|
|
sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", event.getOwnerAccount().getName());
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 00:49:40 +02:00
|
|
|
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) {
|
2018-01-06 17:44:35 +01:00
|
|
|
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
|
|
|
if (owner != null) {
|
2018-01-11 15:29:04 +01:00
|
|
|
sendMessage(owner, Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
|
2018-01-06 17:44:35 +01:00
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 17:44:35 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
protected static void sendSellMessage(TransactionEvent event) {
|
|
|
|
Player player = event.getClient();
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
2019-09-15 00:49:40 +02:00
|
|
|
sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", event.getOwnerAccount().getName());
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 00:49:40 +02:00
|
|
|
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) {
|
2018-01-06 17:44:35 +01:00
|
|
|
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
|
|
|
if (owner != null) {
|
|
|
|
sendMessage(owner, Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName());
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 17:44:35 +01:00
|
|
|
|
|
|
|
private static void sendMessage(Player player, String rawMessage, TransactionEvent event, String... replacements) {
|
2018-08-23 23:10:24 +02:00
|
|
|
Location loc = event.getSign().getLocation();
|
2018-01-06 17:44:35 +01:00
|
|
|
String message = Messages.prefix(rawMessage)
|
2019-04-25 19:44:22 +02:00
|
|
|
.replace("%price", Economy.formatBalance(event.getExactPrice()))
|
2018-08-23 23:10:24 +02:00
|
|
|
.replace("%world", loc.getWorld().getName())
|
|
|
|
.replace("%x", String.valueOf(loc.getBlockX()))
|
|
|
|
.replace("%y", String.valueOf(loc.getBlockY()))
|
|
|
|
.replace("%z", String.valueOf(loc.getBlockZ()));
|
2018-01-06 17:44:35 +01:00
|
|
|
|
|
|
|
for (int i = 0; i + 1 < replacements.length; i+=2) {
|
|
|
|
message = message.replace("%" + replacements[i], replacements[i + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, event.getStock())) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-23 23:10:24 +02:00
|
|
|
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(event.getStock())));
|
2018-01-06 17:44:35 +01:00
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
|
|
|
|
}
|