Skip to content

Commit

Permalink
Restore legacy server compatibility. Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaMug committed Mar 5, 2023
1 parent 0e35c34 commit 338b52b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>me.pikamug.localelib</groupId>
<artifactId>LocaleLib</artifactId>
<version>3.1</version>
<version>3.2</version>

<name>LocaleLib</name>
<url>https://github.com/PikaMug/LocaleLib/</url>
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/me/pikamug/localelib/LocaleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean sendMessage(final Player player, final String message, final Mate
for (final String lk : lvlKeys) {
msg = msg.replaceFirst("<level>", translate(msg, lk, "<level>"));
}
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]");
return true;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public boolean sendMessage(final Player player, final String message, final Map<
msg = message.replaceFirst("<level>", translate(message, lk, "<level>"));
}
}
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]");
return true;
}

Expand All @@ -215,7 +215,7 @@ public boolean sendMessage(final Player player, final String message, final Enti
}
final String key = queryEntityType(type, extra);
final String msg = message.replace("<mob>", translate(message, key, "<mob>"));
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw \"" + player.getName() + "\" [\"" + msg + "\"]");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + formatName(player) + " [\"" + msg + "\"]");
return true;
}

Expand Down Expand Up @@ -491,6 +491,21 @@ private String translate(final String message, final String key, final String pl
return replacement;
}

/**
* Format player name according to server's Bukkit version
*
* @param player Player whose name to format
* @return Formatted name
*/
private String formatName(Player player) {
if (!isBelow113()) {
// Better Geyser/Floodgate compatibility
return "\"" + player.getName() + "\"";
} else {
return player.getName();
}
}

/**
* Checks whether the server's Bukkit version supports use of the ItemMeta#getBasePotionData method.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: LocaleLib
main: me.pikamug.localelib.LocaleLib
version: 3.1
version: 3.2
api-version: 1.13
description: Show translated names of items, entities & more in client's language
website: https://github.com/PikaMug/LocaleLib
Expand Down

0 comments on commit 338b52b

Please sign in to comment.