mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Added book generation to shop info message
This commit is contained in:
parent
98275ef57d
commit
bf6f24313b
@ -20,7 +20,8 @@ public enum Regex {
|
||||
PROPERTY("%PROPERTY%"),
|
||||
VALUE("%VALUE%"),
|
||||
EXTENDED("%EXTENDED%"),
|
||||
REVENUE("%REVENUE%");
|
||||
REVENUE("%REVENUE%"),
|
||||
GENERATION("%GENERATION%");
|
||||
|
||||
private String name;
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package de.epiceric.shopchest.language;
|
||||
|
||||
import de.epiceric.shopchest.nms.CustomBookMeta;
|
||||
|
||||
public class BookGenerationName {
|
||||
|
||||
private String localizedName;
|
||||
private CustomBookMeta.Generation generation;
|
||||
|
||||
public BookGenerationName(CustomBookMeta.Generation generation, String localizedName) {
|
||||
this.generation = generation;
|
||||
this.localizedName = localizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Generation linked to the name
|
||||
*/
|
||||
public CustomBookMeta.Generation getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name linked to the book generation
|
||||
*/
|
||||
public String getLocalizedName() {
|
||||
return localizedName;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package de.epiceric.shopchest.language;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.LanguageConfiguration;
|
||||
import de.epiceric.shopchest.config.Regex;
|
||||
import de.epiceric.shopchest.nms.CustomBookMeta;
|
||||
import de.epiceric.shopchest.nms.SpawnEggMeta;
|
||||
import de.epiceric.shopchest.utils.Utils;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -31,6 +32,7 @@ public class LanguageUtils {
|
||||
private static ArrayList<EntityName> entityNames = new ArrayList<>();
|
||||
private static ArrayList<PotionName> potionNames = new ArrayList<>();
|
||||
private static ArrayList<MusicDiscName> musicDiscNames = new ArrayList<>();
|
||||
private static ArrayList<BookGenerationName> generationNames = new ArrayList<>();
|
||||
private static ArrayList<LocalizedMessage> messages = new ArrayList<>();
|
||||
|
||||
|
||||
@ -44,6 +46,7 @@ public class LanguageUtils {
|
||||
entityNames.clear();
|
||||
potionNames.clear();
|
||||
musicDiscNames.clear();
|
||||
generationNames.clear();
|
||||
messages.clear();
|
||||
|
||||
// Add Block Names
|
||||
@ -906,6 +909,12 @@ public class LanguageUtils {
|
||||
musicDiscNames.add(new MusicDiscName(Material.RECORD_11, langConfig.getString("item.record.11.desc", "C418 - 11")));
|
||||
musicDiscNames.add(new MusicDiscName(Material.RECORD_12, langConfig.getString("item.record.wait.desc", "C418 - wait")));
|
||||
|
||||
// Add Book Generation Names
|
||||
generationNames.add(new BookGenerationName(CustomBookMeta.Generation.ORIGINAL, langConfig.getString("book.generation.0", "Original")));
|
||||
generationNames.add(new BookGenerationName(CustomBookMeta.Generation.COPY_OF_ORIGINAL, langConfig.getString("book.generation.1", "Copy of original")));
|
||||
generationNames.add(new BookGenerationName(CustomBookMeta.Generation.COPY_OF_COPY, langConfig.getString("book.generation.2", "Copy of a copy")));
|
||||
generationNames.add(new BookGenerationName(CustomBookMeta.Generation.TATTERED, langConfig.getString("book.generation.3", "Tattered")));
|
||||
|
||||
// Add ShopChest Messages
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_CREATED, langConfig.getString("message.shop-created", "&6Shop created.")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP, langConfig.getString("message.chest-already-shop", "&cChest already shop.")));
|
||||
@ -920,6 +929,7 @@ public class LanguageUtils {
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, langConfig.getString("message.shopInfo.enchantments", "&6Enchantments: &e%ENCHANTMENT%"), Regex.ENCHANTMENT));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, langConfig.getString("message.shopInfo.potion-effect", "&6Potion Effect: &e%POTION-EFFECT% %EXTENDED%"), Regex.POTION_EFFECT, Regex.EXTENDED));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, langConfig.getString("message.shopInfo.music-disc-title", "&6Music Disc Title: &e%MUSIC-TITLE%"), Regex.MUSIC_TITLE));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_BOOK_GENERATION, langConfig.getString("message.shopInfo.book-generation", "&6Generation: &e%GENERATION%"), Regex.GENERATION));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_NONE, langConfig.getString("message.shopInfo.none", "&7None")));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRICE, langConfig.getString("message.shopInfo.price", "&6Price: Buy: &e%BUY-PRICE%&6 Sell: &e%SELL-PRICE%"), Regex.BUY_PRICE, Regex.SELL_PRICE));
|
||||
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED, langConfig.getString("message.shopInfo.disabled", "&7Disabled")));
|
||||
@ -1161,6 +1171,20 @@ public class LanguageUtils {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generation Generation of the book
|
||||
* @return Localized title of the generation
|
||||
*/
|
||||
public static String getBookGenerationName(CustomBookMeta.Generation generation) {
|
||||
for (BookGenerationName generationName : generationNames) {
|
||||
if (generation == generationName.getGeneration()) {
|
||||
return generationName.getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
return formatDefaultString(generation.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message Message which should be translated
|
||||
* @param replacedRegexes Regexes which might be required to be replaced in the message
|
||||
|
@ -55,6 +55,7 @@ public class LocalizedMessage {
|
||||
SHOP_INFO_ENCHANTMENTS,
|
||||
SHOP_INFO_POTION_EFFECT,
|
||||
SHOP_INFO_MUSIC_TITLE,
|
||||
SHOP_INFO_BOOK_GENERATION,
|
||||
SHOP_INFO_NONE,
|
||||
SHOP_INFO_PRICE,
|
||||
SHOP_INFO_DISABLED,
|
||||
|
@ -17,6 +17,7 @@ import de.epiceric.shopchest.external.PlotSquaredShopFlag;
|
||||
import de.epiceric.shopchest.external.WorldGuardShopFlag;
|
||||
import de.epiceric.shopchest.language.LanguageUtils;
|
||||
import de.epiceric.shopchest.language.LocalizedMessage;
|
||||
import de.epiceric.shopchest.nms.CustomBookMeta;
|
||||
import de.epiceric.shopchest.nms.Hologram;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.shop.Shop.ShopType;
|
||||
@ -48,6 +49,7 @@ import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
@ -582,45 +584,62 @@ public class ShopInteractListener implements Listener {
|
||||
plugin.debug(executor.getName() + " is retrieving shop info (#" + shop.getID() + ")");
|
||||
ShopInfoEvent event = new ShopInfoEvent(executor, shop);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
plugin.debug("Info event cancelled (#" + shop.getID() + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
Chest c = (Chest) shop.getLocation().getBlock().getState();
|
||||
|
||||
int amount = Utils.getAmount(c.getInventory(), shop.getProduct());
|
||||
Material type = shop.getProduct().getType();
|
||||
|
||||
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
|
||||
String vendor = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR, new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName));
|
||||
String product = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
|
||||
String vendorName = (shop.getVendor().getName() == null ?
|
||||
shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
|
||||
|
||||
String vendorString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName));
|
||||
|
||||
String productString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(shop.getProduct())));
|
||||
|
||||
String enchantmentString = "";
|
||||
String potionEffectString = "";
|
||||
String musicDiscName = LanguageUtils.getMusicDiscName(type);
|
||||
String bookGenerationString = "";
|
||||
String musicDiscTitleString = "";
|
||||
|
||||
String disabled = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED);
|
||||
String price = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRICE, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, (shop.getBuyPrice() > 0 ? String.valueOf(shop.getBuyPrice()) : disabled)),
|
||||
|
||||
String priceString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRICE,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, (shop.getBuyPrice() > 0 ? String.valueOf(shop.getBuyPrice()) : disabled)),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, (shop.getSellPrice() > 0 ? String.valueOf(shop.getSellPrice()) : disabled)));
|
||||
String shopType = LanguageUtils.getMessage(shop.getShopType() == ShopType.NORMAL ? LocalizedMessage.Message.SHOP_INFO_NORMAL : LocalizedMessage.Message.SHOP_INFO_ADMIN);
|
||||
String stock = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_STOCK, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(amount)));
|
||||
|
||||
String shopType = LanguageUtils.getMessage(shop.getShopType() == ShopType.NORMAL ?
|
||||
LocalizedMessage.Message.SHOP_INFO_NORMAL : LocalizedMessage.Message.SHOP_INFO_ADMIN);
|
||||
|
||||
String stock = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_STOCK,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(amount)));
|
||||
|
||||
boolean potionExtended = false;
|
||||
|
||||
Map<Enchantment, Integer> enchantmentMap;
|
||||
|
||||
String potionEffectName = "";
|
||||
if (Utils.getMajorVersion() >= 9) {
|
||||
if (type == Material.TIPPED_ARROW || type == Material.LINGERING_POTION || type == Material.SPLASH_POTION) {
|
||||
potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct());
|
||||
potionEffectName = LanguageUtils.getPotionEffectName(shop.getProduct());
|
||||
PotionMeta potionMeta = (PotionMeta) shop.getProduct().getItemMeta();
|
||||
potionExtended = potionMeta.getBasePotionData().isExtended();
|
||||
|
||||
if (potionEffectString == null)
|
||||
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);
|
||||
if (potionEffectName.trim().isEmpty())
|
||||
potionEffectName = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == Material.POTION) {
|
||||
potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct());
|
||||
potionEffectName = LanguageUtils.getPotionEffectName(shop.getProduct());
|
||||
if (Utils.getMajorVersion() < 9) {
|
||||
Potion potion = Potion.fromItemStack(shop.getProduct());
|
||||
potionExtended = potion.hasExtendedDuration();
|
||||
@ -629,11 +648,43 @@ public class ShopInteractListener implements Listener {
|
||||
potionExtended = potionMeta.getBasePotionData().isExtended();
|
||||
}
|
||||
|
||||
if (potionEffectString == null)
|
||||
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);
|
||||
if (potionEffectName.trim().isEmpty())
|
||||
potionEffectName = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE);
|
||||
}
|
||||
|
||||
if (potionEffectName.length() > 0) {
|
||||
String extended = potionExtended ? LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED) : "";
|
||||
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.POTION_EFFECT, potionEffectName),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.EXTENDED, extended));
|
||||
}
|
||||
|
||||
if (type == Material.WRITTEN_BOOK) {
|
||||
BookMeta meta = (BookMeta) shop.getProduct().getItemMeta();
|
||||
CustomBookMeta.Generation generation = CustomBookMeta.Generation.TATTERED;
|
||||
|
||||
if ((Utils.getMajorVersion() == 9 && Utils.getRevision() == 1) || Utils.getMajorVersion() == 8) {
|
||||
CustomBookMeta.Generation gen = CustomBookMeta.getGeneration(shop.getProduct());
|
||||
generation = (gen == null ? CustomBookMeta.Generation.ORIGINAL : gen);
|
||||
} else if (Utils.getMajorVersion() >= 10) {
|
||||
if (meta.hasGeneration()) {
|
||||
generation = CustomBookMeta.Generation.valueOf(meta.getGeneration().toString());
|
||||
} else {
|
||||
generation = CustomBookMeta.Generation.ORIGINAL;
|
||||
}
|
||||
}
|
||||
|
||||
bookGenerationString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_BOOK_GENERATION,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.GENERATION, LanguageUtils.getBookGenerationName(generation)));
|
||||
}
|
||||
|
||||
String musicDiscName = LanguageUtils.getMusicDiscName(type);
|
||||
if (musicDiscName.length() > 0) {
|
||||
musicDiscTitleString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.MUSIC_TITLE, musicDiscName));
|
||||
}
|
||||
|
||||
String enchantmentList = "";
|
||||
if (shop.getProduct().getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
EnchantmentStorageMeta esm = (EnchantmentStorageMeta) shop.getProduct().getItemMeta();
|
||||
enchantmentMap = esm.getStoredEnchants();
|
||||
@ -647,24 +698,26 @@ public class ShopInteractListener implements Listener {
|
||||
Enchantment enchantment = enchantments[i];
|
||||
|
||||
if (i == enchantments.length - 1) {
|
||||
enchantmentString += LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment));
|
||||
enchantmentList += LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment));
|
||||
} else {
|
||||
enchantmentString += LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment)) + ", ";
|
||||
enchantmentList += LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment)) + ", ";
|
||||
}
|
||||
}
|
||||
|
||||
if (enchantmentList.length() > 0) {
|
||||
enchantmentString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS,
|
||||
new LocalizedMessage.ReplacedRegex(Regex.ENCHANTMENT, enchantmentList));
|
||||
}
|
||||
|
||||
executor.sendMessage(" ");
|
||||
if (shop.getShopType() != ShopType.ADMIN) executor.sendMessage(vendor);
|
||||
executor.sendMessage(product);
|
||||
if (shop.getShopType() != ShopType.ADMIN) executor.sendMessage(vendorString);
|
||||
executor.sendMessage(productString);
|
||||
if (shop.getShopType() != ShopType.ADMIN) executor.sendMessage(stock);
|
||||
if (enchantmentString.length() > 0)
|
||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, new LocalizedMessage.ReplacedRegex(Regex.ENCHANTMENT, enchantmentString)));
|
||||
if (potionEffectString.length() > 0)
|
||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, new LocalizedMessage.ReplacedRegex(Regex.POTION_EFFECT, potionEffectString),
|
||||
new LocalizedMessage.ReplacedRegex(Regex.EXTENDED, (potionExtended ? LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED) : ""))));
|
||||
if (musicDiscName.length() > 0)
|
||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, new LocalizedMessage.ReplacedRegex(Regex.MUSIC_TITLE, musicDiscName)));
|
||||
executor.sendMessage(price);
|
||||
if (enchantmentString.length() > 0) executor.sendMessage(enchantmentString);
|
||||
if (potionEffectString.length() > 0) executor.sendMessage(potionEffectString);
|
||||
if (musicDiscTitleString.length() > 0) executor.sendMessage(musicDiscTitleString);
|
||||
if (bookGenerationString.length() > 0) executor.sendMessage(bookGenerationString);
|
||||
executor.sendMessage(priceString);
|
||||
executor.sendMessage(shopType);
|
||||
executor.sendMessage(" ");
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ message.shopInfo.stock=&6Auf Lager: &e%AMOUNT%
|
||||
message.shopInfo.enchantments=&6Verzauberungen: &e%ENCHANTMENT%
|
||||
message.shopInfo.potion-effect=&6Trank-Effekte: &e%POTION-EFFECT% %EXTENDED%
|
||||
message.shopInfo.music-disc-title=&6Schallplattentitel: &e%MUSIC-TITLE%
|
||||
message.shopInfo.book-generation=&6Generation: &e%GENERATION%
|
||||
message.shopInfo.none=&7Keine
|
||||
message.shopInfo.price=&6Preis: Kauf: &e%BUY-PRICE%&6 Verkauf: &e%SELL-PRICE%
|
||||
message.shopInfo.disabled=&7Deaktiviert
|
||||
@ -90,6 +91,11 @@ message.config.set=&6Eigenschaft &a%PROPERTY% &6wurde auf &a%VALUE% &6gesetzt.
|
||||
message.config.added=&6Wert &a%VALUE% &6wurde zu &a%PROPERTY% &6hinzugefügt.
|
||||
message.config.removed=&6Wert &a%VALUE% &6wurde aus &a%PROPERTY% &6entfernt.
|
||||
|
||||
book.generation.0=Original
|
||||
book.generation.1=Kopie des Originals
|
||||
book.generation.2=Kopie einer Kopie
|
||||
book.generation.3=Zerrissen
|
||||
|
||||
effect.absorption=Absorption
|
||||
effect.blindness=Blindheit
|
||||
effect.confusion=Übelkeit
|
||||
|
@ -45,6 +45,10 @@ message.shopInfo.potion-effect=&6Potion Effect: &e%POTION-EFFECT% %EXTENDED%
|
||||
# Usable regex: %MUSIC-TITLE%
|
||||
message.shopInfo.music-disc-title=&6Music Disc Title: &e%MUSIC-TITLE%
|
||||
|
||||
# Set the generation message the player gets after entering '/shop info' if the product is a written book
|
||||
# Usable regex: %GENERATION%
|
||||
message.shopInfo.book-generation=&6Generation: &e%GENERATION%
|
||||
|
||||
# If the product is a tipped arrow but it doesn't have an effect, this gets displayed instead of the arrow effect
|
||||
message.shopInfo.none=&7None
|
||||
|
||||
@ -469,6 +473,12 @@ enchantment.level.8=VIII
|
||||
enchantment.level.9=IX
|
||||
enchantment.level.10=X
|
||||
|
||||
# If the product is a written book, this will be displayed instead of %GENERATION%
|
||||
book.generation.0=Original
|
||||
book.generation.1=Copy of original
|
||||
book.generation.2=Copy of a copy
|
||||
book.generation.3=Tattered
|
||||
|
||||
# If the product is a spawn egg, this will be displayed after 'item.monsterPlacer.name'
|
||||
entity.Creeper.name=Creeper
|
||||
entity.Skeleton.name=Skeleton
|
||||
|
Loading…
Reference in New Issue
Block a user