Expanding McMMOItemSpawnEvent & Fixing a bug with Tree Feller drops

This commit is contained in:
nossr50
2020-11-02 13:51:43 -08:00
parent 9529bbf898
commit 65fba3e20e
18 changed files with 318 additions and 284 deletions

View File

@ -66,7 +66,7 @@ public final class BlockUtils {
* @return true if the block awards XP, false otherwise
*/
public static boolean shouldBeWatched(BlockState blockState) {
return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState)
return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || hasWoodcuttingXP(blockState)
|| Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.MINING, blockState.getType())
|| Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.EXCAVATION, blockState.getType())
|| Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, blockState.getType())
@ -165,10 +165,8 @@ public final class BlockUtils {
* @param blockState The {@link BlockState} of the block to check
* @return true if the block is a log, false otherwise
*/
public static boolean isLog(BlockState blockState) {
if (ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.WOODCUTTING, blockState.getBlockData()))
return true;
return mcMMO.getModManager().isCustomLog(blockState);
public static boolean hasWoodcuttingXP(BlockState blockState) {
return ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.WOODCUTTING, blockState.getBlockData());
}
/**
@ -177,8 +175,8 @@ public final class BlockUtils {
* @param blockState The {@link BlockState} of the block to check
* @return true if the block is a leaf, false otherwise
*/
public static boolean isLeaves(BlockState blockState) {
return mcMMO.getMaterialMapStore().isLeavesWhiteListed(blockState.getType());
public static boolean isNonWoodPartOfTree(BlockState blockState) {
return mcMMO.getMaterialMapStore().isTreeFellerDestructible(blockState.getType());
}
/**

View File

@ -46,6 +46,7 @@ import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@ -73,7 +74,7 @@ public final class EventUtils {
* @param event The {@link Event} in question
* @return Whether this {@link Event} has been faked by mcMMO and should not be processed normally.
*/
public static boolean isFakeEvent(Event event) {
public static boolean isFakeEvent(@NotNull Event event) {
return event instanceof FakeEvent;
}
@ -84,7 +85,7 @@ public final class EventUtils {
* @param event this event
* @return true if damage is NOT from an unnatural mcMMO skill (such as bleed DOTs)
*/
public static boolean isDamageFromMcMMOComplexBehaviour(Event event) {
public static boolean isDamageFromMcMMOComplexBehaviour(@NotNull Event event) {
return event instanceof FakeEntityDamageEvent;
}
@ -94,7 +95,7 @@ public final class EventUtils {
* @param entity target entity
* @return the associated McMMOPlayer for this entity
*/
public static McMMOPlayer getMcMMOPlayer(Entity entity)
public static McMMOPlayer getMcMMOPlayer(@NotNull Entity entity)
{
return UserManager.getPlayer((Player)entity);
}
@ -112,7 +113,7 @@ public final class EventUtils {
* @param entityDamageEvent
* @return
*/
public static boolean isRealPlayerDamaged(EntityDamageEvent entityDamageEvent)
public static boolean isRealPlayerDamaged(@NotNull EntityDamageEvent entityDamageEvent)
{
//Make sure the damage is above 0
double damage = entityDamageEvent.getFinalDamage();
@ -167,14 +168,14 @@ public final class EventUtils {
* Others
*/
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, PrimarySkillType skill) {
public static @NotNull McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(@NotNull Player player, @NotNull PrimarySkillType skill) {
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerProfileLoadEvent callPlayerProfileLoadEvent(Player player, PlayerProfile profile){
public static @NotNull McMMOPlayerProfileLoadEvent callPlayerProfileLoadEvent(@NotNull Player player, @NotNull PlayerProfile profile){
McMMOPlayerProfileLoadEvent event = new McMMOPlayerProfileLoadEvent(player, profile);
mcMMO.p.getServer().getPluginManager().callEvent(event);

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.util;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
@ -15,46 +16,46 @@ import java.util.Locale;
*/
public class MaterialMapStore {
private final HashSet<String> abilityBlackList;
private final HashSet<String> toolBlackList;
private final HashSet<String> mossyWhiteList;
private final HashSet<String> leavesWhiteList;
private final HashSet<String> herbalismAbilityBlackList;
private final HashSet<String> blockCrackerWhiteList;
private final HashSet<String> canMakeShroomyWhiteList;
private final HashSet<String> multiBlockPlant;
private final HashSet<String> foodItemWhiteList;
private final HashSet<String> glassBlocks;
private final @NotNull HashSet<String> abilityBlackList;
private final @NotNull HashSet<String> toolBlackList;
private final @NotNull HashSet<String> mossyWhiteList;
private final @NotNull HashSet<String> treeFellerDestructibleWhiteList;
private final @NotNull HashSet<String> herbalismAbilityBlackList;
private final @NotNull HashSet<String> blockCrackerWhiteList;
private final @NotNull HashSet<String> canMakeShroomyWhiteList;
private final @NotNull HashSet<String> multiBlockPlant;
private final @NotNull HashSet<String> foodItemWhiteList;
private final @NotNull HashSet<String> glassBlocks;
private final HashSet<String> netheriteArmor;
private final HashSet<String> netheriteTools;
private final HashSet<String> woodTools;
private final HashSet<String> stoneTools;
private final HashSet<String> leatherArmor;
private final HashSet<String> ironArmor;
private final HashSet<String> ironTools;
private final HashSet<String> stringTools;
private final HashSet<String> goldArmor;
private final HashSet<String> goldTools;
private final HashSet<String> chainmailArmor;
private final HashSet<String> diamondArmor;
private final HashSet<String> diamondTools;
private final HashSet<String> armors;
private final @NotNull HashSet<String> netheriteArmor;
private final @NotNull HashSet<String> netheriteTools;
private final @NotNull HashSet<String> woodTools;
private final @NotNull HashSet<String> stoneTools;
private final @NotNull HashSet<String> leatherArmor;
private final @NotNull HashSet<String> ironArmor;
private final @NotNull HashSet<String> ironTools;
private final @NotNull HashSet<String> stringTools;
private final @NotNull HashSet<String> goldArmor;
private final @NotNull HashSet<String> goldTools;
private final @NotNull HashSet<String> chainmailArmor;
private final @NotNull HashSet<String> diamondArmor;
private final @NotNull HashSet<String> diamondTools;
private final @NotNull HashSet<String> armors;
private final HashSet<String> swords;
private final HashSet<String> axes;
private final HashSet<String> hoes;
private final HashSet<String> shovels;
private final HashSet<String> pickAxes;
private final HashSet<String> tridents;
private final HashSet<String> bows;
private final HashSet<String> tools;
private final @NotNull HashSet<String> swords;
private final @NotNull HashSet<String> axes;
private final @NotNull HashSet<String> hoes;
private final @NotNull HashSet<String> shovels;
private final @NotNull HashSet<String> pickAxes;
private final @NotNull HashSet<String> tridents;
private final @NotNull HashSet<String> bows;
private final @NotNull HashSet<String> tools;
private final HashSet<String> enchantables;
private final @NotNull HashSet<String> enchantables;
private final HashSet<String> ores;
private final @NotNull HashSet<String> ores;
private final HashMap<String, Integer> tierValue;
private final @NotNull HashMap<String, Integer> tierValue;
public MaterialMapStore()
@ -62,7 +63,7 @@ public class MaterialMapStore {
abilityBlackList = new HashSet<>();
toolBlackList = new HashSet<>();
mossyWhiteList = new HashSet<>();
leavesWhiteList = new HashSet<>();
treeFellerDestructibleWhiteList = new HashSet<>();
herbalismAbilityBlackList = new HashSet<>();
blockCrackerWhiteList = new HashSet<>();
canMakeShroomyWhiteList = new HashSet<>();
@ -104,52 +105,12 @@ public class MaterialMapStore {
fillVanillaMaterialRegisters();
}
public boolean isMultiBlockPlant(Material material)
{
return multiBlockPlant.contains(material.getKey().getKey());
}
public boolean isAbilityActivationBlackListed(Material material)
{
return abilityBlackList.contains(material.getKey().getKey());
}
public boolean isToolActivationBlackListed(Material material)
{
return toolBlackList.contains(material.getKey().getKey());
}
public boolean isMossyWhiteListed(Material material)
{
return mossyWhiteList.contains(material.getKey().getKey());
}
public boolean isLeavesWhiteListed(Material material)
{
return leavesWhiteList.contains(material.getKey().getKey());
}
public boolean isHerbalismAbilityWhiteListed(Material material)
{
return herbalismAbilityBlackList.contains(material.getKey().getKey());
}
public boolean isBlockCrackerWhiteListed(Material material)
{
return blockCrackerWhiteList.contains(material.getKey().getKey());
}
public boolean isShroomyWhiteListed(Material material)
{
return canMakeShroomyWhiteList.contains(material.getKey().getKey());
}
private void fillVanillaMaterialRegisters()
{
fillAbilityBlackList();
fillToolBlackList();
fillMossyWhiteList();
fillLeavesWhiteList();
fillTreeFellerDestructibleWhiteList();
fillHerbalismAbilityBlackList();
fillBlockCrackerWhiteList();
fillShroomyWhiteList();
@ -164,6 +125,46 @@ public class MaterialMapStore {
fillTierMap();
}
public boolean isMultiBlockPlant(@NotNull Material material)
{
return multiBlockPlant.contains(material.getKey().getKey());
}
public boolean isAbilityActivationBlackListed(@NotNull Material material)
{
return abilityBlackList.contains(material.getKey().getKey());
}
public boolean isToolActivationBlackListed(@NotNull Material material)
{
return toolBlackList.contains(material.getKey().getKey());
}
public boolean isMossyWhiteListed(@NotNull Material material)
{
return mossyWhiteList.contains(material.getKey().getKey());
}
public boolean isTreeFellerDestructible(@NotNull Material material)
{
return treeFellerDestructibleWhiteList.contains(material.getKey().getKey());
}
public boolean isHerbalismAbilityWhiteListed(@NotNull Material material)
{
return herbalismAbilityBlackList.contains(material.getKey().getKey());
}
public boolean isBlockCrackerWhiteListed(@NotNull Material material)
{
return blockCrackerWhiteList.contains(material.getKey().getKey());
}
public boolean isShroomyWhiteListed(@NotNull Material material)
{
return canMakeShroomyWhiteList.contains(material.getKey().getKey());
}
private void fillTierMap() {
for(String id : leatherArmor) {
tierValue.put(id, 1);
@ -418,26 +419,7 @@ public class MaterialMapStore {
ironTools.add("iron_shovel");
//Used for repair, remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in 2.2
//TODO: Remove in config update
ironTools.add("bucket");
ironTools.add("flint_and_steel");
ironTools.add("shears");
@ -555,7 +537,7 @@ public class MaterialMapStore {
* @param material target material
* @return true if it is used for armor
*/
public boolean isArmor(Material material) {
public boolean isArmor(@NotNull Material material) {
return isArmor(material.getKey().getKey());
}
@ -564,207 +546,196 @@ public class MaterialMapStore {
* @param id target item id
* @return true if the item id matches armor
*/
public boolean isArmor(String id) {
public boolean isArmor(@NotNull String id) {
return armors.contains(id);
}
public boolean isTool(Material material) {
public boolean isTool(@NotNull Material material) {
return isTool(material.getKey().getKey());
}
public boolean isTool(String id) {
public boolean isTool(@NotNull String id) {
return tools.contains(id);
}
public boolean isEnchantable(Material material) {
public boolean isEnchantable(@NotNull Material material) {
return isEnchantable(material.getKey().getKey());
}
public boolean isEnchantable(String id) {
public boolean isEnchantable(@NotNull String id) {
return enchantables.contains(id);
}
public boolean isOre(Material material) {
public boolean isOre(@NotNull Material material) {
return isOre(material.getKey().getKey());
}
public boolean isOre(String id) {
public boolean isOre(@NotNull String id) {
return ores.contains(id);
}
public boolean isBow(Material material) {
public boolean isBow(@NotNull Material material) {
return isBow(material.getKey().getKey());
}
public boolean isBow(String id) {
public boolean isBow(@NotNull String id) {
return bows.contains(id);
}
public boolean isLeatherArmor(Material material) {
public boolean isLeatherArmor(@NotNull Material material) {
return isLeatherArmor(material.getKey().getKey());
}
public boolean isLeatherArmor(String id) {
public boolean isLeatherArmor(@NotNull String id) {
return leatherArmor.contains(id);
}
public boolean isIronArmor(Material material) {
public boolean isIronArmor(@NotNull Material material) {
return isIronArmor(material.getKey().getKey());
}
public boolean isIronArmor(String id) {
public boolean isIronArmor(@NotNull String id) {
return ironArmor.contains(id);
}
public boolean isGoldArmor(Material material) {
public boolean isGoldArmor(@NotNull Material material) {
return isGoldArmor(material.getKey().getKey());
}
public boolean isGoldArmor(String id) {
public boolean isGoldArmor(@NotNull String id) {
return goldArmor.contains(id);
}
public boolean isDiamondArmor(Material material) {
public boolean isDiamondArmor(@NotNull Material material) {
return isDiamondArmor(material.getKey().getKey());
}
public boolean isDiamondArmor(String id) {
public boolean isDiamondArmor(@NotNull String id) {
return diamondArmor.contains(id);
}
public boolean isChainmailArmor(Material material) {
public boolean isChainmailArmor(@NotNull Material material) {
return isChainmailArmor(material.getKey().getKey());
}
public boolean isChainmailArmor(String id) {
public boolean isChainmailArmor(@NotNull String id) {
return chainmailArmor.contains(id);
}
public boolean isNetheriteArmor(Material material) {
public boolean isNetheriteArmor(@NotNull Material material) {
return isNetheriteArmor(material.getKey().getKey());
}
public boolean isNetheriteArmor(String id) {
public boolean isNetheriteArmor(@NotNull String id) {
return netheriteArmor.contains(id);
}
public boolean isWoodTool(Material material) {
public boolean isWoodTool(@NotNull Material material) {
return isWoodTool(material.getKey().getKey());
}
public boolean isWoodTool(String id) {
public boolean isWoodTool(@NotNull String id) {
return woodTools.contains(id);
}
public boolean isStoneTool(Material material) {
public boolean isStoneTool(@NotNull Material material) {
return isStoneTool(material.getKey().getKey());
}
public boolean isStoneTool(String id) {
public boolean isStoneTool(@NotNull String id) {
return stoneTools.contains(id);
}
public boolean isIronTool(Material material) {
public boolean isIronTool(@NotNull Material material) {
return isIronTool(material.getKey().getKey());
}
public boolean isIronTool(String id) {
public boolean isIronTool(@NotNull String id) {
return ironTools.contains(id);
}
public boolean isGoldTool(Material material) {
public boolean isGoldTool(@NotNull Material material) {
return isGoldTool(material.getKey().getKey());
}
public boolean isGoldTool(String id) {
public boolean isGoldTool(@NotNull String id) {
return goldTools.contains(id);
}
public boolean isDiamondTool(Material material) {
public boolean isDiamondTool(@NotNull Material material) {
return isDiamondTool(material.getKey().getKey());
}
public boolean isDiamondTool(String id) {
public boolean isDiamondTool(@NotNull String id) {
return diamondTools.contains(id);
}
public boolean isSword(Material material) {
public boolean isSword(@NotNull Material material) {
return isSword(material.getKey().getKey());
}
public boolean isSword(String id) {
public boolean isSword(@NotNull String id) {
return swords.contains(id);
}
public boolean isAxe(Material material) {
public boolean isAxe(@NotNull Material material) {
return isAxe(material.getKey().getKey());
}
public boolean isAxe(String id) {
public boolean isAxe(@NotNull String id) {
return axes.contains(id);
}
public boolean isPickAxe(Material material) {
public boolean isPickAxe(@NotNull Material material) {
return isPickAxe(material.getKey().getKey());
}
public boolean isPickAxe(String id) {
public boolean isPickAxe(@NotNull String id) {
return pickAxes.contains(id);
}
public boolean isShovel(Material material) {
public boolean isShovel(@NotNull Material material) {
return isShovel(material.getKey().getKey());
}
public boolean isShovel(String id) {
public boolean isShovel(@NotNull String id) {
return shovels.contains(id);
}
public boolean isHoe(Material material) {
public boolean isHoe(@NotNull Material material) {
return isHoe(material.getKey().getKey());
}
public boolean isHoe(String id) {
public boolean isHoe(@NotNull String id) {
return hoes.contains(id);
}
public boolean isNetheriteTool(Material material) {
public boolean isNetheriteTool(@NotNull Material material) {
return isNetheriteTool(material.getKey().getKey());
}
public boolean isNetheriteTool(String id) {
public boolean isNetheriteTool(@NotNull String id) {
return netheriteTools.contains(id);
}
public boolean isStringTool(Material material) {
public boolean isStringTool(@NotNull Material material) {
return isStringTool(material.getKey().getKey());
}
public boolean isStringTool(String id) {
public boolean isStringTool(@NotNull String id) {
return stringTools.contains(id);
}
public boolean isGlass(Material material) {
public boolean isGlass(@NotNull Material material) {
return glassBlocks.contains(material.getKey().getKey());
}
public boolean isFood(Material material) {
public boolean isFood(@NotNull Material material) {
return foodItemWhiteList.contains(material.getKey().getKey());
}
private void fillMultiBlockPlantSet()
{
//Single Block Plants
// plantBlockSet.add("melon");
// plantBlockSet.add("pumpkin");
// plantBlockSet.add("potatoes");
// plantBlockSet.add("carrots");
// plantBlockSet.add("beetroots");
// plantBlockSet.add("nether_wart");
// plantBlockSet.add("grass");
// plantBlockSet.add("fern");
// plantBlockSet.add("large_fern");
//Multi-Block Plants
multiBlockPlant.add("cactus");
multiBlockPlant.add("chorus_plant");
@ -802,16 +773,18 @@ public class MaterialMapStore {
herbalismAbilityBlackList.add("farmland");
}
private void fillLeavesWhiteList()
private void fillTreeFellerDestructibleWhiteList()
{
leavesWhiteList.add("oak_leaves");
leavesWhiteList.add("acacia_leaves");
leavesWhiteList.add("birch_leaves");
leavesWhiteList.add("dark_oak_leaves");
leavesWhiteList.add("jungle_leaves");
leavesWhiteList.add("spruce_leaves");
leavesWhiteList.add("nether_wart_block");
leavesWhiteList.add("warped_wart_block");
treeFellerDestructibleWhiteList.add("oak_leaves");
treeFellerDestructibleWhiteList.add("acacia_leaves");
treeFellerDestructibleWhiteList.add("birch_leaves");
treeFellerDestructibleWhiteList.add("dark_oak_leaves");
treeFellerDestructibleWhiteList.add("jungle_leaves");
treeFellerDestructibleWhiteList.add("spruce_leaves");
treeFellerDestructibleWhiteList.add("nether_wart_block");
treeFellerDestructibleWhiteList.add("warped_wart_block");
treeFellerDestructibleWhiteList.add("brown_mushroom_block");
treeFellerDestructibleWhiteList.add("red_mushroom_block");
}
private void fillMossyWhiteList()
@ -1090,24 +1063,24 @@ public class MaterialMapStore {
toolBlackList.add("respawn_anchor");
}
public HashSet<String> getNetheriteArmor() {
public @NotNull HashSet<String> getNetheriteArmor() {
return netheriteArmor;
}
public HashSet<String> getNetheriteTools() {
public @NotNull HashSet<String> getNetheriteTools() {
return netheriteTools;
}
public int getTier(Material material) {
public int getTier(@NotNull Material material) {
return getTier(material.getKey().getKey());
}
public int getTier(String id) {
public int getTier(@NotNull String id) {
return tierValue.getOrDefault(id, 1); //1 for unknown items
}
private void addToHashSet(String string, HashSet<String> stringHashSet)
private void addToHashSet(@NotNull String string, @NotNull HashSet<String> stringHashSet)
{
stringHashSet.add(string.toLowerCase(Locale.ENGLISH));
}

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.util;
import com.gmail.nossr50.api.ItemSpawnReason;
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
@ -11,6 +12,8 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Locale;
@ -18,7 +21,7 @@ import java.util.Random;
import java.util.Set;
public final class Misc {
private static final Random random = new Random();
private static final @NotNull Random random = new Random();
public static final int TIME_CONVERSION_FACTOR = 1000;
public static final int TICK_CONVERSION_FACTOR = 20;
@ -37,7 +40,7 @@ public final class Misc {
public static final float LEVELUP_PITCH = 0.5F; // Reduced to differentiate between vanilla level-up
public static final float LEVELUP_VOLUME = 0.75F * Config.getInstance().getMasterVolume(); // Use max volume always*/
public static final Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
public static final @NotNull Set<String> modNames = ImmutableSet.of("LOTR", "BUILDCRAFT", "ENDERIO", "ENHANCEDBIOMES", "IC2", "METALLURGY", "FORESTRY", "GALACTICRAFT", "RAILCRAFT", "TWILIGHTFOREST", "THAUMCRAFT", "GRAVESTONEMOD", "GROWTHCRAFT", "ARCTICMOBS", "DEMONMOBS", "INFERNOMOBS", "SWAMPMOBS", "MARICULTURE", "MINESTRAPPOLATION");
private Misc() {}
@ -54,7 +57,7 @@ public final class Misc {
* @param entity target entity
* @return true if the entity is not a Villager and is not a "NPC"
*/
public static boolean isNPCEntityExcludingVillagers(Entity entity) {
public static boolean isNPCEntityExcludingVillagers(@NotNull Entity entity) {
return (!isVillager(entity)
&& isNPCIncludingVillagers(entity)); //Compatibility with some mod..
}
@ -73,7 +76,7 @@ public final class Misc {
return entityType.equalsIgnoreCase("wandering_trader") || entity instanceof Villager;
}
public static boolean isNPCIncludingVillagers(Entity entity) {
public static boolean isNPCIncludingVillagers(@Nullable Entity entity) {
return (entity == null
|| (hasNPCMetadataTag(entity))
|| (isNPCClassType(entity))
@ -88,7 +91,7 @@ public final class Misc {
* @param maxDistance The max distance apart
* @return true if the distance between {@code first} and {@code second} is less than {@code maxDistance}, false otherwise
*/
public static boolean isNear(Location first, Location second, double maxDistance) {
public static boolean isNear(@NotNull Location first, @NotNull Location second, double maxDistance) {
return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0);
}
@ -102,9 +105,25 @@ public final class Misc {
return blockState.getLocation().add(0.5, 0.5, 0.5);
}
public static void dropItems(Location location, Collection<ItemStack> drops) {
public static void spawnItemsFromCollection(@NotNull Location location, @NotNull Collection<ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) {
for (ItemStack drop : drops) {
dropItem(location, drop);
spawnItem(location, drop, itemSpawnReason);
}
}
/**
* Drops only the first n items in a collection
* Size should always be a positive integer above 0
*
* @param location target drop location
* @param drops collection to iterate over
* @param sizeLimit the number of drops to process
*/
public static void spawnItemsFromCollection(@NotNull Location location, @NotNull Collection<ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason, int sizeLimit) {
ItemStack[] arrayDrops = drops.toArray(new ItemStack[0]);
for(int i = 0; i < sizeLimit-1; i++) {
spawnItem(location, arrayDrops[i], itemSpawnReason);
}
}
@ -115,9 +134,9 @@ public final class Misc {
* @param is The items to drop
* @param quantity The amount of items to drop
*/
public static void dropItems(Location location, ItemStack is, int quantity) {
public static void spawnItems(@NotNull Location location, @NotNull ItemStack is, int quantity, @NotNull ItemSpawnReason itemSpawnReason) {
for (int i = 0; i < quantity; i++) {
dropItem(location, is);
spawnItem(location, is, itemSpawnReason);
}
}
@ -126,15 +145,16 @@ public final class Misc {
*
* @param location The location to drop the item at
* @param itemStack The item to drop
* @param itemSpawnReason the reason for the item drop
* @return Dropped Item entity or null if invalid or cancelled
*/
public static Item dropItem(Location location, ItemStack itemStack) {
if (itemStack.getType() == Material.AIR) {
public static @Nullable Item spawnItem(@NotNull Location location, @NotNull ItemStack itemStack, @NotNull ItemSpawnReason itemSpawnReason) {
if (itemStack.getType() == Material.AIR || location.getWorld() == null) {
return null;
}
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -149,22 +169,23 @@ public final class Misc {
*
* @param location The location to drop the item at
* @param itemStack The item to drop
* @param itemSpawnReason the reason for the item drop
* @return Dropped Item entity or null if invalid or cancelled
*/
public static Item dropItem(Location location, ItemStack itemStack, int count) {
if (itemStack.getType() == Material.AIR) {
public static @Nullable Item spawnItemNaturally(@NotNull Location location, @NotNull ItemStack itemStack, @NotNull ItemSpawnReason itemSpawnReason) {
if (itemStack.getType() == Material.AIR || location.getWorld() == null) {
return null;
}
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack);
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
return location.getWorld().dropItem(location, itemStack);
return location.getWorld().dropItemNaturally(location, itemStack);
}
/**
@ -175,9 +196,9 @@ public final class Misc {
* @param speed the speed that the item should travel
* @param quantity The amount of items to drop
*/
public static void spawnItemsTowardsLocation(Location fromLocation, Location toLocation, ItemStack is, int quantity, double speed) {
public static void spawnItemsTowardsLocation(@NotNull Location fromLocation, @NotNull Location toLocation, @NotNull ItemStack is, int quantity, double speed, @NotNull ItemSpawnReason itemSpawnReason) {
for (int i = 0; i < quantity; i++) {
spawnItemTowardsLocation(fromLocation, toLocation, is, speed);
spawnItemTowardsLocation(fromLocation, toLocation, is, speed, itemSpawnReason);
}
}
@ -191,7 +212,7 @@ public final class Misc {
* @param speed the speed that the item should travel
* @return Dropped Item entity or null if invalid or cancelled
*/
public static Item spawnItemTowardsLocation(Location fromLocation, Location toLocation, ItemStack itemToSpawn, double speed) {
public static @Nullable Item spawnItemTowardsLocation(@NotNull Location fromLocation, @NotNull Location toLocation, @NotNull ItemStack itemToSpawn, double speed, @NotNull ItemSpawnReason itemSpawnReason) {
if (itemToSpawn.getType() == Material.AIR) {
return null;
}
@ -201,12 +222,15 @@ public final class Misc {
Location spawnLocation = fromLocation.clone();
Location targetLocation = toLocation.clone();
if(spawnLocation.getWorld() == null)
return null;
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, clonedItem);
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(spawnLocation, clonedItem, itemSpawnReason);
mcMMO.p.getServer().getPluginManager().callEvent(event);
//Something cancelled the event so back out
if (event.isCancelled() || event.getItemStack() == null) {
if (event.isCancelled()) {
return null;
}
@ -224,7 +248,7 @@ public final class Misc {
return spawnedItem;
}
public static void profileCleanup(String playerName) {
public static void profileCleanup(@NotNull String playerName) {
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
if (player != null) {
@ -239,7 +263,7 @@ public final class Misc {
}
}
public static String getModName(String materialName) {
public static String getModName(@NotNull String materialName) {
for (String mod : modNames) {
if (materialName.contains(mod)) {
return mod;
@ -258,7 +282,7 @@ public final class Misc {
/**
* Gets a random location near the specified location
*/
public static Location getLocationOffset(Location location, double strength) {
public static Location getLocationOffset(@NotNull Location location, double strength) {
double blockX = location.getBlockX();
double blockZ = location.getBlockZ();
@ -272,7 +296,7 @@ public final class Misc {
return new Location(location.getWorld(), blockX, location.getY(), blockZ);
}
public static Random getRandom() {
public static @NotNull Random getRandom() {
return random;
}
}

View File

@ -136,10 +136,6 @@ public class ModManager {
return Config.getInstance().getBlockModsEnabled() && customLogs.contains(state.getType());
}
public boolean isCustomLeaf(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getType());
}
public boolean isCustomAbilityBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customAbilityBlocks.contains(state.getType());
}