Skip to content

Commit

Permalink
Apply coding conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinLMayes committed Aug 25, 2017
1 parent a167443 commit eac731e
Show file tree
Hide file tree
Showing 83 changed files with 3,066 additions and 2,708 deletions.
210 changes: 106 additions & 104 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,109 +1,111 @@
<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>tc.oc</groupId>
<artifactId>tracker</artifactId>
<version>1.8-SNAPSHOT</version>
<name>Tracker</name>
<description>Bukkit plugin and API for tracking entity damage and deaths.</description>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>tc.oc</groupId>
<artifactId>tracker</artifactId>
<version>1.8-SNAPSHOT</version>
<name>Tracker</name>
<description>Bukkit plugin and API for tracking entity damage and deaths.</description>

<scm>
<connection>scm:git:[email protected]:Avicus/Tracker.git</connection>
<developerConnection>scm:git:[email protected]:Avicus/Tracker.git</developerConnection>
<url>https://github.com/Avicus/Tracker</url>
</scm>
<scm>
<connection>scm:git:[email protected]:Avicus/Tracker.git</connection>
<developerConnection>scm:git:[email protected]:Avicus/Tracker.git</developerConnection>
<url>https://github.com/Avicus/Tracker</url>
</scm>

<distributionManagement>
<repository>
<id>avicus-repo</id>
<url>https://repo.avicus.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>avicus-repo</id>
<url>https://repo.avicus.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<distributionManagement>
<repository>
<id>avicus-repo</id>
<url>https://repo.avicus.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>avicus-repo</id>
<url>https://repo.avicus.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

<repositories>
<repository>
<id>overcast</id>
<url>https://repo.oc.tc/content/groups/public</url>
</repository>
<repository>
<id>avicus-public</id>
<url>https://repo.avicus.net/content/groups/public</url>
</repository>
<repository>
<id>avicus-private</id>
<url>https://repo.avicus.net/content/groups/private/</url>
</repository>
</repositories>
<repositories>
<repository>
<id>overcast</id>
<url>https://repo.oc.tc/content/groups/public</url>
</repository>
<repository>
<id>avicus-public</id>
<url>https://repo.avicus.net/content/groups/public</url>
</repository>
<repository>
<id>avicus-private</id>
<url>https://repo.avicus.net/content/groups/private/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.avicus</groupId>
<artifactId>magnet-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>joda-time:joda-time</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.avicus</groupId>
<artifactId>magnet-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>joda-time:joda-time</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
71 changes: 37 additions & 34 deletions src/main/java/tc/oc/tracker/Damage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tc.oc.tracker;

import javax.annotation.Nonnull;

import org.bukkit.Location;
import org.joda.time.Instant;

Expand All @@ -11,40 +10,44 @@
* Implementations should be immutable.
*/
public interface Damage {
/**
* Gets the amount of damage that was inflicted.
*
* Note that this is the raw damage in half-hearts before dampeners (armor,
* potion effects) are applied.
*
* Contract specifies that the result is 0 or greater.
*
* @return Amount of damage inflicted
*/
int getDamage();

/**
* Gets the location where the damage occurred.
*
* Contract specifies that the result is never null.
*
* @return Location of damage
*/
@Nonnull Location getLocation();
/**
* Gets the amount of damage that was inflicted.
*
* Note that this is the raw damage in half-hearts before dampeners (armor,
* potion effects) are applied.
*
* Contract specifies that the result is 0 or greater.
*
* @return Amount of damage inflicted
*/
int getDamage();

/**
* Gets the location where the damage occurred.
*
* Contract specifies that the result is never null.
*
* @return Location of damage
*/
@Nonnull
Location getLocation();

/**
* Gets the time that the damage occurred.
*
* Contract specifies that the result is never null.
*
* @return Time of damage
*/
@Nonnull Instant getTime();
/**
* Gets the time that the damage occurred.
*
* Contract specifies that the result is never null.
*
* @return Time of damage
*/
@Nonnull
Instant getTime();

/**
* Gets additional information regarding this damage.
*
* @return {@link DamageInfo} subclass describing the damage in more detail
*/
@Nonnull DamageInfo getInfo();
/**
* Gets additional information regarding this damage.
*
* @return {@link DamageInfo} subclass describing the damage in more detail
*/
@Nonnull
DamageInfo getInfo();
}
80 changes: 40 additions & 40 deletions src/main/java/tc/oc/tracker/DamageAPI.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package tc.oc.tracker;

import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;

import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;

import tc.oc.tracker.plugin.DamageAPIHelper;

import com.google.common.base.Preconditions;

/**
* Provides convenient static API calls for other plugins to use.
*/
public final class DamageAPI {
private DamageAPI() { }

/**
* Inflicts the given damage on an entity.
*
* This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
*
* @param entity Entity to inflict damage upon
* @param damage Amount of half-hearts of damage to inflict
* @param info {@link DamageInfo} object that details the type of damage
* @return the final {@link Damage} object (never null)
*
* @throws NullPointerException if entity or info is null
* @throws IllegalArgumentExcpetion if hearts is less than zero
*/
public static @Nonnull Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
Preconditions.checkNotNull(entity, "living entity");
Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
Preconditions.checkNotNull(info, "damage info");

DamageAPIHelper helper = DamageAPIHelper.get();

EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
helper.setEventDamageInfo(event, info);

Bukkit.getPluginManager().callEvent(event);

if(event.isCancelled()) {
return null;
}

entity.damage(event.getDamage());

helper.setEventDamageInfo(event, null);

return helper.getOurEvent(event).toDamageObject();

private DamageAPI() {
}

/**
* Inflicts the given damage on an entity.
*
* This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
*
* @param entity Entity to inflict damage upon
* @param damage Amount of half-hearts of damage to inflict
* @param info {@link DamageInfo} object that details the type of damage
* @return the final {@link Damage} object (never null)
* @throws NullPointerException if entity or info is null
* @throws IllegalArgumentExcpetion if hearts is less than zero
*/
public static
@Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
Preconditions.checkNotNull(entity, "living entity");
Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
Preconditions.checkNotNull(info, "damage info");

DamageAPIHelper helper = DamageAPIHelper.get();

EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
helper.setEventDamageInfo(event, info);

Bukkit.getPluginManager().callEvent(event);

if (event.isCancelled()) {
return null;
}

entity.damage(event.getDamage());

helper.setEventDamageInfo(event, null);

return helper.getOurEvent(event).toDamageObject();
}
}
Loading

0 comments on commit eac731e

Please sign in to comment.