Skip to content

Commit

Permalink
Make MedKitHandler apply Regen to nearby players when used
Browse files Browse the repository at this point in the history
Make radius to check for nearby players configurable
Make sure nearby player doesn't heave full health or regeneration
  • Loading branch information
xsmeths committed May 11, 2021
1 parent c285e49 commit 2181025
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/me/smeths/and/rhetorical/Handlers/MedKitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -49,12 +50,27 @@ public void run()
} else if (progress == total) {
if (MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") && MedCraft.getPlugin().getConfig().getBoolean("MedKit.ConsoleCMD") && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
for (Entity e : p.getNearbyEntities(MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"))){
if (e instanceof Player)
if (!((Player) e).hasPotionEffect(PotionEffectType.REGENERATION) && ((Player) e).getHealth() < ((Player) e).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
((Player)e).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
}
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.valueOf(MedCraft.getPlugin().getConfig().get("MedKit.CMD")).replace("[playername]", p.getName()));
} else if (p.getPlayer() != null && MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") && !MedCraft.getPlugin().getConfig().getBoolean("MedKit.ConsoleCMD") && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
for (Entity e : p.getNearbyEntities(MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"))){
if (e instanceof Player)
if (!((Player) e).hasPotionEffect(PotionEffectType.REGENERATION) && ((Player) e).getHealth() < ((Player) e).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
((Player)e).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
}
Bukkit.dispatchCommand(p.getPlayer(),String.valueOf(MedCraft.getPlugin().getConfig().get("MedKit.CMD")).replace("[playername]", p.getName()));
} else if (!MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
for (Entity e : p.getNearbyEntities(MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"),MedCraft.getPlugin().getConfig().getDouble("MedKit.Radius"))){
if (e instanceof Player)
if (!((Player) e).hasPotionEffect(PotionEffectType.REGENERATION) && ((Player) e).getHealth() < ((Player) e).getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
((Player)e).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
}
} else {
p.getWorld().dropItem(p.getLocation(),ItemLoader.getMedKitItem());
MedKitHandler.MedKitPlayers.remove(p);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Bandage:
MedKit:
Material: PAPER
Glows: true
Radius: 5
Warmup-Speed: 1
Result-Amount: 1
ModelData: 18
Expand Down

0 comments on commit 2181025

Please sign in to comment.