1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Minor Bug Fixes

This commit is contained in:
TheBusyBiscuit 2019-09-01 20:29:16 +02:00
parent 2fbad51e53
commit dd0bb1ef8b
13 changed files with 208 additions and 161 deletions

View File

@ -4,20 +4,28 @@ import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
public abstract class SimpleSlimefunItem extends SlimefunItem {
public abstract class SimpleSlimefunItem<T extends ItemHandler> extends SlimefunItem {
public SimpleSlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
public SimpleSlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, id, recipeType, recipe, recipeOutput);
}
public SimpleSlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(category, item, id, recipeType, recipe, keys, values);
}
@Override
public void register(boolean slimefun) {
addItemHandler(onRightClick());
addItemHandler(getItemHandler());
super.register(slimefun);
}
public abstract ItemInteractionHandler onRightClick();
public abstract T getItemHandler();
}

View File

@ -2,43 +2,35 @@ package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
public class DietCookie extends SlimefunItem {
public class DietCookie extends SimpleSlimefunItem<ItemConsumptionHandler> {
public DietCookie(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
@Override
public void register(boolean slimefun) {
addItemHandler(new ItemConsumptionHandler() {
@Override
public boolean onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, getItem(), true)) {
p.sendMessage(ChatColor.YELLOW + "You feel so light...");
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
public ItemConsumptionHandler getItemHandler() {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, getItem(), true)) {
p.sendMessage(ChatColor.YELLOW + "You feel so light...");
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
if (p.hasPotionEffect(PotionEffectType.LEVITATION)) p.removePotionEffect(PotionEffectType.LEVITATION);
p.addPotionEffect(PotionEffectType.LEVITATION.createEffect(60, 1));
return true;
}
return false;
if (p.hasPotionEffect(PotionEffectType.LEVITATION)) p.removePotionEffect(PotionEffectType.LEVITATION);
p.addPotionEffect(PotionEffectType.LEVITATION.createEffect(60, 1));
return true;
}
});
super.register(slimefun);
return false;
};
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionModule.Action;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@ -49,7 +49,8 @@ public class ExplosivePickaxe extends SlimefunItem implements NotPlaceable, Dama
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
Block b = e.getBlock().getRelative(x, y, z);
if (b.getType() != Material.AIR && !b.isLiquid() && !StringUtils.equals(b.getType().toString(), blacklist) && CSCoreLib.getLib().getProtectionManager().canBuild(e.getPlayer().getUniqueId(), b)) {
if (b.getType() != Material.AIR && !b.isLiquid() && !StringUtils.equals(b.getType().toString(), blacklist) && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Action.BREAK_BLOCK)) {
if (SlimefunPlugin.getHooks().isCoreProtectInstalled()) {
SlimefunPlugin.getHooks().getCoreProtectAPI().logRemoval(e.getPlayer().getName(), b.getLocation(), b.getType(), b.getBlockData());
}
@ -94,8 +95,8 @@ public class ExplosivePickaxe extends SlimefunItem implements NotPlaceable, Dama
super.register(slimefun);
damageOnUse = ((Boolean) Slimefun.getItemValue(getID(), "damage-on-use"));
Object value = Slimefun.getItemValue(getID(), "unbreakable-blocks");
blacklist = ((List<?>) value).stream().toArray(String[]::new);
List<?> list = (List<?>) Slimefun.getItemValue(getID(), "unbreakable-blocks");
blacklist = list.toArray(new String[list.size()]);
}
@Override

View File

