Fixed ms and tick delays, and moved to another gui util
This commit is contained in:
parent
19b861c3fd
commit
97e66d65f1
20 changed files with 919 additions and 197 deletions
53
src/main/java/nl/sbdeveloper/showapi/utils/Inventory.java
Normal file
53
src/main/java/nl/sbdeveloper/showapi/utils/Inventory.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package nl.sbdeveloper.showapi.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.showapi.ShowAPIPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static nl.sbdeveloper.showapi.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(ShowAPIPlugin.getInstance());
|
||||
manager.init();
|
||||
}
|
||||
}
|
601
src/main/java/nl/sbdeveloper/showapi/utils/ItemBuilder.java
Normal file
601
src/main/java/nl/sbdeveloper/showapi/utils/ItemBuilder.java
Normal file
|
@ -0,0 +1,601 @@
|
|||
package nl.sbdeveloper.showapi.utils;
|
||||
|
||||
import com.cryptomorin.xseries.SkullUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Blutkrone
|
||||
*/
|
||||
public class ItemBuilder {
|
||||
/*
|
||||
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;
|
||||
private static boolean loaded = false;
|
||||
private static boolean usePotionSetColor = false;
|
||||
|
||||
/** */
|
||||
private static void init() {
|
||||
try {
|
||||
Class.forName("org.bukkit.Color");
|
||||
usePotionSetColor = true;
|
||||
} catch (Exception e) {
|
||||
usePotionSetColor = false;
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemBuilder from scratch.
|
||||
*
|
||||
* @param m The material to create the ItemBuilder with.
|
||||
*/
|
||||
public ItemBuilder(Material m) {
|
||||
this(m, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemBuilder over an existing itemstack.
|
||||
*
|
||||
* @param is The itemstack to create the ItemBuilder over.
|
||||
*/
|
||||
public ItemBuilder(ItemStack is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemBuilder from scratch.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemBuilder from scratch.
|
||||
*
|
||||
* @param m The material of the item.
|
||||
* @param amount The evaluate of the item.
|
||||
* @param durability The durability of the item.
|
||||
*/
|
||||
public ItemBuilder(Material m, int amount, short durability) {
|
||||
this(m, amount, durability, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemBuilder from scratch.
|
||||
*
|
||||
* @param m The material of the item.
|
||||
* @param amount The evaluate of the item.
|
||||
* @param durability The durability of the item.
|
||||
*/
|
||||
public ItemBuilder(Material m, int amount, short durability, Byte data) {
|
||||
if (!loaded) init();
|
||||
|
||||
if (data != null && data > 0 && data <= 15) {
|
||||
is = new ItemStack(m, amount);
|
||||
setDurability(durability);
|
||||
|
||||
// Ensure that we only allow applying data on valid objects.
|
||||
if (is.getType().name().contains("STAINED_GLASS")) {
|
||||
setData(GlassColor.values()[data]);
|
||||
} else if (is.getType().name().contains("WOOL")) {
|
||||
setData(WoolColor.values()[data]);
|
||||
} else if (is.getType().name().contains("DYE") || DyeColor.is(is.getType())) {
|
||||
setData(DyeColor.values()[data]);
|
||||
} else
|
||||
Bukkit.getLogger().warning("Unable to assign " + m + " a data value!");
|
||||
} else {
|
||||
is = new ItemStack(m, amount);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the durability of the item.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the unbreakable of the item.
|
||||
*
|
||||
* @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);
|
||||
is.setItemMeta(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;
|
||||
}
|
||||
|
||||
public ItemBuilder glow() {
|
||||
if (is.getType() == Material.AIR) return this;
|
||||
is.addUnsafeEnchantment(Enchantment.LURE, 0);
|
||||
ItemMeta im = is.getItemMeta();
|
||||
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the skull getOwner for the item. Works on skulls only.
|
||||
*
|
||||
* @param owner The name of the skull's getOwner.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public ItemBuilder setSkullTexture(String url) {
|
||||
if (is.getType() == Material.AIR) return this;
|
||||
is.setItemMeta(SkullUtils.applySkin(is.getItemMeta(), url));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an enchant to the item.
|
||||
*
|
||||
* @param ench The enchant to add
|
||||
* @param level The level
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package nl.sbdeveloper.showapi.utils;
|
||||
|
||||
import com.samjakob.spigui.item.ItemBuilder;
|
||||
import nl.sbdeveloper.showapi.api.ShowCue;
|
||||
import nl.sbdeveloper.showapi.api.TriggerData;
|
||||
import nl.sbdeveloper.showapi.api.TriggerTask;
|
||||
import nl.sbdeveloper.showapi.api.TriggerType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -17,24 +16,28 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class MainUtil {
|
||||
public static String __(String in) {
|
||||
return ChatColor.translateAlternateColorCodes('&', in);
|
||||
}
|
||||
|
||||
public static ItemStack pointToItem(ShowCue point) {
|
||||
ItemBuilder builder = new ItemBuilder(Material.NOTE_BLOCK);
|
||||
builder.name(ChatColor.ITALIC + "TimeCode: " + TimeUtil.showTime(point.getTicks()));
|
||||
builder.setName(ChatColor.ITALIC + "TimeCode: " + TimeUtil.makeReadable(point.getTime()));
|
||||
|
||||
List<String> lores = new ArrayList<>();
|
||||
lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getData().getType().name()));
|
||||
lores.add(ChatColor.GREEN + "Type: " + ChatColor.AQUA + StringUtils.capitalize(point.getTask().getType().name()));
|
||||
lores.add(ChatColor.GREEN + "Data:");
|
||||
for (String str : ChatPaginator.paginate(point.getData().getDataString(), 20).getLines()) {
|
||||
for (String str : ChatPaginator.paginate(point.getTask().getDataString(), 20).getLines()) {
|
||||
lores.add(ChatColor.AQUA + ChatColor.stripColor(str));
|
||||
}
|
||||
lores.add("");
|
||||
lores.add(ChatColor.RED + ChatColor.BOLD.toString() + "Click to remove!");
|
||||
|
||||
builder.lore(lores);
|
||||
return builder.build();
|
||||
builder.setLore(lores);
|
||||
return builder.toItemStack();
|
||||
}
|
||||
|
||||
public static TriggerData parseData(String data) {
|
||||
public static TriggerTask parseData(String data) {
|
||||
String[] dataSplitter = data.split(" ");
|
||||
String[] dataSplitterNew = Arrays.copyOfRange(dataSplitter, 1, dataSplitter.length);
|
||||
|
||||
|
@ -46,7 +49,7 @@ public class MainUtil {
|
|||
}
|
||||
|
||||
try {
|
||||
Constructor<? extends TriggerData> ctor = type.getTrigger().getConstructor(String[].class);
|
||||
Constructor<? extends TriggerTask> ctor = type.getTrigger().getConstructor(String[].class);
|
||||
if (dataSplitter.length < type.getMinArgs()) return null;
|
||||
return ctor.newInstance(new Object[] { dataSplitterNew });
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
|
|
|
@ -1,75 +1,59 @@
|
|||
package nl.sbdeveloper.showapi.utils;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Source from:
|
||||
* https://github.com/Mindgamesnl/OpenAudioMc/blob/master/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/util/TimeParser.java
|
||||
*/
|
||||
public class TimeUtil {
|
||||
private static final int s = 1000;
|
||||
private static final int m = s * 60;
|
||||
private static final int h = m * 60;
|
||||
private static final int d = h * 24;
|
||||
private static final int w = d * 7;
|
||||
private static final int y = (int)(d * 365.25);
|
||||
|
||||
public static String showTime(int seconds) {
|
||||
LocalTime timeOfDay = LocalTime.ofSecondOfDay(seconds / 20);
|
||||
return timeOfDay.toString();
|
||||
}
|
||||
public static Long toMilis(String input) {
|
||||
long time = 0L;
|
||||
|
||||
public static int parseTicks(String str) {
|
||||
try {
|
||||
LocalTime localTime = LocalTime.parse(str);
|
||||
return localTime.toSecondOfDay();
|
||||
} catch (DateTimeParseException ex) {
|
||||
Pattern pattern = Pattern.compile("^(-?(?:\\d+)?\\.?\\d+) *(ticks?|tick?|t|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
|
||||
if (!matcher.find()) return 0;
|
||||
|
||||
float n = Float.parseFloat(matcher.group(1));
|
||||
switch (matcher.group(2).toLowerCase()) {
|
||||
case "years":
|
||||
case "year":
|
||||
case "yrs":
|
||||
case "yr":
|
||||
case "y":
|
||||
return (int)(n * y) / 20000;
|
||||
case "weeks":
|
||||
case "week":
|
||||
case "w":
|
||||
return (int)(n * w) / 20000;
|
||||
case "days":
|
||||
case "day":
|
||||
case "d":
|
||||
return (int)(n * d) / 20000;
|
||||
case "hours":
|
||||
case "hour":
|
||||
case "hrs":
|
||||
case "hr":
|
||||
case "h":
|
||||
return (int)(n * h) / 20000;
|
||||
case "minutes":
|
||||
case "minute":
|
||||
case "mins":
|
||||
case "min":
|
||||
case "m":
|
||||
return (int)(n * m) / 20000;
|
||||
case "seconds":
|
||||
case "second":
|
||||
case "secs":
|
||||
case "sec":
|
||||
case "s":
|
||||
return (int)(n * s) / 20000;
|
||||
case "ticks":
|
||||
case "tick":
|
||||
case "ts":
|
||||
case "t":
|
||||
return (int) n / 20000;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
// ITS A TIMECODE
|
||||
if (input.contains(":")) {
|
||||
return LocalTime.parse(input, DateTimeFormatter.ofPattern("HH:mm:ss")).toSecondOfDay() * 1000L;
|
||||
}
|
||||
|
||||
input = input.toLowerCase() + "-";
|
||||
|
||||
String[] milisSplit = input.split("ms");
|
||||
if (isValid(milisSplit)) {
|
||||
time += Long.parseLong(milisSplit[0]);
|
||||
return time;
|
||||
}
|
||||
|
||||
String[] secondsSplit = input.split("s");
|
||||
if (isValid(secondsSplit)) {
|
||||
time += Math.round(Double.parseDouble(secondsSplit[0]) * 1000);
|
||||
return time;
|
||||
}
|
||||
|
||||
String[] minutesSplit = input.split("m");
|
||||
if (isValid(minutesSplit)) {
|
||||
time += Math.round(Double.parseDouble(minutesSplit[0]) * 60000);
|
||||
return time;
|
||||
}
|
||||
|
||||
String[] tickSplit = input.split("t");
|
||||
if (isValid(tickSplit)) {
|
||||
time += Math.round(Integer.parseInt(tickSplit[0]) * 50);
|
||||
return time;
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValid(String[] array) {
|
||||
return array.length > 1 && array[0].length() > 0;
|
||||
}
|
||||
|
||||
public static Object makeReadable(Long time) {
|
||||
return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time),
|
||||
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
|
||||
TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue