-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added translations #19
Conversation
+ Translations
+ Translations
+ Translations
+ Translations
+ Translations
+ Translations
+ Translations
+ Translations
+ Translations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome that you took it upon yourself to implement these changes but I feel that this could be designed a bit better.
Additionally to the individual comments I think it would be better to avoid all the null checks either by having a central sendMessage method in the main class that handles them or by returning a general "message not found" error when the getting a message with a non-existing key.
That could clean up the code a lot and keep down the number of the changed lines.
} | ||
if(sender.hasPermission("csn.command.cleandatabase") && plugin.getMessage("help.cleandatabase-all") != null) { | ||
helpItems.add(plugin.getMessage("help.cleandatabase-all")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to merge all these so that sender.hasPermission("csn.command.cleandatabase")
is only called once?
src/main/resources/config.yml
Outdated
@@ -1,5 +1,5 @@ | |||
# Chest Shop Notifier | |||
# Config file for 1.2 | |||
# Config file for 1.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to increase the version please also do so in the pom.xml.
@@ -91,7 +105,9 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label, | |||
if (userId != null) { | |||
cleaner.cleanUser(userId); | |||
} else { | |||
sender.sendMessage(ChatColor.RED + args[i + 1] + " is not a valid username/uuid input for " + param.getUsage() + "!"); | |||
if(plugin.getMessage("invalid-username") != null) { | |||
sender.sendMessage(plugin.getMessage("invalid-username").replace("{typo}", args[i + 1]).replace("{usage}", param.getUsage())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good if we could use a better way to replace placeholders in messages. Something like getMessage("invalid-username", "type", args[i + 1])
via a getMessage(String key, String... replacements)
method?
Added changes
Added changes
Added changes
Added changes, reduced size
Added changes
Added changes
updated, added some translations
Updated
Updated
changed version
Should be good to go 👍 |
@@ -73,8 +73,7 @@ private void gatherResults() { | |||
Statement readStatement = c.createStatement(); | |||
int rowsUpdated = readStatement.executeUpdate("UPDATE csnUUID SET `Unread`='1' WHERE `ShopOwnerId`='" + userId.toString() + "'"); | |||
|
|||
if (rowsUpdated > 0 && plugin.getMessage("history-marked-read") != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you removed too much here ;)
// return input; | ||
return ChatColor.translateAlternateColorCodes('&', input); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this extra method just to translate the color codes?
} else { | ||
return "Missing string 'messages." + key + "' in config.yml"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only need one getMessage method as java will just use the one below with a zero sized array if no argument is provided after the first one.
String s = getConfig().getString("messages." + key); | ||
if (s != null && !s.isEmpty()) { | ||
for (int i = 0; i < replacements.length; i++) { | ||
s = s.replace("{" + i + "}", replacements[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to get replacements[i+1]
here and check for i + 1 < replacements.length
Removed too much :P
1 getMessage method; Fixed texty getMessage
wrong file :p
fixed removal
I hope this fixed the getMessage method; im not very skilled in java. Learning with the process 💯 |
|
||
public Help(ChestShopNotifier main) { | ||
plugin = main; | ||
} | ||
|
||
public static void SendDialog(CommandSender sender) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing that I noticed then it should be good:
You either need to pass the plugin instance to the method or make the method non-static and initialise the Help object in the CommandRunner class in order to access the plugin field. (Help is never initialised in the CommandRunner). I suggest fixing the case of the sendDialog method at the same time.
@@ -134,7 +134,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label, | |||
if (userId == null) { | |||
OfflinePlayer target = plugin.getServer().getPlayer(args[1]); | |||
if (target == null) { | |||
target = plugin.getServer().getOfflinePlayer(args[1]); | |||
target = plugin.getServer().getOfflinePlayer(NameManager.getUUID(args[1])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to use this method instead of the deprecated getOfflinePlayer(args[1])
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not really a need to get the OfflinePlayer here as it was only used to get the player's UUID which can be replaced with the NameManager method call.
@@ -25,39 +25,39 @@ public CommandRunner(ChestShopNotifier plugin) { | |||
public boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) { | |||
if(args.length == 0) { | |||
Help.SendDialog(sender); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are still calling a method here statically that isn't static. You need to do something like new Help(this).sendDialog(sender)
. Your IDE should warn you about this. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did not, it gave me an error when using new Help(this).sendDialog(sender)
"Help (com.wfector.notifier.ChestShopNotifier) in Help cannot be applied to (com.wfector.command.CommandRunner)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Help(plugin).SendDialog(sender);
works though
@@ -17,6 +16,7 @@ | |||
|
|||
public class CommandRunner implements CommandExecutor { | |||
private final ChestShopNotifier plugin; | |||
private Help Help; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo. there is no need to store the Help command in a separate field. IT can be instantiated when the command is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could i achieve that? if i remove that line the class would break when trying to get something from Help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the field (that you don't assign anywhere anyways) if you create a new object instance when it is needed. That would be more obvious if you used the normal, lower-case starting naming scheme of variables, fields and methods.
Also there is another help dialog further down on line 114.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not exactly sure what i must do now, do i need to remove the uppercase Help to help? And change that on line 114 too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, instantiate a new Help object on line 114 too and remove the field, it never gets used nor assigned anywhere.
Fixed 📦 |
Added some translations to the config.yml