Search in sources :

Example 6 with Pair

use of com.github.jikoo.planarwrappers.tuple.Pair in project Easterlyn by Easterlyn.

the class Dublexor method unCaptcha.

private Pair<ItemStack, Integer> unCaptcha(ItemStack potentialCaptcha) {
    try {
        Class.forName("com.easterlyn.EasterlynCaptchas");
    } catch (ClassNotFoundException e) {
        return new Pair<>(potentialCaptcha, 1);
    }
    RegisteredServiceProvider<EasterlynCaptchas> registration = getMachines().getServer().getServicesManager().getRegistration(EasterlynCaptchas.class);
    if (registration == null) {
        return new Pair<>(potentialCaptcha, 1);
    }
    int multiplier = 1;
    while (EasterlynCaptchas.isUsedCaptcha(potentialCaptcha)) {
        ItemStack newModInput = registration.getProvider().getItemByCaptcha(potentialCaptcha);
        if (newModInput == null || potentialCaptcha.isSimilar(newModInput)) {
            // Broken captcha, don't infinitely loop.
            potentialCaptcha = barrier;
            break;
        }
        multiplier = Math.multiplyExact(multiplier, Math.max(1, Math.abs(potentialCaptcha.getAmount())));
        potentialCaptcha = newModInput;
    }
    return new Pair<>(potentialCaptcha, multiplier);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) EasterlynCaptchas(com.easterlyn.EasterlynCaptchas) Pair(com.github.jikoo.planarwrappers.tuple.Pair)

Aggregations

Pair (com.github.jikoo.planarwrappers.tuple.Pair)6 Nullable (org.jetbrains.annotations.Nullable)4 Machine (com.easterlyn.machine.Machine)3 Block (org.bukkit.block.Block)3 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ItemStack (org.bukkit.inventory.ItemStack)2 NotNull (org.jetbrains.annotations.NotNull)2 EasterlynCaptchas (com.easterlyn.EasterlynCaptchas)1 Effect (com.easterlyn.effect.Effect)1 ReportableEvent (com.easterlyn.event.ReportableEvent)1 BlockUtil (com.easterlyn.util.BlockUtil)1 ItemUtil (com.easterlyn.util.inventory.ItemUtil)1 BlockMap (com.github.jikoo.planarwrappers.collections.BlockMap)1 BlockMultimap (com.github.jikoo.planarwrappers.collections.BlockMultimap)1 Event (com.github.jikoo.planarwrappers.event.Event)1 Coords (com.github.jikoo.planarwrappers.util.Coords)1 Direction (com.github.jikoo.planarwrappers.world.Direction)1 CreeperConfig (com.nitnelave.CreeperHeal.config.CreeperConfig)1