Skip to content

Instantly share code, notes, and snippets.

@Dark32
Created January 19, 2016 06:59
Show Gist options
  • Save Dark32/836e2dd554bcd5bdaff5 to your computer and use it in GitHub Desktop.
Save Dark32/836e2dd554bcd5bdaff5 to your computer and use it in GitHub Desktop.
final private static Pattern rollPatern = Pattern.compile("\\*(.+?)\\*");
final private static Random rand = new Random();
public static String randomRoll(String message ) {
Matcher mt = rollPatern.matcher(message);
ChatColor.getLastColors(message);
while (mt.find()) {
message = message.replaceFirst("\\*(.+?)\\*", "$1 " + (rand.nextInt(100) > chance ? luck : unluck));
}
message = message.replaceAll("\\*(.+?)\\Z", "$1 " + (rand.nextInt(100) > chance ? luck : unluck));
return message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment