Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
</transformers>
<filters>
<!-- Keep the plugin manifest; dependency manifests describe separate JARs. -->
<filter>
<artifact>org.bstats:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.tfminecraft.musicalinstruments.items;

import net.tfminecraft.musicalinstruments.util.LegacyModelData;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -84,6 +86,8 @@ private ItemStack resolveVanilla(String path) {
}

// modeled(type=paper;name=&6Flute;model=1001)
// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
private ItemStack resolveModeled(String path) {
int open = path.indexOf('(');
int close = path.lastIndexOf(')');
Expand Down Expand Up @@ -114,7 +118,7 @@ private ItemStack resolveModeled(String path) {
}
if (attributes.containsKey("model")) {
try {
meta.setCustomModelData(Integer.parseInt(attributes.get("model")));
LegacyModelData.set(meta, Integer.parseInt(attributes.get("model")));
} catch (NumberFormatException e) {
logger.warning("Invalid model data in modeled item '" + path + "'.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.tfminecraft.musicalinstruments.util;

import java.util.List;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;

/** Preserves the integer model IDs used by existing configuration and resource packs. */
public final class LegacyModelData {
private LegacyModelData() {}

public static boolean has(ItemMeta meta) {
return !meta.getCustomModelDataComponent().getFloats().isEmpty();
}

public static int get(ItemMeta meta) {
List<Float> floats = meta.getCustomModelDataComponent().getFloats();
if (floats.isEmpty()) {
throw new IllegalStateException("We don't have CustomModelData! Check hasCustomModelData first!");
}
return floats.get(0).intValue();
}

public static void set(ItemMeta meta, Integer value) {
if (value == null) {
meta.setCustomModelDataComponent(null);
return;
}
CustomModelDataComponent component = meta.getCustomModelDataComponent();
// The former integer setter replaced the entire component, not just its first float.
component.setFloats(List.of(value.floatValue()));
component.setFlags(List.of());
component.setStrings(List.of());
component.setColors(List.of());
meta.setCustomModelDataComponent(component);
}
}