mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-26 01:05:12 +01:00
Catch LocalizeItemNameManager cache exception
This commit is contained in:
parent
88747a8f76
commit
3509557243
@ -2,6 +2,7 @@ package de.epiceric.shopchest.language.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
@ -10,8 +11,12 @@ import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
|
||||
public class LocalizedItemNameManager implements ItemNameManager {
|
||||
|
||||
private final static String ERROR_ITEM_NAME = "ERROR";
|
||||
|
||||
private final Map<String, String> itemTranslations;
|
||||
|
||||
public LocalizedItemNameManager(@NotNull Map<String, String> itemTranslations) {
|
||||
@ -58,13 +63,19 @@ public class LocalizedItemNameManager implements ItemNameManager {
|
||||
|
||||
@NotNull
|
||||
private String getDefaultName(@NotNull ItemStack stack) {
|
||||
return getCached(stack.getTranslationKey());
|
||||
try {
|
||||
return getCached(stack.getTranslationKey());
|
||||
} catch (Exception e) {
|
||||
ShopChest.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||
return ERROR_ITEM_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getCached(@NotNull String key) {
|
||||
final String cachedTranslation = itemTranslations.get(key);
|
||||
if (cachedTranslation == null) {
|
||||
// Keep this behavior to ensure quick fixes
|
||||
throw new RuntimeException("Could not get the translation for '" + key + "'. Report it to github");
|
||||
}
|
||||
return cachedTranslation;
|
||||
|
Loading…
Reference in New Issue
Block a user