Skip to content

Commit

Permalink
Fix hover event
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Nov 4, 2023
1 parent 960b60e commit b64fa1e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ For Developers:
- Command system, tab complete and some refactor
- Lower version Compatibility
- Look into get entity name
- Fix HoverEvent
- Add version comment in config
- Config
- Improve method naming
- Improve hoverEvent
- More issues can track in [here](https://bbs.breeze.asia/d/128-si-wang-ti-shi-wen-ti)

## Special Thanks To:
Expand Down
90 changes: 50 additions & 40 deletions src/main/java/dev/mrshawn/deathmessages/utils/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.kyori.adventure.nbt.api.BinaryTagHolder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -314,21 +315,23 @@ public static TextComponent getNaturalDeath(PlayerManager pm, String damageCause
} else {
displayName = i.getItemMeta().getDisplayName();
}
String[] spl = msg.split("%weapon%");
if (spl.length != 0 && spl[0] != null && !spl[0].isEmpty()) {
displayName = spl[0] + displayName;
}
if (spl.length != 0 && spl.length != 1 && spl[1] != null && !spl[1].isEmpty()) {
displayName = displayName + spl[1];
}

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

Component showitem = Component.text()
.append(Assets.convertFromLegacy(displayName))
.build()
.hoverEvent(hoverEventComponents);

naturalDeath.append(showitem);
Component deathMessage = Component.text()
.append(convertFromLegacy(msg))
.build()
.replaceText(TextReplacementConfig.builder()
.match("%weapon%")
.replacement(showitem)
.build());

naturalDeath.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
naturalDeath.append(deathMessage);
Expand Down Expand Up @@ -390,21 +393,23 @@ public static TextComponent getWeapon(boolean gang, PlayerManager pm, LivingEnti
} else {
displayName = i.getItemMeta().getDisplayName();
}
String[] spl = msg.split("%weapon%");
if (spl.length != 0 && spl[0] != null && !spl[0].isEmpty()) {
displayName = spl[0] + displayName;
}
if (spl.length != 0 && spl.length != 1 && spl[1] != null && !spl[1].isEmpty()) {
displayName = displayName + spl[1];
}

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

Component showitem = Component.text()
.append(Assets.convertFromLegacy(displayName))
.build()
.hoverEvent(hoverEventComponents);

weaponMessage.append(showitem);
Component deathMessage = Component.text()
.append(convertFromLegacy(msg))
.build()
.replaceText(TextReplacementConfig.builder()
.match("%weapon%")
.replacement(showitem)
.build());

weaponMessage.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
weaponMessage.append(deathMessage);
Expand Down Expand Up @@ -469,21 +474,23 @@ public static TextComponent getEntityDeathWeapon(Player p, Entity e, MobType mob
} else {
displayName = i.getItemMeta().getDisplayName();
}
String[] spl = msg.split("%weapon%");
if (spl.length != 0 && spl[0] != null && !spl[0].isEmpty()) {
displayName = spl[0] + displayName;
}
if (spl.length != 0 && spl.length != 1 && spl[1] != null && !spl[1].isEmpty()) {
displayName = displayName + spl[1];
}

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

Component showitem = Component.text()
.append(Assets.convertFromLegacy(displayName))
.build()
.hoverEvent(hoverEventComponents);

tc.append(showitem);
Component deathMessage = Component.text()
.append(convertFromLegacy(msg))
.build()
.replaceText(TextReplacementConfig.builder()
.match("%weapon%")
.replacement(showitem)
.build());

tc.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
tc.append(deathMessage);
Expand Down Expand Up @@ -583,20 +590,21 @@ public static TextComponent getProjectile(boolean gang, PlayerManager pm, Living
displayName = i.getItemMeta().getDisplayName();
hoverEventComponents = HoverEvent.showItem(Key.key(i.getType().name().toLowerCase()), i.getAmount(), BinaryTagHolder.binaryTagHolder(i.getItemMeta().getAsString()));
}
String[] spl = msg.split("%weapon%");
if (spl.length != 0 && spl[0] != null && !spl[0].isEmpty()) {
displayName = spl[0] + "&r" + displayName;
}
if (spl.length != 0 && spl.length != 1 && spl[1] != null && !spl[1].isEmpty()) {
displayName = displayName + "&r" + spl[1];
}

Component showitem = Component.text()
.append(Assets.convertFromLegacy(displayName))
.build()
.hoverEvent(hoverEventComponents);

tc.append(showitem);
Component deathMessage = Component.text()
.append(convertFromLegacy(msg))
.build()
.replaceText(TextReplacementConfig.builder()
.match("%weapon%")
.replacement(showitem)
.build());

tc.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
tc.append(deathMessage);
Expand Down Expand Up @@ -661,21 +669,23 @@ public static TextComponent getEntityDeathProjectile(Player p, EntityManager em,
} else {
displayName = i.getItemMeta().getDisplayName();
}
String[] spl = msg.split("%weapon%");
if (spl.length != 0 && spl[0] != null && !spl[0].isEmpty()) {
displayName = spl[0] + "&r" + displayName;
}
if (spl.length != 0 && spl.length != 1 && spl[1] != null && !spl[1].isEmpty()) {
displayName = displayName + "&r" + spl[1];
}

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

Component showitem = Component.text()
.append(Assets.convertFromLegacy(displayName))
.build()
.hoverEvent(hoverEventComponents);

tc.append(showitem);
Component deathMessage = Component.text()
.append(convertFromLegacy(msg))
.build()
.replaceText(TextReplacementConfig.builder()
.match("%weapon%")
.replacement(showitem)
.build());

tc.append(deathMessage);
} else {
TextComponent deathMessage = Assets.convertFromLegacy(msg);
tc.append(deathMessage);
Expand Down

0 comments on commit b64fa1e

Please sign in to comment.