Skip to content

Commit

Permalink
implemented fix for not working death messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DerPavlov committed May 17, 2020
1 parent 2992a66 commit 070d13a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
35 changes: 26 additions & 9 deletions src/main/java/at/pavlov/cannons/CreateExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class CreateExplosion {
private final Cannons plugin;
private final Config config;

private FlyingProjectile currentCannonball;

private final HashSet<Entity> affectedEntities = new HashSet<>();
// the entity is used in 1 tick. There should be no garbage collector problem
private final HashMap<Entity, Double> damageMap = new HashMap<>();
Expand Down Expand Up @@ -852,6 +854,7 @@ public void detonate(FlyingProjectile cannonball, org.bukkit.entity.Projectile p
Bukkit.getServer().getPluginManager().callEvent(impactEvent);
canceled = impactEvent.isCancelled();

this.currentCannonball = cannonball;
// if canceled then exit
if (impactEvent.isCancelled()) {
// event cancelled, make some effects - even if the area is protected by a
Expand Down Expand Up @@ -912,14 +915,14 @@ private void fireEntityDeathEvent(FlyingProjectile cannonball) {
// check which entities are affected by the event
for (Entity entity : this.affectedEntities) {
if (entity != null) {
// entity has died
if (entity.isDead() && entity instanceof LivingEntity) {
lEntities.add((LivingEntity) entity);
if (entity instanceof Player) {
this.killedPlayers.put(entity.getUniqueId(), new DeathCause(cannonball.getProjectile(),
cannonball.getCannonUID(), cannonball.getShooterUID()));
}
}
// entity has died
if (entity.isDead() && entity instanceof LivingEntity) {
lEntities.add((LivingEntity) entity);
if (entity instanceof Player) {
this.killedPlayers.put(entity.getUniqueId(), new DeathCause(cannonball.getProjectile(),
cannonball.getCannonUID(), cannonball.getShooterUID()));
}
}
}
}
this.affectedEntities.clear();
Expand All @@ -932,6 +935,16 @@ private void fireEntityDeathEvent(FlyingProjectile cannonball) {
}
}

/**
* was this player affected by cannons, it might have been the death cause
* @param player player to check
* @return true if the player was affected by cannons
*/
public boolean wasAffectedByCannons(Player player){
return this.affectedEntities.contains(player);
}


/**
* makes a sphere with additional explosions around the impact
*
Expand Down Expand Up @@ -1268,7 +1281,7 @@ public void sendExplosionToPlayers(Projectile projectile, Location loc, SoundHol
* @return true if player was killed by a cannonball
*/
public boolean isKilledByCannons(UUID playerUID) {
return this.killedPlayers.containsKey(playerUID);
return this.killedPlayers.containsKey(playerUID);
}

/**
Expand All @@ -1291,4 +1304,8 @@ public DeathCause getDeathCause(UUID playerUID) {
public void removeKilledPlayer(UUID playerUID) {
this.killedPlayers.remove(playerUID);
}

public FlyingProjectile getCurrentCannonball() {
return currentCannonball;
}
}
15 changes: 9 additions & 6 deletions src/main/java/at/pavlov/cannons/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.pavlov.cannons.Enum.InteractAction;
import at.pavlov.cannons.container.DeathCause;
import at.pavlov.cannons.projectile.FlyingProjectile;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -61,15 +62,17 @@ public PlayerListener(Cannons plugin)
public void PlayerDeath(PlayerDeathEvent event)
{
UUID killedUID = event.getEntity().getUniqueId();
if (plugin.getExplosion().isKilledByCannons(killedUID)){
DeathCause cause = plugin.getExplosion().getDeathCause(killedUID);
if (plugin.getExplosion().wasAffectedByCannons(event.getEntity())){
//DeathCause cause = plugin.getExplosion().getDeathCause(killedUID);
plugin.getExplosion().removeKilledPlayer(killedUID);

Player shooter = null;
if (cause.getShooterUID() != null)
shooter = Bukkit.getPlayer(cause.getShooterUID());
Cannon cannon = plugin.getCannon(cause.getCannonUID());
String message = userMessages.getDeathMessage(killedUID, cause.getShooterUID(), cannon, cause.getProjectile());
// if (cause.getShooterUID() != null)
// shooter = Bukkit.getPlayer(cause.getShooterUID());
// Cannon cannon = plugin.getCannon(cause.getCannonUID());
FlyingProjectile c = plugin.getExplosion().getCurrentCannonball();
Cannon cannon = CannonManager.getCannon(c.getCannonUID());
String message = userMessages.getDeathMessage(killedUID, c.getShooterUID(), cannon, c.getProjectile());
if (message != null && !message.equals(" "))
event.setDeathMessage(message);
}
Expand Down

0 comments on commit 070d13a

Please sign in to comment.