mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Merge pull request #2643 from Slimefun/chore/has-unlocked
This commit is contained in:
commit
695ba7c742
@ -79,6 +79,7 @@ public abstract class Network {
|
||||
*
|
||||
* @param l
|
||||
* The {@link Location} to classify
|
||||
*
|
||||
* @return The assigned type of {@link NetworkComponent} for this {@link Location}
|
||||
*/
|
||||
@Nullable
|
||||
|
@ -19,7 +19,6 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* Represents a {@link Category} that cannot be opened until the parent category/categories
|
||||
@ -153,14 +152,12 @@ public class LockedCategory extends Category {
|
||||
* @return Whether the {@link Player} has fully completed all parent categories, otherwise false
|
||||
*/
|
||||
public boolean hasUnlocked(@Nonnull Player p, @Nonnull PlayerProfile profile) {
|
||||
Validate.notNull(p, "The player cannot be null!");
|
||||
Validate.notNull(profile, "The Profile cannot be null!");
|
||||
|
||||
for (Category category : parents) {
|
||||
for (SlimefunItem item : category.getItems()) {
|
||||
/*
|
||||
* Should probably be replaced with Slimefun.hasUnlocked(...)
|
||||
* However this will result in better performance because we don't
|
||||
* request the PlayerProfile everytime
|
||||
*/
|
||||
if (Slimefun.isEnabled(p, item, false) && Slimefun.hasPermission(p, item, false) && !profile.hasUnlocked(item.getResearch())) {
|
||||
if (!item.canUse(p, false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -114,10 +113,11 @@ public abstract class MultiBlockMachine extends SlimefunItem implements NotPlace
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected MultiBlockInteractionHandler getInteractionHandler() {
|
||||
return (p, mb, b) -> {
|
||||
if (mb.equals(getMultiBlock())) {
|
||||
if (!isDisabled() && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK) && Slimefun.hasUnlocked(p, this, true)) {
|
||||
if (canUse(p, true) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK)) {
|
||||
onInteract(p, b);
|
||||
}
|
||||
|
||||
|
@ -218,13 +218,13 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(CommandSender sender, String key, boolean addPrefix) {
|
||||
public void sendMessage(CommandSender recipient, String key, boolean addPrefix) {
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(ChatColors.color(prefix + getMessage((Player) sender, key)));
|
||||
if (recipient instanceof Player) {
|
||||
recipient.sendMessage(ChatColors.color(prefix + getMessage((Player) recipient, key)));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key))));
|
||||
recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,65 +237,65 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(CommandSender sender, String key) {
|
||||
sendMessage(sender, key, true);
|
||||
public void sendMessage(CommandSender recipient, String key) {
|
||||
sendMessage(recipient, key, true);
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender sender, String key, UnaryOperator<String> function) {
|
||||
sendMessage(sender, key, true, function);
|
||||
public void sendMessage(CommandSender recipient, String key, UnaryOperator<String> function) {
|
||||
sendMessage(recipient, key, true, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) {
|
||||
public void sendMessage(CommandSender recipient, String key, boolean addPrefix, UnaryOperator<String> function) {
|
||||
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) sender, key))));
|
||||
if (recipient instanceof Player) {
|
||||
recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) recipient, key))));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key)))));
|
||||
recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key)))));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessages(CommandSender sender, String key) {
|
||||
public void sendMessages(CommandSender recipient, String key) {
|
||||
String prefix = getPrefix();
|
||||
|
||||
if (sender instanceof Player) {
|
||||
for (String translation : getMessages((Player) sender, key)) {
|
||||
if (recipient instanceof Player) {
|
||||
for (String translation : getMessages((Player) recipient, key)) {
|
||||
String message = ChatColors.color(prefix + translation);
|
||||
sender.sendMessage(message);
|
||||
recipient.sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
for (String translation : getMessages(key)) {
|
||||
String message = ChatColors.color(prefix + translation);
|
||||
sender.sendMessage(ChatColor.stripColor(message));
|
||||
recipient.sendMessage(ChatColor.stripColor(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessages(CommandSender sender, String key, boolean addPrefix, UnaryOperator<String> function) {
|
||||
public void sendMessages(CommandSender recipient, String key, boolean addPrefix, UnaryOperator<String> function) {
|
||||
String prefix = addPrefix ? getPrefix() : "";
|
||||
|
||||
if (sender instanceof Player) {
|
||||
for (String translation : getMessages((Player) sender, key)) {
|
||||
if (recipient instanceof Player) {
|
||||
for (String translation : getMessages((Player) recipient, key)) {
|
||||
String message = ChatColors.color(prefix + function.apply(translation));
|
||||
sender.sendMessage(message);
|
||||
recipient.sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
for (String translation : getMessages(key)) {
|
||||
String message = ChatColors.color(prefix + function.apply(translation));
|
||||
sender.sendMessage(ChatColor.stripColor(message));
|
||||
recipient.sendMessage(ChatColor.stripColor(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessages(CommandSender sender, String key, UnaryOperator<String> function) {
|
||||
sendMessages(sender, key, true, function);
|
||||
public void sendMessages(CommandSender recipient, String key, UnaryOperator<String> function) {
|
||||
sendMessages(recipient, key, true, function);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
|
||||
}
|
||||
|
||||
String lore = Slimefun.hasPermission(p, slimefunItem, false) ? "&fNeeds to be unlocked elsewhere" : "&fNo Permission";
|
||||
return Slimefun.hasUnlocked(p, slimefunItem, false) ? item : new CustomItem(Material.BARRIER, ItemUtils.getItemName(item), "&4&l" + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", lore);
|
||||
return slimefunItem.canUse(p, false) ? item : new CustomItem(Material.BARRIER, ItemUtils.getItemName(item), "&4&l" + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", lore);
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunIte
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -66,7 +65,7 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
public ItemDropHandler getItemHandler() {
|
||||
return (e, p, item) -> {
|
||||
if (isItem(item.getItemStack())) {
|
||||
if (Slimefun.hasUnlocked(p, this, true)) {
|
||||
if (canUse(p, true)) {
|
||||
SlimefunPlugin.runSync(() -> {
|
||||
try {
|
||||
addRandomEnchantment(p, item);
|
||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.magical.runes;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -19,7 +21,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -47,7 +48,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
return (e, p, item) -> {
|
||||
if (isItem(item.getItemStack())) {
|
||||
|
||||
if (!Slimefun.hasUnlocked(p, this, true)) {
|
||||
if (!canUse(p, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -59,7 +60,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
private void activate(Player p, Item rune) {
|
||||
private void activate(@Nonnull Player p, @Nonnull Item rune) {
|
||||
// Being sure the entity is still valid and not picked up or whatsoever.
|
||||
if (!rune.isValid()) {
|
||||
return;
|
||||
|
@ -33,7 +33,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class Talisman extends SlimefunItem {
|
||||
@ -167,7 +166,7 @@ public class Talisman extends SlimefunItem {
|
||||
ItemStack talismanItem = talisman.getItem();
|
||||
|
||||
if (SlimefunUtils.containsSimilarItem(p.getInventory(), talismanItem, true)) {
|
||||
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
||||
if (talisman.canUse(p, true)) {
|
||||
activateTalisman(e, p, p.getInventory(), talisman, talismanItem);
|
||||
return true;
|
||||
} else {
|
||||
@ -177,7 +176,7 @@ public class Talisman extends SlimefunItem {
|
||||
ItemStack enderTalisman = talisman.getEnderVariant();
|
||||
|
||||
if (SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalisman, true)) {
|
||||
if (Slimefun.hasUnlocked(p, talisman, true)) {
|
||||
if (talisman.canUse(p, true)) {
|
||||
activateTalisman(e, p, p.getEnderChest(), talisman, enderTalisman);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -19,7 +19,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -48,7 +47,7 @@ abstract class AbstractSmeltery extends MultiBlockMachine {
|
||||
if (canCraft(inv, inputs, i)) {
|
||||
ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, output, true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
|
||||
Inventory outputInv = findOutputInventory(output, dispBlock, inv);
|
||||
|
||||
if (outputInv != null) {
|
||||
|
@ -21,7 +21,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class ArmorForge extends AbstractCraftingTable {
|
||||
@ -44,7 +43,7 @@ public class ArmorForge extends AbstractCraftingTable {
|
||||
if (isCraftable(inv, inputs.get(i))) {
|
||||
ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, output, true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
|
||||
craft(p, output, inv, dispenser);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class EnhancedCraftingTable extends AbstractCraftingTable {
|
||||
@ -43,7 +42,7 @@ public class EnhancedCraftingTable extends AbstractCraftingTable {
|
||||
if (isCraftable(inv, inputs.get(i))) {
|
||||
ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, output, true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
|
||||
craft(inv, dispenser, p, b, output);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class MagicWorkbench extends AbstractCraftingTable {
|
||||
@ -50,7 +49,7 @@ public class MagicWorkbench extends AbstractCraftingTable {
|
||||
if (isCraftable(inv, inputs.get(i))) {
|
||||
ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, output, true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
|
||||
craft(inv, dispenser, p, b, output);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import io.papermc.lib.PaperLib;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
@ -135,7 +134,7 @@ public class OreCrusher extends MultiBlockMachine {
|
||||
ItemStack adding = RecipeType.getRecipeOutput(this, convert);
|
||||
Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
|
||||
|
||||
if (Slimefun.hasUnlocked(p, adding, true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, adding, true)) {
|
||||
if (outputInv != null) {
|
||||
ItemStack removing = current.clone();
|
||||
removing.setAmount(convert.getAmount());
|
||||
|
@ -41,7 +41,6 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for providing the core mechanics of the {@link AncientAltar}
|
||||
@ -105,12 +104,13 @@ public class AncientAltarListener implements Listener {
|
||||
}
|
||||
|
||||
String id = slimefunBlock.get().getId();
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (id.equals(pedestalItem.getId())) {
|
||||
e.cancel();
|
||||
usePedestal(b, e.getPlayer());
|
||||
usePedestal(b, p);
|
||||
} else if (id.equals(altarItem.getId())) {
|
||||
if (!Slimefun.hasUnlocked(e.getPlayer(), altarItem, true) || altarsInUse.contains(b.getLocation())) {
|
||||
if (!altarItem.canUse(p, true) || altarsInUse.contains(b.getLocation())) {
|
||||
e.cancel();
|
||||
return;
|
||||
}
|
||||
@ -119,7 +119,7 @@ public class AncientAltarListener implements Listener {
|
||||
altarsInUse.add(b.getLocation());
|
||||
e.cancel();
|
||||
|
||||
useAltar(b, e.getPlayer());
|
||||
useAltar(b, p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,8 +212,9 @@ public class AncientAltarListener implements Listener {
|
||||
}
|
||||
|
||||
Optional<ItemStack> result = getRecipeOutput(catalyst, input);
|
||||
|
||||
if (result.isPresent()) {
|
||||
if (Slimefun.hasUnlocked(p, result.get(), true)) {
|
||||
if (SlimefunUtils.canPlayerUseItem(p, result.get(), true)) {
|
||||
List<ItemStack> consumed = new ArrayList<>();
|
||||
consumed.add(catalyst);
|
||||
|
||||
|
@ -31,7 +31,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for all events centered around a {@link SlimefunBackpack}.
|
||||
@ -122,7 +121,7 @@ public class BackpackListener implements Listener {
|
||||
@ParametersAreNonnullByDefault
|
||||
public void openBackpack(Player p, ItemStack item, SlimefunBackpack backpack) {
|
||||
if (item.getAmount() == 1) {
|
||||
if (Slimefun.hasUnlocked(p, backpack, true) && !PlayerProfile.get(p, profile -> openBackpack(p, item, profile, backpack.getSize()))) {
|
||||
if (backpack.canUse(p, true) && !PlayerProfile.get(p, profile -> openBackpack(p, item, profile, backpack.getSize()))) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.opening-backpack");
|
||||
}
|
||||
} else {
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.BeeWings;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.BeeWingsTask;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for the slow falling effect given to the {@link Player}
|
||||
@ -44,7 +43,7 @@ public class BeeWingsListener implements Listener {
|
||||
Player player = (Player) e.getEntity();
|
||||
ItemStack chestplate = player.getInventory().getChestplate();
|
||||
|
||||
if (wings.isItem(chestplate) && Slimefun.hasUnlocked(player, chestplate, true)) {
|
||||
if (wings.isItem(chestplate) && wings.canUse(player, true)) {
|
||||
new BeeWingsTask(player).scheduleRepeating(3, 1);
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class BlockListener implements Listener {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null && !(sfItem instanceof NotPlaceable) && Slimefun.isEnabled(e.getPlayer(), sfItem, true)) {
|
||||
if (!Slimefun.hasUnlocked(e.getPlayer(), sfItem, true)) {
|
||||
if (!sfItem.canUse(e.getPlayer(), true)) {
|
||||
e.setCancelled(true);
|
||||
} else {
|
||||
if (SlimefunPlugin.getBlockDataService().isTileEntity(e.getBlock().getType())) {
|
||||
@ -139,7 +139,7 @@ public class BlockListener implements Listener {
|
||||
SlimefunItem tool = SlimefunItem.getByItem(item);
|
||||
|
||||
if (tool != null) {
|
||||
if (Slimefun.hasUnlocked(e.getPlayer(), tool, true)) {
|
||||
if (tool.canUse(e.getPlayer(), true)) {
|
||||
tool.callItemHandler(ToolUseHandler.class, handler -> handler.onToolUse(e, item, fortune, drops));
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
|
@ -21,7 +21,6 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} listens for a {@link FoodLevelChangeEvent} or an {@link EntityDamageEvent} for starvation
|
||||
@ -74,7 +73,7 @@ public class CoolerListener implements Listener {
|
||||
|
||||
for (ItemStack item : p.getInventory().getContents()) {
|
||||
if (cooler.isItem(item)) {
|
||||
if (Slimefun.hasUnlocked(p, cooler, true)) {
|
||||
if (cooler.canUse(p, true)) {
|
||||
takeJuiceFromCooler(p, item);
|
||||
} else {
|
||||
return;
|
||||
|
@ -18,7 +18,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.ElytraCap;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* The {@link Listener} for the {@link ElytraCap}.
|
||||
@ -57,7 +56,7 @@ public class ElytraImpactListener implements Listener {
|
||||
if (helmet.isPresent()) {
|
||||
SlimefunItem item = helmet.get();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, item, true) && profile.hasFullProtectionAgainst(ProtectionType.FLYING_INTO_WALL)) {
|
||||
if (item.canUse(p, true) && profile.hasFullProtectionAgainst(ProtectionType.FLYING_INTO_WALL)) {
|
||||
e.setDamage(0);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1);
|
||||
|
||||
|
@ -14,13 +14,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.Parachute;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedMagnet;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.InfusedMagnetTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetBootsTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetpackTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.InfusedMagnetTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for listening to the {@link PlayerToggleSneakEvent}
|
||||
@ -59,7 +58,7 @@ public class GadgetsListener implements Listener {
|
||||
if (SlimefunUtils.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
|
||||
InfusedMagnet magnet = (InfusedMagnet) SlimefunItems.INFUSED_MAGNET.getItem();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, magnet, true)) {
|
||||
if (magnet.canUse(p, true)) {
|
||||
new InfusedMagnetTask(p, magnet.getRadius()).scheduleRepeating(0, 8);
|
||||
}
|
||||
}
|
||||
@ -67,7 +66,7 @@ public class GadgetsListener implements Listener {
|
||||
}
|
||||
|
||||
private void handleChestplate(@Nonnull Player p, @Nullable SlimefunItem chestplate) {
|
||||
if (chestplate == null || !Slimefun.hasUnlocked(p, chestplate, true)) {
|
||||
if (chestplate == null || !chestplate.canUse(p, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ public class GadgetsListener implements Listener {
|
||||
}
|
||||
|
||||
private void handleBoots(@Nonnull Player p, @Nullable SlimefunItem boots) {
|
||||
if (boots instanceof JetBoots && Slimefun.hasUnlocked(p, boots, true)) {
|
||||
if (boots instanceof JetBoots && boots.canUse(p, true)) {
|
||||
double speed = ((JetBoots) boots).getSpeed();
|
||||
|
||||
if (speed > 0.2) {
|
||||
|
@ -23,7 +23,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.LongFallBoo
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.StomperBoots;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for handling all boots provided by
|
||||
@ -53,7 +52,7 @@ public class SlimefunBootsListener implements Listener {
|
||||
Player p = (Player) e.getEntity();
|
||||
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
|
||||
|
||||
if (boots instanceof EnderBoots && Slimefun.hasUnlocked(p, boots, true)) {
|
||||
if (boots instanceof EnderBoots && boots.canUse(p, true)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -65,7 +64,7 @@ public class SlimefunBootsListener implements Listener {
|
||||
|
||||
if (boots != null) {
|
||||
// Check if the boots were researched
|
||||
if (!Slimefun.hasUnlocked(p, boots, true)) {
|
||||
if (!boots.canUse(p, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ public class SlimefunBootsListener implements Listener {
|
||||
Player p = e.getPlayer();
|
||||
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
|
||||
|
||||
if (boots instanceof FarmerShoes && Slimefun.hasUnlocked(p, boots, true)) {
|
||||
if (boots instanceof FarmerShoes && boots.canUse(p, true)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for handling the {@link ItemConsumptionHandler}
|
||||
@ -33,7 +32,7 @@ public class SlimefunItemConsumeListener implements Listener {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null) {
|
||||
if (Slimefun.hasUnlocked(p, sfItem, true)) {
|
||||
if (sfItem.canUse(p, true)) {
|
||||
sfItem.callItemHandler(ItemConsumptionHandler.class, handler -> handler.onConsume(e, p, item));
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
|
@ -25,7 +25,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
|
||||
@ -94,8 +93,10 @@ public class SlimefunItemInteractListener implements Listener {
|
||||
Optional<SlimefunItem> optional = event.getSlimefunItem();
|
||||
|
||||
if (optional.isPresent()) {
|
||||
if (Slimefun.hasUnlocked(e.getPlayer(), optional.get(), true)) {
|
||||
return optional.get().callItemHandler(ItemUseHandler.class, handler -> handler.onRightClick(event));
|
||||
SlimefunItem sfItem = optional.get();
|
||||
|
||||
if (sfItem.canUse(e.getPlayer(), true)) {
|
||||
return sfItem.callItemHandler(ItemUseHandler.class, handler -> handler.onRightClick(event));
|
||||
} else {
|
||||
event.setUseItem(Result.DENY);
|
||||
}
|
||||
@ -109,12 +110,14 @@ public class SlimefunItemInteractListener implements Listener {
|
||||
Optional<SlimefunItem> optional = event.getSlimefunBlock();
|
||||
|
||||
if (optional.isPresent()) {
|
||||
if (!Slimefun.hasUnlocked(event.getPlayer(), optional.get(), true)) {
|
||||
SlimefunItem sfItem = optional.get();
|
||||
|
||||
if (!sfItem.canUse(event.getPlayer(), true)) {
|
||||
event.getInteractEvent().setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean interactable = optional.get().callItemHandler(BlockUseHandler.class, handler -> handler.onRightClick(event));
|
||||
boolean interactable = sfItem.callItemHandler(BlockUseHandler.class, handler -> handler.onRightClick(event));
|
||||
|
||||
if (!interactable) {
|
||||
String id = optional.get().getId();
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is exclusively used for the {@link VampireBlade}.
|
||||
@ -44,7 +43,7 @@ public class VampireBladeListener implements Listener {
|
||||
Player p = (Player) e.getDamager();
|
||||
|
||||
if (blade.isItem(p.getInventory().getItemInMainHand())) {
|
||||
if (Slimefun.hasUnlocked(p, blade, true)) {
|
||||
if (blade.canUse(p, true)) {
|
||||
blade.heal(p);
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
|
@ -14,7 +14,6 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* The {@link Listener} responsible for a {@link Player} interacting with an {@link Entity}.
|
||||
@ -48,7 +47,7 @@ public class EntityInteractionListener implements Listener {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(itemStack);
|
||||
|
||||
if (sfItem != null) {
|
||||
if (Slimefun.hasUnlocked(e.getPlayer(), sfItem, true)) {
|
||||
if (sfItem.canUse(e.getPlayer(), true)) {
|
||||
sfItem.callItemHandler(EntityInteractHandler.class, handler -> handler.onInteract(e, itemStack, e.getHand() == EquipmentSlot.OFF_HAND));
|
||||
} else if (sfItem.getState() != ItemState.VANILLA_FALLBACK) {
|
||||
/*
|
||||
|
@ -18,7 +18,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
/**
|
||||
* This {@link Listener} is responsible for handling any custom mob drops.
|
||||
@ -55,7 +54,7 @@ public class MobDropListener implements Listener {
|
||||
if (item.getType() != Material.AIR) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null && Slimefun.hasUnlocked(p, sfItem, true)) {
|
||||
if (sfItem != null && sfItem.canUse(p, true)) {
|
||||
sfItem.callItemHandler(EntityKillHandler.class, handler -> handler.onKill(e, e.getEntity(), p, item));
|
||||
}
|
||||
}
|
||||
@ -63,21 +62,21 @@ public class MobDropListener implements Listener {
|
||||
}
|
||||
|
||||
private boolean canDrop(@Nonnull Player p, @Nonnull ItemStack item) {
|
||||
SlimefunItem sfi = SlimefunItem.getByItem(item);
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfi == null) {
|
||||
if (sfItem == null) {
|
||||
return true;
|
||||
} else if (Slimefun.hasUnlocked(p, sfi, true)) {
|
||||
if (sfi instanceof RandomMobDrop) {
|
||||
} else if (sfItem.canUse(p, true)) {
|
||||
if (sfItem instanceof RandomMobDrop) {
|
||||
int random = ThreadLocalRandom.current().nextInt(100);
|
||||
|
||||
if (((RandomMobDrop) sfi).getMobDropChance() <= random) {
|
||||
if (((RandomMobDrop) sfItem).getMobDropChance() <= random) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sfi instanceof BasicCircuitBoard) {
|
||||
return ((BasicCircuitBoard) sfi).isDroppedFromGolems();
|
||||
if (sfItem instanceof BasicCircuitBoard) {
|
||||
return ((BasicCircuitBoard) sfItem).isDroppedFromGolems();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -117,7 +117,7 @@ public class ArmorTask implements Runnable {
|
||||
SlimefunPlugin.runSync(() -> {
|
||||
SlimefunArmorPiece slimefunArmor = armorpiece.getItem().get();
|
||||
|
||||
if (Slimefun.hasUnlocked(p, slimefunArmor, true)) {
|
||||
if (slimefunArmor.canUse(p, true)) {
|
||||
for (PotionEffect effect : slimefunArmor.getPotionEffects()) {
|
||||
p.removePotionEffect(effect.getType());
|
||||
p.addPotionEffect(effect);
|
||||
@ -138,7 +138,7 @@ public class ArmorTask implements Runnable {
|
||||
|
||||
SlimefunItem item = SlimefunItem.getByItem(helmet);
|
||||
|
||||
if (item instanceof SolarHelmet && Slimefun.hasUnlocked(p, item, true)) {
|
||||
if (item instanceof SolarHelmet && item.canUse(p, true)) {
|
||||
((SolarHelmet) item).rechargeItems(p);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -358,4 +359,31 @@ public final class SlimefunUtils {
|
||||
SlimefunPlugin.runSync(new CapacitorTextureUpdateTask(l, charge, capacity));
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks whether the {@link Player} is able to use the given {@link ItemStack}.
|
||||
* It will always return <code>true</code> for non-Slimefun items.
|
||||
* <p>
|
||||
* If you already have an instance of {@link SlimefunItem}, please use {@link SlimefunItem#canUse(Player, boolean)}.
|
||||
*
|
||||
* @param p
|
||||
* The {@link Player}
|
||||
* @param item
|
||||
* The {@link ItemStack} to check
|
||||
* @param sendMessage
|
||||
* Whether to send a message response to the {@link Player}
|
||||
*
|
||||
* @return Whether the {@link Player} is able to use that item.
|
||||
*/
|
||||
public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable ItemStack item, boolean sendMessage) {
|
||||
Validate.notNull(p, "The player cannot be null");
|
||||
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null) {
|
||||
return sfItem.canUse(p, sendMessage);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,11 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.collections.OptionalMap;
|
||||
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
||||
@ -32,6 +34,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemExcepti
|
||||
import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotConfigurable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
|
||||
@ -1012,6 +1015,90 @@ public class SlimefunItem implements Placeable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if the given {@link Player} is able to use this {@link SlimefunItem}.
|
||||
* A {@link Player} can use it if the following conditions apply:
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>The {@link SlimefunItem} is not disabled
|
||||
* <li>The {@link SlimefunItem} was not disabled for that {@link Player}'s {@link World}.
|
||||
* <li>The {@link Player} has the required {@link Permission} (if present)
|
||||
* <li>The {@link Player} has unlocked the required {@link Research} (if present)
|
||||
* </ul>
|
||||
* <p>
|
||||
*
|
||||
* If any of these conditions evaluate to <code>false</code>, then an optional message will be
|
||||
* sent to the {@link Player}.
|
||||
*
|
||||
* @param p
|
||||
* The {@link Player} to check
|
||||
* @param sendMessage
|
||||
* Whether to send that {@link Player} a message response.
|
||||
*
|
||||
* @return Whether this {@link Player} is able to use this {@link SlimefunItem}.
|
||||
*/
|
||||
public boolean canUse(@Nonnull Player p, boolean sendMessage) {
|
||||
Validate.notNull(p, "The Player cannot be null!");
|
||||
|
||||
if (getState() == ItemState.VANILLA_FALLBACK) {
|
||||
// Vanilla items (which fell back) can always be used.
|
||||
return true;
|
||||
} else if (isDisabled()) {
|
||||
// The Item has been disabled in the config
|
||||
if (sendMessage) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.disabled-item", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (!SlimefunPlugin.getWorldSettingsService().isEnabled(p.getWorld(), this)) {
|
||||
// The Item was disabled in the current World
|
||||
if (sendMessage) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.disabled-in-world", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (!SlimefunPlugin.getPermissionsService().hasPermission(p, this)) {
|
||||
// The Player does not have the required permission node
|
||||
if (sendMessage) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.no-permission", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (hasResearch()) {
|
||||
Optional<PlayerProfile> profile = PlayerProfile.find(p);
|
||||
|
||||
if (!profile.isPresent()) {
|
||||
/*
|
||||
* We will return false since we cannot know the answer yet.
|
||||
* But we will schedule the Profile for loading and not send
|
||||
* any message.
|
||||
*/
|
||||
PlayerProfile.request(p);
|
||||
return false;
|
||||
} else if (!profile.get().hasUnlocked(getResearch())) {
|
||||
/*
|
||||
* The Profile is loaded but Player has not unlocked the
|
||||
* required Research to use this SlimefunItem.
|
||||
*/
|
||||
if (sendMessage && !(this instanceof VanillaItem)) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.not-researched", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
/*
|
||||
* The PlayerProfile is loaded and the Player has unlocked
|
||||
* the required Research.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// All checks have passed, the Player can use this item.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
if (obj instanceof SlimefunItem) {
|
||||
|
@ -1,18 +1,15 @@
|
||||
package me.mrCookieSlime.Slimefun.api;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
* Provides a few static convenience methods.
|
||||
* This class is slowly getting stripped away in favour of a more object-oriented approach.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
* @author Walshy
|
||||
@ -31,19 +28,17 @@ public final class Slimefun {
|
||||
* the item to check, not null
|
||||
* @param message
|
||||
* whether a message should be sent to the player or not
|
||||
*
|
||||
* @deprecated Moved to
|
||||
* {@link SlimefunUtils#canPlayerUseItem(Player, ItemStack, boolean)}
|
||||
*
|
||||
* @return <code>true</code> if the item is a SlimefunItem, enabled, researched and if the player has the permission
|
||||
* to use it,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean hasUnlocked(Player p, ItemStack item, boolean message) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem != null) {
|
||||
return hasUnlocked(p, sfItem, message);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return SlimefunUtils.canPlayerUseItem(p, item, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,39 +50,15 @@ public final class Slimefun {
|
||||
* the item to check, not null
|
||||
* @param message
|
||||
* whether a message should be sent to the player or not
|
||||
*
|
||||
* @deprecated Please use {@link SlimefunItem#canUse(Player, boolean)} instead.
|
||||
*
|
||||
* @return <code>true</code> if the item is enabled, researched and the player has the permission to use it,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean hasUnlocked(Player p, SlimefunItem sfItem, boolean message) {
|
||||
if (sfItem.getState() == ItemState.VANILLA_FALLBACK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isEnabled(p, sfItem, message) && hasPermission(p, sfItem, message)) {
|
||||
if (sfItem.getResearch() == null) {
|
||||
return true;
|
||||
} else {
|
||||
Optional<PlayerProfile> profile = PlayerProfile.find(p);
|
||||
|
||||
if (!profile.isPresent()) {
|
||||
// We will return false since we cannot know the answer yet
|
||||
// But we will schedule the Profile for loading.
|
||||
PlayerProfile.request(p);
|
||||
return false;
|
||||
} else if (profile.get().hasUnlocked(sfItem.getResearch())) {
|
||||
return true;
|
||||
} else {
|
||||
if (message && !(sfItem instanceof VanillaItem)) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.not-researched", true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return sfItem.canUse(p, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,10 +97,13 @@ public final class Slimefun {
|
||||
* the item to check, not null
|
||||
* @param message
|
||||
* whether a message should be sent to the player or not
|
||||
*
|
||||
* @deprecated This method will be removed.
|
||||
*
|
||||
* @return <code>true</code> if the item is a SlimefunItem and is enabled in the world the player is in,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isEnabled(Player p, ItemStack item, boolean message) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user