mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-31 20:37:34 +01:00
Remove OddItem support and implement own alias system (Resolves #360)
Reasoning why this is part of the core and not a separate addon: The impact of this function is extremely lightweight when (almost) no aliases are defined so someone who isn't using this should not have a worse experience. Additionally including it in the core (similarly to the discounts, taxes and restrictions) promotes it's availability while not massively increasing the maintainability. As for the OddItem removal: That plugin hasn't been developed for over 7 years and such unique plugin support should really be added via separate addon using the events system which, with the new ItemStringQueryEvent, now actually supports doing that from an external plugin. If someone really managed to run their own private fork of OddItem for all those years then they should be able to also provide such a simple addon.
This commit is contained in:
parent
9dce41aa30
commit
b774258051
17
pom.xml
17
pom.xml
@ -140,23 +140,6 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.somethingodd</groupId>
|
||||
<artifactId>odditem</artifactId>
|
||||
<version>0.9.5</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.herocraftonline.heroes</groupId>
|
||||
|
Binary file not shown.
@ -1 +0,0 @@
|
||||
c7b3b9b7cd7cd27a50c079ce4349f628
|
@ -1 +0,0 @@
|
||||
697ff692f06dc9064badb2610fd52399651b8274
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>info.somethingodd</groupId>
|
||||
<artifactId>odditem</artifactId>
|
||||
<version>0.9.5</version>
|
||||
<description>POM was created from install:install-file</description>
|
||||
</project>
|
@ -1 +0,0 @@
|
||||
9fa8325983cb90581156734d0500aacb
|
@ -1 +0,0 @@
|
||||
288ed3c67d66d532eac2128c120a6d74986823d6
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<groupId>info.somethingodd</groupId>
|
||||
<artifactId>odditem</artifactId>
|
||||
<versioning>
|
||||
<release>0.9.5</release>
|
||||
<versions>
|
||||
<version>0.9.5</version>
|
||||
</versions>
|
||||
<lastUpdated>20130826223956</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
@ -1 +0,0 @@
|
||||
7240080156e6cd8df6f550049950a99c
|
@ -1 +0,0 @@
|
||||
23208c6e99b6df3664c26f771fa941a37387f428
|
@ -4,13 +4,11 @@ import com.Acrobot.Breeze.Collection.SimpleCache;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.MaterialParseEvent;
|
||||
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import de.themoep.ShowItem.api.ShowItem;
|
||||
import de.themoep.minedown.adventure.Replacer;
|
||||
import info.somethingodd.OddItem.OddItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -158,7 +156,9 @@ public class MaterialUtil {
|
||||
*
|
||||
* @param items The items to get the information from
|
||||
* @return The list, including the amount and names of the items
|
||||
* @deprecated Use {@link ItemUtil#getItemList(ItemStack[])} instead!
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getItemList(ItemStack[] items) {
|
||||
ItemStack[] mergedItems = InventoryUtil.mergeSimilarStacks(items);
|
||||
|
||||
@ -173,6 +173,7 @@ public class MaterialUtil {
|
||||
|
||||
/**
|
||||
* Returns item's name
|
||||
* Use {@link ItemUtil#getName(ItemStack, int)} if you want to get name aliases too!
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @return ItemStack's name
|
||||
@ -196,6 +197,7 @@ public class MaterialUtil {
|
||||
|
||||
/**
|
||||
* Returns item's name, just like on the sign
|
||||
* Use {@link ItemUtil#getSignName(ItemStack)} if you want to get name aliases too!
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @return ItemStack's name
|
||||
@ -205,15 +207,15 @@ public class MaterialUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns item's name, with a maximum width
|
||||
* Returns item's name, with a maximum width.
|
||||
* Use {@link ItemUtil#getName(ItemStack, int)} if you want to get name aliases too!
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @param maxWidth The max width that the name should have; 0 or below if it should be unlimited
|
||||
* @return ItemStack's name
|
||||
*/
|
||||
public static String getName(ItemStack itemStack, int maxWidth) {
|
||||
String alias = Odd.getAlias(itemStack);
|
||||
String itemName = alias != null ? alias : itemStack.getType().toString();
|
||||
String itemName = itemStack.getType().toString();
|
||||
|
||||
String durability = "";
|
||||
if (itemStack.getDurability() != 0) {
|
||||
@ -232,17 +234,7 @@ public class MaterialUtil {
|
||||
code = getShortenedName(code, getMinecraftStringWidth(code) - exceeding);
|
||||
}
|
||||
|
||||
code += durability + metaData;
|
||||
|
||||
ItemParseEvent parseEvent = new ItemParseEvent(code);
|
||||
Bukkit.getPluginManager().callEvent(parseEvent);
|
||||
ItemStack codeItem = parseEvent.getItem();
|
||||
if (!equals(itemStack, codeItem)) {
|
||||
throw new IllegalArgumentException("Cannot generate code for item " + itemStack + " with maximum length of " + maxWidth
|
||||
+ " (code " + code + " results in item " + codeItem + ")");
|
||||
}
|
||||
|
||||
return code;
|
||||
return code + durability + metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,12 +313,6 @@ public class MaterialUtil {
|
||||
* @return ItemStack
|
||||
*/
|
||||
public static ItemStack getItem(String itemName) {
|
||||
ItemStack itemStack = Odd.getFromString(itemName);
|
||||
|
||||
if (itemStack != null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
String[] split = itemName.split("[:\\-#]");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
split[i] = split[i].trim();
|
||||
@ -340,7 +326,7 @@ public class MaterialUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
itemStack = new ItemStack(material);
|
||||
ItemStack itemStack = new ItemStack(material);
|
||||
|
||||
ItemMeta meta = getMetadata(itemName);
|
||||
|
||||
@ -458,52 +444,6 @@ public class MaterialUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Odd {
|
||||
private static boolean isInitialized = false;
|
||||
|
||||
/**
|
||||
* Returns the item stack from OddItem plugin
|
||||
*
|
||||
* @param itemName Item name to parse
|
||||
* @return itemStack that was parsed
|
||||
*/
|
||||
public static ItemStack getFromString(String itemName) {
|
||||
if (!isInitialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = itemName.replace(':', ';');
|
||||
|
||||
try {
|
||||
return OddItem.getItemStack(name);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAlias(ItemStack itemStack) {
|
||||
if (!isInitialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Collection<String> aliases = OddItem.getAliases(itemStack);
|
||||
if (!aliases.isEmpty()) {
|
||||
return aliases.iterator().next();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets the class know that it's safe to use the OddItem methods now
|
||||
*/
|
||||
public static void initialize() {
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Show {
|
||||
private static ShowItem showItem = null;
|
||||
|
||||
|
@ -18,7 +18,9 @@ import com.Acrobot.ChestShop.Listeners.Economy.TaxModule;
|
||||
import com.Acrobot.ChestShop.Listeners.AuthMeChestShopListener;
|
||||
import com.Acrobot.ChestShop.Listeners.GarbageTextListener;
|
||||
import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener;
|
||||
import com.Acrobot.ChestShop.Listeners.Item.ItemStringListener;
|
||||
import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.ItemAliasModule;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.MetricsModule;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule;
|
||||
import com.Acrobot.ChestShop.Listeners.SignParseListener;
|
||||
@ -329,6 +331,7 @@ public class ChestShop extends JavaPlugin {
|
||||
registerEvent(new PlayerTeleport());
|
||||
|
||||
registerEvent(new SignParseListener());
|
||||
registerEvent(new ItemStringListener());
|
||||
registerEvent(new ItemInfoListener());
|
||||
registerEvent(new GarbageTextListener());
|
||||
|
||||
@ -398,6 +401,7 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerModules() {
|
||||
registerEvent(new ItemAliasModule());
|
||||
registerEvent(new DiscountModule());
|
||||
registerEvent(new MetricsModule());
|
||||
registerEvent(new PriceRestrictionModule());
|
||||
@ -532,8 +536,9 @@ public class ChestShop extends JavaPlugin {
|
||||
plugin.registerEvent(listener);
|
||||
}
|
||||
|
||||
public static void callEvent(Event event) {
|
||||
public static <E extends Event> E callEvent(E event) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, Messages.Message message, Map<String, String> replacementMap, String... replacements) {
|
||||
|
@ -5,6 +5,7 @@ import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.Breeze.Utils.NumberUtil;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -72,7 +73,7 @@ public class Give implements CommandExecutor {
|
||||
item.setAmount(quantity);
|
||||
InventoryUtil.add(item, receiver.getInventory());
|
||||
|
||||
Messages.ITEM_GIVEN.send(sender, "item", MaterialUtil.getName(item), "player", receiver.getName());
|
||||
Messages.ITEM_GIVEN.send(sender, "item", ItemUtil.getName(item), "player", receiver.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package com.Acrobot.ChestShop.Commands;
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.Breeze.Utils.StringUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -19,7 +19,6 @@ import java.util.logging.Level;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_fullname;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo_shopname;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.replace;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -46,7 +45,7 @@ public class ItemInfo implements CommandExecutor {
|
||||
|
||||
iteminfo.send(sender);
|
||||
try {
|
||||
iteminfo_fullname.send(sender, "item", MaterialUtil.getName(item));
|
||||
iteminfo_fullname.send(sender, "item", ItemUtil.getName(item));
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Error while generating full name. Please contact an admin or take a look at the console/log!");
|
||||
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating full item name", e);
|
||||
@ -54,7 +53,7 @@ public class ItemInfo implements CommandExecutor {
|
||||
}
|
||||
|
||||
try {
|
||||
iteminfo_shopname.send(sender, "item", MaterialUtil.getSignName(item));
|
||||
iteminfo_shopname.send(sender, "item", ItemUtil.getSignName(item));
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Error while generating shop sign name. Please contact an admin or take a look at the console/log!");
|
||||
ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
|
||||
|
@ -171,9 +171,6 @@ public class Dependencies implements Listener {
|
||||
|
||||
listener = heroes;
|
||||
break;
|
||||
case OddItem:
|
||||
MaterialUtil.Odd.initialize();
|
||||
break;
|
||||
case ShowItem:
|
||||
MaterialUtil.Show.initialize(plugin);
|
||||
break;
|
||||
@ -195,8 +192,6 @@ public class Dependencies implements Listener {
|
||||
SimpleChestLock,
|
||||
Residence,
|
||||
|
||||
OddItem,
|
||||
|
||||
WorldGuard,
|
||||
GriefPrevention,
|
||||
RedProtect,
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemStringQueryEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private String itemString = null;
|
||||
private final ItemStack item;
|
||||
private final int maxLength;
|
||||
|
||||
/**
|
||||
* Query the item string representation of a certain item with a certain length
|
||||
* @param item The item to query the string for
|
||||
* @param maxLength The maximum length the string should have. <= 0 means unlimited
|
||||
*/
|
||||
public ItemStringQueryEvent(ItemStack item, int maxLength) {
|
||||
this.item = item;
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item for which the string is queried
|
||||
* @return The item
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum length that the item string should have. <= 0 means unlimited
|
||||
* @return The maximum string length
|
||||
*/
|
||||
public int getMaxLength() {
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item string that represents the item
|
||||
* @return The item string that represents the item
|
||||
*/
|
||||
public String getItemString() {
|
||||
return itemString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item string that represents the item
|
||||
* @param itemString The item string that represents the item
|
||||
*/
|
||||
public void setItemString(String itemString) {
|
||||
this.itemString = itemString;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.Acrobot.ChestShop.Listeners.Item;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.ItemStringQueryEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemStringListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public static void calculateItemString(ItemStringQueryEvent event) {
|
||||
if (event.getItemString() == null) {
|
||||
event.setItemString(MaterialUtil.getName(event.getItem(), event.getMaxLength()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public static void checkValidity(ItemStringQueryEvent event) {
|
||||
ItemParseEvent parseEvent = new ItemParseEvent(event.getItemString());
|
||||
Bukkit.getPluginManager().callEvent(parseEvent);
|
||||
ItemStack codeItem = parseEvent.getItem();
|
||||
if (!MaterialUtil.equals(event.getItem(), codeItem)) {
|
||||
throw new IllegalArgumentException("Cannot generate code for item " + event.getItem()
|
||||
+ " with maximum length of " + event.getMaxLength()
|
||||
+ " (code " + event.getItemString() + " results in item " + codeItem + ")");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.Acrobot.ChestShop.Listeners.Modules;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Events.ChestShopReloadEvent;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.ItemStringQueryEvent;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ItemAliasModule implements Listener {
|
||||
private YamlConfiguration configuration;
|
||||
/**
|
||||
* Map ChestShop item code -> alias
|
||||
*/
|
||||
private BiMap<String, String> aliases;
|
||||
|
||||
public ItemAliasModule() {
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
File file = new File(ChestShop.getFolder(), "itemAliases.yml");
|
||||
|
||||
configuration = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
configuration.options().header(
|
||||
"This file specified optional aliases for certain item codes. (Use the sign name from /iteminfo)"
|
||||
+ "\nPlease note that these aliases should fit on a sign for it to work properly!"
|
||||
);
|
||||
|
||||
if (!file.exists()) {
|
||||
configuration.addDefault("Item String#3d", "My Cool Item");
|
||||
configuration.addDefault("Other Material#Eg", "Some other Item");
|
||||
|
||||
try {
|
||||
configuration.options().copyDefaults(true);
|
||||
configuration.save(ChestShop.loadFile("itemAliases.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
aliases = HashBiMap.create(configuration.getKeys(false).size());
|
||||
|
||||
for (String key : configuration.getKeys(false)) {
|
||||
if (configuration.isString(key)) {
|
||||
aliases.put(key, configuration.getString(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onReload(ChestShopReloadEvent event) {
|
||||
load();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onItemParse(ItemParseEvent event) {
|
||||
String code = aliases.inverse().get(event.getItemString());
|
||||
if (code != null) {
|
||||
event.setItem(MaterialUtil.getItem(code));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onItemStringQuery(ItemStringQueryEvent event) {
|
||||
if (event.getItemString() != null) {
|
||||
String newCode = null;
|
||||
|
||||
if (aliases.containsKey(event.getItemString())) {
|
||||
newCode = aliases.get(event.getItemString());
|
||||
} else if (!event.getItemString().contains("#") && aliases.containsKey(event.getItemString().toLowerCase(Locale.ROOT))) {
|
||||
newCode = aliases.get(event.getItemString().toLowerCase(Locale.ROOT));
|
||||
} else {
|
||||
String[] parts = event.getItemString().split("#", 2);
|
||||
String lowercaseCode = parts[0].toLowerCase(Locale.ROOT) + "#" + parts[1];
|
||||
if (aliases.containsKey(lowercaseCode)) {
|
||||
newCode = aliases.get(lowercaseCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (newCode != null) {
|
||||
event.setItemString(newCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -88,7 +89,7 @@ public class PlayerInteract implements Listener {
|
||||
if (!MaterialUtil.isEmpty(item)) {
|
||||
String itemCode;
|
||||
try {
|
||||
itemCode = MaterialUtil.getSignName(item);
|
||||
itemCode = ItemUtil.getSignName(item);
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Error while generating shop sign item name. Please contact an admin or take a look at the console/log!");
|
||||
com.Acrobot.ChestShop.ChestShop.getPlugin().getLogger().log(Level.SEVERE, "Error while generating shop sign item name", e);
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static com.Acrobot.Breeze.Utils.InventoryUtil.mergeSimilarStacks;
|
||||
import static com.Acrobot.Breeze.Utils.MaterialUtil.getName;
|
||||
import static com.Acrobot.ChestShop.Utils.ItemUtil.getName;
|
||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,7 @@ 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.Utils.ItemUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -75,10 +76,10 @@ public class TransactionMessageSender implements Listener {
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
replacementMap.put("item", MaterialUtil.getItemList(event.getStock()));
|
||||
replacementMap.put("item", ItemUtil.getItemList(event.getStock()));
|
||||
rawMessage.sendWithPrefix(player, replacementMap);
|
||||
} else if (playerName != null) {
|
||||
replacementMap.put("item", MaterialUtil.getItemList(event.getStock()));
|
||||
replacementMap.put("item", ItemUtil.getItemList(event.getStock()));
|
||||
ChestShop.sendBungeeMessage(playerName, rawMessage, replacementMap);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.Breeze.Utils.StringUtil;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
import com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -60,7 +60,7 @@ public class ItemChecker implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
itemCode = MaterialUtil.getSignName(item);
|
||||
itemCode = ItemUtil.getSignName(item);
|
||||
|
||||
if (StringUtil.getMinecraftStringWidth(itemCode) > MAXIMUM_SIGN_WIDTH) {
|
||||
event.setOutcome(INVALID_ITEM);
|
||||
|
@ -8,6 +8,7 @@ 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 com.Acrobot.ChestShop.Utils.ItemUtil;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Table;
|
||||
@ -129,7 +130,7 @@ public class ErrorMessageSender implements Listener {
|
||||
if (player != null || Properties.BUNGEECORD_MESSAGES) {
|
||||
|
||||
if (Properties.NOTIFICATION_MESSAGE_COOLDOWN > 0) {
|
||||
String cacheKey = message.getKey() + "|" + String.join(",", replacements) + "|" + MaterialUtil.getItemList(stock);
|
||||
String cacheKey = message.getKey() + "|" + String.join(",", replacements) + "|" + ItemUtil.getItemList(stock);
|
||||
Long last = notificationCooldowns.get(ownerAccount.getUuid(), cacheKey);
|
||||
if (last != null && last + Properties.NOTIFICATION_MESSAGE_COOLDOWN * 1000 > System.currentTimeMillis()) {
|
||||
return;
|
||||
@ -141,11 +142,11 @@ public class ErrorMessageSender implements Listener {
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, stock, Collections.emptyMap(), replacements)) {
|
||||
return;
|
||||
}
|
||||
String items = MaterialUtil.getItemList(stock);
|
||||
String items = ItemUtil.getItemList(stock);
|
||||
message.sendWithPrefix(player,
|
||||
ImmutableMap.of("material", items, "item", items), replacements);
|
||||
} else {
|
||||
String items = MaterialUtil.getItemList(stock);
|
||||
String items = ItemUtil.getItemList(stock);
|
||||
ChestShop.sendBungeeMessage(ownerAccount.getName(), message,
|
||||
ImmutableMap.of("material", items, "item", items), replacements);
|
||||
}
|
||||
|
@ -4,17 +4,22 @@ import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
||||
import com.Acrobot.ChestShop.Events.MaterialParseEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class SignParseListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public static void onItemParse(ItemParseEvent event) {
|
||||
event.setItem(MaterialUtil.getItem(event.getItemString()));
|
||||
if (event.getItem() == null) {
|
||||
event.setItem(MaterialUtil.getItem(event.getItemString()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public static void onMaterialParse(MaterialParseEvent event) {
|
||||
event.setMaterial(MaterialUtil.getMaterial(event.getMaterialString()));
|
||||
if (event.getMaterial() == null) {
|
||||
event.setMaterial(MaterialUtil.getMaterial(event.getMaterialString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
64
src/main/java/com/Acrobot/ChestShop/Utils/ItemUtil.java
Normal file
64
src/main/java/com/Acrobot/ChestShop/Utils/ItemUtil.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Events.ItemStringQueryEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.Acrobot.Breeze.Utils.MaterialUtil.MAXIMUM_SIGN_WIDTH;
|
||||
|
||||
public class ItemUtil {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @return ItemStack's name
|
||||
*/
|
||||
public static String getName(ItemStack itemStack) {
|
||||
return getName(itemStack, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns item's name, with a maximum width
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @param maxWidth The max width that the name should have; 0 or below if it should be unlimited
|
||||
* @return ItemStack's name
|
||||
*/
|
||||
public static String getName(ItemStack itemStack, int maxWidth) {
|
||||
return ChestShop.callEvent(new ItemStringQueryEvent(itemStack, maxWidth)).getItemString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns item's name, just like on the sign
|
||||
*
|
||||
* @param itemStack ItemStack to name
|
||||
* @return ItemStack's name
|
||||
*/
|
||||
public static String getSignName(ItemStack itemStack) {
|
||||
return getName(itemStack, MAXIMUM_SIGN_WIDTH);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user