Skip to content

Commit

Permalink
revamp of damage system
Browse files Browse the repository at this point in the history
Damage calculation will now take effect for player vs ai and player vs player correctly, and summons particles on the player thats hit

In the future, stamina will be implemented and once a player runs out of stamina they no longer do theyre full amount of damage, thus not creating these particle effects
  • Loading branch information
Burchard36 committed Aug 6, 2021
1 parent cf755b4 commit 37ea5d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/myplugin/MyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.myplugin.command.DragonBallCommand;
import com.myplugin.command.commands.RaceCommand;
import com.myplugin.events.PlayerAttackEvent;
import com.myplugin.events.PlayerTakesDamage;
import com.myplugin.lib.Logger;
import com.myplugin.lib.PlayerDataManager;
import com.myplugin.lib.config.ConfigPath;
Expand Down Expand Up @@ -39,8 +38,6 @@ public void onEnable() {

Logger.debug("Loading event BossBarManager");
this.barManager = new BossBarManager(this);
Logger.debug("Loading event PlayerDamageEvent");
new PlayerTakesDamage(this);
Logger.debug("Loading event PlayerAttackEvent");
new PlayerAttackEvent(this);

Expand Down
35 changes: 31 additions & 4 deletions src/main/java/com/myplugin/events/PlayerAttackEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,43 @@ public PlayerAttackEvent(final MyPlugin plugin) {

@EventHandler
public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Player) {

final boolean playerHitsMob = e.getDamager() instanceof Player && !(e.getEntity() instanceof Player);
final boolean playerHitsPlayer = e.getEntity() instanceof Player && e.getDamager() instanceof Player;
final boolean mobHitsPlayer = !(e.getDamager() instanceof Player) && e.getEntity() instanceof Player;

if (playerHitsMob) {
final Player p = (Player) e.getDamager();
final PlayerData data = this.manager.getPlayerData(p.getUniqueId());
final int damage = data.calculateDamage();
Logger.debug("Player with UUID: " + p.getUniqueId().toString() + " dealt " + damage + " to " + e.getEntity().getType().toString());
e.setDamage(damage);
this.spawnParticle(e.getEntity());

} else if (playerHitsPlayer) {
final Player hurtPlayer = (Player) e.getEntity();
final Player attackingPlayer = (Player) e.getEntity();
final PlayerData attacker = this.manager.getPlayerData(attackingPlayer.getUniqueId());
final PlayerData defender = this.manager.getPlayerData(hurtPlayer.getUniqueId());
final int attackerDamage = attacker.calculateDamage();
defender.applyDamage(attackerDamage);
e.setDamage(0D);
this.spawnParticle(hurtPlayer);
Logger.debug("Player with UUID: " + attackingPlayer.getUniqueId().toString() + " dealt " + attackerDamage + " to " + hurtPlayer.getUniqueId().toString());
} else if (mobHitsPlayer) {
final Player player = (Player) e.getEntity();
final PlayerData data = this.manager.getPlayerData(player.getUniqueId());
data.applyDamage((int)e.getDamage());
this.spawnParticle(player);
Logger.debug("Mob: " + e.getDamager().getType() + " dealt ~"+ e.getDamage() + " to " + player.getUniqueId().toString());
e.setDamage(0D);

final Location loc = e.getEntity().getLocation();
final World world = loc.getWorld();
world.spawnParticle(Particle.CRIT_MAGIC, loc, 10);
}
}

private void spawnParticle(final Entity e) {
final World world = e.getWorld();
final Location loc = e.getLocation();
world.spawnParticle(Particle.CRIT_MAGIC, loc, 10);
}
}
33 changes: 0 additions & 33 deletions src/main/java/com/myplugin/events/PlayerTakesDamage.java

This file was deleted.

0 comments on commit 37ea5d8

Please sign in to comment.