Skip to content

Commit

Permalink
Merge pull request #1 from AleksanderEvensen/totem-fix
Browse files Browse the repository at this point in the history
Totem of Undying fix
  • Loading branch information
griimnak authored Dec 5, 2019
2 parents 22770bc + 7ca8353 commit 5cdf759
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
@@ -36,7 +37,28 @@ public void onPlayerDamage(EntityDamageEvent event) {
}

// if hp - dmg less or equal 0.0
if((damaged.getHealth() - event.getFinalDamage()) <= 0.0D) {
if((damaged.getHealth() - event.getFinalDamage()) <= 0.0D) {

/*
==========
Totem fix
==========
*/
// Check if totems are enabled in the config
if(ConfigManager.config.getBoolean("TotemOfUndyingWorks")){
// Check if player is holding a Totem of Undying in Main- or Offhand
if(damaged.getInventory().getItemInMainHand().getType().equals(Material.TOTEM_OF_UNDYING) ||
damaged.getInventory().getItemInOffHand().getType().equals(Material.TOTEM_OF_UNDYING)){

// Play the totem effect.
// Removing the totem from the players hand is unnecessary because the spawnParticle will handle it.
damaged.spawnParticle(Particle.TOTEM, damaged.getLocation(), 1);
damaged.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + ConfigManager.config.getString("TotemDeathPlayerText"));
// return so the player won't be teleported to their bed or loose the amount of hearts specified.
return;
}
}

// max hp of damaged player
double max_hp = damaged.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
if(max_hp - ConfigManager.config.getDouble("LoseMaxHealthOnRespawnAmmount") > 0.0D) {
8 changes: 8 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -34,3 +34,11 @@ RespawnWildText: "With no place of rest set, you awake from your dream in famili



#Totme fixed
TotemOfUndyingWorks: true # Disable or enable the Totem of Undying
TotemDeathPlayerText: "A magical power saves you from a potential casualty." # Text to display for the user when he/she uses a Totem of Undying





0 comments on commit 5cdf759

Please sign in to comment.