CustomItems

This commit is contained in:
NichtStudioCode 2021-01-27 15:16:52 +01:00
parent 5a63384f36
commit 548b22df97
5 changed files with 96 additions and 29 deletions

@ -1,24 +0,0 @@
package de.studiocode.invgui.item.impl.customtexture;
import de.studiocode.invgui.item.impl.SimpleItem;
import de.studiocode.invgui.item.itembuilder.ItemBuilder;
import de.studiocode.invgui.resourcepack.ForceResourcePack;
import org.bukkit.Material;
public class BackgroundItem extends SimpleItem {
private static final BackgroundItem INSTANCE = new BackgroundItem();
static {
ForceResourcePack.getInstance(); // initializes ForceResourcePack which automatically activates forced resource packs (if not disabled)
}
private BackgroundItem() {
super(new ItemBuilder(Material.POPPY).setDisplayName("§f").setCustomModelData(10000000));
}
public static BackgroundItem getInstance() {
return INSTANCE;
}
}

@ -19,9 +19,9 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.*;
public class ItemBuilder {
public class ItemBuilder implements Cloneable {
protected Material material;
protected int amount = 1;
protected int damage;
protected int customModelData = -1;
@ -167,6 +167,20 @@ public class ItemBuilder {
return this;
}
public ItemBuilder setGameProfile(GameProfile gameProfile) {
this.gameProfile = gameProfile;
return this;
}
@Override
public ItemBuilder clone() {
try {
return (ItemBuilder) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
/**
* Contains the texture value for a player head.
*

@ -0,0 +1,73 @@
package de.studiocode.invgui.resourcepack;
import de.studiocode.invgui.item.Item;
import de.studiocode.invgui.item.impl.SimpleItem;
import de.studiocode.invgui.item.itembuilder.ItemBuilder;
import org.bukkit.Material;
public enum CustomItem {
BACKGROUND(10000000),
ARROW_1_UP(10000001),
ARROW_1_RIGHT(10000002),
ARROW_1_DOWN(10000003),
ARROW_1_LEFT(10000004),
LIGHT_ARROW_1_UP(10000005),
LIGHT_ARROW_1_RIGHT(10000006),
LIGHT_ARROW_1_DOWN(10000007),
LIGHT_ARROW_1_LEFT(10000008),
ARROW_2_UP(10000009),
ARROW_2_RIGHT(10000010),
ARROW_2_DOWN(10000011),
ARROW_2_LEFT(10000012),
LIGHT_ARROW_2_UP(10000013),
LIGHT_ARROW_2_RIGHT(10000014),
LIGHT_ARROW_2_DOWN(10000015),
LIGHT_ARROW_2_LEFT(10000016),
HORIZONTAL_LINE(10000017),
VERTICAL_LINE(10000018),
LIGHT_HORIZONTAL_LINE(10000019),
LIGHT_VERTICAL_LINE(10000020),
CORNER_TOP_LEFT(10000021),
CORNER_TOP_RIGHT(10000022),
CORNER_BOTTOM_LEFT(10000023),
CORNER_BOTTOM_RIGHT(10000024),
LIGHT_CORNER_TOP_LEFT(10000025),
LIGHT_CORNER_TOP_RIGHT(10000026),
LIGHT_CORNER_BOTTOM_LEFT(10000027),
LIGHT_CORNER_BOTTOM_RIGHT(10000028);
private final ItemBuilder itemBuilder;
private final Item item;
CustomItem(int customModelData) {
this.itemBuilder = new ItemBuilder(Material.POPPY)
.setCustomModelData(customModelData)
.setDisplayName("§0");
this.item = new SimpleItem(itemBuilder);
}
/**
* Gets a copy of the {@link ItemBuilder} for this {@link CustomItem}.
*
* @return A copy of the {@link ItemBuilder}
*/
public ItemBuilder getItemBuilder() {
return itemBuilder.clone();
}
/**
* Gets a non-clickable {@link Item} with this texture.
*
* @return A non-clickable {@link Item} with this texture.
*/
public Item getItem() {
return item;
}
}

@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
import java.util.function.Predicate;
@ -130,7 +132,7 @@ public interface Window {
* @param animation The animation to play.
* @param filter The filter that selects which Items should be animated.
*/
void playAnimation(Animation animation, Predicate<ItemStackHolder> filter);
void playAnimation(@NotNull Animation animation, @Nullable Predicate<ItemStackHolder> filter);
/**
* Gets if the player is able to close the {@link Inventory}.

@ -18,6 +18,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Predicate;
@ -186,14 +188,14 @@ public abstract class BaseWindow implements Window {
}
@Override
public void playAnimation(Animation animation, Predicate<ItemStackHolder> filter) {
public void playAnimation(@NotNull Animation animation, @Nullable Predicate<ItemStackHolder> filter) {
if (getViewer() != null) {
this.animation = animation;
List<Integer> slots = new ArrayList<>();
for (int i = 0; i < size; i++) {
ItemStackHolder holder = itemsDisplayed[i];
if (holder != null && filter.test(holder)) {
if (holder != null && (filter == null || filter.test(holder))) {
slots.add(i);
inventory.setItem(i, null);
}