Bumped inv dep, migrated to new SBD classes

This commit is contained in:
Stijn Bannink 2023-09-10 16:05:01 +02:00
parent fc044fcb9e
commit a55cb25680
8 changed files with 276 additions and 655 deletions

View file

@ -121,10 +121,9 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.minuskube.inv</groupId> <groupId>com.github.MinusKube</groupId>
<artifactId>smart-invs</artifactId> <artifactId>SmartInvs</artifactId>
<version>1.2.7</version> <version>9c9dbbee16</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.cryptomorin</groupId> <groupId>com.github.cryptomorin</groupId>

View file

@ -5,7 +5,7 @@ import nl.sbdeveloper.showcontrol.api.ShowAPI;
import nl.sbdeveloper.showcontrol.commands.ShowCMD; import nl.sbdeveloper.showcontrol.commands.ShowCMD;
import nl.sbdeveloper.showcontrol.data.DataStorage; import nl.sbdeveloper.showcontrol.data.DataStorage;
import nl.sbdeveloper.showcontrol.data.Shows; import nl.sbdeveloper.showcontrol.data.Shows;
import nl.sbdeveloper.showcontrol.utils.Inventory; import nl.sbdeveloper.showcontrol.utils.inventories.Inventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -29,7 +29,7 @@ public final class ShowControlPlugin extends JavaPlugin {
commandManager.getCommandCompletions().registerCompletion("showtype", c -> ShowAPI.getTriggers().keySet()); commandManager.getCommandCompletions().registerCompletion("showtype", c -> ShowAPI.getTriggers().keySet());
getLogger().info("Loading GUI manageer..."); getLogger().info("Loading GUI manageer...");
Inventory.init(); Inventory.init(this);
getLogger().info("Loading default triggers..."); getLogger().info("Loading default triggers...");
ShowAPI.index(ShowControlPlugin.class, "nl.sbdeveloper.showcontrol.api.triggers.impl"); ShowAPI.index(ShowControlPlugin.class, "nl.sbdeveloper.showcontrol.api.triggers.impl");

View file

@ -6,9 +6,8 @@ import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotIterator; import fr.minuskube.inv.content.SlotIterator;
import nl.sbdeveloper.showcontrol.api.ShowCuePoint; import nl.sbdeveloper.showcontrol.api.ShowCuePoint;
import nl.sbdeveloper.showcontrol.data.Shows; import nl.sbdeveloper.showcontrol.data.Shows;
import nl.sbdeveloper.showcontrol.utils.Inventory;
import nl.sbdeveloper.showcontrol.utils.ItemBuilder;
import nl.sbdeveloper.showcontrol.utils.MainUtil; import nl.sbdeveloper.showcontrol.utils.MainUtil;
import nl.sbdeveloper.showcontrol.utils.inventories.PaginationInventory;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,48 +18,16 @@ import java.util.List;
import static nl.sbdeveloper.showcontrol.utils.MainUtil.__; import static nl.sbdeveloper.showcontrol.utils.MainUtil.__;
public class ShowCueGUI extends Inventory { public class ShowCueGUI extends PaginationInventory {
private final String showName;
public ShowCueGUI(Player p, String name) { public ShowCueGUI(Player p, String name) {
super(6, ChatColor.DARK_AQUA + "Show Cue Manager:"); super(6, ChatColor.DARK_AQUA + "Show Cue Manager:");
this.showName = name;
open(p);
}
@Override Shows.getPoints(name).stream().sorted(Comparator.comparing(ShowCuePoint::getTime))
public void init(Player player, InventoryContents contents) { .forEach(cue -> addItem(ClickableItem.of(MainUtil.pointToItem(cue), e -> {
Pagination pagination = contents.pagination(); Shows.removePoint(name, cue);
refresh(p);
List<ClickableItem> items = new ArrayList<>();
Shows.getPoints(showName).stream().sorted(Comparator.comparing(ShowCuePoint::getTime))
.forEach(cue -> items.add(ClickableItem.of(MainUtil.pointToItem(cue), e -> {
Shows.removePoint(showName, cue);
open(player, pagination.getPage());
}))); })));
ClickableItem[] itemsArray = new ClickableItem[items.size()]; open(p);
itemsArray = items.toArray(itemsArray);
pagination.setItems(itemsArray);
pagination.setItemsPerPage(45);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 0, 0));
contents.set(5, 0, ClickableItem.of(new ItemBuilder(Material.PLAYER_HEAD, 1)
.setName(__("&7Vorige pagina"))
.setLore(__("&eGa naar de vorige pagina."))
.setSkullTexture("http://textures.minecraft.net/texture/6e8c3ce2aee6cf2faade7db37bbae73a36627ac1473fef75b410a0af97659f")
.toItemStack(), e -> open(player, pagination.previous().getPage())));
contents.set(5, 4, ClickableItem.of(new ItemBuilder(Material.BARRIER, 1)
.setName(__("&7Sluiten"))
.setLore(__("&eSluit dit menu."))
.toItemStack(), e -> player.closeInventory()));
contents.set(5, 8, ClickableItem.of(new ItemBuilder(Material.PLAYER_HEAD, 1)
.setName(__("&7Volgende pagina"))
.setLore(__("&eGa naar de volgende pagina."))
.setSkullTexture("http://textures.minecraft.net/texture/6e8cd53664d9307b6869b9abbae2b7737ab762bb18bb34f31c5ca8f3edb63b6")
.toItemStack(), e -> open(player, pagination.next().getPage())));
} }
} }

