diff --git a/pom.xml b/pom.xml
index 740b92c..838314d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,10 @@
authme-repo
http://ci.xephi.fr/plugin/repository/everything/
+
+ minebench-repo
+ https://repo.minebench.de/
+
local_repo
file://${project.basedir}/repo/
@@ -260,6 +264,13 @@
+
+
+ de.themoep.showitem
+ api
+ 1.2.24
+ provided
+
diff --git a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java
index 3851816..e31e081 100644
--- a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java
+++ b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java
@@ -1,22 +1,32 @@
package com.Acrobot.Breeze.Utils;
import com.Acrobot.ChestShop.ChestShop;
+import com.google.common.collect.ImmutableMap;
+import de.themoep.ShowItem.api.ShowItem;
import info.somethingodd.OddItem.OddItem;
import org.bukkit.CoalType;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.*;
+import org.bukkit.plugin.Plugin;
+import org.json.simple.JSONObject;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* @author Acrobot
@@ -420,4 +430,56 @@ public class MaterialUtil {
isInitialized = true;
}
}
+
+ public static class Show {
+ private static ShowItem showItem = null;
+
+ /**
+ * Lets the class know that it's safe to use the ShowItem methods now
+ *
+ * @param plugin
+ */
+ public static void initialize(Plugin plugin) {
+ showItem = (ShowItem) plugin;
+ }
+
+ /**
+ * Send a message with hover info and icons
+ *
+ * @param player The player to send the message to
+ * @param message The raw message
+ * @param stock The items in stock
+ */
+ public static boolean sendMessage(Player player, String message, ItemStack[] stock) {
+ if (showItem == null) {
+ return false;
+ }
+
+ List itemJson = new ArrayList<>();
+ for (ItemStack item : stock) {
+ try {
+ itemJson.add(showItem.getItemConverter().createComponent(item, Level.OFF).toJsonString(player));
+ } catch (Exception e) {
+ ChestShop.getPlugin().getLogger().log(Level.WARNING, "Error while trying to send message '" + message + "' to player " + player.getName() + ": " + e.getMessage());
+ return false;
+ }
+ }
+
+ String joinedItemJson = itemJson.stream().collect(Collectors.joining("," + new JSONObject(ImmutableMap.of("text", " ")).toJSONString() + ", "));
+
+ String messageJsonString = Arrays.stream(message.split("%item"))
+ .map(s -> new JSONObject(ImmutableMap.of("text", s)).toJSONString())
+ .collect(Collectors.joining("," + joinedItemJson + ","));
+
+ while (messageJsonString.startsWith(",")) {
+ messageJsonString = messageJsonString.substring(1);
+ }
+ while (messageJsonString.endsWith(",")) {
+ messageJsonString = messageJsonString.substring(0, messageJsonString.length() - 1);
+ }
+
+ showItem.tellRaw(player, messageJsonString);
+ return true;
+ }
+ }
}
diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java
index 6480d9b..450d015 100644
--- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java
+++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java
@@ -149,4 +149,8 @@ public class Properties {
@PrecededBySpace
@ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?")
public static double HEROES_EXP = 100;
+
+ @PrecededBySpace
+ @ConfigurationComment("Add icons and make item names hoverable in transaction messages when ShowItem is installed?")
+ public static boolean SHOWITEM_MESSAGE = true;
}
\ No newline at end of file
diff --git a/src/main/java/com/Acrobot/ChestShop/Dependencies.java b/src/main/java/com/Acrobot/ChestShop/Dependencies.java
index b8f983c..3a36d80 100644
--- a/src/main/java/com/Acrobot/ChestShop/Dependencies.java
+++ b/src/main/java/com/Acrobot/ChestShop/Dependencies.java
@@ -109,6 +109,9 @@ public class Dependencies {
case OddItem:
MaterialUtil.Odd.initialize();
break;
+ case ShowItem:
+ MaterialUtil.Show.initialize(plugin);
+ break;
}
if (listener != null) {
@@ -130,6 +133,8 @@ public class Dependencies {
WorldGuard,
- Heroes
+ Heroes,
+
+ ShowItem
}
}
diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java
index 1606333..80f9930 100644
--- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java
+++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java
@@ -34,50 +34,52 @@ public class TransactionMessageSender implements Listener {
}
protected static void sendBuyMessage(TransactionEvent event) {
- String itemName = parseItemInformation(event.getStock());
- String owner = event.getOwnerAccount().getName();
+ String ownerName = event.getOwnerAccount().getName();
Player player = event.getClient();
- String price = Economy.formatBalance(event.getPrice());
-
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
- String message = formatMessage(Messages.YOU_BOUGHT_FROM_SHOP, itemName, price);
- message = message.replace("%owner", owner);
-
- player.sendMessage(message);
+ sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", ownerName);
}
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getName())) {
- String message = formatMessage(Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, itemName, price);
- message = message.replace("%buyer", player.getName());
-
- sendMessageToOwner(message, event);
+ Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
+ if (owner != null) {
+ sendMessage(player, Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
+ }
}
}
-
+
protected static void sendSellMessage(TransactionEvent event) {
- String itemName = parseItemInformation(event.getStock());
- String owner = event.getOwnerAccount().getName();
+ String ownerName = event.getOwnerAccount().getName();
Player player = event.getClient();
- String price = Economy.formatBalance(event.getPrice());
-
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
- String message = formatMessage(Messages.YOU_SOLD_TO_SHOP, itemName, price);
- message = message.replace("%buyer", owner);
-
- player.sendMessage(message);
+ sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", ownerName);
}
- if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(owner)) {
- String message = formatMessage(Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, itemName, price);
- message = message.replace("%seller", player.getName());
-
- sendMessageToOwner(message, event);
+ if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(ownerName)) {
+ Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
+ if (owner != null) {
+ sendMessage(owner, Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName());
+ }
}
}
+
+ private static void sendMessage(Player player, String rawMessage, TransactionEvent event, String... replacements) {
+ String message = Messages.prefix(rawMessage)
+ .replace("%price", Economy.formatBalance(event.getPrice()));
+
+ 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;
+ }
+ player.sendMessage(message.replace("%item", parseItemInformation(event.getStock())));
+ }
private static String parseItemInformation(ItemStack[] items) {
ItemStack[] stock = InventoryUtil.mergeSimilarStacks(items);
@@ -90,20 +92,4 @@ public class TransactionMessageSender implements Listener {
return StringUtil.joinArray(itemText);
}
-
- private static void sendMessageToOwner(String message, TransactionEvent event) {
- UUID owner = event.getOwnerAccount().getUuid();
-
- Player player = Bukkit.getPlayer(owner);
-
- if (player != null) {
- player.sendMessage(message);
- }
- }
-
- private static String formatMessage(String message, String item, String price) {
- return Messages.prefix(message)
- .replace("%item", item)
- .replace("%price", price);
- }
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 8679f64..3e1c2d3 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,7 +5,7 @@ author: Acrobot
authors: ['https://github.com/ChestShop-authors/ChestShop-3/contributors']
description: A chest shop for economy plugins.
depend: [Vault]
-softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence]
+softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence, ShowItem]
commands:
iteminfo: