Added provider API

This commit is contained in:
Auxilor
2021-08-04 20:14:52 +01:00
parent 2483a05d92
commit c1a75f320b
2 changed files with 19 additions and 20 deletions

View File

@@ -28,12 +28,6 @@ public class TalismansPlugin extends EcoPlugin {
@Getter
private static TalismansPlugin instance;
/**
* If bag from TalismansGUI plugin is used or not.
*/
@Getter
private static boolean bagLoaded;
/**
* Internal constructor called by bukkit on plugin load.
*/
@@ -44,14 +38,6 @@ public class TalismansPlugin extends EcoPlugin {
@Override
protected void handleEnable() {
if (this.getServer().getPluginManager().getPlugin("TalismansGUI") != null){
bagLoaded = this.getServer().getPluginManager().getPlugin("TalismansGUI").getDescription().getVersion().compareTo("1.3") >= 0;
}
else {
bagLoaded = false;
}
this.getLogger().info(Talismans.values().size() + " Talismans Loaded");
}

View File

@@ -7,8 +7,6 @@ import com.willfp.talismans.talismans.Talisman;
import com.willfp.talismans.talismans.TalismanLevel;
import com.willfp.talismans.talismans.Talismans;
import lombok.experimental.UtilityClass;
import me.often.talismansgui.Utils.BagUtils;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.block.BlockState;
import org.bukkit.block.ShulkerBox;
@@ -30,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
@UtilityClass
public class TalismanChecks {
@@ -38,6 +37,11 @@ public class TalismanChecks {
*/
public static final Map<UUID, Set<TalismanLevel>> CACHED_TALISMANS = Collections.synchronizedMap(new HashMap<>());
/**
* All providers.
*/
private static final Set<Function<Player, List<ItemStack>>> PROVIDERS = new HashSet<>();
/**
* If ender chests should be checked.
*/
@@ -172,6 +176,10 @@ public class TalismanChecks {
rawContents.addAll(Arrays.asList(extra));
for (Function<Player, List<ItemStack>> provider : PROVIDERS) {
rawContents.addAll(provider.apply(player));
}
for (ItemStack rawContent : rawContents) {
if (rawContent == null) {
continue;
@@ -226,10 +234,6 @@ public class TalismanChecks {
}
}
if (TalismansPlugin.isBagLoaded()){
found.addAll(BagUtils.getBag(player));
}
if (useCache) {
CACHED_TALISMANS.put(player.getUniqueId(), found);
PLUGIN.getScheduler().runLater(() -> CACHED_TALISMANS.remove(player.getUniqueId()), 40);
@@ -238,6 +242,15 @@ public class TalismanChecks {
return found;
}
/**
* Register ItemStack provider (inventory extension, eg talisman bag).
*
* @param provider The provider.
*/
public static void regsiterItemStackProvider(@NotNull final Function<Player, List<ItemStack>> provider) {
PROVIDERS.add(provider);
}
/**
* Get if a player has a specific talisman active.
*