mehrsprachig zwichenstand

This commit is contained in:
Sebastian Zeidler
2019-02-23 11:27:44 +01:00
parent 3dea42842f
commit 8c7f497e0d
2 changed files with 94 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import org.json.JSONObject;
import java.awt.*;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@ -20,6 +22,10 @@ public class dice extends ListenerAdapter {
private String prefixZitat;
private String prefixTest;
private language langDe = new language("de");
private language langEn = new language("en");
Map<String, String> channelList = new HashMap<String, String>();
public dice() {
@ -34,6 +40,9 @@ public class dice extends ListenerAdapter {
return;
}
if(!channelList.containsKey(event.getChannel().getId())) {
channelList.put(event.getChannel().getId(), "de");
}
User author = event.getAuthor();
if (!author.isBot()) {
if (event.getMessage().getContentRaw().startsWith(this.prefixSr))

View File

@ -0,0 +1,85 @@
package Shadowrun;
import java.io.*;
import java.util.Properties;
public class language {
public String language = "Deutsch";
public String emptyCommand = " der %command% befehl benötigt einen Wert";
public String error = " Irgend was dummes ist passiert beim Verstehen von %command%";
public String error2 = " Irgend was dummes ist passiert beim Verstehen von %command%";
public String noNegativ = " es darf kein Negativen Wurf geben";
public String dice = "w";
public String resultText = " %numberOfDice%%dice%%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
public language() {
this.readConfig();
}
/**
*
* @param lang Srache
*/
public language(String lang) {
this.readConfig(lang);
}
public void readConfig() {
this.readConfig("de");
}
public void readConfig(String lang) {
FileInputStream input = null;
OutputStream output = null;
Properties config = new Properties();
try {
File f = new File("config.cfg");
if (f.isFile() && f.canRead()) {
input = new FileInputStream("shadowrun.lang");
config.load(input);
if(config.containsKey(lang + ".language"))
this.language = config.getProperty(lang + ".language");
if(config.containsKey(lang + ".emptyCommand"))
this.emptyCommand = config.getProperty(lang + ".emptyCommand");
if(config.containsKey(lang + ".error"))
this.error = config.getProperty(lang + ".error");
if(config.containsKey(lang + ".error2"))
this.error2 = config.getProperty(lang + ".error2");
if(config.containsKey(lang + ".noNegativ"))
this.noNegativ = config.getProperty(lang + ".noNegativ");
if(config.containsKey(lang + ".dice"))
this.dice = config.getProperty(lang + ".dice");
if(config.containsKey(lang + ".resultText"))
this.resultText = config.getProperty(lang + ".resultText");
}
else {
output = new FileOutputStream("config.cfg");
config.setProperty(lang + ".language", this.language);
config.setProperty(lang + ".emptyCommand", this.emptyCommand);
config.setProperty(lang + ".error", this.error);
config.setProperty(lang + ".error2", this.error2);
config.setProperty(lang + ".noNegativ", this.noNegativ);
config.setProperty(lang + ".dice", this.dice);
config.setProperty(lang + ".resultText", this.resultText);
config.store(output, null);
}
} catch (Exception e) {
}
finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}