Commit plugin beta
This commit is contained in:
parent
2c2c0fe5ae
commit
ac7468db16
11 changed files with 631 additions and 0 deletions
7
.classpath
Normal file
7
.classpath
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Dhalucario/Desktop/spigot-api-1.12.2-R0.1-SNAPSHOT-shaded.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -22,3 +22,4 @@
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
|
.settings
|
17
.project
Normal file
17
.project
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>ZeldaHeartsReborn</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
199
config.yml
Normal file
199
config.yml
Normal file
|
@ -0,0 +1,199 @@
|
||||||
|
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
|
5
plugin.yml
Normal file
5
plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: HealthContainerPlugin
|
||||||
|
main: com.dhalucario.HealthContainer.Main
|
||||||
|
version: 1.0
|
||||||
|
api-version: 1.13
|
||||||
|
commands:
|
136
src/com/dhalucario/HealthContainer/HCConfigLoader.java
Normal file
136
src/com/dhalucario/HealthContainer/HCConfigLoader.java
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
167
src/com/dhalucario/HealthContainer/HCController.java
Normal file
167
src/com/dhalucario/HealthContainer/HCController.java
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
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<HCItem> hcItemList;
|
||||||
|
|
||||||
|
public HCController(JavaPlugin plugin, HCConfigLoader configLoader) {
|
||||||
|
hcPlugin = plugin;
|
||||||
|
hcConfigLoader = configLoader;
|
||||||
|
hcItemList = new ArrayList<HCItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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<HCItem> tempRemoveList = new ArrayList<HCItem>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
src/com/dhalucario/HealthContainer/HCEntityConfig.java
Normal file
32
src/com/dhalucario/HealthContainer/HCEntityConfig.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/com/dhalucario/HealthContainer/HCItem.java
Normal file
27
src/com/dhalucario/HealthContainer/HCItem.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/com/dhalucario/HealthContainer/HealthType.java
Normal file
15
src/com/dhalucario/HealthContainer/HealthType.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package com.dhalucario.HealthContainer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum HealthType {
|
||||||
|
DROP_VALUE,
|
||||||
|
DROP_VAMPIRE,
|
||||||
|
DIRECT_VALUE,
|
||||||
|
DIRECT_VAMPIRE,
|
||||||
|
}
|
25
src/com/dhalucario/HealthContainer/Main.java
Normal file
25
src/com/dhalucario/HealthContainer/Main.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue