From bb88812668c2024ef30b105bbcf9a8ab025e345f Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 5 Feb 2013 22:40:19 -0500 Subject: [PATCH] Added basic support for Mo' Creatures (and other entity mods) - specify mob info in entities.yml --- Changelog.txt | 1 + .../java/com/gmail/nossr50/config/Config.java | 1 + src/main/java/com/gmail/nossr50/mcMMO.java | 5 + .../com/gmail/nossr50/mods/ModChecks.java | 25 +++++ .../mods/config/CustomEntityConfig.java | 82 ++++++++++++++++ .../nossr50/mods/datatypes/CustomEntity.java | 94 +++++++++++++++++++ .../nossr50/skills/utilities/CombatTools.java | 12 ++- src/main/resources/config.yml | 1 + src/main/resources/entities.yml | 66 +++++++++++++ 9 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gmail/nossr50/mods/config/CustomEntityConfig.java create mode 100644 src/main/java/com/gmail/nossr50/mods/datatypes/CustomEntity.java create mode 100644 src/main/resources/entities.yml diff --git a/Changelog.txt b/Changelog.txt index 2f1c8f373..20508657c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -26,6 +26,7 @@ Version 1.4.00-dev + Added particle effect for bleeding + Added methods to check if a player is in party or admin chat to the ChatAPI + Added /mcpurge functionality for Flatfile users + + Added basic support for Mo' Creatures (and other entity mods) - specify mob info in entities.yml = Fixed multiple commands not working properly on offline players = Fixed /mmoedit not giving feedback when modifying another players stats = Fixed the guide usage string showing up every time /skillname was called diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index b3bb507ae..6f5999ae2 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -78,6 +78,7 @@ public class Config extends ConfigLoader { public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } public boolean getArmorModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); } + public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); } /* PARTY SETTINGS */ public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 63e083dfc..33fadccc3 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -43,6 +43,7 @@ import com.gmail.nossr50.listeners.PlayerListener; import com.gmail.nossr50.listeners.WorldListener; 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.party.PartyManager; import com.gmail.nossr50.party.commands.PartyCommand; @@ -229,6 +230,10 @@ public class mcMMO extends JavaPlugin { CustomBlocksConfig.getInstance(); } + if (configInstance.getEntityModsEnabled()) { + CustomEntityConfig.getInstance(); + } + // Load repair configs, make manager, and register them at this time RepairConfigManager rManager = new RepairConfigManager(this); repairables.addAll(rManager.getLoadedRepairables()); diff --git a/src/main/java/com/gmail/nossr50/mods/ModChecks.java b/src/main/java/com/gmail/nossr50/mods/ModChecks.java index 500841432..414fea40e 100644 --- a/src/main/java/com/gmail/nossr50/mods/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/mods/ModChecks.java @@ -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; + } } diff --git a/src/main/java/com/gmail/nossr50/mods/config/CustomEntityConfig.java b/src/main/java/com/gmail/nossr50/mods/config/CustomEntityConfig.java new file mode 100644 index 000000000..a80652eaf --- /dev/null +++ b/src/main/java/com/gmail/nossr50/mods/config/CustomEntityConfig.java @@ -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 customEntityIds = new ArrayList(); + public List customHostileEntityIds = new ArrayList(); + public List customNeutralEntityIds = new ArrayList(); + public List customPassiveEntityIds = new ArrayList(); + public List customEntityTypes = new ArrayList(); + public List customEntities = new ArrayList(); + + 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 entityIdList) { + ConfigurationSection entitySection = config.getConfigurationSection(entityType); + + if (entitySection == null) { + return; + } + + Set 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); + } + } +} diff --git a/src/main/java/com/gmail/nossr50/mods/datatypes/CustomEntity.java b/src/main/java/com/gmail/nossr50/mods/datatypes/CustomEntity.java new file mode 100644 index 000000000..e29698964 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/mods/datatypes/CustomEntity.java @@ -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; + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java index 87dc7deae..8b037fee4 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java @@ -26,6 +26,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.skills.acrobatics.Acrobatics; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; @@ -459,7 +460,12 @@ public final class CombatTools { } else if (!mcMMO.placeStore.isSpawnedMob(target)) { if (target instanceof Animals && !mcMMO.placeStore.isSpawnedPet(target)) { - baseXP = configInstance.getAnimalsXP(); + if (ModChecks.isCustomEntity(target)) { + baseXP = ModChecks.getCustomEntity(target).getXpMultiplier(); + } + else { + baseXP = configInstance.getAnimalsXP(); + } } else { EntityType type = target.getType(); @@ -546,6 +552,10 @@ public final class CombatTools { break; default: + if (ModChecks.isCustomEntity(target)) { + baseXP = ModChecks.getCustomEntity(target).getXpMultiplier(); + } + break; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a28ae0555..a147570bc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -55,6 +55,7 @@ Mods: Tool_Mods_Enabled: false Armor_Mods_Enabled: false Block_Mods_Enabled: false + Entity_Mods_Enabled: false # # Settings for Parties diff --git a/src/main/resources/entities.yml b/src/main/resources/entities.yml new file mode 100644 index 000000000..b06635134 --- /dev/null +++ b/src/main/resources/entities.yml @@ -0,0 +1,66 @@ +# +# Settings for Hostile Mobs +### +Hostile: + Mob_1: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 + Mob_2: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 +# +# Settings for Neutral Mobs +### +Neutral: + Mob_1: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 + Mob_2: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 +# +# Settings for Passive Mobs +### +Passive: + Mob_1: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 + Mob_2: + ID: 9999 + XP_Multiplier: 1.0 + Tameable: false + Taming_XP: 250 + CanBeSummoned: false + COTW_Material_ID: 999 + COTW_Material_Data: 9 + COTW_Material_Amount: 99 \ No newline at end of file