feat: add PlayerTag to DeathMessage and enhance Discord Messages on Death

This commit is contained in:
Simon Giesel 2020-05-31 22:17:31 +02:00
parent 6bcd8324fb
commit 63e48614a7
4 changed files with 66 additions and 31 deletions

View file

@ -1,5 +1,6 @@
package de.cliffbreak.varo.listeners; package de.cliffbreak.varo.listeners;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -34,82 +35,82 @@ public class PlayerDeathListener implements Listener {
e.getEntity().getUniqueId().toString().replace("-", "")); e.getEntity().getUniqueId().toString().replace("-", ""));
} }
System.out.println(damageCause.getCause()); System.out.println(damageCause.getCause());
e.setDeathMessage(null);
switch (damageCause.getCause()) { switch (damageCause.getCause()) {
case BLOCK_EXPLOSION: case BLOCK_EXPLOSION:
// TNT // TNT
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.BLOCK_EXPLOSION)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.BLOCK_EXPLOSION));
break; break;
case CONTACT: case CONTACT:
// Cactus // Cactus
e.setDeathMessage( Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CONTACT));
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CONTACT));
break; break;
case DROWNING: case DROWNING:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.DROWNING)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.DROWNING));
break; break;
case ENTITY_EXPLOSION: case ENTITY_EXPLOSION:
// Creeper // Creeper
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_EXPLOSION)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_EXPLOSION));
break; break;
case ENTITY_ATTACK: case ENTITY_ATTACK:
case ENTITY_SWEEP_ATTACK: case ENTITY_SWEEP_ATTACK:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_ATTACK)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_ATTACK));
break; break;
case FALL: case FALL:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FALL)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FALL));
break; break;
case FALLING_BLOCK: case FALLING_BLOCK:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FALLING_BLOCK)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FALLING_BLOCK));
break; break;
case FIRE: case FIRE:
case FIRE_TICK: case FIRE_TICK:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FIRE)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FIRE));
break; break;
case HOT_FLOOR: case HOT_FLOOR:
// Magma Block // Magma Block
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.HOT_FLOOR)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.HOT_FLOOR));
break; break;
case LAVA: case LAVA:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.LAVA)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.LAVA));
break; break;
case LIGHTNING: case LIGHTNING:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.LIGHTNING)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.LIGHTNING));
break; break;
case MAGIC: case MAGIC:
// Potion (should be impossible) // Potion (should be impossible)
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.MAGIC)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.MAGIC));
break; break;
case POISON: case POISON:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.POISON)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.POISON));
break; break;
case PROJECTILE: case PROJECTILE:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.PROJECTILE)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.PROJECTILE));
break; break;
case STARVATION: case STARVATION:
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.STARVATION)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.STARVATION));
break; break;
case SUFFOCATION: case SUFFOCATION:
// Border damage or sand/gravel // Border damage or sand/gravel
e.setDeathMessage( Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.SUFFOCATION)); this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.SUFFOCATION));
break; break;
case THORNS: case THORNS:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.THORNS)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.THORNS));
break; break;
case VOID: case VOID:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.VOID)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.VOID));
break; break;
case WITHER: case WITHER:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.WITHER)); Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.WITHER));
break; break;
case CRAMMING: // Very rare so handle as default death case CRAMMING: // Very rare so handle as default death
case CUSTOM: // No custom damage provider so impossible case CUSTOM: // No custom damage provider so impossible
@ -119,7 +120,7 @@ public class PlayerDeathListener implements Listener {
case MELTING: // No snowman so impossible case MELTING: // No snowman so impossible
case SUICIDE: // No access to /kill command case SUICIDE: // No access to /kill command
default: default:
e.setDeathMessage(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CUSTOM)); // CUSTOM == default Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CUSTOM)); // CUSTOM == default
break; break;
} }
@ -129,7 +130,18 @@ public class PlayerDeathListener implements Listener {
this.plugin.getBorderManager().addPlayerDeath(); this.plugin.getBorderManager().addPlayerDeath();
this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId()); this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId());
this.plugin.getDiscordBot().broadcastMessage("Der Spieler <@!" + this.plugin.getTeamManager() if (killer == null) {
.getDiscordIdByUuid(e.getEntity().getUniqueId().toString().replace("-", "")) + "> ist gestorben."); this.plugin.getDiscordBot().broadcastMessage(
this.plugin.getLangUtils().get("Discord.PlayerDeath").replace("%id%", this.plugin.getTeamManager()
.getDiscordIdByUuid(e.getEntity().getUniqueId().toString().replace("-", ""))));
} else {
this.plugin.getDiscordBot()
.broadcastMessage(this.plugin.getLangUtils().get("Discord.PlayerDeathKiller")
.replace("%id%",
this.plugin.getTeamManager().getDiscordIdByUuid(
e.getEntity().getUniqueId().toString().replace("-", "")))
.replace("%id_killer%", this.plugin.getTeamManager()
.getDiscordIdByUuid(killer.getUniqueId().toString().replace("-", ""))));
}
} }
} }

