mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-26 01:05:12 +01:00
Add ItemNameManager
This commit is contained in:
parent
6efb778868
commit
8ad01dbe35
@ -3,6 +3,8 @@ package de.epiceric.shopchest.language;
|
|||||||
import de.epiceric.shopchest.ShopChest;
|
import de.epiceric.shopchest.ShopChest;
|
||||||
import de.epiceric.shopchest.config.FileLoader;
|
import de.epiceric.shopchest.config.FileLoader;
|
||||||
import de.epiceric.shopchest.config.LanguageConfigurationLoader;
|
import de.epiceric.shopchest.config.LanguageConfigurationLoader;
|
||||||
|
import de.epiceric.shopchest.language.item.ItemNameManager;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -45,7 +47,7 @@ public class LanguageLoader {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
final Map<String, String> storedItems = languageConfigurationLoader.getTranslations(itemsFile, logger);
|
final Map<String, String> storedItems = languageConfigurationLoader.getTranslations(itemsFile, logger);
|
||||||
final LocalizedItemManager localizedItemManager = new LocalizedItemManager(storedItems);
|
final ItemNameManager localizedItemManager = new ItemNameManager(storedItems);
|
||||||
return new LanguageManager(messageRegistry, localizedItemManager);
|
return new LanguageManager(messageRegistry, localizedItemManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,16 @@ package de.epiceric.shopchest.language;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import de.epiceric.shopchest.language.item.ItemNameManager;
|
||||||
|
|
||||||
public class LanguageManager {
|
public class LanguageManager {
|
||||||
|
|
||||||
private final MessageRegistry messageRegistry;
|
private final MessageRegistry messageRegistry;
|
||||||
private final LocalizedItemManager localizedItemManager;
|
private final ItemNameManager itemNameManager;
|
||||||
|
|
||||||
public LanguageManager(@NotNull MessageRegistry messageRegistry, @NotNull LocalizedItemManager localizedItemManager) {
|
public LanguageManager(@NotNull MessageRegistry messageRegistry, @NotNull ItemNameManager localizedItemManager) {
|
||||||
this.messageRegistry = messageRegistry;
|
this.messageRegistry = messageRegistry;
|
||||||
this.localizedItemManager = localizedItemManager;
|
this.itemNameManager = localizedItemManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -18,8 +20,8 @@ public class LanguageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public LocalizedItemManager getLocalizedItemManager() {
|
public ItemNameManager getItemNameManager() {
|
||||||
return localizedItemManager;
|
return itemNameManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package de.epiceric.shopchest.language.item;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface ItemNameManager {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getItemName(@Nullable ItemStack itemStack);
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
package de.epiceric.shopchest.language;
|
package de.epiceric.shopchest.language.item;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
@ -7,17 +10,16 @@ import org.bukkit.inventory.meta.SkullMeta;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Map;
|
public class LocalizedItemNameManager implements ItemNameManager {
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class LocalizedItemManager {
|
|
||||||
|
|
||||||
private final Map<String, String> itemTranslations;
|
private final Map<String, String> itemTranslations;
|
||||||
|
|
||||||
public LocalizedItemManager(@NotNull Map<String, String> itemTranslations) {
|
public LocalizedItemNameManager(@NotNull Map<String, String> itemTranslations) {
|
||||||
this.itemTranslations = itemTranslations;
|
this.itemTranslations = itemTranslations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getItemName(@Nullable ItemStack stack) {
|
public String getItemName(@Nullable ItemStack stack) {
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
return null;
|
return null;
|
@ -3,6 +3,7 @@ package de.epiceric.shopchest.listeners;
|
|||||||
import de.epiceric.shopchest.ShopChest;
|
import de.epiceric.shopchest.ShopChest;
|
||||||
import de.epiceric.shopchest.config.Placeholder;
|
import de.epiceric.shopchest.config.Placeholder;
|
||||||
import de.epiceric.shopchest.language.*;
|
import de.epiceric.shopchest.language.*;
|
||||||
|
import de.epiceric.shopchest.language.item.ItemNameManager;
|
||||||
import de.epiceric.shopchest.utils.ClickType;
|
import de.epiceric.shopchest.utils.ClickType;
|
||||||
import de.epiceric.shopchest.utils.ClickType.SelectClickType;
|
import de.epiceric.shopchest.utils.ClickType.SelectClickType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -50,9 +51,9 @@ public class CreativeModeListener implements Listener {
|
|||||||
|
|
||||||
final LanguageManager languageManager = plugin.getLanguageManager();
|
final LanguageManager languageManager = plugin.getLanguageManager();
|
||||||
final MessageRegistry messageRegistry = languageManager.getMessageRegistry();
|
final MessageRegistry messageRegistry = languageManager.getMessageRegistry();
|
||||||
final LocalizedItemManager localizedItemManager = languageManager.getLocalizedItemManager();
|
final ItemNameManager itemNameManager = languageManager.getItemNameManager();
|
||||||
p.sendMessage(messageRegistry.getMessage(Message.ITEM_SELECTED,
|
p.sendMessage(messageRegistry.getMessage(Message.ITEM_SELECTED,
|
||||||
new Replacement(Placeholder.ITEM_NAME, localizedItemManager.getItemName(e.getCursor()))
|
new Replacement(Placeholder.ITEM_NAME, itemNameManager.getItemName(e.getCursor()))
|
||||||
));
|
));
|
||||||
plugin.getShopCommand().createShopAfterSelected(p, (SelectClickType) clickType);
|
plugin.getShopCommand().createShopAfterSelected(p, (SelectClickType) clickType);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ShopProduct {
|
|||||||
* @return The localized name of the product's {@link ItemStack} in the selected language file.
|
* @return The localized name of the product's {@link ItemStack} in the selected language file.
|
||||||
*/
|
*/
|
||||||
public String getLocalizedName() {
|
public String getLocalizedName() {
|
||||||
return ShopChest.getInstance().getLanguageManager().getLocalizedItemManager().getItemName(getItemStack());
|
return ShopChest.getInstance().getLanguageManager().getItemNameManager().getItemName(getItemStack());
|
||||||
//LanguageUtils.getItemName(getItemStack());
|
//LanguageUtils.getItemName(getItemStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user