Skip to content

Commit

Permalink
Entity killed by entity should not include in Deathmessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Nov 15, 2023
1 parent 12b3d40 commit d968639
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ synchronized void onEntityDeath(EntityDeathEvent e) {
}
}, () -> new PlayerManager(p));
} else {
// TODO: maybe remove below, unnecessary
Optional<EntityManager> getEntity = EntityManager.getEntity(e.getEntity().getUniqueId());
getEntity.ifPresent(em -> {

// Player killing mob
MobType mobType = MobType.VANILLA;
if (DeathMessages.getInstance().mythicmobsEnabled) {
Expand All @@ -136,6 +136,7 @@ synchronized void onEntityDeath(EntityDeathEvent e) {
}

PlayerManager damager = em.getLastPlayerDamager();
if (damager == null) return; // Entity killed by Entity should not include in DM

TextComponent entityDeath = Assets.entityDeathMessage(em, mobType);
BroadcastEntityDeathMessageEvent event = new BroadcastEntityDeathMessageEvent(damager, e.getEntity(), MessageType.ENTITY, entityDeath, getWorlds(e.getEntity()));
Expand Down
66 changes: 33 additions & 33 deletions src/main/java/dev/mrshawn/deathmessages/utils/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause
//System.out.println(FileStore.INSTANCE.getCONFIG().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES));
//System.out.println(config.getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath()));
if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

Expand All @@ -288,7 +288,7 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause
String material = fb.getBlockData().getMaterial().toString().toLowerCase();
String configValue = Messages.getInstance().getConfig().getString("Blocks." + material);

base.append(Assets.convertFromLegacy(msg.replaceAll("%block%", configValue)));
base.append(convertFromLegacy(msg.replaceAll("%block%", configValue)));
} catch (NullPointerException e) {
LogManager.getLogger().error("Could not parse %block%. Please check your config for a wrong value." +
" Your materials could be spelt wrong or it does not exists in the config. Open a issue if you need help, " + "https://github.com/Winds-Studio/DeathMessages/issues");
Expand All @@ -300,7 +300,7 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause
String material = pm.getLastClimbing().toString().toLowerCase();
String configValue = Messages.getInstance().getConfig().getString("Blocks." + material);

base.append(Assets.convertFromLegacy(msg.replaceAll("%climbable%", configValue)));
base.append(convertFromLegacy(msg.replaceAll("%climbable%", configValue)));
} catch (NullPointerException e) {
pm.setLastClimbing(null);
return getNaturalDeath(pm, getSimpleCause(EntityDamageEvent.DamageCause.FALL));
Expand Down Expand Up @@ -328,15 +328,15 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause
return getNaturalDeath(pm, "Projectile-Unknown");
}
}
displayName = Assets.convertString(i.getType().name());
displayName = convertString(i.getType().name());
} else {
displayName = i.getItemMeta().getDisplayName();
}

HoverEvent<HoverEvent.ShowItem> showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().toString()));

Component weapon = Component.text()
.append(Assets.convertFromLegacy(displayName))
.append(convertFromLegacy(displayName))
.build()
.hoverEvent(showItem);

Expand All @@ -350,12 +350,12 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause

base.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
TextComponent deathMessage = convertFromLegacy(msg);
base.append(deathMessage);
}
// TODO: need to re-write the logic of death message click event & hover text.
// if (msg.length() >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(playerDeathPlaceholders(msg[1], pm, null))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(playerDeathPlaceholders(msg[1], pm, null))));
// }
// if (msg.length() == 3) {
// if (msg[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -391,7 +391,7 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

Expand All @@ -410,15 +410,15 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti
.getString(Config.DISABLE_WEAPON_KILL_WITH_NO_CUSTOM_NAME_SOURCE_WEAPON_DEFAULT_TO));
}
}
displayName = Assets.convertString(i.getType().name());
displayName = convertString(i.getType().name());
} else {
displayName = i.getItemMeta().getDisplayName();
}

HoverEvent<HoverEvent.ShowItem> showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().toString()));

Component weapon = Component.text()
.append(Assets.convertFromLegacy(displayName))
.append(convertFromLegacy(displayName))
.build()
.hoverEvent(showItem);

Expand All @@ -432,11 +432,11 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti

base.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
TextComponent deathMessage = convertFromLegacy(msg);
base.append(deathMessage);
}
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -476,7 +476,7 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

