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
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;

public class CustomModelDataComponent extends ItemComponent {
private final @NotNull Optional<@NotNull List<@NotNull Color>> colors;
private final @NotNull Optional<@NotNull List<@NotNull Boolean>> flags;
private final @NotNull Optional<@NotNull List<@NotNull Float>> floats;
private final @NotNull Optional<@NotNull List<@NotNull String>> string;
private final @NotNull List<@NotNull Color> colors;
private final @NotNull List<@NotNull Boolean> flags;
private final @NotNull List<@NotNull Float> floats;
private final @NotNull List<@NotNull String> strings;

public CustomModelDataComponent(@NotNull Optional<@NotNull List<@NotNull Color>> colors, @NotNull Optional<@NotNull List<@NotNull Boolean>> flags, @NotNull Optional<@NotNull List<@NotNull Float>> floats, @NotNull Optional<@NotNull List<@NotNull String>> string) {
public CustomModelDataComponent(@NotNull List<@NotNull Color> colors, @NotNull List<@NotNull Boolean> flags, @NotNull List<@NotNull Float> floats, @NotNull List<@NotNull String> strings) {
this.colors = colors;
this.flags = flags;
this.floats = floats;
this.string = string;
this.strings = strings;
}

public @NotNull Optional<@NotNull List<@NotNull Color>> getColors() {
public @NotNull List<@NotNull Color> getColors() {
return colors;
}

public @NotNull Optional<@NotNull List<@NotNull Boolean>> getFlags() {
return flags;
public @NotNull List<@NotNull Boolean> getFlags() {
return this.flags;
}

public @NotNull Optional<@NotNull List<@NotNull Float>> getFloats() {
return floats;
public @NotNull List<@NotNull Float> getFloats() {
return this.floats;
}

public @NotNull Optional<@NotNull List<@NotNull String>> getString() {
return string;
public @NotNull List<@NotNull String> getStrings() {
return this.strings;
}

@Override
Expand All @@ -47,10 +46,18 @@ public void apply(@NotNull BuildContext context, @NotNull ItemStack itemStack, @
if (itemMeta != null) {
org.bukkit.inventory.meta.components.CustomModelDataComponent customModelDataComponent = itemMeta.getCustomModelDataComponent();

this.colors.ifPresent(customModelDataComponent::setColors);
this.flags.ifPresent(customModelDataComponent::setFlags);
this.floats.ifPresent(customModelDataComponent::setFloats);
this.string.ifPresent(customModelDataComponent::setStrings);
if (!this.colors.isEmpty()) {
customModelDataComponent.setColors(this.colors);
}
if (!this.flags.isEmpty()) {
customModelDataComponent.setFlags(this.flags);
}
if (!this.floats.isEmpty()) {
customModelDataComponent.setFloats(this.floats);
}
if (!this.strings.isEmpty()) {
customModelDataComponent.setStrings(this.strings);
}

itemStack.setItemMeta(itemMeta);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class SpigotCustomModelDataItemComponentLoader extends AbstractColorItemComponentLoader {

Expand All @@ -24,44 +23,50 @@ public SpigotCustomModelDataItemComponentLoader(){
@Override
public @Nullable ItemComponent load(@NotNull MenuItemStackContext context, @NotNull File file, @NotNull YamlConfiguration configuration, @NotNull String path, @Nullable ConfigurationSection componentSection) {
if (componentSection == null) return null;
Optional<List<Float>> floatList;
List<Float> floats = componentSection.getFloatList("floats");
floatList = floats.isEmpty() ? Optional.empty() : Optional.of(floats);
List<Float> floats = getFloats(componentSection);

Optional<List<Boolean>> booleanList;
List<Boolean> booleans = componentSection.getBooleanList("flags");
booleanList = booleans.isEmpty() ? Optional.empty() : Optional.of(booleans);
List<Boolean> booleans = getBooleans(componentSection);

Optional<List<String>> stringList;
List<String> strings = componentSection.getStringList("strings");
stringList = strings.isEmpty() ? Optional.empty() : Optional.of(strings);
List<String> strings = getStrings(componentSection);

Optional<List<Color>> colorList;
List<?> colorsList = componentSection.getList("colors");
if (colorsList == null || colorsList.isEmpty()) {
colorList = Optional.empty();
} else {
List<Color> colors = new ArrayList<>();
for (Object obj : colorsList) {
Color color = parseColor(obj);
if (color != null) {
colors.add(color);
}
}
colorList = colors.isEmpty() ? Optional.empty() : Optional.of(colors);
}
List<Color> colorList = getColors(componentSection);

if (colorList.isEmpty() && booleanList.isEmpty() && floatList.isEmpty() && stringList.isEmpty()) {
if (colorList.isEmpty() && booleans.isEmpty() && floats.isEmpty() && strings.isEmpty()) {
return null;
}

return new CustomModelDataComponent(
colorList,
booleanList,
floatList,
stringList
booleans,
floats,
strings
);
}

protected @NotNull List<Float> getFloats(@NotNull ConfigurationSection section) {
return section.getFloatList("floats");
}

protected @NotNull List<Boolean> getBooleans(@NotNull ConfigurationSection section) {
return section.getBooleanList("flags");
}

protected @NotNull List<String> getStrings(@NotNull ConfigurationSection section) {
return section.getStringList("strings");
}

protected @NotNull List<Color> getColors(@NotNull ConfigurationSection section) {
List<Color> colors = new ArrayList<>();
List<?> colorsList = section.getList("colors");
if (colorsList != null) {
for (Object obj : colorsList) {
Color color = parseColor(obj);
if (color != null) {
colors.add(color);
}
}
}
return colors;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.maxlego08.menu.itemstack.components.paper;

import fr.maxlego08.menu.api.context.BuildContext;
import fr.maxlego08.menu.api.itemstack.ItemComponent;
import io.papermc.paper.datacomponent.DataComponentTypes;
import io.papermc.paper.datacomponent.item.CustomModelData;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PaperCustomModelDataComponent extends ItemComponent {
private final CustomModelData customModelData;

public PaperCustomModelDataComponent(@NotNull CustomModelData customModelData) {
this.customModelData = customModelData;
}

@Override
public void apply(@NotNull BuildContext context, @NotNull ItemStack itemStack, @Nullable Player player) {

itemStack.setData(DataComponentTypes.CUSTOM_MODEL_DATA, this.customModelData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fr.maxlego08.menu.loader.components.paper;

import fr.maxlego08.menu.api.context.MenuItemStackContext;
import fr.maxlego08.menu.api.itemstack.ItemComponent;
import fr.maxlego08.menu.itemstack.components.paper.PaperCustomModelDataComponent;
import fr.maxlego08.menu.loader.components.spigot.SpigotCustomModelDataItemComponentLoader;
import io.papermc.paper.datacomponent.item.CustomModelData;
import org.bukkit.Color;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;

public class PaperCustomModelDataComponentLoader extends SpigotCustomModelDataItemComponentLoader {

@Override
public @Nullable ItemComponent load(@NotNull MenuItemStackContext context, @NotNull File file, @NotNull YamlConfiguration configuration, @NotNull String path, @Nullable ConfigurationSection componentSection) {
if (componentSection == null) return null;
List<Float> floats = getFloats(componentSection);

List<Boolean> booleans = getBooleans(componentSection);

List<String> strings = getStrings(componentSection);

List<Color> colorList = getColors(componentSection);

if (colorList.isEmpty() && booleans.isEmpty() && floats.isEmpty() && strings.isEmpty()) {
return null;
}

CustomModelData.Builder builder = CustomModelData.customModelData();
if (!colorList.isEmpty()) {
builder.addColors(colorList);
}
if (!booleans.isEmpty()) {
builder.addFlags(booleans);
}
if (!floats.isEmpty()) {
builder.addFloats(floats);
}
if (!strings.isEmpty()) {
builder.addStrings(strings);
}
return new PaperCustomModelDataComponent(builder.build());
}
}
Loading
Loading