@ -10,7 +10,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialTools;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionModule.Action;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
@ -39,31 +39,32 @@ public class ExplosiveShovel extends SlimefunItem implements NotPlaceable, Damag
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.EXPLOSIVE_SHOVEL, true)) {
e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), 0.0F);
e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
Block b = e.getBlock().getRelative(x, y, z);
boolean correctType = false;
for (Material mat : MaterialTools.getShovelItems()) {
if (b.getType() == mat) {
correctType = true;
break;
}
}
if (correctType) {
if (CSCoreLib.getLib().getProtectionManager().canBuild(e.getPlayer().getUniqueId(), b)) {
if (SlimefunPlugin.getHooks().isCoreProtectInstalled()) {
SlimefunPlugin.getHooks().getCoreProtectAPI().logRemoval(e.getPlayer().getName(), b.getLocation(), b.getType(), b.getBlockData());
}
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
for (ItemStack drop: b.getDrops()) {
b.getWorld().dropItemNaturally(b.getLocation(), drop);
}
b.setType(Material.AIR);
damageItem(e.getPlayer(), item);
if (correctType && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), Action.BREAK_BLOCK)) {
if (SlimefunPlugin.getHooks().isCoreProtectInstalled()) {
SlimefunPlugin.getHooks().getCoreProtectAPI().logRemoval(e.getPlayer().getName(), b.getLocation(), b.getType(), b.getBlockData());
}
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
for (ItemStack drop: b.getDrops()) {
b.getWorld().dropItemNaturally(b.getLocation(), drop);
}
b.setType(Material.AIR);
damageItem(e.getPlayer(), item);
}
}
}

View File

@ -21,14 +21,14 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.utils.Utilities;
public class GrapplingHook extends SimpleSlimefunItem {
public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
public GrapplingHook(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
@Override
public ItemInteractionHandler onRightClick() {
public ItemInteractionHandler getItemHandler() {
Utilities utilities = SlimefunPlugin.getUtilities();
return (e, p, item) -> {

View File

@ -0,0 +1,36 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items;
import org.bukkit.Sound;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerInventory;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public class MagicSugar extends SimpleSlimefunItem<ItemInteractionHandler> {
public MagicSugar(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(category, item, id, recipeType, recipe, keys, values);
}
@Override
public ItemInteractionHandler getItemHandler() {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MAGIC_SUGAR, true)) {
PlayerInventory.consumeItemInHand(p);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, (Integer) Slimefun.getItemValue("MAGIC_SUGAR", "effects.SPEED")));
return true;
}
else return false;
};
}
}

View File

@ -0,0 +1,39 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
public class MonsterJerky extends SimpleSlimefunItem<ItemConsumptionHandler> {
public MonsterJerky(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
@Override
public ItemConsumptionHandler getItemHandler() {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, getItem(), true)) {
SlimefunPlugin.instance.getServer().getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
if (p.hasPotionEffect(PotionEffectType.HUNGER)) {
p.removePotionEffect(PotionEffectType.HUNGER);
}
p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 5, 0));
}, 1L);
return true;
}
else {
return false;
}
};
}
}

View File

