Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (objMsg.getContentRaw().equalsIgnoreCase(Reference.prefix + "roll"))
- {
- String param = objMsg.getContentRaw();
- int toRoll = 1;
- try{
- if (param.contains("d")){
- toRoll = Integer.parseInt( param.substring(0,param.indexOf("d")));
- //param = param.substring(param.indexOf("d")+1);
- }
- //String[] parts = param.split("[^\\d]");
- Pattern rollPat = Pattern.compile("(\\d+)d(\\d+)");
- System.out.println(param);
- Matcher match = rollPat.matcher(param);
- int min = 1, max = 1, result = 0;
- while (match.find()){
- max = Integer.parseInt(match.group(2));
- toRoll = Integer.parseInt(match.group(1));
- }
- String modS = "?";
- boolean pos = false;
- if (param.contains("+")){
- modS = param.substring(param.indexOf("+")+1);
- pos = true;
- } else if (param.contains("-")){
- modS = param.substring(param.indexOf("-")+1);
- pos = false;
- }
- else
- modS = "0";
- int modV = Integer.parseInt(modS);
- int roll = 0;
- List<Integer> rolls = new ArrayList();
- if (toRoll == 1)
- roll = ThreadLocalRandom.current().nextInt(min, max + 1);
- else for (int i = 0; i < toRoll; i++){
- int cur = ThreadLocalRandom.current().nextInt(min, max + 1);
- roll += cur;
- rolls.add(cur);
- System.out.println(cur);
- }
- String mod = "";
- if (pos){
- result = roll + modV;
- mod = "_+" + modV + "_";
- }
- else{
- result = roll - modV;
- mod = "_-" + modV + "_";
- }
- if (modV == 0)
- mod = "";
- String res = "";
- if (toRoll != 1){
- for (int i:rolls){
- res += i + "+";
- }
- System.out.println(rolls);
- System.out.println(res);
- res = res.substring(0, res.length()-1);
- }
- else
- res = roll + "";
- objMsgCh.sendMessage("_Result for " + evt.getAuthor().getAsMention() + "'s roll:_\n **" + result + "** (" + res + mod + ")").queue();}
- catch (Exception e)
- {
- objMsgCh.sendMessage("Invalid roll").queue();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement