Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. if (objMsg.getContentRaw().equalsIgnoreCase(Reference.prefix + "roll"))
  2. {
  3. String param = objMsg.getContentRaw();
  4. int toRoll = 1;
  5. try{
  6. if (param.contains("d")){
  7. toRoll = Integer.parseInt( param.substring(0,param.indexOf("d")));
  8. //param = param.substring(param.indexOf("d")+1);
  9. }
  10. //String[] parts = param.split("[^\\d]");
  11. Pattern rollPat = Pattern.compile("(\\d+)d(\\d+)");
  12. System.out.println(param);
  13. Matcher match = rollPat.matcher(param);
  14.  
  15. int min = 1, max = 1, result = 0;
  16. while (match.find()){
  17. max = Integer.parseInt(match.group(2));
  18. toRoll = Integer.parseInt(match.group(1));
  19. }
  20. String modS = "?";
  21. boolean pos = false;
  22. if (param.contains("+")){
  23. modS = param.substring(param.indexOf("+")+1);
  24. pos = true;
  25. } else if (param.contains("-")){
  26. modS = param.substring(param.indexOf("-")+1);
  27. pos = false;
  28. }
  29. else
  30. modS = "0";
  31.  
  32. int modV = Integer.parseInt(modS);
  33. int roll = 0;
  34. List<Integer> rolls = new ArrayList();
  35.  
  36. if (toRoll == 1)
  37. roll = ThreadLocalRandom.current().nextInt(min, max + 1);
  38. else for (int i = 0; i < toRoll; i++){
  39. int cur = ThreadLocalRandom.current().nextInt(min, max + 1);
  40. roll += cur;
  41. rolls.add(cur);
  42. System.out.println(cur);
  43. }
  44.  
  45. String mod = "";
  46. if (pos){
  47. result = roll + modV;
  48. mod = "_+" + modV + "_";
  49. }
  50. else{
  51. result = roll - modV;
  52. mod = "_-" + modV + "_";
  53. }
  54. if (modV == 0)
  55. mod = "";
  56.  
  57. String res = "";
  58. if (toRoll != 1){
  59. for (int i:rolls){
  60. res += i + "+";
  61. }
  62. System.out.println(rolls);
  63. System.out.println(res);
  64. res = res.substring(0, res.length()-1);
  65. }
  66. else
  67. res = roll + "";
  68. objMsgCh.sendMessage("_Result for " + evt.getAuthor().getAsMention() + "'s roll:_\n **" + result + "** (" + res + mod + ")").queue();}
  69. catch (Exception e)
  70. {
  71. objMsgCh.sendMessage("Invalid roll").queue();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement