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;
|
2019-11-19 21:50:17 +01:00
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
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;
|
2021-01-03 01:55:01 +01:00
|
|
|
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
2012-06-08 15:28:36 +02:00
|
|
|
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
|
|
|
|
2020-06-28 19:00:09 +02:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
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-11-19 21:50:17 +01:00
|
|
|
sendMessage(player, event.getClient().getName(), 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());
|
2019-11-19 21:50:17 +01:00
|
|
|
sendMessage(owner, event.getOwnerAccount().getName(), Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
|
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-11-19 21:50:17 +01:00
|
|
|
sendMessage(player, event.getClient().getName(), 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());
|
2019-11-19 21:50:17 +01:00
|
|
|
sendMessage(owner, event.getOwnerAccount().getName(), 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
|
|
|
|
2020-06-28 19:00:09 +02:00
|
|
|
private static void sendMessage(Player player, String playerName, Messages.Message rawMessage, TransactionEvent event, String... replacements) {
|
2018-08-23 23:10:24 +02:00
|
|
|
Location loc = event.getSign().getLocation();
|
2020-06-28 19:00:09 +02:00
|
|
|
Map<String, String> replacementMap = new LinkedHashMap<>();
|
|
|
|
replacementMap.put("price", Economy.formatBalance(event.getExactPrice()));
|
|
|
|
replacementMap.put("world", loc.getWorld().getName());
|
|
|
|
replacementMap.put("x", String.valueOf(loc.getBlockX()));
|
|
|
|
replacementMap.put("y", String.valueOf(loc.getBlockY()));
|
|
|
|
replacementMap.put("z", String.valueOf(loc.getBlockZ()));
|
2020-07-03 19:13:40 +02:00
|
|
|
replacementMap.put("material", "%item");
|
2018-01-06 17:44:35 +01:00
|
|
|
|
|
|
|
for (int i = 0; i + 1 < replacements.length; i+=2) {
|
2020-06-28 19:00:09 +02:00
|
|
|
replacementMap.put(replacements[i], replacements[i + 1]);
|
2018-01-06 17:44:35 +01:00
|
|
|
}
|
2019-11-19 21:50:17 +01:00
|
|
|
|
2020-07-03 19:24:14 +02:00
|
|
|
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, playerName, rawMessage, event.getStock(), replacementMap)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 21:50:17 +01:00
|
|
|
if (player != null) {
|
2021-01-03 01:55:01 +01:00
|
|
|
replacementMap.put("item", ItemUtil.getItemList(event.getStock()));
|
2020-06-28 19:00:09 +02:00
|
|
|
rawMessage.sendWithPrefix(player, replacementMap);
|
2019-11-19 21:50:17 +01:00
|
|
|
} else if (playerName != null) {
|
2021-01-03 01:55:01 +01:00
|
|
|
replacementMap.put("item", ItemUtil.getItemList(event.getStock()));
|
2020-06-28 19:00:09 +02:00
|
|
|
ChestShop.sendBungeeMessage(playerName, rawMessage, replacementMap);
|
2018-01-06 17:44:35 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 15:28:36 +02:00
|
|
|
|
|
|
|
}
|