Initial commit

v1.0
This commit is contained in:
YouHaveTrouble
2020-01-18 11:28:08 +01:00
commit d487766eb8
6 changed files with 193 additions and 0 deletions
@@ -0,0 +1,38 @@
package pl.laststation.youhavetrouble.dynamichelp.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import pl.laststation.youhavetrouble.dynamichelp.dynamichelp;
import pl.laststation.youhavetrouble.dynamichelp.langmodule.lang;
public class helpCommand implements CommandExecutor {
public helpCommand(dynamichelp plugin) {
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
new lang.translate();
Player p = (Player) commandSender;
if (args.length > 1) {
commandSender.sendMessage(lang.getTranslatedString(p, "too-many-arguments"));
return true;
} else if (args.length == 1) {
if (dynamichelp.getPlugin().getConfig().getString("lang.en_us."+args[0]) == null) {
commandSender.sendMessage(lang.getTranslatedString(p, "invalid-page"));
return true;
}
commandSender.sendMessage(lang.getTranslatedString(p, args[0]));
return true;
}
commandSender.sendMessage(lang.getTranslatedString(p, "1"));
return true;
}
}
@@ -0,0 +1,21 @@
package pl.laststation.youhavetrouble.dynamichelp;
import org.bukkit.plugin.java.JavaPlugin;
import pl.laststation.youhavetrouble.dynamichelp.commands.helpCommand;
public class dynamichelp extends JavaPlugin {
public void onEnable() {
plugin = this;
saveDefaultConfig();
getCommand("help").setExecutor(new helpCommand(this));
}
private static dynamichelp plugin;
public static dynamichelp getPlugin(){ return plugin; }
}
@@ -0,0 +1,36 @@
package pl.laststation.youhavetrouble.dynamichelp.langmodule;
import org.bukkit.entity.Player;
import pl.laststation.youhavetrouble.dynamichelp.dynamichelp;
public class lang {
/**
*
* @param p Player of whom locale we're getting
* @param msg Message string
* @return Message translated to language based on player's locale
*/
public static String getTranslatedString(Player p, String msg) {
String plocale = p.getLocale();
String tmessage = dynamichelp.getPlugin().getConfig().getString("lang." + plocale + "." + msg);
String dmessage = dynamichelp.getPlugin().getConfig().getString("lang.en_us." + msg);
if (tmessage == null) {
if (dmessage == null) {
return " ";
}
return dmessage;
} else {
return tmessage;
}
}
public static class translate {
public static translate translate;
public translate() {
this.translate = this;
}
}
}
+39
View File
@@ -0,0 +1,39 @@
#Use this file to create your own help subcommands
#If user does not specify an argument, the message will default to "la_ng.1"
#Default minecraft formatting codes are working in all messages! (https://minecraft.gamepedia.com/Formatting_codes)
#
#MAKE SURE THAT EN_US SECTION ALWAYS HAS ALL THE MESSAGES OR THE COMMANDS WON'T WORK
lang:
en_us:
too-many-arguments: "Too many arguments"
invalid-argument: "Invalid argument"
invalid-page: "There is no page with that index"
1: |
&b-------- DynamicLangHelp (en_us) --------
Default help message for en_us locale!
See DynamicLangHelp/config.yml to change this message
You can add as many lines as you want, but remember,
that default client only shows 15 lines of text while
chat is open!
#This message will appear after typing /help info
info: |
An example of custom /help info subcommand
You can make any /help subcommand you want
pl_pl:
too-many-arguments: "Zbyt dużo argumentów"
invalid-argument: "nieprawidłowy argument"
invalid-page: "Nie ma strony o takim indeksie"
1: |
-------- DynamicLangHelp (pl_pl) --------
Domyślna wiadomość pomocy dla lokalizacji pl_pl!
Sprawdź DynamicLangHelp/config.yml żeby zmienić tę wiadomość
Możesz dodać dowolną ilość linii, ale pamiętaj,
że domyślny klient pokazuje tylko 15 linii tekstu
przy otwartym czacie!
#Ta wiadomość wyświetli się po wpisaniu /help info
info: |
Przykład subkomendy /help info
Mozesz zrobić dowolną subkomendę /help
+9
View File
@@ -0,0 +1,9 @@
main: pl.laststation.youhavetrouble.dynamichelp.dynamichelp
name: DynamicLangHelp
version: 1.0.0
description: Dynamic Locale Help command
author: YouHaveTrouble
commands:
help:
description: Main command for the plugin
usage: /<command> <arg>