Skip to content

Commit

Permalink
Reduce message related error& Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Nov 17, 2023
1 parent 0c02112 commit 3cba049
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return arguments;
} else if (args[0].equalsIgnoreCase("blacklist")) {
arguments.clear();
for (Player player : Bukkit.getOnlinePlayers()) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
arguments.add(player.getName());
}
return arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ synchronized void onEntityDeath(EntityDeathEvent e) {
if (explosionManager.getMaterial().name().contains("BED")) {
naturalDeath = Assets.getNaturalDeath(pm, "Bed");
}
if (DeathMessages.majorVersion() >= 16 && explosionManager.getMaterial().equals(Material.RESPAWN_ANCHOR)) {
naturalDeath = Assets.getNaturalDeath(pm, "Respawn-Anchor");
if (DeathMessages.majorVersion() >= 16) {
if (explosionManager.getMaterial().equals(Material.RESPAWN_ANCHOR)) {
naturalDeath = Assets.getNaturalDeath(pm, "Respawn-Anchor");
}
}
BroadcastDeathMessageEvent event = new BroadcastDeathMessageEvent(p, null, MessageType.NATURAL, naturalDeath, getWorlds(p), false);
Bukkit.getPluginManager().callEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void onInteract(PlayerInteractEvent e) {
}
callEvent(e, b, effected);
}
} else if (!b.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
if (DeathMessages.majorVersion() >= 16) {
} else if (DeathMessages.majorVersion() >= 16) {
if (!b.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
if (b.getType().equals(Material.RESPAWN_ANCHOR)) {
RespawnAnchor anchor = (RespawnAnchor) b.getBlockData();
if (!(anchor.getCharges() == anchor.getMaximumCharges()) && !e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.GLOWSTONE))
Expand Down
105 changes: 60 additions & 45 deletions src/main/java/dev/mrshawn/deathmessages/utils/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ public static TextComponent entityDeathMessage(EntityManager em, MobType mobType
public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause) {
List<String> msgs = sortList(getPlayerDeathMessages().getStringList("Natural-Cause." + damageCause), pm.getPlayer(), pm.getPlayer());

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println("Natural-Cause." + damageCause); // Dreeam - debug
if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + "Natural-Cause." + damageCause + "] in PlayerDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report issue on Github");
msgs = sortList(getPlayerDeathMessages().getStringList("Natural-Cause.Unknown"), pm.getPlayer(), pm.getPlayer());
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("Fallback this death to [Natural-Cause.Unknown] message node");
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));
msg = playerDeathPlaceholders(msg, pm, null);
Expand Down Expand Up @@ -383,7 +388,12 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti
msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + ".Weapon"), pm.getPlayer(), mob);
}

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println(mode + "." + affiliation + ".Weapon"); // Dreeam - debug
if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + mode + "." + affiliation + ".Weapon" + "] in PlayerDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");
msgs = sortList(getPlayerDeathMessages().getStringList(DeathModes.BASIC_MODE.getValue() + "." + affiliation + ".Weapon"), pm.getPlayer(), mob);
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("Fallback this death to Basic-Mode of PlayerDeathMessages");
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));
msg = playerDeathPlaceholders(msg, pm, mob);
Expand Down Expand Up @@ -468,7 +478,12 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob
if (tameable.getOwner() != null) hasOwner = true;
}

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println("Entities." + entityName + ".Weapon"); // Dreeam - debug
if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + "Entities." + entityName + ".Weapon" + "] in EntityDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("The message for this death will not broadcast");
return null;
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));
msg = entityDeathPlaceholders(msg, p, e, hasOwner);
Expand Down Expand Up @@ -547,14 +562,17 @@ public static TextComponent get(boolean gang, PlayerManager pm, LivingEntity mob
msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + damageCause), pm.getPlayer(), mob);
}

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println(mode + "." + affiliation + "." + damageCause); // Dreeam - debug

if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + mode + "." + affiliation + "." + damageCause + "] in PlayerDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");

