Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
m1919810 committed Dec 29, 2024
1 parent 5cf0268 commit 3b663d6
Showing 1 changed file with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,46 @@ public class SlimefunItemStack extends ItemStack {
private boolean locked = false;
private String texture = null;

public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer<ItemMeta> consumer) {
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {
super(item.getType(), item.getAmount());

if (item.hasItemMeta()) {
setItemMeta(item.getItemMeta());
}

Validate.notNull(id, "The Item id must never be null!");
Validate.isTrue(
id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')");
id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')");

if (Slimefun.instance() == null) {
throw new PrematureCodeException(
"A SlimefunItemStack must never be be created before your Plugin was enabled.");
"A SlimefunItemStack must never be be created before your Plugin was enabled.");
}

this.id = id;

ItemMeta meta = item.hasItemMeta()?item.getItemMeta(): getItemMeta();
ItemMeta meta = getItemMeta();

Slimefun.getItemDataService().setItemData(meta, id);
Slimefun.getItemTextureService().setTexture(meta, id);
consumer.accept(meta);

setItemMeta(meta);
}
private static final Consumer<ItemMeta> DEFAULT_CONSUMER=(itemMeta -> {});
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {
this(id, item,DEFAULT_CONSUMER);

public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer<ItemMeta> consumer) {
this(id, item);

ItemMeta im = getItemMeta();
consumer.accept(im);
setItemMeta(im);
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Consumer<ItemMeta> consumer) {
this(id, new ItemStack(type), consumer);
}

public SlimefunItemStack(
@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
this(id, type, meta -> {
if (name != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
Expand Down Expand Up @@ -110,7 +117,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable S
}

public SlimefunItemStack(
@Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) {
@Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) {
this(id, type, im -> {
if (name != null) {
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
Expand All @@ -137,11 +144,11 @@ public SlimefunItemStack(
}

public SlimefunItemStack(
@Nonnull String id,
@Nonnull Color color,
@Nonnull PotionEffect effect,
@Nullable String name,
String... lore) {
@Nonnull String id,
@Nonnull Color color,
@Nonnull PotionEffect effect,
@Nullable String name,
String... lore) {
this(id, Material.POTION, im -> {
if (name != null) {
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
Expand Down Expand Up @@ -183,7 +190,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull HeadTexture head, @Nullabl
}

public SlimefunItemStack(
@Nonnull String id, @Nonnull String texture, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
@Nonnull String id, @Nonnull String texture, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
this(id, getSkull(id, texture), meta -> {
if (name != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
Expand Down Expand Up @@ -302,22 +309,17 @@ public void lock() {
return texture;
} else if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) {
String value =
"{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}";
"{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}";
return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
} else {
throw new IllegalArgumentException(
"The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!");
"The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!");
}
}
//fix issue 988 : addon menu can't open propertly due to cast error in 1.21+paper

@Override
public ItemStack clone() {
//return new SlimefunItemStack(id, this);
ItemStack stack=super.clone();
if(stack instanceof SlimefunItemStack sfitem){
sfitem.locked=false;
}
return stack;
return new SlimefunItemStack(id, this);
}

@Override
Expand Down

0 comments on commit 3b663d6

Please sign in to comment.