View file

@ -1,53 +0,0 @@
package nl.sbdeveloper.showcontrol.utils;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import nl.sbdeveloper.showcontrol.ShowControlPlugin;
import org.bukkit.entity.Player;
import static nl.sbdeveloper.showcontrol.utils.MainUtil.__;
public abstract class Inventory implements InventoryProvider {
/*
This file is part of FrogRacing.
Copyright (c) 2018-2021 FrogNetwork - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential
Written by Stijn Bannink <stijnbannink23@gmail.com>, March 2020
*/
private static InventoryManager manager;
protected SmartInventory inventory;
public Inventory(int rows, String title) {
this(rows, title, true); //Standaard sluitbaar!
}
public Inventory(int rows, String title, boolean closeable) {
this.inventory = SmartInventory.builder().id(title).provider(this).manager(manager).size(rows, 9).closeable(closeable).title(__("&8" + title)).build();
}
@Override
public void update(Player player, InventoryContents contents) {
// Niet altijd nodig, daarom staat hij hier alvast.
}
protected void open(Player player) {
this.inventory.open(player);
}
protected void open(Player player, int page) {
this.inventory.open(player, page);
}
public void close(Player player) {
this.inventory.close(player);
}
public static void init() {
manager = new InventoryManager(ShowControlPlugin.getInstance());
manager.init();
}
}

View file

