-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# ========================= | ||
# Operating System Files | ||
# ========================= | ||
|
||
# OSX | ||
# ========================= | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear on external disk | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# Windows | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
# ZEINTELLIJ | ||
.idea | ||
*.iml | ||
workspace.xml | ||
tasks.xml | ||
.idea/libraries | ||
.idea/copyright | ||
out/ | ||
target/ | ||
*.MF | ||
*.name |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>to.us.mlgfort</groupId> | ||
<artifactId>MLGDamageIndicators</artifactId> | ||
<version>1.0</version> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<repositories> | ||
<repository> | ||
<id>paper-repo</id> | ||
<url>https://repo.destroystokyo.com/repository/maven-public/</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<finalName>${project.name}</finalName> | ||
<resources> | ||
<resource> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>plugin.yml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.destroystokyo.paper</groupId> | ||
<artifactId>paper-api</artifactId> | ||
<version>1.12-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.gmail.filoghost</groupId> | ||
<artifactId>HolographicDisplays</artifactId> | ||
<version>2.2.1</version> | ||
<scope>system</scope> | ||
<systemPath>${basedir}/lib/HolographicDisplays.jar</systemPath> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.MLG-Fortress</groupId> | ||
<artifactId>AbsorptionShields</artifactId> | ||
<version>beta</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
126 changes: 126 additions & 0 deletions
126
src/main/java/to/us/mlgfort/mlgdamageindicators/MLGDamageIndicators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package to.us.mlgfort.mlgdamageindicators; | ||
|
||
import com.gmail.filoghost.holographicdisplays.api.Hologram; | ||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.EntityRegainHealthEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.math.RoundingMode; | ||
import java.text.DecimalFormat; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* Created on 7/7/2017. | ||
* | ||
* @author RoboMWM | ||
*/ | ||
public class MLGDamageIndicators extends JavaPlugin implements Listener | ||
{ | ||
JavaPlugin instance; | ||
Set<Hologram> activeHolograms = new HashSet<>(); | ||
DecimalFormat df = new DecimalFormat("#.#"); | ||
|
||
public void onEnable() | ||
{ | ||
instance = this; | ||
instance.getServer().getPluginManager().registerEvents(this, instance); | ||
if (instance.getServer().getPluginManager().getPlugin("AbsorptionShields") != null) | ||
instance.getServer().getPluginManager().registerEvents(new ShieldDamageListener(this), instance); | ||
df.setRoundingMode(RoundingMode.HALF_UP); | ||
} | ||
|
||
public void onDisable() | ||
{ | ||
getLogger().info("Cleaning up any active damage indicator holograms..."); | ||
getLogger().info(String.valueOf(cleanupDamageIndicators()) + " holograms removed."); | ||
} | ||
|
||
public int cleanupDamageIndicators() | ||
{ | ||
for (Hologram hologram : activeHolograms) | ||
{ | ||
hologram.delete(); | ||
} | ||
int i = activeHolograms.size(); | ||
activeHolograms.clear(); | ||
return i; | ||
} | ||
|
||
//I'm trying to remember why I use highest instead of Monitor. Maybe for plugins that alter behavior (e.g. respawns, minigames) in damage event? | ||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
void onDisplayDamageIndicator(EntityDamageByEntityEvent event) | ||
{ | ||
if (event.getFinalDamage() <= 0.05D) | ||
return; | ||
if (!(event.getEntity() instanceof LivingEntity)) | ||
return; | ||
Entity entity = event.getEntity(); | ||
displayIndicator(entity.getLocation(), event.getFinalDamage() / 2D, true); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
void onDisplayHealthRegenIndicator(EntityRegainHealthEvent event) | ||
{ | ||
if (event.getAmount() <= 0.05D) | ||
return; | ||
if (!(event.getEntity() instanceof LivingEntity)) | ||
return; | ||
Entity entity = event.getEntity(); | ||
displayIndicator(entity.getLocation(), event.getAmount() / 2D, false); | ||
} | ||
|
||
public static Double r4nd0m(double min, double max) { | ||
return ThreadLocalRandom.current().nextDouble(min, max); | ||
} | ||
|
||
public void displayIndicator(final Location location, final double value, final boolean isDamage) | ||
{ | ||
ChatColor color; | ||
if (isDamage) | ||
color = ChatColor.RED; | ||
else | ||
color = ChatColor.GREEN; | ||
displayIndicator(location, value, isDamage, color); | ||
} | ||
|
||
public void displayIndicator(final Location location, final double value, final boolean isDamage, ChatColor color) | ||
{ | ||
double x = r4nd0m(-0.3D, 0.3D); | ||
double z = r4nd0m(-0.3D, 0.3D); | ||
Hologram hologram = HologramsAPI.createHologram(instance, location.add(x, 2D, z)); | ||
if (isDamage) | ||
hologram.appendTextLine(color + "-" + df.format(value)); | ||
else | ||
hologram.appendTextLine(color + "+" + df.format(value)); | ||
activeHolograms.add(hologram); | ||
|
||
new BukkitRunnable() | ||
{ | ||
int duration = 2; | ||
|
||
public void run() | ||
{ | ||
duration--; | ||
if (duration <= 0) | ||
{ | ||
hologram.delete(); | ||
activeHolograms.remove(hologram); | ||
this.cancel(); | ||
return; | ||
} | ||
hologram.teleport(hologram.getLocation().add(0D, 1D, 0D)); | ||
} | ||
}.runTaskTimer(instance, 1L, ((long)value / 2) + 20L); //Increase display duration by a second per 40 hearts of damage. | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/to/us/mlgfort/mlgdamageindicators/ShieldDamageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package to.us.mlgfort.mlgdamageindicators; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import to.us.tf.absorptionshields.event.ShieldDamageEvent; | ||
|
||
/** | ||
* Created on 7/7/2017. | ||
* | ||
* @author RoboMWM | ||
*/ | ||
public class ShieldDamageListener implements Listener | ||
{ | ||
MLGDamageIndicators instance; | ||
|
||
ShieldDamageListener(MLGDamageIndicators plugin) | ||
{ | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
instance = plugin; | ||
} | ||
|
||
@EventHandler | ||
private void onShieldDamage(ShieldDamageEvent event) | ||
{ | ||
if (!(event.getBaseEvent() instanceof EntityDamageByEntityEvent)) | ||
return; | ||
if (event.getDamage() <= 0.05D) | ||
return; | ||
instance.displayIndicator(event.getVictim().getLocation(), event.getDamage(), true, ChatColor.BLUE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: MLGDamageIndicators | ||
version: ${project.version} | ||
website: https://github.com/MLG-Fortress | ||
description: Displays damage indicators in the form of holograms. Is used and originally created for the MLG Fortress server as part of the MountainDewritoes server plugin. | ||
author: RoboMWM | ||
main: to.us.mlgfort.mlgdamageindicators.MLGDamageIndicators | ||
depend: | ||
- HolographicDisplays | ||
softdepend: | ||
- AbsorptionShields |