if (Settings.getInstance().getConfig().getBoolean(Config.DEFAULT_NATURAL_DEATH_NOT_DEFINED.getPath()))
return getNaturalDeath(pm, damageCause);
if (Settings.getInstance().getConfig().getBoolean(Config.DEFAULT_MELEE_LAST_DAMAGE_NOT_DEFINED.getPath()))
return get(gang, pm, mob, getSimpleCause(EntityDamageEvent.DamageCause.ENTITY_ATTACK));
return null;

msgs = sortList(getPlayerDeathMessages().getStringList(DeathModes.BASIC_MODE.getValue() + "." + affiliation + "." + damageCause), pm.getPlayer(), mob);
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("Fallback this death to Basic-Mode of PlayerDeathMessages");
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));
Expand Down Expand Up @@ -595,7 +613,12 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living
msgs = sortList(getPlayerDeathMessages().getStringList("Custom-Mobs.Mythic-Mobs." + internalMobType + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob);
}

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println(mode + "." + affiliation + "." + projectileDamage); // Dreeam - debug
if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + mode + "." + affiliation + "." + projectileDamage + "] in PlayerDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");
msgs = sortList(getPlayerDeathMessages().getStringList(DeathModes.BASIC_MODE.getValue() + "." + affiliation + "." + projectileDamage), pm.getPlayer(), mob);
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("Fallback this death to Basic-Mode of PlayerDeathMessages");
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));
msg = playerDeathPlaceholders(msg, pm, mob);
Expand Down Expand Up @@ -670,10 +693,12 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em,
}

if (msgs.isEmpty()) {
if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println("Entities." + entityName + "." + projectileDamage); // Dreeam - debug
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + "Entities." + entityName + "." + projectileDamage + "] in EntityDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");
if (Settings.getInstance().getConfig().getBoolean(Config.DEFAULT_MELEE_LAST_DAMAGE_NOT_DEFINED.getPath())) {
return getEntityDeath(p, em.getEntity(), getSimpleCause(EntityDamageEvent.DamageCause.ENTITY_ATTACK), mobType);
}
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("The message for this death will not broadcast");
return null;
}

Expand Down Expand Up @@ -766,7 +791,12 @@ public static TextComponent getEntityDeath(Player player, Entity e, String damag
msgs = sortList(getEntityDeathMessages().getStringList("Mythic-Mobs-Entities." + internalMobType + "." + damageCause), player, e);
}

if (Settings.getInstance().getConfig().getBoolean(Config.DEBUG.getPath())) System.out.println("Entities." + entityName + "." + damageCause); // Dreeam - debug
if (msgs.isEmpty()) {
LogManager.getLogger(DeathMessages.getInstance().getName()).error("Can't find message node: [" + "Entities." + entityName + "." + damageCause + "] in EntityDeathMessages.yml");
LogManager.getLogger(DeathMessages.getInstance().getName()).error("This should not happen, please check your config or report this issue on Github");
LogManager.getLogger(DeathMessages.getInstance().getName()).warn("The message for this death will not broadcast");
return null;
}

String msg = msgs.get(ThreadLocalRandom.current().nextInt(msgs.size()));

