Move to IntelliJ and add notifications
This commit is contained in:
parent
ac7468db16
commit
28d4edd794
19 changed files with 460 additions and 621 deletions
|
@ -1,7 +0,0 @@
|
|||
<?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>
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -23,3 +23,7 @@
|
|||
hs_err_pid*
|
||||
|
||||
.settings
|
||||
|
||||
# IDEA
|
||||
.idea
|
||||
out
|
||||
|
|
17
.project
17
.project
|
@ -1,17 +0,0 @@
|
|||
<?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>
|
14
HeartContainersReloaded.iml
Normal file
14
HeartContainersReloaded.iml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Spigot-API-1.14.4-065a373-20190828-0953" level="project" />
|
||||
</component>
|
||||
</module>
|
199
config.yml
199
config.yml
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||
name: HealthContainerPlugin
|
||||
main: com.dhalucario.HealthContainer.Main
|
||||
version: 1.0
|
||||
api-version: 1.13
|
||||
commands:
|
31
res/config.yml
Normal file
31
res/config.yml
Normal file
|
@ -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
|
5
res/plugin.yml
Normal file
5
res/plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: HeartContainersReloaded
|
||||
main: com.dhalucario.HeartContainersReloaded.Main
|
||||
version: 1.0
|
||||
api-version: 1.13
|
||||
commands:
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
139
src/com/dhalucario/HeartContainersReloaded/HCConfigLoader.java
Normal file
139
src/com/dhalucario/HeartContainersReloaded/HCConfigLoader.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
176
src/com/dhalucario/HeartContainersReloaded/HCController.java
Normal file
176
src/com/dhalucario/HeartContainersReloaded/HCController.java
Normal file
|
@ -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<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_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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
27
src/com/dhalucario/HeartContainersReloaded/HCItem.java
Normal file
27
src/com/dhalucario/HeartContainersReloaded/HCItem.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
@ -12,4 +12,5 @@ public enum HealthType {
|
|||
DROP_VAMPIRE,
|
||||
DIRECT_VALUE,
|
||||
DIRECT_VAMPIRE,
|
||||
NONE,
|
||||
}
|
25
src/com/dhalucario/HeartContainersReloaded/Main.java
Normal file
25
src/com/dhalucario/HeartContainersReloaded/Main.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in a new issue