@ -16,14 +16,14 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
public class PickaxeOfTheSeeker extends SimpleSlimefunItem {
public class PickaxeOfTheSeeker extends SimpleSlimefunItem<ItemInteractionHandler> {
public PickaxeOfTheSeeker(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
@Override
public ItemInteractionHandler onRightClick() {
public ItemInteractionHandler getItemHandler() {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_THE_SEEKER, true)) {
Block closest = null;

View File

@ -26,14 +26,14 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.utils.DamageableItem;
public class SeismicAxe extends SimpleSlimefunItem implements NotPlaceable, DamageableItem {
public class SeismicAxe extends SimpleSlimefunItem<ItemInteractionHandler> implements NotPlaceable, DamageableItem {
public SeismicAxe(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
}
@Override
public ItemInteractionHandler onRightClick() {
public ItemInteractionHandler getItemHandler() {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.SEISMIC_AXE, true)) {
List<Block> blocks = p.getLineOfSight(null, 10);
@ -48,9 +48,12 @@ public class SeismicAxe extends SimpleSlimefunItem implements NotPlaceable, Dama
}
}
}
b.getWorld().playEffect(ground, Effect.STEP_SOUND, ground.getBlock().getType());
if (ground.getBlock().getRelative(BlockFace.UP).getType() == null || ground.getBlock().getRelative(BlockFace.UP).getType() == Material.AIR) {
FallingBlock block = ground.getWorld().spawnFallingBlock(ground.getBlock().getRelative(BlockFace.UP).getLocation(), ground.getBlock().getBlockData());
Location loc = ground.getBlock().getRelative(BlockFace.UP).getLocation().add(0.5, 0.0, 0.5);
FallingBlock block = ground.getWorld().spawnFallingBlock(loc, ground.getBlock().getBlockData());
block.setDropItem(false);
block.setVelocity(new Vector(0, 0.4 + i * 0.01, 0));
SlimefunPlugin.getUtilities().blocks.add(block.getUniqueId());

View File

@ -8,24 +8,22 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionModule;
import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.Messages;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
public class StormStaff extends SlimefunItem {
public class StormStaff extends SimpleSlimefunItem<ItemInteractionHandler> {
private final static int MAX_USES = 8;
@ -46,84 +44,79 @@ public class StormStaff extends SlimefunItem {
}
@Override
public void register(boolean slimefun) {
addItemHandler(new ItemInteractionHandler() {
public ItemInteractionHandler getItemHandler() {
return (e, p, item) -> {
//Not checking if lores equals because we need a special one for that.
if (SlimefunManager.isItemSimiliar(item, getItem(), false)) {
@Override
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
//Not checking if lores equals because we need a special one for that.
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.STAFF_STORM, false)) {
if (!item.hasItemMeta()) return false;
ItemMeta itemM = item.getItemMeta();
if (!itemM.hasLore()) return false;
List<String> itemML = itemM.getLore();
if (!item.hasItemMeta()) return false;
ItemMeta itemM = item.getItemMeta();
if (!itemM.hasLore()) return false;
List<String> itemML = itemM.getLore();
ItemStack SFitem = getItem();
ItemMeta SFitemM = SFitem.getItemMeta();
List<String> SFitemML = SFitemM.getLore();
if (itemML.size() < 6) {
// Index 1 and 3 in SlimefunItems.STAFF_STORM has lores with words and stuff so we check for them.
if (itemML.get(1).equals(SFitemML.get(1)) && itemML.get(3).equals(SFitemML.get(3))) {
if (p.getFoodLevel() >= 4 || p.getGameMode() == GameMode.CREATIVE) {
// Get a target block with max. 30 blocks of distance
Location loc = p.getTargetBlock(null, 30).getLocation();
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
if (loc.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, loc, ProtectionModule.Action.PVP)) {
loc.getWorld().strikeLightning(loc);
ItemStack SFitem = SlimefunItems.STAFF_STORM;
ItemMeta SFitemM = SFitem.getItemMeta();
List<String> SFitemML = SFitemM.getLore();
if (itemML.size() < 6) {
// Index 1 and 3 in SlimefunItems.STAFF_STORM has lores with words and stuff so we check for them.
if (itemML.get(1).equals(SFitemML.get(1)) && itemML.get(3).equals(SFitemML.get(3))) {
if (p.getFoodLevel() >= 4 || p.getGameMode() == GameMode.CREATIVE) {
// Get a target block with max. 30 blocks of distance
Location loc = p.getTargetBlock(null, 30).getLocation();
if (loc.getWorld() != null && loc.getChunk().isLoaded()) {
if (loc.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, loc, ProtectionModule.Action.PVP)) {
loc.getWorld().strikeLightning(loc);
if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) {
FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 4);
Bukkit.getPluginManager().callEvent(event);
p.setFoodLevel(event.getFoodLevel());
}
for (int i = MAX_USES; i > 0; i--) {
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemML.get(4))) {
e.setCancelled(true);
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
item.setAmount(0);
return true;
}
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemML.get(4))) {
itemML.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + " " + (i > 2 ? "Uses": "Use") + " &7left"));
e.setCancelled(true);
// Saving the changes to lore and item.
itemM.setLore(itemML);
item.setItemMeta(itemM);
if (e.getParentEvent().getHand() == EquipmentSlot.HAND) {
p.getInventory().setItemInMainHand(item);
}
else {
p.getInventory().setItemInOffHand(item);
}
return true;
}
}
return false;
}
else {
Messages.local.sendTranslation(p, "messages.no-pvp", true);
if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) {
FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 4);
Bukkit.getPluginManager().callEvent(event);
p.setFoodLevel(event.getFoodLevel());
}
for (int i = MAX_USES; i > 0; i--) {
if (i == 1 && ChatColor.translateAlternateColorCodes('&', "&e1 Use &7left").equals(itemML.get(4))) {
e.setCancelled(true);
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
item.setAmount(0);
return true;
}
else if (ChatColor.translateAlternateColorCodes('&', "&e" + i + " Uses &7left").equals(itemML.get(4))) {
itemML.set(4, ChatColor.translateAlternateColorCodes('&', "&e" + (i - 1) + " " + (i > 2 ? "Uses": "Use") + " &7left"));
e.setCancelled(true);
// Saving the changes to lore and item.
itemM.setLore(itemML);
item.setItemMeta(itemM);
if (e.getParentEvent().getHand() == EquipmentSlot.HAND) {
p.getInventory().setItemInMainHand(item);
}
else {
p.getInventory().setItemInOffHand(item);
}
return true;
}
}
return false;
}
else {
Messages.local.sendTranslation(p, "messages.no-pvp", true);
}
}
else {
Messages.local.sendTranslation(p, "messages.hungry", true);
}
return true;
}
else {
Messages.local.sendTranslation(p, "messages.hungry", true);
}
return true;
}
}
return false;
}
});
super.register(slimefun);
return false;
};
}
}

