mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Add custom mobs automatically as they're killed.
This commit is contained in:
@ -14,6 +14,25 @@ import com.gmail.nossr50.config.party.ItemWeightConfig;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
/**
|
||||
* Checks if the item is a bow.
|
||||
*
|
||||
* @param item Item to check
|
||||
* @return true if the item is a bow, false otherwise
|
||||
*/
|
||||
public static boolean isBow(ItemStack item) {
|
||||
Material type = item.getType();
|
||||
|
||||
switch (type) {
|
||||
case BOW:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomBow(type));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the item is a sword.
|
||||
*
|
||||
@ -32,7 +51,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customSwords.contains(type));
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomSword(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +73,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customHoes.contains(type));
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomHoe(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +95,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customShovels.contains(type));
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomShovel(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +117,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customAxes.contains(type));
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomAxe(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +139,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().customPickaxes.contains(type));
|
||||
return (Config.getInstance().getToolModsEnabled() && CustomToolConfig.getInstance().isCustomPickaxe(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +161,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().customHelmets.contains(type);
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomHelmet(type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +183,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().customChestplates.contains(type);
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomChestplate(type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +205,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().customLeggings.contains(type);
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomLeggings(type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,7 +227,7 @@ public class ItemUtils {
|
||||
return true;
|
||||
|
||||
default:
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().customBoots.contains(type);
|
||||
return Config.getInstance().getArmorModsEnabled() && CustomArmorConfig.getInstance().isCustomBoots(type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,12 +488,11 @@ public class ItemUtils {
|
||||
case SHEARS:
|
||||
case FISHING_ROD:
|
||||
case CARROT_STICK:
|
||||
case BOW:
|
||||
case FLINT_AND_STEEL:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return isArmor(item) || isSword(item) || isAxe(item) || isShovel(item) || isPickaxe(item);
|
||||
return isArmor(item) || isSword(item) || isAxe(item) || isShovel(item) || isPickaxe(item) || isBow(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.mods.CustomArmorConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomBlockConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomEntityConfig;
|
||||
import com.gmail.nossr50.config.mods.CustomToolConfig;
|
||||
@ -13,11 +17,11 @@ import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||
|
||||
|
||||
public final class ModUtils {
|
||||
private static Config configInstance = Config.getInstance();
|
||||
|
||||
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
|
||||
private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
|
||||
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
|
||||
private static boolean customEntitiesEnabled = configInstance.getEntityModsEnabled();
|
||||
|
||||
@ -30,38 +34,27 @@ public final class ModUtils {
|
||||
* @return the tool if it exists, null otherwise
|
||||
*/
|
||||
public static CustomTool getToolFromItemStack(ItemStack item) {
|
||||
return CustomToolConfig.getInstance().customToolMap.get(item.getType());
|
||||
return CustomToolConfig.getInstance().getCustomTool(item.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom entity associated with an entity.
|
||||
*
|
||||
* @param entity The entity to check
|
||||
* @return the entity is if exists, null otherwise
|
||||
*/
|
||||
public static CustomEntity getCustomEntity(Entity entity) {
|
||||
return CustomEntityConfig.getInstance().getCustomEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom block associated with an block.
|
||||
*
|
||||
* @param blockState The block to check
|
||||
* @param blockState The BlockState of the bloc to check
|
||||
* @return the block if it exists, null otherwise
|
||||
*/
|
||||
public static CustomBlock getCustomBlock(BlockState blockState) {
|
||||
return CustomBlockConfig.getInstance().customBlockMap.get(blockState.getData());
|
||||
}
|
||||
|
||||
public static CustomEntity getCustomEntity(Entity entity) {
|
||||
CustomEntity customEntity = CustomEntityConfig.getInstance().customEntityTypeMap.get(entity.getType().toString());
|
||||
|
||||
if (customEntity == null) {
|
||||
try {
|
||||
customEntity = CustomEntityConfig.getInstance().customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (NoSuchFieldException e){
|
||||
return null;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return customEntity;
|
||||
return CustomBlockConfig.getInstance().getCustomBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +64,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents a custom woodcutting block, false otherwise
|
||||
*/
|
||||
public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomWoodcuttingBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +74,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents an ability block, false otherwise
|
||||
*/
|
||||
public static boolean isCustomAbilityBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customAbilityBlocks.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomAbilityBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +84,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents a custom mining block, false otherwise
|
||||
*/
|
||||
public static boolean isCustomMiningBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customMiningBlocks.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomMiningBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +94,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents a custom excavation block, false otherwise
|
||||
*/
|
||||
public static boolean isCustomExcavationBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customExcavationBlocks.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomExcavationBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +104,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents a custom herbalism block, false otherwise
|
||||
*/
|
||||
public static boolean isCustomHerbalismBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customHerbalismBlocks.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomHerbalismBlock(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +114,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents leaves, false otherwise
|
||||
*/
|
||||
public static boolean isCustomLeafBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customLeaves.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLeaf(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +124,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents a log, false otherwise
|
||||
*/
|
||||
public static boolean isCustomLogBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customLogs.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLog(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +134,7 @@ public final class ModUtils {
|
||||
* @return true if the block represents an ore, false otherwise
|
||||
*/
|
||||
public static boolean isCustomOreBlock(BlockState blockState) {
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().customOres.contains(blockState.getData());
|
||||
return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(blockState.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,40 +144,17 @@ public final class ModUtils {
|
||||
* @return true if the item is a custom tool, false otherwise
|
||||
*/
|
||||
public static boolean isCustomTool(ItemStack item) {
|
||||
return customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType());
|
||||
return customToolsEnabled && CustomToolConfig.getInstance().isCustomTool(item.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if an item is custom armor.
|
||||
* Checks to see if an entity is a custom entity.
|
||||
*
|
||||
* @param item Item to check
|
||||
* @return true if the item is custom armor, false otherwise
|
||||
* @param entity Entity to check
|
||||
* @return true if the entity is a custom entity, false otherwise
|
||||
*/
|
||||
public static boolean isCustomArmor(ItemStack item) {
|
||||
return customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType());
|
||||
}
|
||||
|
||||
public static boolean isCustomEntity(Entity entity) {
|
||||
if (!customEntitiesEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CustomEntityConfig.getInstance().customEntityTypeMap.containsKey(entity.getType().toString())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return CustomEntityConfig.getInstance().customEntityClassMap.containsKey(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (NoSuchFieldException e){
|
||||
return false;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
return false;
|
||||
}
|
||||
return customEntitiesEnabled && CustomEntityConfig.getInstance().isCustomEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,4 +167,52 @@ public final class ModUtils {
|
||||
//TODO: Finish this method
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addCustomEntity(Entity entity) {
|
||||
if (!customEntitiesEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
File entityFile = CustomEntityConfig.getInstance().getFile();
|
||||
YamlConfiguration entitiesFile = YamlConfiguration.loadConfiguration(entityFile);
|
||||
|
||||
String entityName = entity.getType().toString();
|
||||
String sanitizedEntityName = entityName.replace(".", "_");
|
||||
|
||||
if (entitiesFile.getKeys(false).contains(sanitizedEntityName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
entitiesFile.set(sanitizedEntityName + ".XP_Multiplier", 1.0D);
|
||||
entitiesFile.set(sanitizedEntityName + ".Tameable", false);
|
||||
entitiesFile.set(sanitizedEntityName + ".Taming_XP", 0);
|
||||
entitiesFile.set(sanitizedEntityName + ".CanBeSummoned", false);
|
||||
entitiesFile.set(sanitizedEntityName + ".COTW_Material", "");
|
||||
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Data", 0);
|
||||
entitiesFile.set(sanitizedEntityName + ".COTW_Material_Amount", 0);
|
||||
|
||||
String className = "";
|
||||
|
||||
try {
|
||||
className = ((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
|
||||
className = entity.getClass().getName();
|
||||
}
|
||||
else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
CustomEntityConfig.getInstance().addEntity(new CustomEntity(1.0D, false, 0, false, null, 0), className, entityName);
|
||||
|
||||
try {
|
||||
entitiesFile.save(entityFile);
|
||||
mcMMO.p.debug(entity.getType().toString() + " was added to the custom entities file!");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -498,10 +498,6 @@ public final class CombatUtils {
|
||||
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
||||
break;
|
||||
|
||||
case UNKNOWN:
|
||||
baseXP = 1.0;
|
||||
break;
|
||||
|
||||
case SKELETON:
|
||||
switch (((Skeleton) target).getSkeletonType()) {
|
||||
case WITHER:
|
||||
@ -520,6 +516,8 @@ public final class CombatUtils {
|
||||
break;
|
||||
|
||||
default:
|
||||
baseXP = 1.0;
|
||||
ModUtils.addCustomEntity(target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user