diff --git a/.classpath b/.classpath
deleted file mode 100644
index 684bae5..0000000
--- a/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
index 027669e..ee4a769 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,4 +22,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
-.settings
\ No newline at end of file
+.settings
+
+# IDEA
+.idea
+out
diff --git a/.project b/.project
deleted file mode 100644
index abf3e89..0000000
--- a/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- ZeldaHeartsReborn
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/HeartContainersReloaded.iml b/HeartContainersReloaded.iml
new file mode 100644
index 0000000..a453569
--- /dev/null
+++ b/HeartContainersReloaded.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config.yml b/config.yml
deleted file mode 100644
index 4dba6b2..0000000
--- a/config.yml
+++ /dev/null
@@ -1,199 +0,0 @@
-start_health: 3.0
-max_health: 30.0
-drop_config:
- ELDER_GUARDIAN:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- WITHER_SKELETON:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- STRAY:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- HUSK:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ZOMBIE_VILLAGER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SKELETON_HORSE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ZOMBIE_HORSE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- DONKEY:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- MULE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- EVOKER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- VEX:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- VINDICATOR:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ILLUSIONER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- CREEPER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SKELETON:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SPIDER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ZOMBIE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SLIME:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- GHAST:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- PIG_ZOMBIE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ENDERMAN:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- CAVE_SPIDER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SILVERFISH:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- BLAZE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- MAGMA_CUBE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ENDER_DRAGON:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- WITHER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- BAT:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- WITCH:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- ENDERMITE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- GUARDIAN:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SHULKER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- PIG:
- health_type: "DROP_VAMPIRE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SHEEP:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- COW:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- CHICKEN:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SQUID:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- WOLF:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- MUSHROOM_COW:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- SNOWMAN:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- OCELOT:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- IRON_GOLEM:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- HORSE:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- RABBIT:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- POLAR_BEAR:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- LLAMA:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- PARROT:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- VILLAGER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
- PLAYER:
- health_type: "DIRECT_VALUE"
- health_value: 0.5
- vampire_multiplicator: 0.5
\ No newline at end of file
diff --git a/plugin.yml b/plugin.yml
deleted file mode 100644
index a517443..0000000
--- a/plugin.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-name: HealthContainerPlugin
-main: com.dhalucario.HealthContainer.Main
-version: 1.0
-api-version: 1.13
-commands:
\ No newline at end of file
diff --git a/res/config.yml b/res/config.yml
new file mode 100644
index 0000000..6e5364b
--- /dev/null
+++ b/res/config.yml
@@ -0,0 +1,31 @@
+# Set the default health
+start_health: 20.0
+# Set the maximum health a player can reach
+max_health: 30.0
+
+# Configure the type of health that is going to be dropped
+health_config:
+
+ # Set the Entity which drops/gives the health to the killer
+ # Mob types can be found at
+ PLAYER:
+ # Sets how you get the heart (as a drop or direct) and how health is calculated.
+ health_type: "DIRECT_VALUE"
+
+ # When using DIRECT_VALUE or DROP_VALUE health_value
+ # is dropped or added to the max health of the player
+ health_value: 0.5
+
+ # When using DIRECT_VAMPIRE or DROP_VAMPIRE (vampire_multiplicator * killed enemy health)
+ # is dropped or added to the player.
+ vampire_multiplicator: 0.5
+
+# Example:
+# drop_config:
+# MOB_TYPE:
+# health_type: DROP_VALUE | DROP_VAMPIRE | DIRECT_VALUE | DIRECT_VAMPIRE | NONE
+# health_value: 0.5
+# vampire_multiplicator: 0.5
+# PIG:
+# health_type: "DROP_VAMPIRE"
+# vampire_multiplicator: 0.5
\ No newline at end of file
diff --git a/res/plugin.yml b/res/plugin.yml
new file mode 100644
index 0000000..dc10d89
--- /dev/null
+++ b/res/plugin.yml
@@ -0,0 +1,5 @@
+name: HeartContainersReloaded
+main: com.dhalucario.HeartContainersReloaded.Main
+version: 1.0
+api-version: 1.13
+commands:
\ No newline at end of file
diff --git a/src/com/dhalucario/HealthContainer/HCConfigLoader.java b/src/com/dhalucario/HealthContainer/HCConfigLoader.java
deleted file mode 100644
index eac114c..0000000
--- a/src/com/dhalucario/HealthContainer/HCConfigLoader.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package com.dhalucario.HealthContainer;
-
-import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.configuration.MemorySection;
-import org.bukkit.entity.*;
-
-public class HCConfigLoader {
-
- JavaPlugin hcPlugin;
-
- public HCConfigLoader(JavaPlugin plugin) {
- hcPlugin = plugin;
- }
-
- public void loadDefaults() {
-
- hcPlugin.getConfig().options().copyDefaults(true);
-
- hcPlugin.getConfig().addDefault("start_health", 3.0);
- hcPlugin.getConfig().addDefault("max_health", 30.0);
- hcPlugin.getConfig().addDefault("spawning_resets_health", true);
-
- for (EntityType entType : EntityType.values()) {
-
- /*
- * drop_value: Drops a heart which contains the value specified using health_value
- * drop_vampire: Drops a heart which contains the (health of the target * vampire_multiplicator)
- * direct_value: Adds the value specified in health_value directly to the max health
- * direct_vampire: Adds the value of (health of the target * vampire_multiplicator) directly to the max health
- */
- hcPlugin.getConfig().addDefault("drop_config." + entType.name() + ".health_type", "DIRECT_VALUE");
- hcPlugin.getConfig().addDefault("drop_config." + entType.name() + ".health_value", 0.5);
- hcPlugin.getConfig().addDefault("drop_config." + entType.name() + ".vampire_multiplicator", 0.5);
- }
-
- hcPlugin.saveDefaultConfig();
- }
-
- public HCEntityConfig getConfigForEntity(EntityType target) {
-
- HCEntityConfig entityConfig = new HCEntityConfig();
- MemorySection dropConfig = (MemorySection) hcPlugin.getConfig().get("drop_config");
- MemorySection damageEntityConfig = (MemorySection) dropConfig.get(target.name());
-
- if (damageEntityConfig != null) {
- if (damageEntityConfig.isString("health_type")) {
-
- switch (damageEntityConfig.getString("health_type")) {
- case "DROP_VALUE":
- entityConfig.setHealthType(HealthType.DROP_VALUE);
- break;
- case "DROP_VAMPIRE":
- entityConfig.setHealthType(HealthType.DROP_VAMPIRE);
- break;
- case "DIRECT_VALUE":
- entityConfig.setHealthType(HealthType.DIRECT_VALUE);
- break;
- case "DIRECT_VAMPIRE":
- entityConfig.setHealthType(HealthType.DIRECT_VAMPIRE);
- break;
- default:
- hcPlugin.getLogger().warning("\"health_type\" for entity " + target.name() + " is invalid type");
- hcPlugin.getLogger().warning("Falling back to default (0.5)");
- entityConfig.setHealthType(HealthType.DROP_VALUE);
- break;
- }
- } else {
- entityConfig.setVampireMultiplicator(0.5);
- hcPlugin.getLogger().warning("\"health_type\" for entity " + target.name() + " is invalid primitive");
- hcPlugin.getLogger().warning("Falling back to default (0.5)");
- }
-
- if (damageEntityConfig.isDouble("health_value")) {
- entityConfig.setHealthValue(damageEntityConfig.getDouble("health_value"));
- } else if (damageEntityConfig.isInt("health_value")) {
- entityConfig.setHealthValue(damageEntityConfig.getInt("health_value"));
- } else {
- entityConfig.setHealthValue(damageEntityConfig.getInt("health_value"));
- hcPlugin.getLogger().warning("\"health_value\" for entity " + target.name() + " is invalid primitive");
- hcPlugin.getLogger().warning("Falling back to default (0.5)");
- }
-
- if (damageEntityConfig.isDouble("vampire_multiplicator")) {
- entityConfig.setVampireMultiplicator(damageEntityConfig.getDouble("vampire_multiplicator"));
- } else if (damageEntityConfig.isInt("vampire_multiplicator")) {
- entityConfig.setVampireMultiplicator((double)damageEntityConfig.getInt("vampire_multiplicator"));
- } else {
- entityConfig.setVampireMultiplicator(0.5);
- hcPlugin.getLogger().warning("\"vampire_multiplicator\" for entity " + target.name() + " is invalid primitive");
- hcPlugin.getLogger().warning("Falling back to default (0.5)");
- }
- } else {
- entityConfig = null;
- }
-
- return entityConfig;
-
- }
-
- public boolean playerRespawnResetsHealth() {
- boolean respawnResetsHealth = false;
-
- if (hcPlugin.getConfig().isBoolean("spawning_resets_health")) {
- respawnResetsHealth = hcPlugin.getConfig().getBoolean("spawning_resets_health");
- } else {
- respawnResetsHealth = true;
- hcPlugin.getLogger().warning("\"spawning_resets_health\" is invalid primitive");
- hcPlugin.getLogger().warning("Falling back to default (true)");
- }
-
- return respawnResetsHealth;
- }
-
- public double getPlayerRespawnHealth() {
-
- double respawnHealth = 0;
-
- if (hcPlugin.getConfig().isDouble("start_health")) {
- respawnHealth = hcPlugin.getConfig().getDouble("start_health");
- } else if (hcPlugin.getConfig().isInt("start_health")) {
- respawnHealth = (double)hcPlugin.getConfig().getInt("start_health");
- } else {
- respawnHealth = 30;
- hcPlugin.getLogger().warning("\"start_health\" is invalid primitive");
- hcPlugin.getLogger().warning("Falling back to default (true)");
- }
-
- return respawnHealth;
-
- }
-
- public void save() {
- hcPlugin.saveDefaultConfig();
- }
-
-}
diff --git a/src/com/dhalucario/HealthContainer/HCController.java b/src/com/dhalucario/HealthContainer/HCController.java
deleted file mode 100644
index 2bfc6db..0000000
--- a/src/com/dhalucario/HealthContainer/HCController.java
+++ /dev/null
@@ -1,167 +0,0 @@
-package com.dhalucario.HealthContainer;
-
-import java.util.ArrayList;
-
-import org.bukkit.Material;
-import org.bukkit.attribute.Attribute;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.event.entity.EntityDamageByEntityEvent;
-import org.bukkit.event.entity.EntityPickupItemEvent;
-import org.bukkit.event.entity.ItemDespawnEvent;
-import org.bukkit.event.player.PlayerRespawnEvent;
-import org.bukkit.inventory.ItemStack;
-
-public class HCController implements Listener {
-
- JavaPlugin hcPlugin;
- HCConfigLoader hcConfigLoader;
- ArrayList hcItemList;
-
- public HCController(JavaPlugin plugin, HCConfigLoader configLoader) {
- hcPlugin = plugin;
- hcConfigLoader = configLoader;
- hcItemList = new ArrayList();
- }
-
- @EventHandler
- public void onPlayerRespawn(PlayerRespawnEvent e) {
- if (hcConfigLoader.playerRespawnResetsHealth()) {
- e.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hcConfigLoader.getPlayerRespawnHealth());
- }
- }
-
- @EventHandler
- public void onDamage(EntityDamageByEntityEvent e) {
-
- Entity damager = e.getDamager();
- Entity damagee = e.getEntity();
- double damage = e.getDamage();
-
- if (damager instanceof Player && damagee instanceof LivingEntity) {
-
- LivingEntity target = (LivingEntity) damagee;
- if ((target.getHealth() - damage) <= 0) {
- handleHeartContainer("death", (Player) damager, target);
- }
- }
- }
-
- @EventHandler
- public void onPlayerPickup(EntityPickupItemEvent e) {
- //Todo: Check if hearts are picked up
-
- if (e.getEntity() instanceof Player) {
-
- Player pickupPlayer = (Player)e.getEntity();
- int eventItemId = e.getItem().getEntityId();
-
- for (HCItem hcItem : hcItemList) {
- if (eventItemId == hcItem.healthItem.getEntityId()) {
- handleHeartContainer("pickup", pickupPlayer, hcItem.healthTarget);
- e.getItem().remove();
- e.setCancelled(true);
- }
- }
-
- }
- }
-
- public void onItemDespawn(ItemDespawnEvent e) {
-
- ArrayList tempRemoveList = new ArrayList();
-
- for (HCItem hcItem : hcItemList) {
- if (hcItem.healthItem.getEntityId() == e.getEntity().getEntityId()) {
- tempRemoveList.add(hcItem);
- }
- }
-
- for (HCItem tempItem : tempRemoveList) {
- hcItemList.remove(tempItem);
- }
-
- }
-
- void handleHeartContainer(String eventType, Player attacker, LivingEntity target) {
-
- HCEntityConfig entHealthConfig = hcConfigLoader.getConfigForEntity(target.getType());
-
- if (eventType == "death") {
-
- switch (entHealthConfig.getHealthType()) {
- case DROP_VALUE:
- handleDamageDrop(attacker, target);
- case DROP_VAMPIRE:
- handleDamageDrop(attacker, target);
- break;
- case DIRECT_VALUE:
- handleHealthDirectValue(attacker, entHealthConfig);
- break;
- case DIRECT_VAMPIRE:
- handleHealthDirectVampire(attacker, target, entHealthConfig);
- break;
- default:
- break;
- }
-
- } else if (eventType == "pickup") {
- switch (entHealthConfig.getHealthType()) {
- case DROP_VALUE:
- handleDamageDropPickupValue(attacker, entHealthConfig);
- break;
- case DROP_VAMPIRE:
- handleDamageDropPickupVampire(attacker, target, entHealthConfig);
- break;
- default:
- break;
- }
- }
-
- }
-
-
- void handleDamageDrop(Player attacker, LivingEntity target) {
- ItemStack healthDrop = new ItemStack(Material.RED_ROSE);
-
- HCItem hcItem = new HCItem();
- hcItem.setHealthTarget(target);
- hcItem.setHealthItemStack(target.getWorld().dropItemNaturally(target.getLocation(), healthDrop));
-
- hcItemList.add(hcItem);
- }
-
- void handleDamageDropPickupValue(Player attacker, HCEntityConfig healthConfig) {
- handleHealthDirectValue(attacker, healthConfig);
- }
-
- void handleDamageDropPickupVampire(Player attacker, LivingEntity target, HCEntityConfig healthConfig) {
- handleHealthDirectVampire(attacker, target, healthConfig);
- }
-
- void handleHealthDirectValue(Player attacker, HCEntityConfig healthConfig) {
- double attackerHealth = attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
-
- attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH)
- .setBaseValue(attackerHealth + healthConfig.getHealthValue());
- }
-
- void handleHealthDirectVampire(Player attacker, LivingEntity target, HCEntityConfig entConfig) {
- // Todo: Add health directly to the player
-
- double attackerHealth = attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
- HCEntityConfig healthConfig = hcConfigLoader.getConfigForEntity(target.getType());
- attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH)
- .setBaseValue(attackerHealth + getTargetVampireHealth(target, healthConfig));
- }
-
- double getTargetVampireHealth(LivingEntity target, HCEntityConfig healthConfig) {
- double targetHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
- return (targetHealth * healthConfig.getVampireMultiplicator());
- }
-
-}
\ No newline at end of file
diff --git a/src/com/dhalucario/HealthContainer/HCEntityConfig.java b/src/com/dhalucario/HealthContainer/HCEntityConfig.java
deleted file mode 100644
index 9d7682a..0000000
--- a/src/com/dhalucario/HealthContainer/HCEntityConfig.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.dhalucario.HealthContainer;
-
-public class HCEntityConfig {
- public HealthType healthType;
- public double healthValue;
- public double vampireMultiplicator;
-
- public HealthType getHealthType() {
- return healthType;
- }
-
- public void setHealthType(HealthType value) {
- healthType = value;
- }
-
- public void setHealthValue(double value) {
- healthValue = value;
- }
-
- public double getHealthValue() {
- return healthValue;
- }
-
- public double getVampireMultiplicator() {
- return vampireMultiplicator;
- }
-
- public void setVampireMultiplicator(double value) {
- vampireMultiplicator = value;
- }
-
-}
diff --git a/src/com/dhalucario/HealthContainer/HCItem.java b/src/com/dhalucario/HealthContainer/HCItem.java
deleted file mode 100644
index 9497967..0000000
--- a/src/com/dhalucario/HealthContainer/HCItem.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.dhalucario.HealthContainer;
-
-import org.bukkit.entity.Item;
-import org.bukkit.entity.LivingEntity;
-
-public class HCItem {
-
- public LivingEntity healthTarget;
- public Item healthItem;
-
- public LivingEntity getHealthTarget() {
- return healthTarget;
- }
-
- public void setHealthTarget(LivingEntity value) {
- healthTarget = value;
- }
-
- public void setHealthItemStack(Item value) {
- healthItem = value;
- }
-
- public Item getHealthItemStack() {
- return healthItem;
- }
-
-}
diff --git a/src/com/dhalucario/HealthContainer/Main.java b/src/com/dhalucario/HealthContainer/Main.java
deleted file mode 100644
index a164b7b..0000000
--- a/src/com/dhalucario/HealthContainer/Main.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.dhalucario.HealthContainer;
-
-import org.bukkit.plugin.java.JavaPlugin;
-
-public class Main extends JavaPlugin {
-
- HCConfigLoader hcConfigLoader;
-
- // Fired when plugin is first enabled
- @Override
- public void onEnable() {
- hcConfigLoader = new HCConfigLoader(this);
- hcConfigLoader.loadDefaults();
- getServer().getPluginManager().registerEvents(new HCController(this, hcConfigLoader), this);
- }
-
- // Fired when plugin is disabled
- @Override
- public void onDisable() {
- hcConfigLoader.save();
- hcConfigLoader = null;
- }
-
-}
-
diff --git a/src/com/dhalucario/HeartContainersReloaded/HCConfigLoader.java b/src/com/dhalucario/HeartContainersReloaded/HCConfigLoader.java
new file mode 100644
index 0000000..b0cb9e7
--- /dev/null
+++ b/src/com/dhalucario/HeartContainersReloaded/HCConfigLoader.java
@@ -0,0 +1,139 @@
+package com.dhalucario.HeartContainersReloaded;
+
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.configuration.MemorySection;
+import org.bukkit.entity.*;
+
+public class HCConfigLoader {
+
+ JavaPlugin hcPlugin;
+
+ public HCConfigLoader(JavaPlugin plugin) {
+ hcPlugin = plugin;
+ }
+
+ public void loadDefaults() {
+
+ hcPlugin.getConfig().options().copyDefaults(true);
+
+ hcPlugin.getConfig().addDefault("start_health", 3.0);
+ hcPlugin.getConfig().addDefault("max_health", 30.0);
+ hcPlugin.getConfig().addDefault("spawning_resets_health", true);
+
+ for (EntityType entType : EntityType.values()) {
+
+ /*
+ * drop_value: Drops a heart which contains the value specified using health_value
+ * drop_vampire: Drops a heart which contains the (health of the target * vampire_multiplicator)
+ * direct_value: Adds the value specified in health_value directly to the max health
+ * direct_vampire: Adds the value of (health of the target * vampire_multiplicator) directly to the max health
+ */
+ hcPlugin.getConfig().addDefault("health_config." + entType.name() + ".health_type", "NONE");
+ hcPlugin.getConfig().addDefault("health_config." + entType.name() + ".health_value", 0.5);
+ hcPlugin.getConfig().addDefault("health_config." + entType.name() + ".vampire_multiplicator", 0.5);
+ }
+
+ hcPlugin.saveDefaultConfig();
+ }
+
+ public HCEntityConfig getConfigForEntity(EntityType target) {
+
+ HCEntityConfig entityConfig = new HCEntityConfig();
+ MemorySection dropConfig = (MemorySection) hcPlugin.getConfig().get("health_config");
+ MemorySection damageEntityConfig = (MemorySection) dropConfig.get(target.name());
+
+ if (damageEntityConfig != null) {
+ if (damageEntityConfig.isString("health_type")) {
+
+ switch (damageEntityConfig.getString("health_type")) {
+ case "DROP_VALUE":
+ entityConfig.setHealthType(HealthType.DROP_VALUE);
+ break;
+ case "DROP_VAMPIRE":
+ entityConfig.setHealthType(HealthType.DROP_VAMPIRE);
+ break;
+ case "DIRECT_VALUE":
+ entityConfig.setHealthType(HealthType.DIRECT_VALUE);
+ break;
+ case "DIRECT_VAMPIRE":
+ entityConfig.setHealthType(HealthType.DIRECT_VAMPIRE);
+ break;
+ case "NONE":
+ entityConfig.setHealthType(HealthType.NONE);
+ break;
+ default:
+ hcPlugin.getLogger().warning("\"health_type\" for entity " + target.name() + " is an invalid type");
+ hcPlugin.getLogger().warning("Falling back to default (0.5)");
+ entityConfig.setHealthType(HealthType.DROP_VALUE);
+ break;
+ }
+ } else {
+ entityConfig.setVampireMultiplicator(0.5);
+ hcPlugin.getLogger().warning("\"health_type\" for entity " + target.name() + " is an invalid primitive");
+ hcPlugin.getLogger().warning("Falling back to default (0.5)");
+ }
+
+ if (damageEntityConfig.isDouble("health_value")) {
+ entityConfig.setHealthValue(damageEntityConfig.getDouble("health_value"));
+ } else if (damageEntityConfig.isInt("health_value")) {
+ entityConfig.setHealthValue(damageEntityConfig.getInt("health_value"));
+ } else {
+ entityConfig.setHealthValue(damageEntityConfig.getInt("health_value"));
+ hcPlugin.getLogger().warning("\"health_value\" for entity " + target.name() + " is an invalid primitive");
+ hcPlugin.getLogger().warning("Falling back to default (0.5)");
+ }
+
+ if (damageEntityConfig.isDouble("vampire_multiplicator")) {
+ entityConfig.setVampireMultiplicator(damageEntityConfig.getDouble("vampire_multiplicator"));
+ } else if (damageEntityConfig.isInt("vampire_multiplicator")) {
+ entityConfig.setVampireMultiplicator((double) damageEntityConfig.getInt("vampire_multiplicator"));
+ } else {
+ entityConfig.setVampireMultiplicator(0.5);
+ hcPlugin.getLogger().warning("\"vampire_multiplicator\" for entity " + target.name() + " is an invalid primitive");
+ hcPlugin.getLogger().warning("Falling back to default (0.5)");
+ }
+ } else {
+ entityConfig = null;
+ }
+
+ return entityConfig;
+
+ }
+
+ public boolean playerRespawnResetsHealth() {
+ boolean respawnResetsHealth = false;
+
+ if (hcPlugin.getConfig().isBoolean("spawning_resets_health")) {
+ respawnResetsHealth = hcPlugin.getConfig().getBoolean("spawning_resets_health");
+ } else {
+ respawnResetsHealth = true;
+ hcPlugin.getLogger().warning("\"spawning_resets_health\" is an invalid primitive");
+ hcPlugin.getLogger().warning("Falling back to default (true)");
+ }
+
+ return respawnResetsHealth;
+ }
+
+ public double getPlayerRespawnHealth() {
+
+ double respawnHealth = 0;
+
+ if (hcPlugin.getConfig().isDouble("start_health")) {
+ respawnHealth = hcPlugin.getConfig().getDouble("start_health");
+ } else if (hcPlugin.getConfig().isInt("start_health")) {
+ respawnHealth = (double) hcPlugin.getConfig().getInt("start_health");
+ } else {
+ respawnHealth = 30;
+ hcPlugin.getLogger().warning("\"start_health\" is an invalid primitive");
+ hcPlugin.getLogger().warning("Falling back to default (true)");
+ }
+
+ return respawnHealth;
+
+ }
+
+ public void save() {
+ hcPlugin.saveDefaultConfig();
+ }
+
+}
diff --git a/src/com/dhalucario/HeartContainersReloaded/HCController.java b/src/com/dhalucario/HeartContainersReloaded/HCController.java
new file mode 100644
index 0000000..df83ecc
--- /dev/null
+++ b/src/com/dhalucario/HeartContainersReloaded/HCController.java
@@ -0,0 +1,176 @@
+package com.dhalucario.HeartContainersReloaded;
+
+import java.util.ArrayList;
+
+import org.bukkit.Material;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.entity.EntityPickupItemEvent;
+import org.bukkit.event.entity.ItemDespawnEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class HCController implements Listener {
+
+ JavaPlugin hcPlugin;
+ HCConfigLoader hcConfigLoader;
+ ArrayList hcItemList;
+
+ public HCController(JavaPlugin plugin, HCConfigLoader configLoader) {
+ hcPlugin = plugin;
+ hcConfigLoader = configLoader;
+ hcItemList = new ArrayList();
+ }
+
+ @EventHandler
+ public void onPlayerRespawn(PlayerRespawnEvent e) {
+ if (hcConfigLoader.playerRespawnResetsHealth()) {
+ e.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hcConfigLoader.getPlayerRespawnHealth());
+ }
+ }
+
+ @EventHandler
+ public void onDamage(EntityDamageByEntityEvent e) {
+
+ Entity damager = e.getDamager();
+ Entity damagee = e.getEntity();
+ double damage = e.getDamage();
+
+ if (damager instanceof Player && damagee instanceof LivingEntity) {
+
+ LivingEntity target = (LivingEntity) damagee;
+ if ((target.getHealth() - damage) <= 0) {
+ handleHeartContainer("death", (Player) damager, target);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerPickup(EntityPickupItemEvent e) {
+ //Todo: Check if hearts are picked up
+
+ if (e.getEntity() instanceof Player) {
+
+ Player pickupPlayer = (Player) e.getEntity();
+ int eventItemId = e.getItem().getEntityId();
+
+ for (HCItem hcItem : hcItemList) {
+ if (eventItemId == hcItem.healthItem.getEntityId()) {
+ handleHeartContainer("pickup", pickupPlayer, hcItem.healthTarget);
+ e.getItem().remove();
+ e.setCancelled(true);
+ }
+ }
+
+ }
+ }
+
+ public void onItemDespawn(ItemDespawnEvent e) {
+
+ ArrayList tempRemoveList = new ArrayList();
+
+ for (HCItem hcItem : hcItemList) {
+ if (hcItem.healthItem.getEntityId() == e.getEntity().getEntityId()) {
+ tempRemoveList.add(hcItem);
+ }
+ }
+
+ for (HCItem tempItem : tempRemoveList) {
+ hcItemList.remove(tempItem);
+ }
+
+ }
+
+ void handleHeartContainer(String eventType, Player attacker, LivingEntity target) {
+
+ HCEntityConfig entHealthConfig = hcConfigLoader.getConfigForEntity(target.getType());
+
+ if (eventType == "death") {
+
+ switch (entHealthConfig.getHealthType()) {
+ case DROP_VALUE:
+ handleDamageDrop(attacker, target);
+ case DROP_VAMPIRE:
+ handleDamageDrop(attacker, target);
+ break;
+ case DIRECT_VALUE:
+ handleHealthDirectValue(attacker, entHealthConfig);
+ break;
+ case DIRECT_VAMPIRE:
+ handleHealthDirectVampire(attacker, target, entHealthConfig);
+ break;
+ default:
+ break;
+ }
+
+ } else if (eventType == "pickup") {
+ switch (entHealthConfig.getHealthType()) {
+ case DROP_VALUE:
+ handleDamageDropPickupValue(attacker, entHealthConfig);
+ break;
+ case DROP_VAMPIRE:
+ handleDamageDropPickupVampire(attacker, target, entHealthConfig);
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+
+ void handleDamageDrop(Player attacker, LivingEntity target) {
+ ItemStack healthDrop = new ItemStack(Material.RED_DYE);
+
+ HCItem hcItem = new HCItem();
+ hcItem.setHealthTarget(target);
+ hcItem.setHealthItemStack(target.getWorld().dropItemNaturally(target.getLocation(), healthDrop));
+
+ hcItemList.add(hcItem);
+ }
+
+ void handleDamageDropPickupValue(Player attacker, HCEntityConfig healthConfig) {
+ handleHealthDirectValue(attacker, healthConfig);
+ }
+
+ void handleDamageDropPickupVampire(Player attacker, LivingEntity target, HCEntityConfig healthConfig) {
+ handleHealthDirectVampire(attacker, target, healthConfig);
+ }
+
+ void handleHealthDirectValue(Player attacker, HCEntityConfig healthConfig) {
+ double attackerHealth = attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
+ double additionalHealth = healthConfig.getHealthValue();
+ double newHealthValue = attackerHealth + additionalHealth;
+
+ attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH)
+ .setBaseValue(attackerHealth + healthConfig.getHealthValue());
+
+ attacker.sendMessage("Your new health value is " + Double.toString(newHealthValue) + " (+" + Double.toString(additionalHealth) + ")");
+ }
+
+ void handleHealthDirectVampire(Player attacker, LivingEntity target, HCEntityConfig entConfig) {
+ // Todo: Add health directly to the player
+ HCEntityConfig healthConfig = hcConfigLoader.getConfigForEntity(target.getType());
+
+ double attackerHealth = attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
+ double vampireHealth = getTargetVampireHealth(target, healthConfig);
+ double newHealthValue = attackerHealth + vampireHealth;
+
+ attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH)
+ .setBaseValue(newHealthValue);
+
+ attacker.sendMessage("Your new health value is " + Double.toString(newHealthValue) + " (+" + Double.toString(vampireHealth) + ")");
+ }
+
+ double getTargetVampireHealth(LivingEntity target, HCEntityConfig healthConfig) {
+ double targetHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
+ return (targetHealth * healthConfig.getVampireMultiplicator());
+ }
+
+}
\ No newline at end of file
diff --git a/src/com/dhalucario/HeartContainersReloaded/HCEntityConfig.java b/src/com/dhalucario/HeartContainersReloaded/HCEntityConfig.java
new file mode 100644
index 0000000..25a0017
--- /dev/null
+++ b/src/com/dhalucario/HeartContainersReloaded/HCEntityConfig.java
@@ -0,0 +1,32 @@
+package com.dhalucario.HeartContainersReloaded;
+
+public class HCEntityConfig {
+ public HealthType healthType;
+ public double healthValue;
+ public double vampireMultiplicator;
+
+ public HealthType getHealthType() {
+ return healthType;
+ }
+
+ public void setHealthType(HealthType value) {
+ healthType = value;
+ }
+
+ public void setHealthValue(double value) {
+ healthValue = value;
+ }
+
+ public double getHealthValue() {
+ return healthValue;
+ }
+
+ public double getVampireMultiplicator() {
+ return vampireMultiplicator;
+ }
+
+ public void setVampireMultiplicator(double value) {
+ vampireMultiplicator = value;
+ }
+
+}
diff --git a/src/com/dhalucario/HeartContainersReloaded/HCItem.java b/src/com/dhalucario/HeartContainersReloaded/HCItem.java
new file mode 100644
index 0000000..f452759
--- /dev/null
+++ b/src/com/dhalucario/HeartContainersReloaded/HCItem.java
@@ -0,0 +1,27 @@
+package com.dhalucario.HeartContainersReloaded;
+
+import org.bukkit.entity.Item;
+import org.bukkit.entity.LivingEntity;
+
+public class HCItem {
+
+ public LivingEntity healthTarget;
+ public Item healthItem;
+
+ public LivingEntity getHealthTarget() {
+ return healthTarget;
+ }
+
+ public void setHealthTarget(LivingEntity value) {
+ healthTarget = value;
+ }
+
+ public void setHealthItemStack(Item value) {
+ healthItem = value;
+ }
+
+ public Item getHealthItemStack() {
+ return healthItem;
+ }
+
+}
diff --git a/src/com/dhalucario/HealthContainer/HealthType.java b/src/com/dhalucario/HeartContainersReloaded/HealthType.java
similarity index 76%
rename from src/com/dhalucario/HealthContainer/HealthType.java
rename to src/com/dhalucario/HeartContainersReloaded/HealthType.java
index ed9cf89..68b2720 100644
--- a/src/com/dhalucario/HealthContainer/HealthType.java
+++ b/src/com/dhalucario/HeartContainersReloaded/HealthType.java
@@ -1,4 +1,4 @@
-package com.dhalucario.HealthContainer;
+package com.dhalucario.HeartContainersReloaded;
/*
* drop_value: Drops a heart which contains the value specified using health_value
@@ -8,8 +8,9 @@ package com.dhalucario.HealthContainer;
*/
public enum HealthType {
- DROP_VALUE,
- DROP_VAMPIRE,
- DIRECT_VALUE,
- DIRECT_VAMPIRE,
+ DROP_VALUE,
+ DROP_VAMPIRE,
+ DIRECT_VALUE,
+ DIRECT_VAMPIRE,
+ NONE,
}
diff --git a/src/com/dhalucario/HeartContainersReloaded/Main.java b/src/com/dhalucario/HeartContainersReloaded/Main.java
new file mode 100644
index 0000000..15058e4
--- /dev/null
+++ b/src/com/dhalucario/HeartContainersReloaded/Main.java
@@ -0,0 +1,25 @@
+package com.dhalucario.HeartContainersReloaded;
+
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Main extends JavaPlugin {
+
+ HCConfigLoader hcConfigLoader;
+
+ // Fired when plugin is first enabled
+ @Override
+ public void onEnable() {
+ hcConfigLoader = new HCConfigLoader(this);
+ hcConfigLoader.loadDefaults();
+ getServer().getPluginManager().registerEvents(new HCController(this, hcConfigLoader), this);
+ }
+
+ // Fired when plugin is disabled
+ @Override
+ public void onDisable() {
+ hcConfigLoader.save();
+ hcConfigLoader = null;
+ }
+
+}
+