View File

@ -72,7 +72,7 @@ public class BlockPlacer extends SlimefunItem {
super.register(slimefun);
Object value = Slimefun.getItemValue(getID(), "unplaceable-blocks");
blacklist = ((List<?>) value).stream().toArray(String[]::new);
List<?> list = (List<?>) Slimefun.getItemValue(getID(), "unplaceable-blocks");
blacklist = list.toArray(new String[list.size()]);
}
}

View File

@ -34,7 +34,6 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -102,6 +101,8 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.DietCookie;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.ExplosivePickaxe;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.ExplosiveShovel;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.GrapplingHook;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.MagicSugar;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.MonsterJerky;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.PickaxeOfTheSeeker;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.SeismicAxe;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items.StormStaff;
@ -155,7 +156,6 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockPlaceHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemConsumptionHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.MultiBlockInteractionHandler;
import me.mrCookieSlime.Slimefun.Objects.tasks.RainbowTicker;
@ -315,43 +315,13 @@ public final class SlimefunSetup {
}
});
new SlimefunItem(Categories.FOOD, SlimefunItems.MAGIC_SUGAR, "MAGIC_SUGAR", RecipeType.ENHANCED_CRAFTING_TABLE,
new MagicSugar(Categories.FOOD, SlimefunItems.MAGIC_SUGAR, "MAGIC_SUGAR", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {new ItemStack(Material.SUGAR), new ItemStack(Material.REDSTONE), new ItemStack(Material.GLOWSTONE_DUST), null, null, null, null, null, null}, new String[] {"effects.SPEED"}, new Integer[] {4})
.register(true, new ItemInteractionHandler() {
.register(true);
@Override
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MAGIC_SUGAR, true)) {
PlayerInventory.consumeItemInHand(p);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, (Integer) Slimefun.getItemValue("MAGIC_SUGAR", "effects.SPEED")));
return true;
}
else return false;
}
});
new SlimefunItem(Categories.FOOD, SlimefunItems.MONSTER_JERKY, "MONSTER_JERKY", RecipeType.ENHANCED_CRAFTING_TABLE,
new MonsterJerky(Categories.FOOD, SlimefunItems.MONSTER_JERKY, "MONSTER_JERKY", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.SALT, new ItemStack(Material.ROTTEN_FLESH), null, null, null, null, null, null, null})
.register(true, new ItemConsumptionHandler() {
@Override
public boolean onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MONSTER_JERKY, true)) {
SlimefunPlugin.instance.getServer().getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
if (p.hasPotionEffect(PotionEffectType.HUNGER)) {
p.removePotionEffect(PotionEffectType.HUNGER);
}
p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 5, 0));
}, 1L);
return true;
}
else {
return false;
}
}
});
.register(true);
new SlimefunItem(Categories.MAGIC_ARMOR, SlimefunItems.SLIME_HELMET, "SLIME_HELMET", RecipeType.ARMOR_FORGE,
new ItemStack[] {new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.IRON_INGOT), null, new ItemStack(Material.IRON_INGOT), null, null, null})

View File

@ -1,5 +1,6 @@
package me.mrCookieSlime.Slimefun.utils;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -12,7 +13,10 @@ public interface DamageableItem {
boolean isDamageable();
default void damageItem(Player p, ItemStack item) {
if (item != null && item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + 40 / (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
if (item == null || item.getType() == null || item.getType() == Material.AIR) {
return;
}
else if (item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + 40 / (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
ItemMeta meta = item.getItemMeta();
Damageable damageable = (Damageable) meta;