Skip to content

Commit

Permalink
Improve player ping support
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley1808 committed Feb 10, 2024
1 parent 347308d commit 7d90c43
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=1.20.4
loader_version=0.15.3
loader_version=0.15.6

# Mod Properties
mod_version=1.4
maven_group=me.wesley1808
archives_base_name=advancedchat

# API dependencies
fabric_version=0.91.3+1.20.4
fabric_version=0.96.0+1.20.4
placeholder_api_version=2.3.0+1.20.3
playerdata_api_version=0.4.0+1.20.3
predicate_api_version=0.3.0+1.20.2
permission_api_version=0.3-SNAPSHOT

# Other dependencies
styledchat_version=2.4.0+1.20.3
vanish_version=1.5.0+1.20.3-rc1
vanish_version=1.5.1+1.20.4
4 changes: 4 additions & 0 deletions src/main/java/me/wesley1808/advancedchat/impl/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public static <T, R> List<R> map(Collection<T> collection, Function<T, R> functi
return result;
}

public static boolean isWhiteSpace(String string, int index) {
return index < 0 || index >= string.length() || Character.isWhitespace(string.charAt(index));
}

public static CompletableFuture<Suggestions> suggest(SuggestionsBuilder builder, Collection<String> suggestions) {
if (suggestions.isEmpty()) {
return Suggestions.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public ServerGamePacketListenerImplMixin(MinecraftServer minecraftServer, Connec

@Inject(method = "sendPlayerChatMessage", at = @At("HEAD"))
private void advancedchat$onChatMessage(PlayerChatMessage message, ChatType.Bound bound, CallbackInfo ci) {
String pingName = '@' + this.player.getScoreboardName();
if (message.signedContent().contains(pingName)) {
String playerName = this.player.getScoreboardName();
String content = message.signedContent();
int index = content.indexOf(playerName);

if (index >= 0 && Util.isWhiteSpace(content, index - 1) && Util.isWhiteSpace(content, index + playerName.length())) {
Util.playSound(this.player, Config.instance().chatPingSound);
}
}
Expand Down

0 comments on commit 7d90c43

Please sign in to comment.