Enable backwards compatibility.

Adds protection for bee breeding too.
This commit is contained in:
tastybento 2020-06-30 15:50:12 -07:00
parent 2773c4a104
commit bf36ec5dd8

View File

@ -2,9 +2,10 @@ package world.bentobox.bentobox.listeners.flags.protection;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import org.bukkit.Material;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EntityType;
@ -15,6 +16,8 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Enums;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
@ -31,30 +34,41 @@ public class BreedingListener extends FlagListener {
* This list may need to be extended with future versions of Minecraft.
* See this Minecraft Wiki page for reference: https://minecraft.gamepedia.com/Breeding#Breeding_foods.
*/
private static final ImmutableMap<EntityType, List<Material>> BREEDING_ITEMS = new ImmutableMap.Builder<EntityType, List<Material>>()
.put(EntityType.HORSE, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT))
.put(EntityType.DONKEY, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT))
.put(EntityType.COW, Collections.singletonList(Material.WHEAT))
.put(EntityType.MUSHROOM_COW, Collections.singletonList(Material.WHEAT))
.put(EntityType.SHEEP, Collections.singletonList(Material.WHEAT))
.put(EntityType.PIG, Arrays.asList(Material.CARROT, Material.POTATO, Material.BEETROOT))
.put(EntityType.CHICKEN, Arrays.asList(Material.WHEAT_SEEDS, Material.PUMPKIN_SEEDS, Material.MELON_SEEDS, Material.BEETROOT_SEEDS))
.put(EntityType.WOLF, Arrays.asList(Material.PORKCHOP, Material.COOKED_PORKCHOP, Material.BEEF, Material.COOKED_BEEF,
Material.CHICKEN, Material.COOKED_CHICKEN, Material.RABBIT, Material.COOKED_RABBIT,
Material.MUTTON, Material.COOKED_MUTTON, Material.ROTTEN_FLESH))
.put(EntityType.CAT, Arrays.asList(Material.COD, Material.SALMON))
.put(EntityType.OCELOT, Arrays.asList(Material.COD, Material.SALMON))
.put(EntityType.RABBIT, Arrays.asList(Material.DANDELION, Material.CARROT, Material.GOLDEN_CARROT))
.put(EntityType.LLAMA, Collections.singletonList(Material.HAY_BLOCK))
.put(EntityType.TRADER_LLAMA, Collections.singletonList(Material.HAY_BLOCK))
.put(EntityType.TURTLE, Collections.singletonList(Material.SEAGRASS))
.put(EntityType.PANDA, Collections.singletonList(Material.BAMBOO))
.put(EntityType.FOX, Collections.singletonList(Material.SWEET_BERRIES))
.put(EntityType.HOGLIN, Collections.singletonList(Material.CRIMSON_FUNGUS)) // 1.16.1
.put(EntityType.STRIDER, Collections.singletonList(Material.WARPED_FUNGUS)) // 1.16.1
.build();
private static final Map<EntityType, List<Material>> BREEDING_ITEMS;
static {
Map<EntityType, List<Material>> bi = new HashMap<>();
bi.put(EntityType.HORSE, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
bi.put(EntityType.DONKEY, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
bi.put(EntityType.COW, Collections.singletonList(Material.WHEAT));
bi.put(EntityType.MUSHROOM_COW, Collections.singletonList(Material.WHEAT));
bi.put(EntityType.SHEEP, Collections.singletonList(Material.WHEAT));
bi.put(EntityType.PIG, Arrays.asList(Material.CARROT, Material.POTATO, Material.BEETROOT));
bi.put(EntityType.CHICKEN, Arrays.asList(Material.WHEAT_SEEDS, Material.PUMPKIN_SEEDS, Material.MELON_SEEDS, Material.BEETROOT_SEEDS));
bi.put(EntityType.WOLF, Arrays.asList(Material.PORKCHOP, Material.COOKED_PORKCHOP, Material.BEEF, Material.COOKED_BEEF,
Material.CHICKEN, Material.COOKED_CHICKEN, Material.RABBIT, Material.COOKED_RABBIT,
Material.MUTTON, Material.COOKED_MUTTON, Material.ROTTEN_FLESH));
bi.put(EntityType.CAT, Arrays.asList(Material.COD, Material.SALMON));
bi.put(EntityType.OCELOT, Arrays.asList(Material.COD, Material.SALMON));
bi.put(EntityType.RABBIT, Arrays.asList(Material.DANDELION, Material.CARROT, Material.GOLDEN_CARROT));
bi.put(EntityType.LLAMA, Collections.singletonList(Material.HAY_BLOCK));
bi.put(EntityType.TRADER_LLAMA, Collections.singletonList(Material.HAY_BLOCK));
bi.put(EntityType.TURTLE, Collections.singletonList(Material.SEAGRASS));
bi.put(EntityType.PANDA, Collections.singletonList(Material.BAMBOO));
bi.put(EntityType.FOX, Collections.singletonList(Material.SWEET_BERRIES));
if (Enums.getIfPresent(EntityType.class, "BEES").isPresent()) { // 1.15.2
bi.put(EntityType.BEE, Arrays.asList(Material.SUNFLOWER, Material.ORANGE_TULIP, Material.PINK_TULIP,
Material.RED_TULIP, Material.WHITE_TULIP, Material.ALLIUM,
Material.AZURE_BLUET, Material.BLUE_ORCHID, Material.CORNFLOWER,
Material.DANDELION, Material.OXEYE_DAISY, Material.PEONY, Material.POPPY));
}
if (Enums.getIfPresent(EntityType.class, "HOGLIN").isPresent()) {
bi.put(EntityType.HOGLIN, Collections.singletonList(Material.CRIMSON_FUNGUS)); // 1.16.1
bi.put(EntityType.STRIDER, Collections.singletonList(Material.WARPED_FUNGUS)); // 1.16.1
}
BREEDING_ITEMS = Collections.unmodifiableMap(bi);
}
//TODO: add bees when switching to 1.15.x only
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {