Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. //Not sure if this still works and too lazy to test
  2. public static void sendActionText(Player player, String message){
  3. PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(message), (byte)2);
  4. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  5. }
  6.  
  7. //Checks if a string is a int
  8. public static boolean isInt(String s) {
  9. try {
  10. Integer.parseInt(s);
  11. } catch (NumberFormatException nfe) {
  12. return false;
  13. }
  14. return true;
  15. }
  16.  
  17. //Checks if a stirng is a double
  18. public static boolean isDouble(String s) {
  19. try {
  20. Double.parseDouble(s);
  21. } catch (NumberFormatException nfe) {
  22. return false;
  23. }
  24. return true;
  25. }
  26.  
  27. //Just checks if a string is a number (int or a double)
  28. public static boolean isNumeric(String s) {
  29. if(isInt(s) || isDouble(s)) {
  30. return true;
  31. }else {
  32. return false;
  33. }
  34. }
  35.  
  36. /*This is pretty useful for me when ever I need
  37. //to store a location in a config file instead of
  38. //having it all on multiple lines this makes it nice
  39. //and neat all on one line
  40. // x y z world-name
  41. //Format - 11:64:320:world */
  42. public static String locToString(Location loc){
  43. return loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + ":" + loc.getWorld().getName();
  44. }
  45.  
  46. //This will convert the above string to a Location
  47. public static Location stringToLoc(String loc) {
  48. String[] words = loc.split("\\:");
  49. String x = words[0];
  50. String y = words[1];
  51. String z = words[2];
  52. String world = words[3];
  53. World wrld = Bukkit.getWorld(world);
  54. Location loca = new Location(wrld, Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z));
  55. return loca;
  56. }
  57.  
  58. //Stuff for random
  59.  
  60. //Just returns a random num within range of the min and max
  61. public static int getRandomNumber(int min, int max){
  62. return ThreadLocalRandom.current().nextInt(min, max + 1);
  63. }
  64.  
  65. //Does a random chance
  66. public static Boolean doRandomChance(int chance){
  67. int i = ThreadLocalRandom.current().nextInt(100);
  68.  
  69. if(i < chance){
  70. return true;
  71. }else{
  72. return false;
  73. }
  74. }
  75.  
  76. //Format string
  77. //Nice if you are displaying a number to make it more readable
  78. public String formatInt(int format) {
  79. DecimalFormat formatter = new DecimalFormat("#,###.00");
  80. String formatted = formatter.format(format);
  81. return formatted;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement