Added basic support for Mo' Creatures (and other entity mods) - specify

mob info in entities.yml
This commit is contained in:
GJ
2013-02-05 22:40:19 -05:00
parent 94a9230525
commit bb88812668
9 changed files with 286 additions and 1 deletions

View File

@ -1,14 +1,17 @@
package com.gmail.nossr50.mods;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mods.config.CustomArmorConfig;
import com.gmail.nossr50.mods.config.CustomBlocksConfig;
import com.gmail.nossr50.mods.config.CustomEntityConfig;
import com.gmail.nossr50.mods.config.CustomToolsConfig;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.mods.datatypes.CustomEntity;
import com.gmail.nossr50.mods.datatypes.CustomItem;
import com.gmail.nossr50.mods.datatypes.CustomTool;
@ -17,6 +20,7 @@ public final class ModChecks {
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
private static boolean customEntitiesEnabled = configInstance.getEntityModsEnabled();
private ModChecks() {}
@ -62,6 +66,19 @@ public final class ModChecks {
return null;
}
public static CustomEntity getCustomEntity(Entity entity) {
if (!CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId()) && !CustomEntityConfig.getInstance().customEntityTypes.contains(entity.getType())) {
return null;
}
for (CustomEntity customEntity : CustomEntityConfig.getInstance().customEntities) {
if ((customEntity.getEntityID() == entity.getEntityId()) && (customEntity.getEntityType() == entity.getType())) {
return customEntity;
}
}
return null;
}
/**
* Check if a custom block is a custom block.
*
@ -169,4 +186,12 @@ public final class ModChecks {
return false;
}
public static boolean isCustomEntity(Entity entity) {
if (customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId())) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,82 @@
package com.gmail.nossr50.mods.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.mods.datatypes.CustomEntity;
public class CustomEntityConfig extends ConfigLoader {
private static CustomEntityConfig instance;
public List<Integer> customEntityIds = new ArrayList<Integer>();
public List<Integer> customHostileEntityIds = new ArrayList<Integer>();
public List<Integer> customNeutralEntityIds = new ArrayList<Integer>();
public List<Integer> customPassiveEntityIds = new ArrayList<Integer>();
public List<EntityType> customEntityTypes = new ArrayList<EntityType>();
public List<CustomEntity> customEntities = new ArrayList<CustomEntity>();
public CustomEntityConfig() {
super("ModConfigs", "entities.yml");
loadKeys();
}
public static CustomEntityConfig getInstance() {
if (instance == null) {
instance = new CustomEntityConfig();
}
return instance;
}
@Override
protected void loadKeys() {
loadMobs("Hostile", customHostileEntityIds);
loadMobs("Neutral", customNeutralEntityIds);
loadMobs("Passive", customPassiveEntityIds);
}
private void loadMobs(String entityType, List<Integer> entityIdList) {
ConfigurationSection entitySection = config.getConfigurationSection(entityType);
if (entitySection == null) {
return;
}
Set<String> entityConfigSet = entitySection.getKeys(false);
for (String entityName : entityConfigSet) {
int id = config.getInt(entityType + "." + entityName + ".ID", 0);
EntityType type = EntityType.fromId(id);
double xpMultiplier = config.getDouble(entityType + "." + entityName + ".XP_Multiplier", 1.0D);
boolean canBeTamed = config.getBoolean(entityType + "." + entityName + ".Tameable", false);
int tamingXp = config.getInt(entityType + "." + entityName + ".Tameable.Taming_XP", 0);
boolean canBeSummoned = config.getBoolean(entityType + "." + entityName + ".Tameable.CanBeSummoned", false);
int callOfTheWildId = config.getInt(entityType + "." + entityName + ".Tameable.COTW_Material_ID", 0);
int callOfTheWildData = config.getInt(entityType + "." + entityName + ".Tameable.COTW_Material_Data", 0);
int callOfTheWildAmount = config.getInt(entityType + "." + entityName + ".Tameable.COTW_Material_Amount", 0);
CustomEntity entity;
if (id == 0) {
plugin.getLogger().warning("Missing ID. This block will be skipped.");
continue;
}
if (canBeSummoned && (callOfTheWildId == 0 || callOfTheWildAmount == 0)) {
plugin.getLogger().warning("Incomplete Call of the Wild information. This enitity will not be able to be summoned by Call of the Wild.");
canBeSummoned = false;
}
entity = new CustomEntity(id, type, xpMultiplier, canBeTamed, tamingXp, canBeSummoned, new ItemStack(callOfTheWildId, callOfTheWildData), callOfTheWildAmount);
entityIdList.add(id);
customEntityTypes.add(type);
customEntities.add(entity);
}
}
}

View File

@ -0,0 +1,94 @@
package com.gmail.nossr50.mods.datatypes;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
public class CustomEntity {
private int entityID;
private EntityType entityType;
private double xpMultiplier;
private boolean canBeTamed;
private int tamingXP;
private boolean canBeSummoned;
private ItemStack callOfTheWildItem;
private int callOfTheWildAmount;
public CustomEntity(int entityID, EntityType entityType, double xpMultiplier, boolean canBeTamed, int tamingXP, boolean canBeSummoned, ItemStack callOfTheWildItem, int callOfTheWildAmount) {
this.entityID = entityID;
this.entityType = entityType;
this.xpMultiplier = xpMultiplier;
this.canBeTamed = canBeTamed;
this.tamingXP = tamingXP;
this.canBeSummoned = canBeSummoned;
this.callOfTheWildItem = callOfTheWildItem;
this.callOfTheWildAmount = callOfTheWildAmount;
}
public int getEntityID() {
return entityID;
}
public void setEntityID(int entityID) {
this.entityID = entityID;
}
public EntityType getEntityType() {
return entityType;
}
public void setEntityType(EntityType entityType) {
this.entityType = entityType;
}
public double getXpMultiplier() {
return xpMultiplier;
}
public void setXpMultiplier(double xpMultiplier) {
this.xpMultiplier = xpMultiplier;
}
public boolean isCanBeTamed() {
return canBeTamed;
}
public void setCanBeTamed(boolean canBeTamed) {
this.canBeTamed = canBeTamed;
}
public int getTamingXP() {
return tamingXP;
}
public void setTamingXP(int tamingXP) {
this.tamingXP = tamingXP;
}
public boolean isCanBeSummoned() {
return canBeSummoned;
}
public void setCanBeSummoned(boolean canBeSummoned) {
this.canBeSummoned = canBeSummoned;
}
public ItemStack getCallOfTheWildItem() {
return callOfTheWildItem;
}
public void setCallOfTheWildItem(ItemStack callOfTheWildItem) {
this.callOfTheWildItem = callOfTheWildItem;
}
public int getCallOfTheWildAmount() {
return callOfTheWildAmount;
}
public void setCallOfTheWildAmount(int callOfTheWildAmount) {
this.callOfTheWildAmount = callOfTheWildAmount;
}
}