mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-09 16:47:36 +01:00
Merge branch '1.12' into 1.13
This commit is contained in:
commit
cf9e5bafde
@ -107,6 +107,24 @@ public class MaterialUtil {
|
||||
return material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list with item information
|
||||
*
|
||||
* @param items The items to get the information from
|
||||
* @return The list, including the amount and names of the items
|
||||
*/
|
||||
public static String getItemList(ItemStack[] items) {
|
||||
ItemStack[] mergedItems = InventoryUtil.mergeSimilarStacks(items);
|
||||
|
||||
List<String> itemText = new ArrayList<>();
|
||||
|
||||
for (ItemStack item : mergedItems) {
|
||||
itemText.add(item.getAmount() + " " + getName(item));
|
||||
}
|
||||
|
||||
return String.join(", ", itemText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns item's name
|
||||
*
|
||||
@ -440,7 +458,7 @@ public class MaterialUtil {
|
||||
List<String> itemJson = new ArrayList<>();
|
||||
for (ItemStack item : InventoryUtil.mergeSimilarStacks(stock)) {
|
||||
try {
|
||||
itemJson.add(showItem.getItemConverter().createComponent(item, Level.OFF).toJsonString(player));
|
||||
itemJson.add(showItem.getItemConverter().createComponent(item, Level.FINE).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;
|
||||
|
@ -30,19 +30,19 @@ public class Messages {
|
||||
public static String NOT_ENOUGH_SPACE_IN_INVENTORY = "You haven't got enough space in inventory!";
|
||||
public static String NOT_ENOUGH_SPACE_IN_CHEST = "There isn't enough space in chest!";
|
||||
public static String NOT_ENOUGH_ITEMS_TO_SELL = "You don't have enough items to sell!";
|
||||
public static String NOT_ENOUGH_SPACE_IN_YOUR_SHOP = "%material&7 shop at &r%world/%x/%y/%z&7 is full! (%seller tried to sell)";
|
||||
public static String NOT_ENOUGH_SPACE_IN_YOUR_SHOP = "%price %item&7 shop at &r%world/%x/%y/%z&7 is full! (%seller tried to sell)";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String NOT_ENOUGH_STOCK = "This shop is out of stock.";
|
||||
public static String NOT_ENOUGH_STOCK_IN_YOUR_SHOP = "%material&7 shop at &r%world/%x/%y/%z&7 is out of stock! (%buyer tried to buy)";
|
||||
public static String NOT_ENOUGH_STOCK_IN_YOUR_SHOP = "%price %item&7 shop at &r%world/%x/%y/%z&7 is out of stock! (%buyer tried to buy)";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String YOU_BOUGHT_FROM_SHOP = "You bought %item from %owner for %price.";
|
||||
public static String SOMEBODY_BOUGHT_FROM_YOUR_SHOP = "%buyer bought %item for %price from you.";
|
||||
public static String SOMEBODY_BOUGHT_FROM_YOUR_SHOP = "%buyer bought %item for %price from your shop at %world/%x/%y/%z.";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String YOU_SOLD_TO_SHOP = "You sold %item to %buyer for %price.";
|
||||
public static String SOMEBODY_SOLD_TO_YOUR_SHOP = "%seller sold %item for %price to you.";
|
||||
public static String SOMEBODY_SOLD_TO_YOUR_SHOP = "%seller sold %item for %price to your shop at %world/%x/%y/%z.";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String YOU_CANNOT_CREATE_SHOP = "You can't create this type of shop!";
|
||||
|
@ -1,24 +1,17 @@
|
||||
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.Breeze.Utils.StringUtil;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -68,8 +61,13 @@ public class TransactionMessageSender implements Listener {
|
||||
}
|
||||
|
||||
private static void sendMessage(Player player, String rawMessage, TransactionEvent event, String... replacements) {
|
||||
Location loc = event.getSign().getLocation();
|
||||
String message = Messages.prefix(rawMessage)
|
||||
.replace("%price", Economy.formatBalance(event.getPrice()));
|
||||
.replace("%price", Economy.formatBalance(event.getPrice()))
|
||||
.replace("%world", loc.getWorld().getName())
|
||||
.replace("%x", String.valueOf(loc.getBlockX()))
|
||||
.replace("%y", String.valueOf(loc.getBlockY()))
|
||||
.replace("%z", String.valueOf(loc.getBlockZ()));
|
||||
|
||||
for (int i = 0; i + 1 < replacements.length; i+=2) {
|
||||
message = message.replace("%" + replacements[i], replacements[i + 1]);
|
||||
@ -78,18 +76,7 @@ public class TransactionMessageSender implements Listener {
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, event.getStock())) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(message.replace("%item", parseItemInformation(event.getStock())));
|
||||
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(event.getStock())));
|
||||
}
|
||||
|
||||
private static String parseItemInformation(ItemStack[] items) {
|
||||
ItemStack[] stock = InventoryUtil.mergeSimilarStacks(items);
|
||||
|
||||
List<String> itemText = new ArrayList<>();
|
||||
|
||||
for (ItemStack item : stock) {
|
||||
itemText.add(item.getAmount() + " " + MaterialUtil.getName(item));
|
||||
}
|
||||
|
||||
return StringUtil.joinArray(itemText);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Database.Account;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -51,13 +51,13 @@ public class ErrorMessageSender implements Listener {
|
||||
if (Properties.SHOW_MESSAGE_FULL_SHOP && !Properties.CSTOGGLE_TOGGLES_FULL_SHOP || !Toggle.isIgnoring(event.getOwnerAccount().getName())) {
|
||||
Location loc = event.getSign().getLocation();
|
||||
String messageNotEnoughSpace = Messages.prefix(NOT_ENOUGH_SPACE_IN_YOUR_SHOP)
|
||||
.replace("%material", getItemNames(event.getStock()))
|
||||
.replace("%price", Economy.formatBalance(event.getPrice()))
|
||||
.replace("%seller", event.getClient().getName())
|
||||
.replace("%world", loc.getWorld().getName())
|
||||
.replace("%x", String.valueOf(loc.getBlockX()))
|
||||
.replace("%y", String.valueOf(loc.getBlockY()))
|
||||
.replace("%z", String.valueOf(loc.getBlockZ()));
|
||||
sendMessageToOwner(event.getOwnerAccount(), messageNotEnoughSpace);
|
||||
sendMessageToOwner(event.getOwnerAccount(), messageNotEnoughSpace, event.getStock());
|
||||
}
|
||||
message = Messages.NOT_ENOUGH_SPACE_IN_CHEST;
|
||||
break;
|
||||
@ -71,13 +71,13 @@ public class ErrorMessageSender implements Listener {
|
||||
if (Properties.SHOW_MESSAGE_OUT_OF_STOCK && !Properties.CSTOGGLE_TOGGLES_OUT_OF_STOCK || !Toggle.isIgnoring(event.getOwnerAccount().getName())) {
|
||||
Location loc = event.getSign().getLocation();
|
||||
String messageOutOfStock = Messages.prefix(NOT_ENOUGH_STOCK_IN_YOUR_SHOP)
|
||||
.replace("%material", getItemNames(event.getStock()))
|
||||
.replace("%price", Economy.formatBalance(event.getPrice()))
|
||||
.replace("%buyer", event.getClient().getName())
|
||||
.replace("%world", loc.getWorld().getName())
|
||||
.replace("%x", String.valueOf(loc.getBlockX()))
|
||||
.replace("%y", String.valueOf(loc.getBlockY()))
|
||||
.replace("%z", String.valueOf(loc.getBlockZ()));
|
||||
sendMessageToOwner(event.getOwnerAccount(), messageOutOfStock);
|
||||
sendMessageToOwner(event.getOwnerAccount(), messageOutOfStock, event.getStock());
|
||||
}
|
||||
message = Messages.NOT_ENOUGH_STOCK;
|
||||
break;
|
||||
@ -104,22 +104,14 @@ public class ErrorMessageSender implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getItemNames(ItemStack[] stock) {
|
||||
ItemStack[] items = InventoryUtil.mergeSimilarStacks(stock);
|
||||
|
||||
StringBuilder names = new StringBuilder(MaterialUtil.getName(items[0]));
|
||||
|
||||
for (int i = 1; i < items.length; i++) {
|
||||
names.append(MaterialUtil.getName(items[i])).append(',').append(' ');
|
||||
}
|
||||
|
||||
return names.toString();
|
||||
}
|
||||
|
||||
private static void sendMessageToOwner(Account ownerAccount, String message) {
|
||||
private static void sendMessageToOwner(Account ownerAccount, String message, ItemStack... stock) {
|
||||
Player player = Bukkit.getPlayer(ownerAccount.getUuid());
|
||||
if (player != null) {
|
||||
player.sendMessage(message);
|
||||
message = message.replace("%material", "%item");
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, stock)) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(stock)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user