mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Refactoring and some annotations
This commit is contained in:
parent
35c1fa6a23
commit
f4091e931b
7
pom.xml
7
pom.xml
@ -304,7 +304,14 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Development / Testing dependencies -->
|
<!-- Development / Testing dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.annotation</groupId>
|
||||||
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -62,7 +64,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
|
|||||||
this(category, item, recipe, new ItemStack[0], trigger);
|
this(category, item, recipe, new ItemStack[0], trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerDefaultRecipes(List<ItemStack> recipes) {
|
protected void registerDefaultRecipes(@Nonnull List<ItemStack> recipes) {
|
||||||
// Override this method to register some default recipes
|
// Override this method to register some default recipes
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +89,7 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(SlimefunAddon addon) {
|
public void register(@Nonnull SlimefunAddon addon) {
|
||||||
addItemHandler(getInteractionHandler());
|
addItemHandler(getInteractionHandler());
|
||||||
super.register(addon);
|
super.register(addon);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
@ -15,10 +14,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.inventory.meta.Repairable;
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
|
||||||
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
|
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
|
||||||
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
|
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
@ -26,7 +23,6 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
|
|||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
|
|
||||||
@ -64,51 +60,7 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tick(Block b) {
|
protected MachineRecipe findNextRecipe(BlockMenu menu) {
|
||||||
BlockMenu menu = BlockStorage.getInventory(b);
|
|
||||||
|
|
||||||
if (isProcessing(b)) {
|
|
||||||
int timeleft = progress.get(b);
|
|
||||||
if (timeleft > 0) {
|
|
||||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
|
||||||
|
|
||||||
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeCharge(b.getLocation(), getEnergyConsumption());
|
|
||||||
progress.put(b, timeleft - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
|
||||||
|
|
||||||
for (ItemStack item : processing.get(b).getOutput()) {
|
|
||||||
menu.pushItem(item, getOutputSlots());
|
|
||||||
}
|
|
||||||
|
|
||||||
progress.remove(b);
|
|
||||||
processing.remove(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MachineRecipe recipe = findRecipe(menu);
|
|
||||||
|
|
||||||
if (recipe != null) {
|
|
||||||
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int slot : getInputSlots()) {
|
|
||||||
menu.consumeItem(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
processing.put(b, recipe);
|
|
||||||
progress.put(b, recipe.getTicks());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MachineRecipe findRecipe(BlockMenu menu) {
|
|
||||||
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
||||||
Set<ItemEnchantment> emeraldEnchantments = new HashSet<>();
|
Set<ItemEnchantment> emeraldEnchantments = new HashSet<>();
|
||||||
|
|
||||||
@ -156,7 +108,17 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(disenchantedItem, ench.getEnchantment(), 0);
|
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(disenchantedItem, ench.getEnchantment(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MachineRecipe(90 * amount, new ItemStack[] { target, item }, new ItemStack[] { disenchantedItem, book });
|
MachineRecipe recipe = new MachineRecipe(90 * amount, new ItemStack[] { target, item }, new ItemStack[] { disenchantedItem, book });
|
||||||
|
|
||||||
|
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int inputSlot : getInputSlots()) {
|
||||||
|
menu.consumeItem(inputSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,12 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
|
||||||
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
|
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
|
||||||
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
|
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
@ -22,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
|
|||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
|
|
||||||
@ -52,52 +48,7 @@ public class AutoEnchanter extends AContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tick(Block b) {
|
protected MachineRecipe findNextRecipe(BlockMenu menu) {
|
||||||
BlockMenu menu = BlockStorage.getInventory(b.getLocation());
|
|
||||||
|
|
||||||
if (isProcessing(b)) {
|
|
||||||
int timeleft = progress.get(b);
|
|
||||||
|
|
||||||
if (timeleft > 0) {
|
|
||||||
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
|
|
||||||
|
|
||||||
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeCharge(b.getLocation(), getEnergyConsumption());
|
|
||||||
progress.put(b, timeleft - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
|
||||||
|
|
||||||
for (ItemStack item : processing.get(b).getOutput()) {
|
|
||||||
menu.pushItem(item, getOutputSlots());
|
|
||||||
}
|
|
||||||
|
|
||||||
progress.remove(b);
|
|
||||||
processing.remove(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MachineRecipe recipe = findRecipe(menu);
|
|
||||||
|
|
||||||
if (recipe != null) {
|
|
||||||
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int slot : getInputSlots()) {
|
|
||||||
menu.consumeItem(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
processing.put(b, recipe);
|
|
||||||
progress.put(b, recipe.getTicks());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MachineRecipe findRecipe(BlockMenu menu) {
|
|
||||||
for (int slot : getInputSlots()) {
|
for (int slot : getInputSlots()) {
|
||||||
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]);
|
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]);
|
||||||
|
|
||||||
@ -108,7 +59,6 @@ public class AutoEnchanter extends AContainer {
|
|||||||
|
|
||||||
ItemStack item = menu.getItemInSlot(slot);
|
ItemStack item = menu.getItemInSlot(slot);
|
||||||
|
|
||||||
// Enchant
|
|
||||||
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
|
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
|
||||||
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
||||||
Set<ItemEnchantment> emeraldEnchantments = new HashSet<>();
|
Set<ItemEnchantment> emeraldEnchantments = new HashSet<>();
|
||||||
@ -147,7 +97,17 @@ public class AutoEnchanter extends AContainer {
|
|||||||
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(enchantedItem, ench.getEnchantment(), ench.getLevel());
|
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(enchantedItem, ench.getEnchantment(), ench.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MachineRecipe(75 * amount, new ItemStack[] { target, item }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) });
|
MachineRecipe recipe = new MachineRecipe(75 * amount, new ItemStack[] { target, item }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) });
|
||||||
|
|
||||||
|
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int inputSlot : getInputSlots()) {
|
||||||
|
menu.consumeItem(inputSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||||
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
|
public abstract class MedicalSupply<T extends ItemHandler> extends SimpleSlimefunItem<T> {
|
||||||
|
|
||||||
|
private final int healAmount;
|
||||||
|
|
||||||
|
public MedicalSupply(Category category, int healAmount, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
|
this.healAmount = healAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method clears any negative {@link PotionEffect} from the given {@link Player}.
|
||||||
|
*
|
||||||
|
* @param p
|
||||||
|
* The {@link Player}
|
||||||
|
*/
|
||||||
|
public void clearNegativeEffects(@Nonnull Player p) {
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||||
|
if (p.hasPotionEffect(PotionEffectType.BAD_OMEN)) p.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void heal(@Nonnull Player p) {
|
||||||
|
double health = p.getHealth() + healAmount;
|
||||||
|
double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||||
|
p.setHealth(Math.min(health, maxHealth));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,39 +1,24 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;
|
||||||
|
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
public class Medicine extends SimpleSlimefunItem<ItemConsumptionHandler> {
|
public class Medicine extends MedicalSupply<ItemConsumptionHandler> {
|
||||||
|
|
||||||
private static final double HEALING_AMOUNT = 8.0;
|
|
||||||
|
|
||||||
public Medicine(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public Medicine(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, 8, item, recipeType, recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemConsumptionHandler getItemHandler() {
|
public ItemConsumptionHandler getItemHandler() {
|
||||||
return (e, p, item) -> {
|
return (e, p, item) -> {
|
||||||
if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
|
|
||||||
|
|
||||||
double health = p.getHealth() + HEALING_AMOUNT;
|
|
||||||
double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
|
||||||
p.setHealth(Math.min(health, maxHealth));
|
|
||||||
|
|
||||||
p.setFireTicks(0);
|
p.setFireTicks(0);
|
||||||
|
clearNegativeEffects(p);
|
||||||
|
heal(p);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,52 +2,35 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical;
|
|||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
public class Vitamins extends SimpleSlimefunItem<ItemUseHandler> {
|
public class Vitamins extends MedicalSupply<ItemUseHandler> {
|
||||||
|
|
||||||
private static final double HEALING_AMOUNT = 8.0;
|
|
||||||
|
|
||||||
public Vitamins(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public Vitamins(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, 8, item, recipeType, recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemUseHandler getItemHandler() {
|
public ItemUseHandler getItemHandler() {
|
||||||
return e -> {
|
return e -> {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
|
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
|
||||||
|
|
||||||
if (p.getGameMode() != GameMode.CREATIVE) {
|
if (p.getGameMode() != GameMode.CREATIVE) {
|
||||||
ItemUtils.consumeItem(e.getItem(), false);
|
ItemUtils.consumeItem(e.getItem(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
|
|
||||||
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
|
|
||||||
if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
|
|
||||||
|
|
||||||
p.setFireTicks(0);
|
|
||||||
|
|
||||||
double health = p.getHealth() + HEALING_AMOUNT;
|
|
||||||
double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
|
||||||
p.setHealth(Math.min(health, maxHealth));
|
|
||||||
|
|
||||||
e.cancel();
|
e.cancel();
|
||||||
|
p.setFireTicks(0);
|
||||||
|
clearNegativeEffects(p);
|
||||||
|
heal(p);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ public class EnhancedCraftingTable extends BackpackCrafter {
|
|||||||
if (state instanceof Dispenser) {
|
if (state instanceof Dispenser) {
|
||||||
Dispenser disp = (Dispenser) state;
|
Dispenser disp = (Dispenser) state;
|
||||||
Inventory inv = disp.getInventory();
|
Inventory inv = disp.getInventory();
|
||||||
|
|
||||||
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);
|
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this);
|
||||||
|
|
||||||
for (int i = 0; i < inputs.size(); i++) {
|
for (int i = 0; i < inputs.size(); i++) {
|
||||||
@ -51,6 +50,7 @@ public class EnhancedCraftingTable extends BackpackCrafter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -30,7 +32,7 @@ public class GrindStone extends MultiBlockMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerDefaultRecipes(List<ItemStack> recipes) {
|
protected void registerDefaultRecipes(@Nonnull List<ItemStack> recipes) {
|
||||||
recipes.add(new ItemStack(Material.BLAZE_ROD));
|
recipes.add(new ItemStack(Material.BLAZE_ROD));
|
||||||
recipes.add(new ItemStack(Material.BLAZE_POWDER, 4));
|
recipes.add(new ItemStack(Material.BLAZE_POWDER, 4));
|
||||||
|
|
||||||
@ -106,6 +108,7 @@ public class GrindStone extends MultiBlockMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -40,7 +42,7 @@ public class Smeltery extends AbstractSmeltery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerDefaultRecipes(List<ItemStack> recipes) {
|
protected void registerDefaultRecipes(@Nonnull List<ItemStack> recipes) {
|
||||||
recipes.add(SlimefunItems.IRON_DUST);
|
recipes.add(SlimefunItems.IRON_DUST);
|
||||||
recipes.add(new ItemStack(Material.IRON_INGOT));
|
recipes.add(new ItemStack(Material.IRON_INGOT));
|
||||||
}
|
}
|
||||||
@ -50,7 +52,7 @@ public class Smeltery extends AbstractSmeltery {
|
|||||||
List<ItemStack> items = new ArrayList<>();
|
List<ItemStack> items = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < recipes.size() - 1; i += 2) {
|
for (int i = 0; i < recipes.size() - 1; i += 2) {
|
||||||
if (Arrays.stream(recipes.get(i)).skip(1).anyMatch(Objects::nonNull)) {
|
if (recipes.get(i) == null || Arrays.stream(recipes.get(i)).skip(1).anyMatch(Objects::nonNull)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +104,7 @@ public class Smeltery extends AbstractSmeltery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Inventory findIgnitionChamber(Block b) {
|
private Inventory findIgnitionChamber(@Nonnull Block b) {
|
||||||
for (BlockFace face : faces) {
|
for (BlockFace face : faces) {
|
||||||
if (b.getRelative(face).getType() == Material.DROPPER && BlockStorage.check(b.getRelative(face), "IGNITION_CHAMBER")) {
|
if (b.getRelative(face).getType() == Material.DROPPER && BlockStorage.check(b.getRelative(face), "IGNITION_CHAMBER")) {
|
||||||
BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
|
BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
|
||||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.utils;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -22,7 +24,7 @@ public final class ChatUtils {
|
|||||||
|
|
||||||
private ChatUtils() {}
|
private ChatUtils() {}
|
||||||
|
|
||||||
public static void sendURL(CommandSender sender, String url) {
|
public static void sendURL(@Nonnull CommandSender sender, @Nonnull String url) {
|
||||||
// If we get access to the URL prompt one day, we can just prompt the link to the Player that way.
|
// If we get access to the URL prompt one day, we can just prompt the link to the Player that way.
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.link-prompt", false);
|
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.link-prompt", false);
|
||||||
@ -30,11 +32,11 @@ public final class ChatUtils {
|
|||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removeColorCodes(String string) {
|
public static String removeColorCodes(@Nonnull String string) {
|
||||||
return ChatColor.stripColor(ChatColors.color(string));
|
return ChatColor.stripColor(ChatColors.color(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String crop(ChatColor color, String string) {
|
public static String crop(@Nonnull ChatColor color, @Nonnull String string) {
|
||||||
if (ChatColor.stripColor(color + string).length() > 19) {
|
if (ChatColor.stripColor(color + string).length() > 19) {
|
||||||
return (color + ChatColor.stripColor(string)).substring(0, 18) + "...";
|
return (color + ChatColor.stripColor(string)).substring(0, 18) + "...";
|
||||||
}
|
}
|
||||||
@ -43,11 +45,11 @@ public final class ChatUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String christmas(String text) {
|
public static String christmas(@Nonnull String text) {
|
||||||
return ChatColors.alternating(text, ChatColor.GREEN, ChatColor.RED);
|
return ChatColors.alternating(text, ChatColor.GREEN, ChatColor.RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void awaitInput(Player p, Consumer<String> callback) {
|
public static void awaitInput(@Nonnull Player p, @Nonnull Consumer<String> callback) {
|
||||||
ChatInput.waitForPlayer(SlimefunPlugin.instance(), p, callback);
|
ChatInput.waitForPlayer(SlimefunPlugin.instance(), p, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ public final class ChatUtils {
|
|||||||
*
|
*
|
||||||
* @return A human-friendly version of the given {@link String}
|
* @return A human-friendly version of the given {@link String}
|
||||||
*/
|
*/
|
||||||
public static String humanize(String string) {
|
public static String humanize(@Nonnull String string) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String[] segments = PatternUtils.UNDERSCORE.split(string.toLowerCase(Locale.ROOT));
|
String[] segments = PatternUtils.UNDERSCORE.split(string.toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.utils;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.FireworkEffect;
|
import org.bukkit.FireworkEffect;
|
||||||
@ -19,7 +21,7 @@ public final class FireworkUtils {
|
|||||||
|
|
||||||
private FireworkUtils() {}
|
private FireworkUtils() {}
|
||||||
|
|
||||||
public static void launchFirework(Location l, Color color) {
|
public static void launchFirework(@Nonnull Location l, @Nonnull Color color) {
|
||||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||||
FireworkMeta meta = fw.getFireworkMeta();
|
FireworkMeta meta = fw.getFireworkMeta();
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ public final class FireworkUtils {
|
|||||||
fw.setFireworkMeta(meta);
|
fw.setFireworkMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Firework createFirework(Location l, Color color) {
|
public static Firework createFirework(@Nonnull Location l, @Nonnull Color color) {
|
||||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||||
FireworkMeta meta = fw.getFireworkMeta();
|
FireworkMeta meta = fw.getFireworkMeta();
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ public final class FireworkUtils {
|
|||||||
return fw;
|
return fw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void launchRandom(Entity n, int amount) {
|
public static void launchRandom(@Nonnull Entity n, int amount) {
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Location l = n.getLocation().clone();
|
Location l = n.getLocation().clone();
|
||||||
l.setX(l.getX() + ThreadLocalRandom.current().nextInt(amount));
|
l.setX(l.getX() + ThreadLocalRandom.current().nextInt(amount));
|
||||||
@ -55,7 +57,7 @@ public final class FireworkUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FireworkEffect getRandomEffect(Random random, Color color) {
|
public static FireworkEffect getRandomEffect(@Nonnull Random random, @Nonnull Color color) {
|
||||||
return FireworkEffect.builder().flicker(random.nextBoolean()).withColor(color).with(random.nextBoolean() ? Type.BALL : Type.BALL_LARGE).trail(random.nextBoolean()).build();
|
return FireworkEffect.builder().flicker(random.nextBoolean()).withColor(color).with(random.nextBoolean() ? Type.BALL : Type.BALL_LARGE).trail(random.nextBoolean()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.utils;
|
package io.github.thebusybiscuit.slimefun4.utils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +110,8 @@ public enum HeadTexture {
|
|||||||
|
|
||||||
private final String texture;
|
private final String texture;
|
||||||
|
|
||||||
HeadTexture(String texture) {
|
HeadTexture(@Nonnull String texture) {
|
||||||
|
Validate.notNull(texture, "Texture cannot be null");
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@ import java.time.Duration;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
public final class NumberUtils {
|
public final class NumberUtils {
|
||||||
@ -18,7 +22,8 @@ public final class NumberUtils {
|
|||||||
return NumberFormat.getNumberInstance(Locale.US).format(i);
|
return NumberFormat.getNumberInstance(Locale.US).format(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalDateTime parseGitHubDate(String date) {
|
public static LocalDateTime parseGitHubDate(@Nonnull String date) {
|
||||||
|
Validate.notNull(date, "Provided date was null");
|
||||||
return LocalDateTime.parse(date.substring(0, date.length() - 1));
|
return LocalDateTime.parse(date.substring(0, date.length() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +36,8 @@ public final class NumberUtils {
|
|||||||
else return ChatColor.GREEN;
|
else return ChatColor.GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getElapsedTime(LocalDateTime date) {
|
public static String getElapsedTime(@Nonnull LocalDateTime date) {
|
||||||
|
Validate.notNull(date, "Provided date was null");
|
||||||
long hours = Duration.between(date, LocalDateTime.now()).toHours();
|
long hours = Duration.between(date, LocalDateTime.now()).toHours();
|
||||||
|
|
||||||
if (hours == 0) {
|
if (hours == 0) {
|
||||||
@ -88,15 +94,15 @@ public final class NumberUtils {
|
|||||||
return DECIMAL_FORMAT.format(number);
|
return DECIMAL_FORMAT.format(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLong(Long value, long defaultValue) {
|
public static long getLong(@Nullable Long value, long defaultValue) {
|
||||||
return value == null ? defaultValue : value;
|
return value == null ? defaultValue : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt(Integer value, int defaultValue) {
|
public static int getInt(@Nullable Integer value, int defaultValue) {
|
||||||
return value == null ? defaultValue : value;
|
return value == null ? defaultValue : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getFloat(Float value, float defaultValue) {
|
public static float getFloat(@Nullable Float value, float defaultValue) {
|
||||||
return value == null ? defaultValue : value;
|
return value == null ? defaultValue : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@ import java.util.Base64;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -62,7 +66,7 @@ public final class SlimefunUtils {
|
|||||||
* The {@link Item} to query
|
* The {@link Item} to query
|
||||||
* @return Whether the {@link Item} is excluded from being picked up
|
* @return Whether the {@link Item} is excluded from being picked up
|
||||||
*/
|
*/
|
||||||
public static boolean hasNoPickupFlag(Item item) {
|
public static boolean hasNoPickupFlag(@Nonnull Item item) {
|
||||||
return item.hasMetadata(NO_PICKUP_METADATA);
|
return item.hasMetadata(NO_PICKUP_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +79,7 @@ public final class SlimefunUtils {
|
|||||||
* @param context
|
* @param context
|
||||||
* The context in which this {@link Item} was flagged
|
* The context in which this {@link Item} was flagged
|
||||||
*/
|
*/
|
||||||
public static void markAsNoPickup(Item item, String context) {
|
public static void markAsNoPickup(@Nonnull Item item, @Nonnull String context) {
|
||||||
item.setMetadata(NO_PICKUP_METADATA, new FixedMetadataValue(SlimefunPlugin.instance(), context));
|
item.setMetadata(NO_PICKUP_METADATA, new FixedMetadataValue(SlimefunPlugin.instance(), context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,19 +90,15 @@ public final class SlimefunUtils {
|
|||||||
* The {@link ItemStack} to check for
|
* The {@link ItemStack} to check for
|
||||||
* @return Whether the given item is soulbound
|
* @return Whether the given item is soulbound
|
||||||
*/
|
*/
|
||||||
public static boolean isSoulbound(ItemStack item) {
|
public static boolean isSoulbound(@Nullable ItemStack item) {
|
||||||
if (item == null || item.getType() == Material.AIR) {
|
if (item == null || item.getType() == Material.AIR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
|
ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
|
||||||
|
|
||||||
if (meta != null && SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
|
if (hasSoulboundFlag(meta)) {
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
return true;
|
||||||
|
|
||||||
if (container.has(SOULBOUND_KEY, PersistentDataType.BYTE)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SlimefunPlugin.getThirdPartySupportService().isEmeraldEnchantsInstalled()) {
|
if (SlimefunPlugin.getThirdPartySupportService().isEmeraldEnchantsInstalled()) {
|
||||||
@ -123,6 +123,18 @@ public final class SlimefunUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean hasSoulboundFlag(@Nullable ItemMeta meta) {
|
||||||
|
if (meta != null && SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (container.has(SOULBOUND_KEY, PersistentDataType.BYTE)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles an {@link ItemStack} to be Soulbound.<br>
|
* Toggles an {@link ItemStack} to be Soulbound.<br>
|
||||||
* If true is passed, this will add the {@link #SOULBOUND_LORE} and
|
* If true is passed, this will add the {@link #SOULBOUND_LORE} and
|
||||||
@ -137,7 +149,7 @@ public final class SlimefunUtils {
|
|||||||
*
|
*
|
||||||
* @see #isSoulbound(ItemStack)
|
* @see #isSoulbound(ItemStack)
|
||||||
*/
|
*/
|
||||||
public static void setSoulbound(ItemStack item, boolean makeSoulbound) {
|
public static void setSoulbound(@Nullable ItemStack item, boolean makeSoulbound) {
|
||||||
if (item == null || item.getType() == Material.AIR) {
|
if (item == null || item.getType() == Material.AIR) {
|
||||||
throw new IllegalArgumentException("A soulbound item cannot be null or air!");
|
throw new IllegalArgumentException("A soulbound item cannot be null or air!");
|
||||||
}
|
}
|
||||||
@ -179,7 +191,7 @@ public final class SlimefunUtils {
|
|||||||
*
|
*
|
||||||
* @return Whether this {@link ItemStack} is radioactive or not
|
* @return Whether this {@link ItemStack} is radioactive or not
|
||||||
*/
|
*/
|
||||||
public static boolean isRadioactive(ItemStack item) {
|
public static boolean isRadioactive(@Nullable ItemStack item) {
|
||||||
return SlimefunItem.getByItem(item) instanceof Radioactive;
|
return SlimefunItem.getByItem(item) instanceof Radioactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,9 +201,12 @@ public final class SlimefunUtils {
|
|||||||
*
|
*
|
||||||
* @param texture
|
* @param texture
|
||||||
* The texture for this head (base64 or hash)
|
* The texture for this head (base64 or hash)
|
||||||
|
*
|
||||||
* @return An {@link ItemStack} with this Head texture
|
* @return An {@link ItemStack} with this Head texture
|
||||||
*/
|
*/
|
||||||
public static ItemStack getCustomHead(String texture) {
|
public static ItemStack getCustomHead(@Nonnull String texture) {
|
||||||
|
Validate.notNull(texture, "The provided texture is null");
|
||||||
|
|
||||||
if (SlimefunPlugin.instance() == null) {
|
if (SlimefunPlugin.instance() == null) {
|
||||||
throw new PrematureCodeException("You cannot instantiate a custom head before Slimefun was loaded.");
|
throw new PrematureCodeException("You cannot instantiate a custom head before Slimefun was loaded.");
|
||||||
}
|
}
|
||||||
@ -233,11 +248,11 @@ public final class SlimefunUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore) {
|
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore) {
|
||||||
return isItemSimilar(item, sfitem, checkLore, true);
|
return isItemSimilar(item, sfitem, checkLore, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore, boolean checkAmount) {
|
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) {
|
||||||
if (item == null) return sfitem == null;
|
if (item == null) return sfitem == null;
|
||||||
if (sfitem == null) return false;
|
if (sfitem == null) return false;
|
||||||
if (item.getType() != sfitem.getType()) return false;
|
if (item.getType() != sfitem.getType()) return false;
|
||||||
@ -271,7 +286,7 @@ public final class SlimefunUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equalsItemMeta(ItemMeta itemMeta, ImmutableItemMeta meta, boolean checkLore) {
|
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ImmutableItemMeta meta, boolean checkLore) {
|
||||||
Optional<String> displayName = meta.getDisplayName();
|
Optional<String> displayName = meta.getDisplayName();
|
||||||
|
|
||||||
if (itemMeta.hasDisplayName() != displayName.isPresent()) {
|
if (itemMeta.hasDisplayName() != displayName.isPresent()) {
|
||||||
@ -295,7 +310,7 @@ public final class SlimefunUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equalsItemMeta(ItemMeta itemMeta, ItemMeta sfitemMeta, boolean checkLore) {
|
private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta sfitemMeta, boolean checkLore) {
|
||||||
if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) {
|
if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -313,7 +328,7 @@ public final class SlimefunUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equalsLore(List<String> lore, List<String> lore2) {
|
private static boolean equalsLore(@Nonnull List<String> lore, @Nonnull List<String> lore2) {
|
||||||
StringBuilder string1 = new StringBuilder();
|
StringBuilder string1 = new StringBuilder();
|
||||||
StringBuilder string2 = new StringBuilder();
|
StringBuilder string2 = new StringBuilder();
|
||||||
|
|
||||||
@ -332,7 +347,10 @@ public final class SlimefunUtils {
|
|||||||
return string1.toString().equals(string2.toString());
|
return string1.toString().equals(string2.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCapacitorTexture(Location l, int charge, int capacity) {
|
public static void updateCapacitorTexture(@Nonnull Location l, int charge, int capacity) {
|
||||||
|
Validate.notNull(l, "Cannot update a texture for null");
|
||||||
|
Validate.isTrue(capacity > 0, "Capacity must be greater than zero!");
|
||||||
|
|
||||||
Slimefun.runSync(() -> {
|
Slimefun.runSync(() -> {
|
||||||
Block b = l.getBlock();
|
Block b = l.getBlock();
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ import java.util.Set;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -324,7 +326,7 @@ public class SlimefunItem implements Placeable {
|
|||||||
* @param addon
|
* @param addon
|
||||||
* The {@link SlimefunAddon} that this {@link SlimefunItem} belongs to.
|
* The {@link SlimefunAddon} that this {@link SlimefunItem} belongs to.
|
||||||
*/
|
*/
|
||||||
public void register(SlimefunAddon addon) {
|
public void register(@Nonnull SlimefunAddon addon) {
|
||||||
Validate.notNull(addon, "A SlimefunAddon cannot be null!");
|
Validate.notNull(addon, "A SlimefunAddon cannot be null!");
|
||||||
Validate.notNull(addon.getJavaPlugin(), "SlimefunAddon#getJavaPlugin() is not allowed to return null!");
|
Validate.notNull(addon.getJavaPlugin(), "SlimefunAddon#getJavaPlugin() is not allowed to return null!");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user