View file

@ -228,6 +228,7 @@ public class NPCManager {
final PlayerConnection connection = ((CraftPlayer) connectionPlayer) final PlayerConnection connection = ((CraftPlayer) connectionPlayer)
.getHandle().playerConnection; .getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true)); connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc));
} }
if (isCritical) if (isCritical)
world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F); world.playSound(loc, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0F, 1.0F);
@ -246,12 +247,17 @@ public class NPCManager {
this.plugin.getBanUtils().addBan(npc.getUniqueID()); this.plugin.getBanUtils().addBan(npc.getUniqueID());
Bukkit.broadcastMessage(this.plugin.getMessageUtils() Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(npc.getBukkitEntity().getPlayer(),
.getDeathMessage(npc.getBukkitEntity().getPlayer(), damager, DamageCause.CUSTOM)); damager, DamageCause.CUSTOM));
this.plugin.getDatabase().addKill(damager.getUniqueId().toString().replace("-", ""), this.plugin.getDatabase().addKill(damager.getUniqueId().toString().replace("-", ""),
npc.getUniqueID().toString().replace("-", "")); npc.getUniqueID().toString().replace("-", ""));
this.plugin.getDiscordBot().broadcastMessage("Der Spieler <@!" + this.plugin.getTeamManager() this.plugin.getDiscordBot()
.getDiscordIdByUuid(npc.getUniqueID().toString().replace("-", "")) + "> ist gestorben."); .broadcastMessage(this.plugin.getLangUtils().get("Discord.PlayerDeathKiller")
.replace("%id%",
this.plugin.getTeamManager()
.getDiscordIdByUuid(npc.getUniqueID().toString().replace("-", "")))
.replace("%id_killer%", this.plugin.getTeamManager()
.getDiscordIdByUuid(damager.getUniqueId().toString().replace("-", ""))));
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override

View file

@ -44,6 +44,9 @@ public class LangUtils {
this.config.addDefault("Discord.BorderUpdate", this.config.addDefault("Discord.BorderUpdate",
"@everyone In 30 Minuten geht es los!\nDie Border schrumpft heute auf %size%x%size% Blöcke."); "@everyone In 30 Minuten geht es los!\nDie Border schrumpft heute auf %size%x%size% Blöcke.");
this.config.addDefault("Discord.PlayerStats", "Der Spieler <@!%id%> hat momentan %kills% Kills."); this.config.addDefault("Discord.PlayerStats", "Der Spieler <@!%id%> hat momentan %kills% Kills.");
this.config.addDefault("Discord.PlayerDeath", "Der Spieler <@!%id%> ist gestorben.");
this.config.addDefault("Discord.PlayerDeathKiller",
"Der Spieler <@!%id%> wurde von <@!%id_killer%> getötet.");
this.config.addDefault("Death.CUSTOM", "%player% ist gestorben."); this.config.addDefault("Death.CUSTOM", "%player% ist gestorben.");
this.config.addDefault("Death.CUSTOMkiller", "%player% wurde von %killer% getötet."); this.config.addDefault("Death.CUSTOMkiller", "%player% wurde von %killer% getötet.");
this.config.addDefault("Death.BLOCK_EXPLOSION", "%player% ist explodiert."); this.config.addDefault("Death.BLOCK_EXPLOSION", "%player% ist explodiert.");

View file

@ -61,12 +61,26 @@ public class MessageUtils {
return component; return component;
} }
public String getDeathMessage(final Player victim, final Player killer, final DamageCause cause) { public TextComponent getDeathMessage(final Player victim, final Player killer, final DamageCause cause) {
final TextComponent component = new TextComponent(" ");
component.addExtra(getTimeStamp());
component.addExtra(new TextComponent("§c§l>>§r "));
if (killer == null) { if (killer == null) {
return this.plugin.getLangUtils().get("Death." + cause.toString()).replace("%player%", victim.getName()); final String[] text = this.plugin.getLangUtils().get("Death." + cause.toString()).split("%player%");
component.addExtra(new TextComponent(text[0]));
component.addExtra(getPlayerComponent(victim.getName()));
component.addExtra(new TextComponent("§r" + text[1]));
return component;
} else { } else {
return this.plugin.getLangUtils().get("Death." + cause.toString() + "killer") final String[] text = this.plugin.getLangUtils().get("Death." + cause.toString() + "killer")
.replace("%player%", victim.getName()).replace("%killer%", killer.getName()); .split("%player%");
final String[] text2 = text[1].split("%killer%");
component.addExtra(new TextComponent(text[0]));
component.addExtra(getPlayerComponent(victim.getName()));
component.addExtra(new TextComponent("§r" + text2[0]));
component.addExtra(getPlayerComponent(killer.getName()));
component.addExtra(new TextComponent("§r" + text2[1]));
return component;
} }
} }
} }