mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Improved code
This commit is contained in:
parent
68dc6d560d
commit
37bb6005e8
@ -1,11 +1,14 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -14,6 +17,7 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
|||||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||||
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.cscorelib2.item.CustomItem;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.events.AutoEnchantEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
@ -24,8 +28,7 @@ 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.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link AutoEnchanter}, in contrast to the {@link AutoDisenchanter}, adds
|
* The {@link AutoEnchanter}, in contrast to the {@link AutoDisenchanter}, adds
|
||||||
@ -70,6 +73,13 @@ public class AutoEnchanter extends AContainer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AutoEnchantEvent event = new AutoEnchantEvent(target);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack item = menu.getItemInSlot(slot);
|
ItemStack item = menu.getItemInSlot(slot);
|
||||||
|
|
||||||
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
|
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
|
||||||
@ -120,21 +130,26 @@ public class AutoEnchanter extends AContainer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEnchantable(ItemStack item) {
|
private boolean isEnchantable(@Nullable ItemStack item) {
|
||||||
SlimefunItem sfItem = null;
|
if (item == null) {
|
||||||
if (item != null && item.hasItemMeta() && item.getItemMeta().hasLore()) {
|
return false;
|
||||||
|
} else {
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta != null && itemMeta.hasLore()) {
|
||||||
for (String lore : cantEnchantLores.getValue()) {
|
for (String lore : cantEnchantLores.getValue()) {
|
||||||
if (item.getItemMeta().getLore().contains(ChatColors.color(lore))) {
|
if (itemMeta.getLore().contains(ChatColors.color(lore))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stops endless checks of getByItem for enchanted book stacks.
|
|
||||||
if (item != null && item.getType() != Material.ENCHANTED_BOOK) {
|
|
||||||
sfItem = SlimefunItem.getByItem(item);
|
|
||||||
}
|
}
|
||||||
|
// stops endless checks of getByItem for enchanted book stacks.
|
||||||
|
if (item.getType() != Material.ENCHANTED_BOOK) {
|
||||||
|
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||||
return sfItem == null || sfItem.isEnchantable();
|
return sfItem == null || sfItem.isEnchantable();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user