Expand Down Expand Up @@ -849,6 +879,7 @@ public static String entityDeathPlaceholders(String msg, Player player, Entity e
.replaceAll("%x%", String.valueOf(entity.getLocation().getBlock().getX()))
.replaceAll("%y%", String.valueOf(entity.getLocation().getBlock().getY()))
.replaceAll("%z%", String.valueOf(entity.getLocation().getBlock().getZ()));

if (owner && entity instanceof Tameable tameable && tameable.getOwner() != null && tameable.getOwner().getName() != null) {
msg = msg
.replaceAll("%owner%", tameable.getOwner().getName());
Expand All @@ -869,25 +900,26 @@ public static String entityDeathPlaceholders(String msg, Player player, Entity e
}

public static String playerDeathPlaceholders(String msg, PlayerManager pm, LivingEntity mob) {
if (mob == null) {
msg = msg
.replaceAll("%player%", pm.getName())
.replaceAll("%player_display%", pm.getPlayer().getDisplayName())
.replaceAll("%world%", pm.getLastLocation().getWorld().getName())
.replaceAll("%world_environment%", getEnvironment(pm.getLastLocation().getWorld().getEnvironment()))
.replaceAll("%x%", String.valueOf(pm.getLastLocation().getBlock().getX()))
.replaceAll("%y%", String.valueOf(pm.getLastLocation().getBlock().getY()))
.replaceAll("%z%", String.valueOf(pm.getLastLocation().getBlock().getZ()));

try {
msg = msg
.replaceAll("%player%", pm.getName())
.replaceAll("%player_display%", pm.getPlayer().getDisplayName())
.replaceAll("%world%", pm.getLastLocation().getWorld().getName())
.replaceAll("%world_environment%", getEnvironment(pm.getLastLocation().getWorld().getEnvironment()))
.replaceAll("%x%", String.valueOf(pm.getLastLocation().getBlock().getX()))
.replaceAll("%y%", String.valueOf(pm.getLastLocation().getBlock().getY()))
.replaceAll("%z%", String.valueOf(pm.getLastLocation().getBlock().getZ()));
try {
msg = msg
.replaceAll("%biome%", pm.getLastLocation().getBlock().getBiome().name());
} catch (NullPointerException e) {
LogManager.getLogger().error("Custom Biome detected. Using 'Unknown' for a biome name.");
LogManager.getLogger().error("Custom Biomes are not supported yet.'");
msg = msg
.replaceAll("%biome%", "Unknown");
}
} else {
.replaceAll("%biome%", pm.getLastLocation().getBlock().getBiome().name());
} catch (NullPointerException e) {
LogManager.getLogger().error("Custom Biome detected. Using 'Unknown' for a biome name.");
LogManager.getLogger().error("Custom Biomes are not supported yet.'");
msg = msg
.replaceAll("%biome%", "Unknown");
}

if (mob != null) {
String mobName = mob.getName();
if (Settings.getInstance().getConfig().getBoolean(Config.RENAME_MOBS_ENABLED.getPath())) {
String[] chars = Settings.getInstance().getConfig().getString(Config.RENAME_MOBS_IF_CONTAINS.getPath()).split("(?!^)");
Expand All @@ -902,25 +934,8 @@ public static String playerDeathPlaceholders(String msg, PlayerManager pm, Livin
mobName = Messages.getInstance().getConfig().getString("Mobs." + mob.getType().toString().toLowerCase());
}
msg = msg
.replaceAll("%player%", pm.getName())
.replaceAll("%player_display%", pm.getPlayer().getDisplayName())
.replaceAll("%killer%", mobName)
.replaceAll("%killer_type%", Messages.getInstance().getConfig().getString("Mobs."
+ mob.getType().toString().toLowerCase()))
.replaceAll("%world%", pm.getLastLocation().getWorld().getName())
.replaceAll("%world_environment%", getEnvironment(pm.getLastLocation().getWorld().getEnvironment()))
.replaceAll("%x%", String.valueOf(pm.getLastLocation().getBlock().getX()))
.replaceAll("%y%", String.valueOf(pm.getLastLocation().getBlock().getY()))
.replaceAll("%z%", String.valueOf(pm.getLastLocation().getBlock().getZ()));
try {
msg = msg
.replaceAll("%biome%", pm.getLastLocation().getBlock().getBiome().name());
} catch (NullPointerException e) {
LogManager.getLogger().error("Custom Biome detected. Using 'Unknown' for a biome name.");
LogManager.getLogger().error("Custom Biomes are not supported yet.'");
msg = msg
.replaceAll("%biome%", "Unknown");
}
.replaceAll("%killer_type%", Messages.getInstance().getConfig().getString("Mobs." + mob.getType().toString().toLowerCase()));

if (mob instanceof Player p) {
msg = msg
Expand Down
46 changes: 46 additions & 0 deletions src/main/resources/PlayerDeathMessages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,43 @@ Basic-Mode:
- "%player% was shot by a %killer% using %weapon%"
Explosion:
- "%player% was blown up by a %killer%"
Projectile-Fireball:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-ShulkerBullet:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-Trident:
- "%player% was shot by a %killer% somehow using %weapon%"
Magic:
- "%player% was killed by a %killer% using magic"
Sonic-Boom:
- "%player% was obliterated by a sonically-charged shriek"
Weapon:
- "%player% was slain by a %killer% using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Contact:
- "%player% was pushed into a cactus by %killer%"
Gang:
Projectile-Arrow:
- "%player% was shot by a group of %killer%'s using %weapon%"
Explosion:
- "%player% was blown up by a group of %killer%"
Projectile-Fireball:
- "%player% was shot by a group of %killer% somehow using %weapon%"
Projectile-ShulkerBullet:
- "%player% was shot by a group of %killer% somehow using %weapon%"
Projectile-Trident:
- "%player% was shot by a group of %killer% somehow using %weapon%"
Magic:
- "%player% was killed by a group of %killer%'s using magic"
Sonic-Boom:
- "%player% was obliterated by a sonically-charged shriek"
Weapon:
- "%player% was slain by a group of %killer%'s somehow using %weapon%"
Melee:
- "%player% was slain by a group of %killer%'s"
Contact:
- "%player% was pushed into a cactus by a group of %killer%"

Natural-Cause:
Bed:
Expand Down Expand Up @@ -402,6 +424,8 @@ Mobs:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
- "%player% was ganed up on by some %killer%'s! One wacked them with %weapon%"
Explosion:
- "%player% was blown up by some %killer%"
Melee:
- "%player% was slain by a bunch of %killer%'s"
skeleton:
Expand Down Expand Up @@ -481,13 +505,17 @@ Mobs:
- "%player% was slain by a bunch of %killer%'s"
ghast:
Solo:
Projectile-Arrow:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-Fireball:
- "%player% was shot by a %killer% somehow using %weapon%"
Weapon:
- "%player% was slain by a %killer% somehow using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Gang:
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Projectile-Fireball:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down Expand Up @@ -556,13 +584,17 @@ Mobs:
- "%player% was slain by a bunch of %killer%'s"
blaze:
Solo:
Projectile-Arrow:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-Fireball:
- "%player% was shot by a %killer% somehow using %weapon%"
Weapon:
- "%player% was slain by a %killer% somehow using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Gang:
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Projectile-Fireball:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down Expand Up @@ -688,13 +720,17 @@ Mobs:
- "%player% was slain by a bunch of %killer%'s"
shulker:
Solo:
Projectile-Arrow:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-ShulkerBullet:
- "%player% was shot by a %killer% somehow using %weapon%"
Weapon:
- "%player% was slain by a %killer% somehow using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Gang:
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Projectile-ShulkerBullet:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down Expand Up @@ -900,11 +936,15 @@ Mobs:
Solo:
Projectile-LlamaSpit:
- "%player% was spat on by a %killer%"
Projectile-Arrow:
- "%player% was ganged up on by a %killer%! One shot them with %weapon%"
Weapon:
- "%player% was slain by a %killer% somehow using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Gang:
Projectile-LlamaSpit:
- "%player% was spat on by some %killer%"
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down Expand Up @@ -1033,13 +1073,17 @@ Mobs:
- "%player% was slain by a bunch of %killer%'s"
drowned:
Solo:
Projectile-Arrow:
- "%player% was shot by a %killer% somehow using %weapon%"
Projectile-Trident:
- "%player% was shot by a %killer% somehow using %weapon%"
Weapon:
- "%player% was slain by a %killer% somehow using %weapon%"
Melee:
- "%player% was slain by a %killer%"
Gang:
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Projectile-Trident:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down Expand Up @@ -1102,6 +1146,8 @@ Mobs:
Melee:
- "%player% was slain by a %killer%"
Gang:
Contact:
- "%player% was pushed into a cactus by some %killer%"
Projectile-Arrow:
- "%player% was ganged up on by some %killer%! One shot them with %weapon%"
Weapon:
Expand Down

0 comments on commit 3cba049

Please sign in to comment.