Einfaches /roll Modul
This commit is contained in:
90
src/main/java/Simpleroll/messageInterpreter.java
Normal file
90
src/main/java/Simpleroll/messageInterpreter.java
Normal file
@ -0,0 +1,90 @@
|
||||
package Simpleroll;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class messageInterpreter {
|
||||
|
||||
private Integer diceart = 6;
|
||||
private Integer numberOfDice = 1;
|
||||
private Integer typ = 0;
|
||||
private Integer intResult = 0;
|
||||
|
||||
private language activLang;
|
||||
private MessageReceivedEvent event;
|
||||
|
||||
|
||||
public Integer getDiceart() {
|
||||
return diceart;
|
||||
}
|
||||
|
||||
public Integer getNumberOfDice() {
|
||||
return numberOfDice;
|
||||
}
|
||||
|
||||
public Integer getIntResult() {
|
||||
return intResult;
|
||||
}
|
||||
|
||||
public boolean isNum() {
|
||||
if(typ == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDice() {
|
||||
if(typ == 2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param event JDA Event
|
||||
* @param activLang Aktive Sprache
|
||||
*/
|
||||
public messageInterpreter(MessageReceivedEvent event, language activLang) {
|
||||
this.event = event;
|
||||
this.activLang = activLang;
|
||||
}
|
||||
private void reset() {
|
||||
diceart = 6;
|
||||
numberOfDice = 1;
|
||||
typ = 0;
|
||||
intResult = 0;
|
||||
}
|
||||
public void inputInterpreter(String Input) {
|
||||
reset();
|
||||
Scanner sc = new Scanner(Input.trim());
|
||||
|
||||
if(sc.hasNextInt()) { // ist eine Zahl
|
||||
typ = 1;
|
||||
intResult = Integer.parseInt(Input.trim());
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (Input.trim().toLowerCase().replace(" ", "").matches("([0-9]*)[dw]([0-9].*)")) { // format besteh aus (Zahlen)d(Zahlen) oder (Zahlen)w(Zahlen)
|
||||
String[] diceInterpreter = Input.trim().toLowerCase().replace(" ", "").split("[wd]");
|
||||
try {
|
||||
diceart = Integer.parseInt(diceInterpreter[1]);
|
||||
numberOfDice = Integer.parseInt(diceInterpreter[0]);
|
||||
typ = 2;
|
||||
} catch (NumberFormatException e) {
|
||||
String message = activLang.error;
|
||||
message = message.replace("%command%", Input.trim().toLowerCase());
|
||||
//event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
|
||||
typ = -1;
|
||||
throw new IllegalArgumentException( message );
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = activLang.error;
|
||||
message = message.replace("%command%", Input.trim().toLowerCase());
|
||||
typ = -1;
|
||||
throw new IllegalArgumentException( message );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user