Expand All @@ -495,15 +495,15 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob
Settings.getInstance().getConfig().getString(Config.DISABLE_WEAPON_KILL_WITH_NO_CUSTOM_NAME_SOURCE_WEAPON_DEFAULT_TO.getPath()), mobType);
}
}
displayName = Assets.convertString(i.getType().name());
displayName = convertString(i.getType().name());
} else {
displayName = i.getItemMeta().getDisplayName();
}

HoverEvent<HoverEvent.ShowItem> showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().toString()));

Component weapon = Component.text()
.append(Assets.convertFromLegacy(displayName))
.append(convertFromLegacy(displayName))
.build()
.hoverEvent(showItem);

Expand All @@ -517,11 +517,11 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob

base.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
TextComponent deathMessage = convertFromLegacy(msg);
base.append(deathMessage);
}
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(entityDeathPlaceholders(sec[1], p, e, hasOwner))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(entityDeathPlaceholders(sec[1], p, e, hasOwner))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -562,14 +562,14 @@ public static TextComponent get(boolean gang, PlayerManager pm, LivingEntity mob
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

TextComponent deathMessage = Assets.convertFromLegacy(playerDeathPlaceholders(msg, pm, mob));
TextComponent deathMessage = convertFromLegacy(playerDeathPlaceholders(msg, pm, mob));
base.append(deathMessage);
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -603,7 +603,7 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

Expand All @@ -618,15 +618,15 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living
return getProjectile(gang, pm, mob, Settings.getInstance().getConfig().getString(Config.DISABLE_WEAPON_KILL_WITH_NO_CUSTOM_NAME_SOURCE_PROJECTILE_DEFAULT_TO.getPath()));
}
}
displayName = Assets.convertString(i.getType().name());
displayName = convertString(i.getType().name());
showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount());
} else {
displayName = i.getItemMeta().getDisplayName();
showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().toString()));
}

Component weapon = Component.text()
.append(Assets.convertFromLegacy(displayName))
.append(convertFromLegacy(displayName))
.build()
.hoverEvent(showItem);

Expand All @@ -640,11 +640,11 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living

base.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
TextComponent deathMessage = convertFromLegacy(msg);
base.append(deathMessage);
}
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(playerDeathPlaceholders(sec[1], pm, mob))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -688,7 +688,7 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em,
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

Expand All @@ -703,15 +703,15 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em,
Settings.getInstance().getConfig().getString(Config.DISABLE_WEAPON_KILL_WITH_NO_CUSTOM_NAME_SOURCE_PROJECTILE_DEFAULT_TO.getPath()), mobType);
}
}
displayName = Assets.convertString(i.getType().name());
displayName = convertString(i.getType().name());
} else {
displayName = i.getItemMeta().getDisplayName();
}

HoverEvent<HoverEvent.ShowItem> showItem = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().toString()));

Component weapon = Component.text()
.append(Assets.convertFromLegacy(displayName))
.append(convertFromLegacy(displayName))
.build()
.hoverEvent(showItem);

Expand All @@ -725,11 +725,11 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em,

base.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
TextComponent deathMessage = convertFromLegacy(msg);
base.append(deathMessage);
}
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(entityDeathPlaceholders(sec[1], p, em.getEntity(), hasOwner))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(entityDeathPlaceholders(sec[1], p, em.getEntity(), hasOwner))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down Expand Up @@ -773,14 +773,14 @@ public static TextComponent getEntityDeath(Player player, Entity e, String damag
TextComponent.Builder base = Component.text();

if (Settings.getInstance().getConfig().getBoolean(Config.ADD_PREFIX_TO_ALL_MESSAGES.getPath())) {
TextComponent prefix = Assets.convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
TextComponent prefix = convertFromLegacy(Messages.getInstance().getConfig().getString("Prefix"));
base.append(prefix);
}

TextComponent deathMessage = Assets.convertFromLegacy(entityDeathPlaceholders(msg, player, e, hasOwner));
TextComponent deathMessage = convertFromLegacy(entityDeathPlaceholders(msg, player, e, hasOwner));
base.append(deathMessage);
// if (sec.length >= 2) {
// tc.hoverEvent(HoverEvent.showText(Assets.convertFromLegacy(entityDeathPlaceholders(sec[1], player, entity, hasOwner))));
// tc.hoverEvent(HoverEvent.showText(convertFromLegacy(entityDeathPlaceholders(sec[1], player, entity, hasOwner))));
// }
// if (sec.length == 3) {
// if (sec[2].startsWith("COMMAND:")) {
Expand Down

0 comments on commit d968639

Please sign in to comment.