diff --git a/.gitignore b/.gitignore index 33891e0..cbbcf35 100644 --- a/.gitignore +++ b/.gitignore @@ -133,4 +133,7 @@ spigot.yml .project .settings/ bin/ -!libs/ \ No newline at end of file +!libs/ + +# local.properties +local.properties \ No newline at end of file diff --git a/build.gradle b/build.gradle index 2bc86a3..5a8d1d4 100644 --- a/build.gradle +++ b/build.gradle @@ -38,4 +38,28 @@ processResources { filesMatching('paper-plugin.yml') { expand(pluginProps) } +} + +// * Propriété locale +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') + +if (localPropertiesFile.exists()) { + localPropertiesFile.withInputStream { + localProperties.load(it) + } +} + +tasks.jar { + destinationDirectory.set(file('./builds/')) +} + +tasks.register('copyJarToServer', Copy) { + dependsOn tasks.jar + + from tasks.jar + + if (localProperties.getProperty('minecraftServerDir')) { + into file("${localProperties.getProperty('minecraftServerDir')}/plugins") + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 28f79ae..05b0013 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ # NMS & paper lib -paperWeightUserDevVersion = 2.0.0-beta.23 +paperWeightUserDevVersion = 2.0.0-beta.24 # Paper version -minecraftVersion = 26.2 -paperVersion = 118-stable +minecraftVersion = 26.3 +paperVersion = 180-stable # Dependencies versions itemsAdderVersion = 4.0.18-beta-10 diff --git a/libs/OpenMC.jar b/libs/OpenMC.jar index 425d23d..1ebfe43 100644 Binary files a/libs/OpenMC.jar and b/libs/OpenMC.jar differ diff --git a/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java b/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java index 9c06133..550ad10 100644 --- a/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java +++ b/src/main/java/fr/openmc/riftengine/core/RiftRegistry.java @@ -6,7 +6,6 @@ import fr.openmc.core.bootstrap.registries.RegistryContext; import fr.openmc.core.bootstrap.registries.RegistryLoadingType; import fr.openmc.riftengine.core.registry.glyphs.GlyphsRegistry; -import fr.openmc.riftengine.core.registry.scanner.ScannerRegistry; import java.util.ArrayList; import java.util.Arrays; @@ -15,16 +14,12 @@ public final class RiftRegistry { // * Registre globaux public static GlyphsRegistry GLYPHS; - public static ScannerRegistry SCANNERS; private static final List LOADED = new ArrayList<>(); private static final List ALL = List.of( new RegistryContext( () -> GLYPHS = new GlyphsRegistry(), - RegistryLoadingType.RUNTIME), - new RegistryContext( - () -> SCANNERS = new ScannerRegistry(), RegistryLoadingType.RUNTIME) ); diff --git a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java index fdbf74e..39140ce 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/ConverterManager.java @@ -3,9 +3,10 @@ import fr.openmc.core.OMCRegistry; import fr.openmc.core.bootstrap.integration.OMCLogger; import fr.openmc.core.utils.FilesUtils; +import fr.openmc.core.utils.ZipUtils; +import fr.openmc.riftengine.api.scanner.items.ItemEntry; import fr.openmc.riftengine.core.RiftConfig; import fr.openmc.riftengine.core.RiftPlugin; -import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.converter.writers.glyph.font.FontWriter; import fr.openmc.riftengine.core.converter.writers.glyph.icons.IconsWriter; @@ -18,12 +19,9 @@ import fr.openmc.riftengine.core.converter.writers.manifest.PackIdentity; import fr.openmc.riftengine.core.converter.writers.translations.TranslationInjector; import fr.openmc.riftengine.core.converter.writers.ui.ScoreboardUiWriter; -import fr.openmc.riftengine.core.scanner.items.ItemEntry; -import fr.openmc.riftengine.core.utils.ZipUtils; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -44,7 +42,7 @@ public ConverterManager(RiftPlugin plugin) { try { identity = PackIdentity.loadOrCreate(plugin); - List items = RiftRegistry.SCANNERS.ITEMS.scan(itemsAdderContents); + List items = OMCRegistry.SCANNERS.ITEMS.scan(itemsAdderContents); writers.addAll(List.of( new IconWriter(), new ManifestWriter(identity), diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsType.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsType.java index 09aa602..f3a5dc3 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsType.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsType.java @@ -1,6 +1,6 @@ package fr.openmc.riftengine.core.converter.writers.glyph.icons; -import fr.openmc.riftengine.core.scanner.icons.IconEntry; +import fr.openmc.riftengine.api.scanner.icons.IconEntry; import java.awt.*; @@ -81,6 +81,25 @@ public int yOffset(IconEntry entry, int height) { } }, + + // todo: faire un EMOJI_{x} avec x un entier + EMOJI_13 { + @Override + public boolean matches(int width, int height) { + return false; // a detecter manuellement via config/icons_type.yml + } + + @Override + public Dimension finalSize(IconEntry entry, int width, int height) { + return new Dimension(13, 13); + } + + @Override + public int yOffset(IconEntry entry, int height) { + return entry.yPosition() != null ? -entry.yPosition() : DEFAULT_Y_OFFSET; + } + }, + EMOJI_16 { @Override public boolean matches(int width, int height) { diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsWriter.java index 15389f1..2a5e844 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/IconsWriter.java @@ -1,13 +1,14 @@ package fr.openmc.riftengine.core.converter.writers.glyph.icons; +import fr.openmc.core.OMCRegistry; import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.api.scanner.icons.IconEntry; +import fr.openmc.riftengine.api.scanner.icons.IconScanner; import fr.openmc.riftengine.core.RiftPlugin; import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.registry.glyphs.GlyphsRegistry; import fr.openmc.riftengine.core.registry.glyphs.types.IconGlyph; -import fr.openmc.riftengine.core.scanner.icons.IconEntry; -import fr.openmc.riftengine.core.scanner.icons.IconScanner; import javax.imageio.ImageIO; import java.awt.*; @@ -34,9 +35,9 @@ public IconsWriter(Path itemsAdderContentsPath) { @Override public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { IconsTypeConfig forcedType = IconsTypeConfig.load(RiftPlugin.getInstance().CONFIG_FOLDER - .resolve("icons_types.yml")); + .resolve("icons_types.yml")); // todo: degeu ça - IconScanner scanner = RiftRegistry.SCANNERS.ICONS; + IconScanner scanner = OMCRegistry.SCANNERS.ICONS; List entries; try { entries = scanner.scan(itemsAdderContentsPath); diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/SymbolWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/SymbolWriter.java index 6cfa336..aed89ea 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/SymbolWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/glyph/icons/SymbolWriter.java @@ -1,13 +1,13 @@ package fr.openmc.riftengine.core.converter.writers.glyph.icons; import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.core.utils.YmlUtils; import fr.openmc.riftengine.core.RiftPlugin; import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.converter.writers.PackWriter; import fr.openmc.riftengine.core.listeners.LoadAfterItemsAdderListener; import fr.openmc.riftengine.core.registry.glyphs.Glyph; import fr.openmc.riftengine.core.registry.glyphs.types.IconGlyph; -import fr.openmc.riftengine.core.utils.YmlUtils; import org.bukkit.Bukkit; import org.yaml.snakeyaml.Yaml; diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java index a74e178..f98b6dc 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsMappingWriter.java @@ -5,20 +5,16 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.api.scanner.items.ItemEntry; import fr.openmc.riftengine.core.RiftPlugin; -import fr.openmc.riftengine.core.RiftRegistry; import fr.openmc.riftengine.core.converter.writers.PackWriter; -import fr.openmc.riftengine.core.scanner.items.ItemEntry; import fr.openmc.riftengine.core.utils.PathUtils; import org.bukkit.Material; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -39,24 +35,24 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception { Map byMaterial = new HashMap<>(); for (ItemEntry item : items) { - JsonObject def = new JsonObject(); + Map resources = item.getBestResourcesId(); - if (item.getCustomModelData() != null) { - def.addProperty("type", "legacy"); - def.addProperty("custom_model_data", item.getCustomModelData()); + if (resources == null) continue; + + if (resources.size() == 1) { + // * Gestion des items a une texture + byMaterial.computeIfAbsent(item.getMaterial().getKey().asString(), _ -> new JsonArray()) + .add(handleUniqueTexture(item)); } else { - def.addProperty("type", "definition"); + // * Gestion des items a plusieurs textures + JsonObject def = new JsonObject(); + def.addProperty("type", "group"); def.addProperty("model", item.getNamespace() + ":ia_auto/" + item.getKey()); - } + def.add("definitions", handleMultipleTexture(item)); - def.addProperty("bedrock_identifier", item.namespacedId()); - - JsonObject options = new JsonObject(); - options.addProperty("icon", item.namespacedId()); - def.add("bedrock_options", options); - - byMaterial.computeIfAbsent(item.getMaterial().getKey().asString(), _ -> new JsonArray()) - .add(def); + byMaterial.computeIfAbsent(item.getMaterial().getKey().asString(), _ -> new JsonArray()) + .add(def); + } } JsonObject itemsSetter = new JsonObject(); @@ -69,9 +65,66 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws Exception { Files.writeString(outputFile, GSON.toJson(root), StandardCharsets.UTF_8); } - private ItemEntry getByNamespace(String namespacedId) { - return items.stream(). - filter(item -> item.namespacedId().equals(namespacedId)) - .findFirst().orElse(null); + private JsonObject handleUniqueTexture(ItemEntry item) { + JsonObject def = new JsonObject(); + if (item.getCustomModelData() != null) { + def.addProperty("type", "legacy"); + def.addProperty("custom_model_data", item.getCustomModelData()); + } else { + def.addProperty("type", "definition"); + def.addProperty("model", item.getNamespace() + ":ia_auto/" + item.getKey()); + } + + def.addProperty("bedrock_identifier", item.namespacedId()); + + JsonObject options = new JsonObject(); + options.addProperty("icon", item.namespacedId()); + def.add("bedrock_options", options); + + return def; + } + + private JsonArray handleMultipleTexture(ItemEntry item) { + JsonArray definitionsArray = new JsonArray(); + + Map bestResources = item.getBestResourcesId(); + if (bestResources == null) { + OMCLogger.warn("Item {} : n'a pas de best resources", item.namespacedId()); + return definitionsArray; + } + + for (var entry : bestResources.entrySet()) { + String stateResource = entry.getKey(); + + JsonObject defObject = new JsonObject(); + + String namespaceId = item.namespacedId(); + + if (!stateResource.equals("normal")) + namespaceId += "_" + stateResource; + + defObject.addProperty("bedrock_identifier", namespaceId); + + JsonObject options = new JsonObject(); + options.addProperty("icon", namespaceId); + options.addProperty("display_handheld", true); + + // y'a 5 types de conditions (broken, damaged, custom_model_data, has_component, fishing_rod_cast), + // note pour plus tard si ajout elytra + if (!stateResource.equals("normal") && item.getMaterial().equals(Material.FISHING_ROD)) { + options.addProperty("display_handheld", true); + JsonObject predicate = new JsonObject(); + predicate.addProperty("type", "condition"); + predicate.addProperty("property", "fishing_rod_cast"); + defObject.add("predicate", predicate); + } + + + defObject.add("bedrock_options", options); + + definitionsArray.add(defObject); + } + + return definitionsArray; } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java index 8ff178c..232ab8a 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureJsonWriter.java @@ -2,23 +2,23 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.api.scanner.items.ItemEntry; import fr.openmc.riftengine.core.converter.writers.PackWriter; -import fr.openmc.riftengine.core.scanner.items.ItemEntry; import fr.openmc.riftengine.core.utils.IdentifierUtils; import fr.openmc.riftengine.core.utils.PathUtils; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.List; -import java.util.Locale; +import java.util.Map; +/** + * Ecrit le item_texture.json qui sert grosso modo a relier les textures aux items (une ref = une resource) + */ public class ItemsTextureJsonWriter implements PackWriter { private final List items; @@ -35,32 +35,24 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { JsonObject textureData = new JsonObject(); for (ItemEntry itemEntry : items) { - String resourceId = itemEntry.getBestResourceId(); - String texture = null; - - if (resourceId == null) { - texture = "textures/items/" + itemEntry.getMaterial().name().toLowerCase();; - } else if (resourceId.startsWith("minecraft:")) { - String path = IdentifierUtils.normalizeId(resourceId).split(":", 2)[1]; - texture = IdentifierUtils.toBedrockTexturePath("textures/" + path); - } else { - Path resourcePath = itemEntry.getResourcePath().apply(javaRootPath); - Path reducedPath = resourcePath == null ? null - : PathUtils.getPathFromRoot(resourcePath, "textures"); - if (reducedPath != null) { - texture = IdentifierUtils.toBedrockTexturePath(reducedPath.toString()) - .replaceFirst("\\.[^/.]+$", ""); - } - } - - if (texture == null) { - OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId()); + Map bestResources = itemEntry.getBestResourcesId(); + if (bestResources == null) { + OMCLogger.warn("Item {} : n'a pas de best resources", itemEntry.namespacedId()); continue; } - JsonObject itemData = new JsonObject(); - itemData.addProperty("textures", texture); - textureData.add(itemEntry.namespacedId(), itemData); + for (var entry : bestResources.entrySet()) { + String[] textureDataStr = getTextureData(itemEntry, entry.getKey(), entry.getValue(), javaRootPath); + + if (textureDataStr == null) { + OMCLogger.warn("Item {} : textureDataStr n'a pas de contenu", itemEntry.namespacedId()); + continue; + } + + JsonObject itemData = new JsonObject(); + itemData.addProperty("textures", textureDataStr[1]); + textureData.add(textureDataStr[0], itemData); + } } root.addProperty("texture_name", "atlas.items"); @@ -70,4 +62,55 @@ public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { Files.createDirectories(outputFile.getParent()); Files.writeString(outputFile, GSON.toJson(root), StandardCharsets.UTF_8); } + + /** + * Retourne les id du namespace et de la resource + * (en fonction de si y'a des textures multiples ect fishing rod) + * Note a moi meme: + * - le state normal est skip, a ma vue c'est le state par défaut + */ + public String[] getTextureData(ItemEntry itemEntry, String stateResource, String resourceId, Path javaRootPath) { + String texture = null; + String namespace = itemEntry.namespacedId(); + + if (resourceId.isEmpty()) { + texture = "textures/items/" + itemEntry.getMaterial().name().toLowerCase();; + } else if (resourceId.startsWith("minecraft:")) { + String path = IdentifierUtils.normalizeId(resourceId).split(":", 2)[1]; + texture = IdentifierUtils.toBedrockTexturePath("textures/" + path); + } else { + Map resources = itemEntry.getResourcePath().apply(javaRootPath); + if (resources == null) { + OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId()); + return null; + } + + if (resources.isEmpty()) { + OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId()); + return null; + } + + Path resourcePath; + if (resources.size() > 1) { + resourcePath = resources.get(stateResource); + if (!stateResource.equals("normal")) + namespace = itemEntry.namespacedId() + "_" + stateResource; + } else { + resourcePath = resources.values().stream().findFirst().get(); + } + + Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); + if (reducedPath != null) { + texture = IdentifierUtils.toBedrockTexturePath(reducedPath.toString()) + .replaceFirst("\\.[^/.]+$", ""); + } + } + + if (texture == null) { + OMCLogger.warn("Item {} : impossible de déterminer la texture", itemEntry.namespacedId()); + return null; + } + + return new String[] {namespace, texture}; + } } diff --git a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java index 409808f..edbdf4b 100644 --- a/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java +++ b/src/main/java/fr/openmc/riftengine/core/converter/writers/items/ItemsTextureWriter.java @@ -1,12 +1,8 @@ package fr.openmc.riftengine.core.converter.writers.items; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import fr.openmc.core.bootstrap.integration.OMCLogger; +import fr.openmc.riftengine.api.scanner.items.ItemEntry; import fr.openmc.riftengine.core.converter.writers.PackWriter; -import fr.openmc.riftengine.core.scanner.items.ItemEntry; import fr.openmc.riftengine.core.utils.IdentifierUtils; import fr.openmc.riftengine.core.utils.PathUtils; @@ -15,6 +11,7 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.List; +import java.util.Map; public class ItemsTextureWriter implements PackWriter { private final List items; @@ -26,30 +23,46 @@ public ItemsTextureWriter(List items) { @Override public void write(Path bedrockRootPath, Path javaRootPath) throws IOException { for (ItemEntry itemEntry : items) { - String ressouceId = itemEntry.getBestResourceId(); - if (ressouceId == null) { - OMCLogger.warn("Item {} a pas de resource id", itemEntry.namespacedId()); + Map bestResources = itemEntry.getBestResourcesId(); + if (bestResources == null) { + OMCLogger.warn("Item {} : n'a pas de best resources", itemEntry.namespacedId()); continue; } - if (ressouceId.split(":")[0].equals("minecraft")) continue; + for (var entry : bestResources.entrySet()) { + String stateResource = entry.getKey(); + String resourceId = entry.getValue(); - Path resourcePath = itemEntry.getResourcePath().apply(javaRootPath); - if (resourcePath == null) { - OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); - continue; - } + if (resourceId.isEmpty()) { + OMCLogger.warn("Item {} a pas de resource id", itemEntry.namespacedId()); + continue; + } - Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); - if (reducedPath == null) { - OMCLogger.warn("Item {} a un Path impossible a réduire {}", itemEntry.namespacedId(), resourcePath.toString()); - continue; - } + if (resourceId.split(":")[0].equals("minecraft")) continue; - Path outputFile = bedrockRootPath.resolve( - IdentifierUtils.toBedrockTexturePath(reducedPath.toString())); - Files.createDirectories(outputFile.getParent()); - Files.copy(resourcePath, outputFile, StandardCopyOption.REPLACE_EXISTING); + Map resources = itemEntry.getResourcePath().apply(javaRootPath); + if (resources == null) { + OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); + continue; + } + + Path resourcePath = resources.get(stateResource); + if (resourcePath == null) { + OMCLogger.warn("Item {} a aucune resource (Model ou texture)", itemEntry.namespacedId()); + continue; + } + + Path reducedPath = PathUtils.getPathFromRoot(resourcePath, "textures"); + if (reducedPath == null) { + OMCLogger.warn("Item {} a un Path impossible a réduire {}", itemEntry.namespacedId(), resourcePath.toString()); + continue; + } + + Path outputFile = bedrockRootPath.resolve( + IdentifierUtils.toBedrockTexturePath(reducedPath.toString())); + Files.createDirectories(outputFile.getParent()); + Files.copy(resourcePath, outputFile, StandardCopyOption.REPLACE_EXISTING); + } } } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/registry/glyphs/types/IconGlyph.java b/src/main/java/fr/openmc/riftengine/core/registry/glyphs/types/IconGlyph.java index 2b37fcf..01c36d7 100644 --- a/src/main/java/fr/openmc/riftengine/core/registry/glyphs/types/IconGlyph.java +++ b/src/main/java/fr/openmc/riftengine/core/registry/glyphs/types/IconGlyph.java @@ -1,7 +1,7 @@ package fr.openmc.riftengine.core.registry.glyphs.types; +import fr.openmc.riftengine.api.scanner.icons.IconEntry; import fr.openmc.riftengine.core.registry.glyphs.Glyph; -import fr.openmc.riftengine.core.scanner.icons.IconEntry; import lombok.Getter; @Getter diff --git a/src/main/java/fr/openmc/riftengine/core/registry/scanner/AbstractScanner.java b/src/main/java/fr/openmc/riftengine/core/registry/scanner/AbstractScanner.java deleted file mode 100644 index dd40f95..0000000 --- a/src/main/java/fr/openmc/riftengine/core/registry/scanner/AbstractScanner.java +++ /dev/null @@ -1,5 +0,0 @@ -package fr.openmc.riftengine.core.registry.scanner; - -public abstract class AbstractScanner { - public abstract T scan(P param) throws Exception; -} diff --git a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java b/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java deleted file mode 100644 index fe190ee..0000000 --- a/src/main/java/fr/openmc/riftengine/core/registry/scanner/ScannerRegistry.java +++ /dev/null @@ -1,24 +0,0 @@ -package fr.openmc.riftengine.core.registry.scanner; - -import fr.openmc.core.bootstrap.registries.KeyedRegistry; -import fr.openmc.core.bootstrap.registries.Registry; -import fr.openmc.riftengine.core.scanner.general.YamlNamespaceIAScanner; -import fr.openmc.riftengine.core.scanner.general.YamlScanner; -import fr.openmc.riftengine.core.scanner.icons.IconScanner; -import fr.openmc.riftengine.core.scanner.items.CustomModelDataScanner; -import fr.openmc.riftengine.core.scanner.items.ItemScanner; - -public class ScannerRegistry extends Registry> - implements KeyedRegistry> { - - public final IconScanner ICONS = register(new IconScanner()); - public final ItemScanner ITEMS = register(new ItemScanner()); - public final CustomModelDataScanner CUSTOM_MODEL_DATA_CACHE = register(new CustomModelDataScanner()); - public final YamlNamespaceIAScanner YAML_ITEMSADDER_NAMESPACE = register(new YamlNamespaceIAScanner()); - public final YamlScanner YAML = register(new YamlScanner()); - - @Override - public String key(AbstractScanner abstractScanner) { - return abstractScanner.getClass().getSimpleName(); - } -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlNamespaceIAScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlNamespaceIAScanner.java deleted file mode 100644 index 0474668..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlNamespaceIAScanner.java +++ /dev/null @@ -1,16 +0,0 @@ -package fr.openmc.riftengine.core.scanner.general; - -import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; - -import java.util.Map; - -public class YamlNamespaceIAScanner extends AbstractScanner> { - @Override - public String scan(Map rootYaml) { - if (rootYaml.get("info") instanceof Map infoMap && infoMap.get("namespace") != null) { - return infoMap.get("namespace").toString(); - } - - return null; - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlScanner.java deleted file mode 100644 index 542eacb..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/general/YamlScanner.java +++ /dev/null @@ -1,26 +0,0 @@ -package fr.openmc.riftengine.core.scanner.general; - -import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; - -public class YamlScanner extends AbstractScanner, Path> { - @Override - public List scan(Path path) throws Exception { - try (Stream walk = Files.walk(path)) { - return walk - .filter(Files::isRegularFile) - .filter(p -> { - String name = p.getFileName().toString().toLowerCase(Locale.ROOT); - return name.endsWith(".yml") || name.endsWith(".yaml"); - }) - .toList(); - } catch (IOException e) { - throw new RuntimeException("Erreur lors du scan des fichiers yml dans " + path, e);} - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconEntry.java b/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconEntry.java deleted file mode 100644 index c7b7110..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconEntry.java +++ /dev/null @@ -1,47 +0,0 @@ -package fr.openmc.riftengine.core.scanner.icons; - -import fr.openmc.riftengine.core.utils.IdentifierUtils; -import fr.openmc.riftengine.core.utils.YmlUtils; - -import java.nio.file.Path; -import java.util.Map; -import java.util.function.Function; - -public record IconEntry( - String namespace, - String key, - Function path, - String permission, - boolean showInGui, - Double scaleRatio, - Integer yPosition, - Path sourceYml -) { - public static IconEntry from(Path sourceYml, String namespace, String key, Map data) { - String permission; - - if (data.get("permission") instanceof String perm) { - permission = perm; - } else if (data.get("permission") instanceof Number num) { - permission = "ia.user.image.use." + num.intValue(); - } else { - permission = null; - } - - return new IconEntry( - namespace, - key, - javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, - IdentifierUtils.normalizeId(String.valueOf(data.get("path")), namespace)), - permission, - YmlUtils.getBool(data.get("show_in_gui"), true), - YmlUtils.getDouble(data.get("scale_ratio"), null), - YmlUtils.getInt(data.get("y_position"), null), - sourceYml - ); - } - - public String namespacedId() { - return namespace + ":" + key; - } -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconScanner.java deleted file mode 100644 index af679fe..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/icons/IconScanner.java +++ /dev/null @@ -1,42 +0,0 @@ -package fr.openmc.riftengine.core.scanner.icons; - -import fr.openmc.riftengine.core.RiftRegistry; -import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; -import fr.openmc.riftengine.core.utils.YmlUtils; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Scan tout les icons initialisé par ItemsAdder - */ -public class IconScanner extends AbstractScanner, Path> { - public List scan(Path itemsAdderContentsPath) throws Exception { - if (!Files.isDirectory(itemsAdderContentsPath)) return new ArrayList<>(); - - List ymlFiles = RiftRegistry.SCANNERS.YAML.scan(itemsAdderContentsPath); - - List result = new ArrayList<>(); - - for (Path ymlFile : ymlFiles) { - Map root = YmlUtils.loadYml(ymlFile); - - Object fontImagesObj = root.get("font_images"); - if (!(fontImagesObj instanceof Map fontImagesMap)) continue; - - String namespace = RiftRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); - - for (Map.Entry entry : fontImagesMap.entrySet()) { - String key = String.valueOf(entry.getKey()); - if (!(entry.getValue() instanceof Map data)) continue; - - result.add(IconEntry.from(ymlFile, namespace, key, data)); - } - } - - return result; - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java deleted file mode 100644 index f0b745d..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/CustomModelDataScanner.java +++ /dev/null @@ -1,54 +0,0 @@ -package fr.openmc.riftengine.core.scanner.items; - -import fr.openmc.riftengine.core.RiftPlugin; -import fr.openmc.riftengine.core.RiftRegistry; -import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; -import fr.openmc.riftengine.core.utils.PathUtils; -import fr.openmc.riftengine.core.utils.YmlUtils; -import org.bukkit.Material; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Scan le cache des CustomModelData qui sont assignés par ItemsAdder - */ -public class CustomModelDataScanner extends AbstractScanner>, Void> { - private final String CACHE_FILE_NAME = "items_ids_cache.yml"; - - public Map> scan(Void voyd) throws Exception { - Path cmdPath = PathUtils.getItemsAdderPath(RiftPlugin.getInstance().getDataPath()).resolve("storage").resolve(CACHE_FILE_NAME); - - Map root = YmlUtils.loadYml(cmdPath); - Map> mappedCache = new HashMap<>(); - - for (var iterRoot : root.entrySet()) { - String key = iterRoot.getKey(); - Material materialKey = Material.valueOf(key); - - Map value = new HashMap<>(); - - if (!(iterRoot.getValue() instanceof Map valueMap)) continue; - - Map namespacedIdCmdMap = (Map) valueMap; - - for (var entryIdCmd : namespacedIdCmdMap.entrySet()) { - String namespacedId = entryIdCmd.getKey(); - // todo: __manually_handled, qui serait utile lors de l'impl des CustomEmotes et des models par ailleurs - if (namespacedId.startsWith("__")) continue; - - Integer cmd = entryIdCmd.getValue(); - - value.put(namespacedId, cmd); - } - - mappedCache.put(materialKey, value); - } - - return mappedCache; - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java deleted file mode 100644 index 8affe18..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemEntry.java +++ /dev/null @@ -1,138 +0,0 @@ -package fr.openmc.riftengine.core.scanner.items; - -import fr.openmc.riftengine.core.scanner.items.entry.ItemGraphics; -import fr.openmc.riftengine.core.scanner.items.entry.ItemResource; -import fr.openmc.riftengine.core.utils.IdentifierUtils; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Material; - -import java.nio.file.Path; -import java.util.Map; -import java.util.function.Function; - -@Getter -public class ItemEntry { - private final String namespace; - private final String key; - private final Integer customModelData; - private final Material material; - - private final ItemResource resource; - private final ItemGraphics graphics; - private final Function resourcePath; - - private final Path sourceYml; - - private ItemEntry( - String namespace, - String key, - Integer customModelData, - Material material, - - // * Méthodes de création d'items (moderne ou legacy) - ItemResource resource, - ItemGraphics graphics, - Function resourcePath, - - Path sourceYml - ) { - this.namespace = namespace; - this.key = key; - this.customModelData = customModelData; - this.material = material; - this.resource = resource; - this.graphics = graphics; - this.resourcePath = resourcePath; - this.sourceYml = sourceYml; - } - - public static ItemEntry from(Map> cmdCache, Path sourceYml, String namespace, String key, Map data) { - ItemResource itemResource = ItemResource.from(data); - ItemGraphics itemGraphics = ItemGraphics.from(data); - - Material material = getMaterial(itemResource, itemGraphics); - - Integer customModelData = null; - - Map map = cmdCache.get(material); - if (map != null && map.get(namespace + ":" + key) != null) - customModelData = map.get(namespace + ":" + key); - - return new ItemEntry( - namespace, - key, - customModelData, - material, - itemResource, - itemGraphics, - resolvePathFunction(namespace, itemGraphics, itemResource), - sourceYml - ); - } - - public String getBestResourceId() { - if (resource != null) { - if (resource.hasTextures()) - return IdentifierUtils.normalizeId(resource.textures().getFirst(), namespace); - else if (resource.hasModel()) - return IdentifierUtils.normalizeId(resource.model(), namespace); - } - - // * Méthode graphics - if (graphics != null) { - if (graphics.hasModel()) { - return IdentifierUtils.normalizeId(graphics.model(), namespace); - } - if (graphics.hasTexture()) { - return IdentifierUtils.normalizeId(graphics.texture(), namespace); - } - } - - return null; - } - - private static Material getMaterial(ItemResource resource, ItemGraphics graphics) { - Material byDefault = Material.valueOf(ItemResource.DEFAULT_MATERIAL); - Material resourceMaterial = resource.material(); - Material graphicsMaterial = graphics.material(); - - if (resourceMaterial != byDefault) - return resourceMaterial; - if (graphicsMaterial != byDefault) - return graphicsMaterial; - - return byDefault; - } - - private static Function resolvePathFunction(String namespace, ItemGraphics graphics, ItemResource resource) { - // * Méthode legacy - if (resource != null) { - if (resource.hasTextures()) - // todo: support multiple textures - return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, - IdentifierUtils.normalizeId(resource.textures().getFirst(), namespace)); - else if (resource.hasModel()) - return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, - IdentifierUtils.normalizeId(resource.model(), namespace)); - } - - // * Méthode graphics - if (graphics != null) { - if (graphics.hasModel()) { - return javaRoot -> IdentifierUtils.resolveModelId(javaRoot, - IdentifierUtils.normalizeId(graphics.model(), namespace)); - } - if (graphics.hasTexture()) { - return javaRoot -> IdentifierUtils.resolveTextureId(javaRoot, - IdentifierUtils.normalizeId(graphics.texture(), namespace)); - } - } - - return _ -> null; - } - - public String namespacedId() { - return namespace + ":" + key; - } -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java deleted file mode 100644 index 69b545c..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/ItemScanner.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.openmc.riftengine.core.scanner.items; - -import fr.openmc.riftengine.core.RiftRegistry; -import fr.openmc.riftengine.core.registry.scanner.AbstractScanner; -import fr.openmc.riftengine.core.utils.YmlUtils; -import org.bukkit.Material; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Scan tout les items initialisé par ItemsAdder - */ -public class ItemScanner extends AbstractScanner, Path> { - public List scan(Path itemsAdderContentsPath) throws Exception { - if (!Files.isDirectory(itemsAdderContentsPath)) return new ArrayList<>(); - - List ymlFiles = RiftRegistry.SCANNERS.YAML.scan(itemsAdderContentsPath); - - List result = new ArrayList<>(); - - for (Path ymlFile : ymlFiles) { - Map root = YmlUtils.loadYml(ymlFile); - - Object itemsObj = root.get("items"); - if (!(itemsObj instanceof Map itemsMap)) continue; - - String namespace = RiftRegistry.SCANNERS.YAML_ITEMSADDER_NAMESPACE.scan(root); - Map> mappedCache = RiftRegistry.SCANNERS.CUSTOM_MODEL_DATA_CACHE.scan(null); - - for (Map.Entry entry : itemsMap.entrySet()) { - String key = String.valueOf(entry.getKey()); - if (!(entry.getValue() instanceof Map data)) continue; - - result.add(ItemEntry.from(mappedCache, ymlFile, namespace, key, data)); - } - } - - return result; - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java deleted file mode 100644 index 4b405f0..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemGraphics.java +++ /dev/null @@ -1,40 +0,0 @@ -package fr.openmc.riftengine.core.scanner.items.entry; - -import fr.openmc.riftengine.core.utils.YmlUtils; -import org.bukkit.Material; - -import java.util.Map; - -public record ItemGraphics( - String texture, - String model, - Material material -) { - public static ItemGraphics from(Map data) { - if (!(data.get("graphics") instanceof Map graphics)) { - return new ItemGraphics(null, null, Material.PAPER); - } - - // todo: supporter textures (pour block, ou bow, fishing rod, ect) - String texture = YmlUtils.getString(graphics.get("texture"), null); - String model = YmlUtils.getString(graphics.get("model"), null); - Material material = Material.valueOf(YmlUtils.getString( - data.get("material"), ItemResource.DEFAULT_MATERIAL).toUpperCase()); - - return new ItemGraphics(texture, model, material); - } - - public boolean hasTexture() { - if (texture == null) return false; - return !texture.isEmpty(); - } - - public boolean hasModel() { - if (model == null) return false; - return !model.isEmpty(); - } - - public boolean isPresent() { - return hasTexture() || hasModel(); - } -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java b/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java deleted file mode 100644 index 2c4c203..0000000 --- a/src/main/java/fr/openmc/riftengine/core/scanner/items/entry/ItemResource.java +++ /dev/null @@ -1,53 +0,0 @@ -package fr.openmc.riftengine.core.scanner.items.entry; - -import fr.openmc.riftengine.core.utils.YmlUtils; -import org.bukkit.Material; - -import java.util.List; -import java.util.Map; - -public record ItemResource( - Material material, - boolean generate, - List textures, - String model -) { - public static final String DEFAULT_MATERIAL = "PAPER"; - - public static ItemResource from(Map data) { - Object resourceObj = data.get("resource"); - if (!(resourceObj instanceof Map resource)) - return new ItemResource(Material.valueOf(DEFAULT_MATERIAL), false, List.of(), null); - - Material material = Material.valueOf(YmlUtils.getString( - resource.get("material"), DEFAULT_MATERIAL).toUpperCase()); - - boolean generate = YmlUtils.getBool(resource.get("generate"), false); - - List textures = resource.get("textures") instanceof List list && resource.get("textures") != null - ? list.stream().map(String::valueOf).toList() - : List.of(); - - if (resource.get("textures") == null && resource.get("texture") != null && textures.isEmpty()) - textures = List.of(String.valueOf(resource.get("texture"))); - - if (textures.isEmpty() && resource.get("textures") instanceof String string) - textures = List.of(string); - - String modelPath = resource.get("model_path") != null - ? String.valueOf(resource.get("model_path")) - : null; - - return new ItemResource(material, generate, textures, modelPath); - } - - public boolean hasTextures() { - if (textures == null) return false; - return !textures.isEmpty(); - } - - public boolean hasModel() { - if (model == null) return false; - return !model.isEmpty(); - } -} \ No newline at end of file diff --git a/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java index c4923e5..d92fea2 100644 --- a/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java +++ b/src/main/java/fr/openmc/riftengine/core/utils/PathUtils.java @@ -18,13 +18,6 @@ public static Path getPathFromRoot(Path path, String rootName) { return reducedPath; } - public static Path getItemsAdderPath(Path dataPath) { - File pluginsDir = dataPath.toFile().getParentFile(); // * root/plugins - File itemsAdderDir = new File(pluginsDir, "ItemsAdder"); // * root/plugins/ItemsAdder - - return itemsAdderDir.toPath(); - } - public static Path getGeyserPath(Path dataPath) { File pluginsDir = dataPath.toFile().getParentFile(); // * root/plugins File geyserDir = new File(pluginsDir, "Geyser-Spigot"); // * root/plugins/Geyser-Spigot diff --git a/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java deleted file mode 100644 index f3aeb57..0000000 --- a/src/main/java/fr/openmc/riftengine/core/utils/YmlUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -package fr.openmc.riftengine.core.utils; - -import org.yaml.snakeyaml.Yaml; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; - -public class YmlUtils { - public static Map loadYml(Path path) throws IOException { - try (InputStream in = Files.newInputStream(path)) { - return new Yaml().load(in); - } catch (Exception e) { - throw new IOException("Erreur lors de la lecture du fichier yml " + path, e); - } - } - - public static String getString(Object obj, String def) { - if (obj == null) return def; - if (obj instanceof String s) return s; - return String.valueOf(obj); - } - - public static Integer getInt(Object obj, Integer def) { - if (obj == null) return def; - if (obj instanceof Number n) return n.intValue(); - return Integer.parseInt(obj.toString()); - } - - public static Boolean getBool(Object obj, Boolean def) { - if (obj == null) return def; - if (obj instanceof Boolean b) return b; - return Boolean.parseBoolean(obj.toString()); - } - - public static Double getDouble(Object obj, Double def) { - if (obj == null) return def; - if (obj instanceof Number n) return n.doubleValue(); - return Double.parseDouble(obj.toString()); - } -} diff --git a/src/main/java/fr/openmc/riftengine/core/utils/ZipUtils.java b/src/main/java/fr/openmc/riftengine/core/utils/ZipUtils.java deleted file mode 100644 index b12b5b8..0000000 --- a/src/main/java/fr/openmc/riftengine/core/utils/ZipUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -package fr.openmc.riftengine.core.utils; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -public class ZipUtils { - public static void unzip(Path zipPath, Path targetDir) throws IOException { - Files.createDirectories(targetDir); - - try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(zipPath))) { - ZipEntry entry; - - while ((entry = zis.getNextEntry()) != null) { - Path newPath = targetDir.resolve(entry.getName()); - - if (entry.isDirectory()) { - Files.createDirectories(newPath); - } else { - Files.createDirectories(newPath.getParent()); - Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING); - } - - zis.closeEntry(); - } - } - } - - public static void zip(Path sourceDir, Path zipPath) throws IOException { - Files.createDirectories(zipPath.getParent()); - - try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipPath))) { - Files.walk(sourceDir) - .filter(Files::isRegularFile) - .forEach(path -> { - try { - String entryName = sourceDir - .relativize(path) - .toString() - .replace('\\', '/'); - - ZipEntry entry = new ZipEntry(entryName); - zos.putNextEntry(entry); - Files.copy(path, zos); - zos.closeEntry(); - - } catch (IOException e) { - throw new UncheckedIOException(e); - } - }); - } - } - -}