Advertisement
Darksoul676

Dice Roller

Apr 12th, 2018
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.47 KB | None | 0 0
  1. package me.Darksoul676.ElonyrDiceRoller;
  2.  
  3. import java.util.Arrays;
  4. import java.util.concurrent.ThreadLocalRandom;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. import net.md_5.bungee.api.ChatColor;
  14.  
  15. public class ElonyrDiceRoller extends JavaPlugin
  16. {
  17.      Logger myPluginLogger = Bukkit.getLogger();
  18.      
  19.     public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
  20.     {  
  21.         Player thePlayer = (Player)theSender;
  22.         int min = 1;
  23.         int max = 20;
  24.         int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);
  25.         String randomNumString = Integer.toString(randomNum);
  26.         String playerName = thePlayer.getName();
  27.         String playerString = Arrays.toString(args);
  28.         int dLocation = 0;
  29.         int plusLocation = 0;
  30.         int minusLocation = 0;
  31.         boolean isThereAPlus = false;
  32.         boolean isThereAMinus = false;
  33.         int stringLength = playerString.length();
  34.         String numberOfDice = "0";
  35.         String typeOfDice = "0";
  36.         String modifierOfDice = "0";
  37.         String modifierOfDiceSubOne = "0";
  38.        
  39.         if(commandLabel.equalsIgnoreCase("roll"))
  40.         {
  41.             if(theSender instanceof Player)
  42.             {          
  43.                 if(args.length == 1)
  44.                 {                      
  45.                     for (int i = 0 ; i<playerString.length() ; i++)
  46.                     if(playerString.charAt(i) == 'd')
  47.                     {
  48.                         dLocation = i;
  49.                         String stringChunkOne = playerString.substring(1, dLocation);
  50.                         numberOfDice = stringChunkOne;                         
  51.                     }
  52.                    
  53.                     for (int b = 0 ; b<playerString.length() ; b++)
  54.                         if(playerString.charAt(b) == '+')
  55.                         {
  56.                             isThereAPlus = true;
  57.                         }
  58.                         else
  59.                         {
  60.                            
  61.                         }
  62.                    
  63.                     for (int p = 0 ; p<playerString.length() ; p++)
  64.                         if(playerString.charAt(p) == '-')
  65.                         {
  66.                             isThereAMinus = true;
  67.  
  68.                         }
  69.                         else
  70.                         {
  71.                            
  72.                         }
  73.                    
  74.                         if( isThereAPlus || isThereAMinus == true)
  75.                         {
  76.                             for (int l = 0 ; l<playerString.length() ; l++)
  77.                                 if(playerString.charAt(l) == '+')
  78.                                 {
  79.                                     plusLocation = l;
  80.                                     String stringChunkThree = playerString.substring(plusLocation + 1, stringLength - 1);
  81.                                     String stringChunkThreeWithPlusOrMinus = playerString.substring(plusLocation, stringLength - 1);
  82.                                     modifierOfDice = stringChunkThree;
  83.                                     modifierOfDiceSubOne = stringChunkThreeWithPlusOrMinus;
  84.                                 }
  85.                             for (int h = 0 ; h<playerString.length() ; h++)
  86.                                 if(playerString.charAt(h) == '-')
  87.                                 {
  88.                                     minusLocation = h;
  89.                                     String stringChunkThree = playerString.substring(minusLocation + 1, stringLength - 1);
  90.                                     String stringChunkThreeWithPlusOrMinus = playerString.substring(minusLocation, stringLength - 1);
  91.                                     modifierOfDice = stringChunkThree;
  92.                                     modifierOfDiceSubOne = stringChunkThreeWithPlusOrMinus;
  93.                                 }                                                  
  94.                             for (int a = 0 ; a<playerString.length() ; a++)
  95.                                 if(playerString.charAt(a) == '+')
  96.                                 {
  97.                                     plusLocation = a;
  98.                                     String stringChunkTwo = playerString.substring(dLocation + 1, plusLocation);
  99.                                     typeOfDice = stringChunkTwo;
  100.                                     int maxTwo = Integer.valueOf(stringChunkTwo);
  101.                                     int randomNumTwo = ThreadLocalRandom.current().nextInt(min, maxTwo + 1);
  102.                                     String randomNumStringTwo = Integer.toString(randomNumTwo);
  103.                                     int intModifiedNumberOne = randomNumTwo;
  104.                                     int intModifiedNumberTwo = Integer.valueOf(modifierOfDice);
  105.                                     int modifiedNumberSum = intModifiedNumberOne + intModifiedNumberTwo;
  106.                                     String modifiedNumberSumString = Integer.toString(modifiedNumberSum);
  107.                                     int intNumberOfDice = Integer.valueOf(numberOfDice);
  108.                                    
  109.                                     if(isThereAPlus == true || isThereAMinus == false)
  110.                                     {                              
  111.                                             for (int times = 0; times < intNumberOfDice; ++times)
  112.                                             {                                                                              
  113.                                             thePlayer.sendMessage(ChatColor.BLUE + playerName + ChatColor.GRAY + " rolled " + ChatColor.YELLOW + numberOfDice + "d" + typeOfDice + modifierOfDiceSubOne);  
  114.                                             thePlayer.sendMessage(ChatColor.GRAY + "(" + randomNumStringTwo + "+" + modifierOfDice + ")" + " = " + modifiedNumberSumString);                           
  115.                                             }
  116.                                     }
  117.                                 }
  118.                            
  119.                                 else
  120.                                 {
  121.                                     for (int o = 0 ; o<playerString.length() ; o++)
  122.                                         if(playerString.charAt(o) == '-')
  123.                                         {
  124.                                             minusLocation = o;
  125.                                             String stringChunkTwo = playerString.substring(dLocation + 1, minusLocation);
  126.                                             typeOfDice = stringChunkTwo;                                       
  127.                                             int maxTwo = Integer.valueOf(stringChunkTwo);
  128.                                             int randomNumTwo = ThreadLocalRandom.current().nextInt(min, maxTwo + 1);
  129.                                             String randomNumStringTwo = Integer.toString(randomNumTwo);
  130.                                             int intModifiedNumberOne = randomNumTwo;
  131.                                             int intModifiedNumberTwo = Integer.valueOf(modifierOfDice);
  132.                                             int modifiedNumberSum = intModifiedNumberOne - intModifiedNumberTwo;
  133.                                             String modifiedNumberSumString = Integer.toString(modifiedNumberSum);                                      
  134.                                             int intNumberOfDice = Integer.valueOf(numberOfDice);
  135.                                            
  136.                                             if (isThereAMinus == true || isThereAPlus == false)
  137.                                             {
  138.                                                     for (int times = 0; times < intNumberOfDice; ++times)
  139.                                                     {
  140.                                                     thePlayer.sendMessage(ChatColor.BLUE + playerName + ChatColor.GRAY + " rolled " + ChatColor.YELLOW + numberOfDice + "d" + typeOfDice + modifierOfDiceSubOne);
  141.                                                     thePlayer.sendMessage(ChatColor.GRAY + "(" + randomNumStringTwo + "-" + modifierOfDice + ")" + " = " + modifiedNumberSumString);   
  142.                                                     }
  143.                                             }            
  144.                                         }
  145.                                         else
  146.                                         {
  147.                                            
  148.                                         }
  149.                                 }                                          
  150.                         }
  151.                         // Else it will determine the stringChunk using the in-game character limit instead. FIXED.
  152.                         else
  153.                         {
  154.                             String stringChunkTwo = playerString.substring(dLocation + 1, stringLength - 1);
  155.                             typeOfDice = stringChunkTwo;
  156.                             int maxTwo = Integer.valueOf(stringChunkTwo);
  157.                             int randomNumTwo = ThreadLocalRandom.current().nextInt(min, maxTwo + 1);
  158.                             String randomNumStringTwo = Integer.toString(randomNumTwo);
  159.                            
  160.                             if(args.length == 1)
  161.                             {
  162.                                 if(args.length == 1)
  163.                                 {      
  164.                                     if(args.length == 1)
  165.                                     {          
  166.                                         thePlayer.sendMessage(ChatColor.BLUE + playerName + ChatColor.GRAY + " rolled " + ChatColor.YELLOW + numberOfDice + "d" + typeOfDice);     
  167.                                         thePlayer.sendMessage(ChatColor.GRAY + "(" + randomNumStringTwo + "+" + "0" + ")" + " = " + randomNumStringTwo);                                   
  168.                                     }                                                                                  
  169.                                 }
  170.                             }
  171.                         }
  172.                 }
  173.                 else
  174.                 {
  175.                     thePlayer.sendMessage(ChatColor.BLUE + playerName + ChatColor.GRAY + " rolled " + ChatColor.YELLOW + "1d20");      
  176.                     thePlayer.sendMessage(ChatColor.GRAY + "(" + randomNumString + "+0)" + " = " + randomNumString);
  177.                 }
  178.             }      
  179.         }          
  180.         return true;   
  181.     }
  182.    
  183.     public void OnEnable()
  184.     {
  185.  
  186.     }  
  187.    
  188.     public void OnDisable()
  189.     {
  190.  
  191.     }
  192.    
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement