mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-10 09:07:39 +01:00
Added ability to show item icons and hover info with ShowItem
This commit is contained in:
parent
110d98d599
commit
ac73442643
11
pom.xml
11
pom.xml
@ -40,6 +40,10 @@
|
|||||||
<id>authme-repo</id>
|
<id>authme-repo</id>
|
||||||
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
|
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>minebench-repo</id>
|
||||||
|
<url>https://repo.minebench.de/</url>
|
||||||
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>local_repo</id>
|
<id>local_repo</id>
|
||||||
<url>file://${project.basedir}/repo/</url>
|
<url>file://${project.basedir}/repo/</url>
|
||||||
@ -260,6 +264,13 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.themoep.showitem</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>1.2.24</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,22 +1,32 @@
|
|||||||
package com.Acrobot.Breeze.Utils;
|
package com.Acrobot.Breeze.Utils;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import de.themoep.ShowItem.api.ShowItem;
|
||||||
import info.somethingodd.OddItem.OddItem;
|
import info.somethingodd.OddItem.OddItem;
|
||||||
import org.bukkit.CoalType;
|
import org.bukkit.CoalType;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.TreeSpecies;
|
import org.bukkit.TreeSpecies;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.material.*;
|
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.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
@ -420,4 +430,56 @@ public class MaterialUtil {
|
|||||||
isInitialized = true;
|
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<String> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,4 +149,8 @@ public class Properties {
|
|||||||
@PrecededBySpace
|
@PrecededBySpace
|
||||||
@ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?")
|
@ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?")
|
||||||
public static double HEROES_EXP = 100;
|
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;
|
||||||
}
|
}
|
@ -109,6 +109,9 @@ public class Dependencies {
|
|||||||
case OddItem:
|
case OddItem:
|
||||||
MaterialUtil.Odd.initialize();
|
MaterialUtil.Odd.initialize();
|
||||||
break;
|
break;
|
||||||
|
case ShowItem:
|
||||||
|
MaterialUtil.Show.initialize(plugin);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
@ -130,6 +133,8 @@ public class Dependencies {
|
|||||||
|
|
||||||
WorldGuard,
|
WorldGuard,
|
||||||
|
|
||||||
Heroes
|
Heroes,
|
||||||
|
|
||||||
|
ShowItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,51 +34,53 @@ public class TransactionMessageSender implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void sendBuyMessage(TransactionEvent event) {
|
protected static void sendBuyMessage(TransactionEvent event) {
|
||||||
String itemName = parseItemInformation(event.getStock());
|
String ownerName = event.getOwnerAccount().getName();
|
||||||
String owner = event.getOwnerAccount().getName();
|
|
||||||
|
|
||||||
Player player = event.getClient();
|
Player player = event.getClient();
|
||||||
|
|
||||||
String price = Economy.formatBalance(event.getPrice());
|
|
||||||
|
|
||||||
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
||||||
String message = formatMessage(Messages.YOU_BOUGHT_FROM_SHOP, itemName, price);
|
sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", ownerName);
|
||||||
message = message.replace("%owner", owner);
|
|
||||||
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getName())) {
|
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getName())) {
|
||||||
String message = formatMessage(Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, itemName, price);
|
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
||||||
message = message.replace("%buyer", player.getName());
|
if (owner != null) {
|
||||||
|
sendMessage(player, Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName());
|
||||||
sendMessageToOwner(message, event);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void sendSellMessage(TransactionEvent event) {
|
protected static void sendSellMessage(TransactionEvent event) {
|
||||||
String itemName = parseItemInformation(event.getStock());
|
String ownerName = event.getOwnerAccount().getName();
|
||||||
String owner = event.getOwnerAccount().getName();
|
|
||||||
|
|
||||||
Player player = event.getClient();
|
Player player = event.getClient();
|
||||||
|
|
||||||
String price = Economy.formatBalance(event.getPrice());
|
|
||||||
|
|
||||||
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) {
|
||||||
String message = formatMessage(Messages.YOU_SOLD_TO_SHOP, itemName, price);
|
sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", ownerName);
|
||||||
message = message.replace("%buyer", owner);
|
|
||||||
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(owner)) {
|
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(ownerName)) {
|
||||||
String message = formatMessage(Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, itemName, price);
|
Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid());
|
||||||
message = message.replace("%seller", player.getName());
|
if (owner != null) {
|
||||||
|
sendMessage(owner, Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName());
|
||||||
sendMessageToOwner(message, event);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
private static String parseItemInformation(ItemStack[] items) {
|
||||||
ItemStack[] stock = InventoryUtil.mergeSimilarStacks(items);
|
ItemStack[] stock = InventoryUtil.mergeSimilarStacks(items);
|
||||||
|
|
||||||
@ -90,20 +92,4 @@ public class TransactionMessageSender implements Listener {
|
|||||||
|
|
||||||
return StringUtil.joinArray(itemText);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ author: Acrobot
|
|||||||
authors: ['https://github.com/ChestShop-authors/ChestShop-3/contributors']
|
authors: ['https://github.com/ChestShop-authors/ChestShop-3/contributors']
|
||||||
description: A chest shop for economy plugins.
|
description: A chest shop for economy plugins.
|
||||||
depend: [Vault]
|
depend: [Vault]
|
||||||
softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence]
|
softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence, ShowItem]
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
iteminfo:
|
iteminfo:
|
||||||
|
Loading…
Reference in New Issue
Block a user