@ -1,601 +1,167 @@
package nl.sbdeveloper.showcontrol.utils; package nl.sbdeveloper.showcontrol.utils;
import com.cryptomorin.xseries.SkullUtils; import com.cryptomorin.xseries.SkullUtils;
import org.bukkit.Bukkit; import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.potion.PotionData;
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.*; import java.util.ArrayList;
import java.util.function.Function; import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.UnaryOperator;
/** @Getter
* @author Blutkrone
*/
public class ItemBuilder { public class ItemBuilder {
/* private final ItemStack itemStack;
This file is part of FrogRacing.
Copyright (c) 2018-2021 FrogNetwork - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential
Written by Stijn Bannink <stijnbannink23@gmail.com>, March 2020
*/
private final ItemStack is; public ItemBuilder(Material material) {
private static boolean loaded = false; this.itemStack = new ItemStack(material);
private static boolean usePotionSetColor = false;
/** */
private static void init() {
try {
Class.forName("org.bukkit.Color");
usePotionSetColor = true;
} catch (Exception e) {
usePotionSetColor = false;
} }
loaded = true; public ItemBuilder(ItemStack stack) {
this.itemStack = stack.clone();
} }
/** public ItemBuilder(XMaterial material) {
* Create a new ItemBuilder from scratch. ItemStack item = material.parseItem();
* if (item == null) {
* @param m The material to create the ItemBuilder with. throw new IllegalArgumentException("Received invalid / unsupported XMaterial: " + material.name());
*/ }
public ItemBuilder(Material m) { this.itemStack = item;
this(m, 1);
} }
/** private void applyToMeta(UnaryOperator<ItemMeta> callback) {
* Create a new ItemBuilder over an existing itemstack. this.itemStack.setItemMeta(callback.apply(this.itemStack.getItemMeta()));
*
* @param is The itemstack to create the ItemBuilder over.
*/
public ItemBuilder(ItemStack is) {
this.is = is;
} }
/** public ItemBuilder amount(int amount) {
* Create a new ItemBuilder from scratch. this.itemStack.setAmount(amount);
* return this;
* @param m The material of the item.
* @param amount The evaluate of the item.
*/
public ItemBuilder(Material m, int amount) {
this(m, amount, (short) 0);
} }
/** public ItemBuilder displayname(String name) {
* Create a new ItemBuilder from scratch. applyToMeta(meta -> {
* meta.setDisplayName(name);
* @param m The material of the item. return meta;
* @param amount The evaluate of the item. });
* @param durability The durability of the item. return this;
*/
public ItemBuilder(Material m, int amount, short durability) {
this(m, amount, durability, null);
} }
/** public ItemBuilder lore(String... lore) {
* Create a new ItemBuilder from scratch. applyToMeta(meta -> {
* List<String> lores = meta.getLore();
* @param m The material of the item. if (lores == null) lores = new ArrayList<>();
* @param amount The evaluate of the item. for (String loreString : lore) {
* @param durability The durability of the item. String[] loreParts = loreString.split("[\\r\\n]+");
*/ Collections.addAll(lores, loreParts);
public ItemBuilder(Material m, int amount, short durability, Byte data) { }
if (!loaded) init(); meta.setLore(lores);
return meta;
});
return this;
}
if (data != null && data > 0 && data <= 15) { public ItemBuilder lore(List<String> lore) {
is = new ItemStack(m, amount); lore(lore.toArray(String[]::new));
setDurability(durability); return this;
}
// Ensure that we only allow applying data on valid objects. public ItemBuilder flag(ItemFlag... flags) {
if (is.getType().name().contains("STAINED_GLASS")) { applyToMeta(meta -> {
setData(GlassColor.values()[data]); meta.addItemFlags(flags);
} else if (is.getType().name().contains("WOOL")) { return meta;
setData(WoolColor.values()[data]); });
} else if (is.getType().name().contains("DYE") || DyeColor.is(is.getType())) { return this;
setData(DyeColor.values()[data]); }
} else
Bukkit.getLogger().warning("Unable to assign " + m + " a data value!"); public ItemBuilder hideAllFlags() {
return flag(ItemFlag.values());
}
public ItemBuilder customModelData(int customModelData) {
if (XMaterial.supports(13)) {
applyToMeta(meta -> {
meta.setCustomModelData(customModelData);
return meta;
});
}
return this;
}
public ItemBuilder enchant(Map<Enchantment, Integer> enchantments) {
itemStack.addEnchantments(enchantments);
return this;
}
public ItemBuilder enchant(Enchantment enchantment, int level) {
itemStack.addEnchantment(enchantment, level);
return this;
}
public ItemBuilder durability(int damage) {
if (XMaterial.supports(13)) {
applyToMeta(meta -> {
if (!(meta instanceof org.bukkit.inventory.meta.Damageable)) return meta;
((org.bukkit.inventory.meta.Damageable) meta).setDamage(damage);
return meta;
});
} else { } else {
is = new ItemStack(m, amount); itemStack.setDurability((short) damage);
setDurability(durability);
}
}
public static ItemBuilder create(ItemStack from) {
return new ItemBuilder(from);
}
public ItemBuilder setData(GlassColor color) {
if (is.getType().name().contains("STAINED_GLASS")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(WoolColor color) {
if (is.getType().name().contains("WOOL")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(DyeColor color) {
if (is.getType().name().contains("DYE") || DyeColor.is(is.getType())) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
public ItemBuilder setData(PotionColor color) {
if (is.getType().name().contains("POTION")) {
color.apply(this);
} else
throw new IllegalArgumentException("Cannot apply " + color.getClass().getSimpleName() + " on " + is.getType());
return this;
}
/**
* Clone the ItemBuilder into a new one.
*
* @return The cloned instance.
*/
public ItemBuilder clone() {
return new ItemBuilder(is.clone());
}
/**
* Change the durability of the item.
*
* @param dur The durability to set it to.
*/
public ItemBuilder setDurability(short dur) {
if (is.getType() == Material.AIR) return this;
ItemMeta meta = is.getItemMeta();
if (meta instanceof org.bukkit.inventory.meta.Damageable) {
((org.bukkit.inventory.meta.Damageable) meta).setDamage(dur);
is.setItemMeta(meta);
} }
return this; return this;
} }
/** public ItemBuilder unbreakable() {
* Change the durability of the item. return unbreakable(true);
*
* @param data The durability to set it to.
*/
@Deprecated
public ItemBuilder setData(byte data) {
if (is.getType() == Material.AIR) return this;
is.setData(new MaterialData(is.getType(), data));
return this;
} }
/** public ItemBuilder unbreakable(boolean unbreakable) {
* Change the unbreakable of the item. applyToMeta(meta -> {
*
* @param unbreakable The unbreakable to set it to.
*/
public ItemBuilder setUnbreakable(boolean unbreakable) {
if (is.getType() == Material.AIR) return this;
ItemMeta meta = is.getItemMeta();
meta.setUnbreakable(unbreakable); meta.setUnbreakable(unbreakable);
is.setItemMeta(meta); return meta;
return this; });
}
/**
* Change the evaluate of the item.
*
* @param amount The evaluate to set it to.
*/
public ItemBuilder setAmount(int amount) {
if (is.getType() == Material.AIR) return this;
is.setAmount(amount);
return this;
}
/**
* Add an item flag
*
* @param flags item flagS
*/
public ItemBuilder addFlags(ItemFlag... flags) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.addItemFlags(flags);
is.setItemMeta(im);
return this;
}
/**
* Remove an item flag
*
* @param flags item flagS
*/
public ItemBuilder removeFlags(ItemFlag... flags) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.removeItemFlags(flags);
is.setItemMeta(im);
return this;
}
/**
* Set the displayname of the item.
*
* @param name The name to change it to.
*/
public ItemBuilder setName(String name) {
if (is.getType() == Material.AIR || name == null || name.isEmpty()) return this;
ItemMeta im = is.getItemMeta();
im.setDisplayName(name);
is.setItemMeta(im);
return this;
}
/**
* Add an unsafe enchantment.
*
* @param ench The enchantment to add.
* @param level The level to put the enchant on.
*/
public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level) {
if (is.getType() == Material.AIR) return this;
is.addUnsafeEnchantment(ench, level);
return this;
}
/**
* Remove a certain enchant from the item.
*
* @param ench The enchantment to remove
*/
public ItemBuilder removeEnchantment(Enchantment ench) {
if (is.getType() == Material.AIR) return this;
is.removeEnchantment(ench);
return this; return this;
} }
public ItemBuilder glow() { public ItemBuilder glow() {
if (is.getType() == Material.AIR) return this; this.itemStack.addUnsafeEnchantment(Enchantment.LURE, 0);
is.addUnsafeEnchantment(Enchantment.LURE, 0); flag(ItemFlag.HIDE_ENCHANTS);
ItemMeta im = is.getItemMeta();
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
is.setItemMeta(im);
return this; return this;
} }
/** public ItemBuilder skullTexture(String identifier) {
* Set the skull getOwner for the item. Works on skulls only. applyToMeta(meta -> {
* SkullUtils.applySkin(meta, identifier);
* @param owner The name of the skull's getOwner. return meta;
*/ });
public ItemBuilder setSkullOwner(String owner) {
if (is.getType() == Material.AIR) return this;
try {
SkullMeta im = (SkullMeta) is.getItemMeta();
im.setOwner(owner);
is.setItemMeta(im);
} catch (ClassCastException expected) {
}
return this; return this;
} }
public ItemBuilder setSkullTexture(String url) { public ItemBuilder armorColor(Color color) {
if (is.getType() == Material.AIR) return this; applyToMeta(meta -> {
is.setItemMeta(SkullUtils.applySkin(is.getItemMeta(), url)); if (!(meta instanceof LeatherArmorMeta)) return meta;
((LeatherArmorMeta) meta).setColor(color);
return meta;
});
return this; return this;
} }
/** public ItemBuilder potionEffect(PotionType type) {
* Add an enchant to the item. if (!itemStack.getType().name().contains("POTION")) throw new UnsupportedOperationException("ItemStack is not a potion! (Type: " + itemStack.getType().name() + ")");
* applyToMeta(meta -> {
* @param ench The enchant to add if (!(meta instanceof org.bukkit.inventory.meta.PotionMeta)) return meta;
* @param level The level ((org.bukkit.inventory.meta.PotionMeta) meta).setBasePotionData(new PotionData(type));
*/ return meta;
public ItemBuilder addEnchant(Enchantment ench, int level) { });
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.addEnchant(ench, level, true);
is.setItemMeta(im);
return this; return this;
} }
/**
* Add multiple enchants at once.
*
* @param enchantments The enchants to add.
*/
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
if (is.getType() == Material.AIR) return this;
is.addEnchantments(enchantments);
return this;
}
/**
* Sets infinity durability on the item by setting the durability to Short.MAX_VALUE.
*/
public ItemBuilder setInfinityDurability() {
if (is.getType() == Material.AIR) return this;
is.setDurability(Short.MAX_VALUE);
return this;
}
/**
* Re-sets the lore.
*
* @param lore The lore to set it to.
*/
public ItemBuilder setLore(String... lore) {
if (is.getType() == Material.AIR || lore == null) return this;
ItemMeta im = is.getItemMeta();
im.setLore(Arrays.asList(lore));
is.setItemMeta(im);
return this;
}
/**
* Re-sets the lore.
*
* @param lore The lore to set it to.
*/
public ItemBuilder setLore(List<String> lore) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Remove a lore line.
*
* @param line The lore to remove.
*/
public ItemBuilder removeLoreLine(String line) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
if (!lore.contains(line)) return this;
lore.remove(line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Remove a lore line.
*
* @param index The index of the lore line to remove.
*/
public ItemBuilder removeLoreLine(int index) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
if (index < 0 || index > lore.size()) return this;
lore.remove(index);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Add a lore line.
*
* @param line The lore line to add.
*/
public ItemBuilder addLoreLine(String line) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>();
if (im.hasLore()) lore = new ArrayList<>(im.getLore());
lore.add(line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
public ItemBuilder addLoreLine(String... lines) {
if (is.getType() == Material.AIR) return this;
for (String line : lines) {
addLoreLine(line);
}
return this;
}
public ItemBuilder addLoreLine(Collection<String> lines) {
if (is.getType() == Material.AIR) return this;
for (String line : lines) {
addLoreLine(line);
}
return this;
}
/**
* Add a lore line.
*
* @param line The lore line to add.
* @param pos The index of where to put it.
*/
public ItemBuilder addLoreLine(String line, int pos) {
if (is.getType() == Material.AIR) return this;
ItemMeta im = is.getItemMeta();
List<String> lore = new ArrayList<>(im.getLore());
lore.set(pos, line);
im.setLore(lore);
is.setItemMeta(im);
return this;
}
/**
* Direct access to the item meta
*
* @param modifier function to modify the meta.
*/
public ItemBuilder writeMeta(
Function<ItemMeta, ItemMeta> modifier
) {
if (is.getType() == Material.AIR) return this;
is.setItemMeta(modifier.apply(is.getItemMeta()));
return this;
}
/**
* Retrieves the itemstack from the ItemBuilder.
*
* @return The itemstack created/modified by the ItemBuilder instance.
*/
public ItemStack toItemStack() {
return is;
}
public enum GlassColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
private void apply(ItemBuilder builder) {
boolean panel = builder.is.getType().name().contains("STAINED_GLASS_PANE");
builder.is.setType(Material.valueOf(name() + (panel ? "_STAINED_GLASS_PANE" : "STAINED_GLASS")));
}
}
public enum WoolColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
private void apply(ItemBuilder builder) {
builder.is.setType(Material.valueOf(name() + "_WOOL"));
}
}
public enum DyeColor {
BLACK(0, "INK_SACK"),
RED(1, "ROSE_RED"),
GREEN(2, "CACTUS_GREEN"),
BROWN(3, "COCOA_BEANS"),
BLUE(4, "LAPIS_LAZULI"),
PURPLE(5, "PURPLE_DYE"),
CYAN(6, "CYAN_DYE"),
LIGHT_GRAY(7, "LIGHT_GRAY_DYE"),
GRAY(8, "GRAY_DYE"),
PINK(9, "PINK_DYE"),
LIME(10, "LIME_DYE"),
YELLOW(11, "DANDELION_YELLOW"),
LIGHT_BLUE(12, "LIGHT_BLUE_DYE"),
MAGENTA(13, "MAGENTA_DYE"),
ORANGE(14, "ORANGE_DYE"),
WHITE(15, "BONE_MEAL");
private final String coded;
DyeColor(int data, String coded) {
this.coded = coded;
}
static boolean is(Material mat) {
if (mat.name().contains("DYE")) return true;
if (mat.name().contains("INK_SAC")) return true;
for (DyeColor dyeColor : values()) {
if (dyeColor.name().equalsIgnoreCase(mat.name()))
return true;
}
return false;
}
private void apply(ItemBuilder builder) {
builder.is.setType(Material.valueOf(coded));
}
}
public enum PotionColor {
PINK("REGEN", 0xF442E2),
CYAN("SPEED", 0x42f1f4),
GOLD("FIRE_RESISTANCE", 0xf4b942),
DARK_GREEN("POISON", 0x365b0e),
RED("INSTANT_HEAL", 0xe5251b),
DARK_BLUE("NIGHT_VISION", 0x092366),
DARK_GRAY("WEAKNESS", 0x2e2f33),
DARK_RED("STRENGTH", 0x4f0a01),
GRAY("SLOWNESS", 0x939393),
LIGHT_GREEN("JUMP", 0x42f4b0),
BROWN("INSTANT_DAMAGE", 0xa54126),
BLUE("WATER_BREATHING", 0x0e59ef), // TEAL
LIGHT_GRAY("INVISIBILITY", 0xc4c4c4),
GREEN("LUCK", 0x1f890f),
BLACK(null, 0x161616),
LIGHT_BROWN("TURTLE_MASTER", 0xad581b),
SILVER("SLOW_FALLING", 0xd8ccc3);
private final String potionType;
private final int rgb;
PotionColor(String potionType, int rgb) {
this.potionType = potionType;
this.rgb = rgb;
}
private void apply(ItemBuilder builder) {
PotionMeta meta = (PotionMeta) builder.is.getItemMeta();
if (usePotionSetColor) {
meta.setColor(Color.fromRGB(rgb));
} else if (potionType != null) {
try {
meta.setBasePotionData(new org.bukkit.potion.PotionData(PotionType.valueOf(potionType)));
} catch (Exception e) {
Bukkit.getLogger().severe("Unknown Potion Color: " + this + ", " +
"the underlying " + potionType + " handle isn't available in this version!");
}
}
builder.is.setItemMeta(meta);
}
}
public enum FireworkColor {
}
} }

