mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-09 16:47:36 +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>
|
||||
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>minebench-repo</id>
|
||||
<url>https://repo.minebench.de/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>local_repo</id>
|
||||
<url>file://${project.basedir}/repo/</url>
|
||||
@ -260,6 +264,13 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>de.themoep.showitem</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>1.2.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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<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
|
||||
@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;
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user