Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
d0by1 committed Dec 16, 2022
2 parents 8ae60c0 + 6925990 commit 66bd265
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import eu.decentsoftware.holograms.api.utils.location.LocationUtils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -20,6 +21,10 @@ public class DamageDisplayFeature extends AbstractFeature implements Listener {
private static final DecentHolograms PLUGIN = DecentHologramsAPI.get();
private int duration = 40;
private String appearance = "&c+ {damage}";
private boolean displayForPlayers = true;
private boolean displayForMobs = true;
private boolean zeroDamage = false;
private double heightOffset = 0.0;

public DamageDisplayFeature() {
super("damage_display");
Expand All @@ -35,6 +40,12 @@ public void reload() {
duration = config.getInt("damage-display.duration", duration);
appearance = config.getString("damage-display.appearance", appearance);

heightOffset = config.getDouble("healing-display.height", heightOffset);

displayForPlayers = config.getBoolean("damage-display.players", displayForPlayers);
displayForMobs = config.getBoolean("damage-display.mobs", displayForMobs);
zeroDamage = config.getBoolean("damage-display.mobs", zeroDamage);

if (enabled) {
this.enable();
}
Expand Down Expand Up @@ -70,12 +81,22 @@ public void onDamage(EntityDamageEvent e) {
}

double damage = e.getFinalDamage();
if (damage <= 0d) {

if (damage <= 0d && !zeroDamage) {
return;
}

Entity entity = e.getEntity();
Location location = LocationUtils.randomizeLocation(entity.getLocation().clone().add(0, 1, 0));

if (entity instanceof Player && !displayForPlayers) {
return;
}

if (!(entity instanceof Player) && !displayForMobs) {
return;
}

Location location = LocationUtils.randomizeLocation(entity.getLocation().clone().add(0, 1 + heightOffset, 0));
String text = appearance.replace("{damage}", FeatureCommons.formatNumber(damage));
PLUGIN.getHologramManager().spawnTemporaryHologramLine(location, text, duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import eu.decentsoftware.holograms.api.utils.location.LocationUtils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -20,6 +21,9 @@ public class HealingDisplayFeature extends AbstractFeature implements Listener {
private static final DecentHolograms PLUGIN = DecentHologramsAPI.get();
private int duration = 40;
private String appearance = "&a+ {heal}";
private boolean displayForPlayers = true;
private boolean displayForMobs = true;
private double heightOffset = 0.0;

public HealingDisplayFeature() {
super("healing_display");
Expand All @@ -35,6 +39,11 @@ public void reload() {
duration = config.getInt("healing-display.duration", duration);
appearance = config.getString("healing-display.appearance", appearance);

heightOffset = config.getDouble("healing-display.height", heightOffset);

displayForPlayers = config.getBoolean("damage-display.players", displayForPlayers);
displayForMobs = config.getBoolean("damage-display.mobs", displayForMobs);

if (enabled) {
this.enable();
}
Expand Down Expand Up @@ -64,7 +73,7 @@ public String getDescription() {
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityRegainHealthEvent e) {
public void onRegain(EntityRegainHealthEvent e) {
if (e.isCancelled()) {
return;
}
Expand All @@ -75,7 +84,16 @@ public void onDamage(EntityRegainHealthEvent e) {
}

Entity entity = e.getEntity();
Location location = LocationUtils.randomizeLocation(entity.getLocation().clone().add(0, 1, 0));

if (entity instanceof Player && !displayForPlayers) {
return;
}

if (!(entity instanceof Player) && !displayForMobs) {
return;
}

Location location = LocationUtils.randomizeLocation(entity.getLocation().clone().add(0, 1 + heightOffset, 0));
String text = appearance.replace("{heal}", FeatureCommons.formatNumber(heal));
PLUGIN.getHologramManager().spawnTemporaryHologramLine(location, text, duration);
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ allow-placeholders-inside-animations: false
damage-display:
# Do you want this feature enabled? [true/false]
enabled: false
# Do you want to display damage for players? [true/false]
players: true
# Do you want to display damage for mobs? [true/false]
mobs: true
# Do you want to display 0 (or less) damage? [true/false]
zero-damage: false
# How long will the hologram stay in ticks
duration: 40
# Damage placeholder: {damage}
# Animations and Placeholders DO work here
appearance: '&c{damage}'
# Height offset
height: 0



Expand All @@ -88,12 +96,17 @@ damage-display:
healing-display:
# Do you want this feature enabled? [true/false]
enabled: false
# Do you want to display healing for players? [true/false]
players: true
# Do you want to display healing for mobs? [true/false]
mobs: true
# How long will the hologram stay in ticks
duration: 40
# Heal placeholder: {heal}
# Animations and Placeholders DO work here
appearance: '&a+ {heal}'

# Height offset
height: 0


# # # # # # # # # # # # # # # # #
Expand Down

0 comments on commit 66bd265

Please sign in to comment.