View file

@ -17,9 +17,6 @@ public class MainUtil {
public static ItemStack pointToItem(ShowCuePoint point) { public static ItemStack pointToItem(ShowCuePoint point) {
TriggerIdentifier identifier = point.getTask().getClass().getAnnotation(TriggerIdentifier.class); TriggerIdentifier identifier = point.getTask().getClass().getAnnotation(TriggerIdentifier.class);
ItemBuilder builder = new ItemBuilder(identifier.item());
builder.setName(ChatColor.ITALIC + "TimeCode: " + TimeUtil.makeReadable(point.getTime()));
List<String> lores = new ArrayList<>(); List<String> lores = new ArrayList<>();
lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + capitalize(point.getTask().getTriggerId())); lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + capitalize(point.getTask().getTriggerId()));
lores.add(ChatColor.GREEN + "Data:"); lores.add(ChatColor.GREEN + "Data:");
@ -29,8 +26,9 @@ public class MainUtil {
lores.add(""); lores.add("");
lores.add(ChatColor.RED + ChatColor.BOLD.toString() + "Click to remove!"); lores.add(ChatColor.RED + ChatColor.BOLD.toString() + "Click to remove!");
builder.setLore(lores); return new ItemBuilder(identifier.item())
return builder.toItemStack(); .displayname(ChatColor.ITALIC + "TimeCode: " + TimeUtil.makeReadable(point.getTime()))
.lore(lores).getItemStack();
} }
public static String capitalize(String str) { public static String capitalize(String str) {

View file

@ -0,0 +1,59 @@
package nl.sbdeveloper.showcontrol.utils.inventories;
import com.cryptomorin.xseries.XMaterial;
import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import nl.sbdeveloper.showcontrol.utils.ItemBuilder;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import static nl.sbdeveloper.showcontrol.utils.MainUtil.__;
public abstract class Inventory implements InventoryProvider {
private static InventoryManager manager;
protected SmartInventory inventory;
private final boolean filler;
public Inventory(int rows, String title, boolean filler) {
this(rows, title, filler, true);
}
public Inventory(int rows, String title, boolean filler, boolean closeable) {
if (rows < 1 || rows > 6) {
throw new IllegalArgumentException("Amount of rows must be between 1 and 6");
}
this.inventory = SmartInventory.builder().id(title).provider(this).manager(manager).size(rows, 9).closeable(closeable).title(__("&8" + title)).build();
this.filler = filler;
}
protected void open(Player player) {
this.inventory.open(player);
}
protected void open(Player player, int page) {
this.inventory.open(player, page);
}
public void close(Player player) {
this.inventory.close(player);
}
public static void init(JavaPlugin plugin) {
manager = new InventoryManager(plugin);
manager.init();
}
@Override
public void init(Player player, InventoryContents inventoryContents) {
if (filler) {
inventoryContents.fill(ClickableItem.empty(new ItemBuilder(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem()).displayname(__("&r")).getItemStack()));
}
addItems(player, inventoryContents);
}
public abstract void addItems(Player player, InventoryContents contents);
}

View file

@ -0,0 +1,85 @@
package nl.sbdeveloper.showcontrol.utils.inventories;
import com.cryptomorin.xseries.XMaterial;
import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotIterator;
import nl.sbdeveloper.showcontrol.utils.ItemBuilder;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import static nl.sbdeveloper.showcontrol.utils.MainUtil.__;
public abstract class PaginationInventory extends Inventory {
private final int paginationRows; //Amount of rows for pagination (excluding button row)
private final int paginationRow; //The start row of the pagination (starts from 0)
private final List<ClickableItem> items = new ArrayList<>();
private Pagination pagination; //Available after init() is called, can only be used in the event of a ClickableItem!!!
private final int staticRows; //Amount of rows that are static
private final boolean filler;
protected PaginationInventory(int paginationRows, String title) {
//Default full-inventory pagination
this(paginationRows, 0, 0, title, false);
}
protected PaginationInventory(int paginationRows, int staticRows, String title, boolean filler) {
this(paginationRows, 0, staticRows, title, filler);
}
protected PaginationInventory(int paginationRows, int paginationRow, int staticRows, String title, boolean filler) {
//Custom pagination with static rows
super(paginationRows + 1 + staticRows, title, false);
this.paginationRows = paginationRows;
this.paginationRow = paginationRow;
this.staticRows = staticRows;
this.filler = filler;
}
public void addItem(ClickableItem item) {
this.items.add(item);
}
public void refresh(Player player) {
open(player, pagination.getPage());
}
@Override
public void addItems(Player player, InventoryContents contents) {
//Set up static items
if (filler) {
//Fill all static rows
for (int i = paginationRows + 1; i <= paginationRows + staticRows; i++) {
contents.fillRow(i, ClickableItem.empty(new ItemBuilder(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem()).displayname(__("&r")).getItemStack()));
}
}
addStaticItems(player, contents);
//Set up pagination
pagination = contents.pagination();
pagination.setItems(items.toArray(ClickableItem[]::new));
pagination.setItemsPerPage(9 * paginationRows);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, paginationRow, 0));
contents.set(paginationRows, 0, ClickableItem.of(new ItemBuilder(XMaterial.ARROW.parseItem()).displayname(__("&6First page"))
.lore(__("&fGo to the first page (" + pagination.first().getPage() + ")")).getItemStack(),
e -> open(player, pagination.first().getPage())));
contents.set(paginationRows, 3, ClickableItem.of(new ItemBuilder(XMaterial.OAK_SIGN.parseItem()).displayname(__("&6Previous"))
.lore(__("&fGo to the previous page (" + pagination.previous().getPage() + ")")).getItemStack(),
e -> open(player, pagination.previous().getPage())));
contents.set(paginationRows, 5, ClickableItem.of(new ItemBuilder(XMaterial.OAK_SIGN.parseItem()).displayname(__("&6Next"))
.lore(__("&fGo to the next page (" + pagination.next().getPage() + ")")).getItemStack(),
e -> open(player, pagination.next().getPage())));
contents.set(paginationRows, 8, ClickableItem.of(new ItemBuilder(XMaterial.ARROW.parseItem()).displayname(__("&6Last page"))
.lore(__("&fGo to the last page (" + pagination.last().getPage() + ")")).getItemStack(),
e -> open(player, pagination.last().getPage())));
}
public void addStaticItems(Player player, InventoryContents contents) {
//Override this method to add static items
}
}