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;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -34,82 +35,82 @@ public class PlayerDeathListener implements Listener {
e.getEntity().getUniqueId().toString().replace("-", ""));
}
System.out.println(damageCause.getCause());
e.setDeathMessage(null);
switch (damageCause.getCause()) {
case BLOCK_EXPLOSION:
// TNT
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.BLOCK_EXPLOSION));
break;
case CONTACT:
// Cactus
e.setDeathMessage(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CONTACT));
Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.CONTACT));
break;
case DROWNING:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.DROWNING));
break;
case ENTITY_EXPLOSION:
// Creeper
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_EXPLOSION));
break;
case ENTITY_ATTACK:
case ENTITY_SWEEP_ATTACK:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.ENTITY_ATTACK));
break;
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;
case FALLING_BLOCK:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.FALLING_BLOCK));
break;
case FIRE:
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;
case HOT_FLOOR:
// Magma Block
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.HOT_FLOOR));
break;
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;
case LIGHTNING:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.LIGHTNING));
break;
case MAGIC:
// 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;
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;
case PROJECTILE:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.PROJECTILE));
break;
case STARVATION:
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.STARVATION));
break;
case SUFFOCATION:
// Border damage or sand/gravel
e.setDeathMessage(
Bukkit.broadcast(
this.plugin.getMessageUtils().getDeathMessage(e.getEntity(), killer, DamageCause.SUFFOCATION));
break;
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;
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;
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;
case CRAMMING: // Very rare so handle as default death
case CUSTOM: // No custom damage provider so impossible
@ -119,7 +120,7 @@ public class PlayerDeathListener implements Listener {
case MELTING: // No snowman so impossible
case SUICIDE: // No access to /kill command
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;
}
@ -129,7 +130,18 @@ public class PlayerDeathListener implements Listener {
this.plugin.getBorderManager().addPlayerDeath();
this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId());
this.plugin.getDiscordBot().broadcastMessage("Der Spieler <@!" + this.plugin.getTeamManager()
.getDiscordIdByUuid(e.getEntity().getUniqueId().toString().replace("-", "")) + "> ist gestorben.");
if (killer == null) {
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)
.getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));
connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc));
}
if (isCritical)
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());
Bukkit.broadcastMessage(this.plugin.getMessageUtils()
.getDeathMessage(npc.getBukkitEntity().getPlayer(), damager, DamageCause.CUSTOM));
Bukkit.broadcast(this.plugin.getMessageUtils().getDeathMessage(npc.getBukkitEntity().getPlayer(),
damager, DamageCause.CUSTOM));
this.plugin.getDatabase().addKill(damager.getUniqueId().toString().replace("-", ""),
npc.getUniqueID().toString().replace("-", ""));
this.plugin.getDiscordBot().broadcastMessage("Der Spieler <@!" + this.plugin.getTeamManager()
.getDiscordIdByUuid(npc.getUniqueID().toString().replace("-", "")) + "> ist gestorben.");
this.plugin.getDiscordBot()
.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() {
@Override

View file

@ -44,6 +44,9 @@ public class LangUtils {
this.config.addDefault("Discord.BorderUpdate",
"@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.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.CUSTOMkiller", "%player% wurde von %killer% getötet.");
this.config.addDefault("Death.BLOCK_EXPLOSION", "%player% ist explodiert.");

View file

@ -61,12 +61,26 @@ public class MessageUtils {
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) {
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 {
return this.plugin.getLangUtils().get("Death." + cause.toString() + "killer")
.replace("%player%", victim.getName()).replace("%killer%", killer.getName());
final String[] text = this.plugin.getLangUtils().get("Death." + cause.toString() + "killer")
.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;
}
}
}