Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Not sure if this still works and too lazy to test
- public static void sendActionText(Player player, String message){
- PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(message), (byte)2);
- ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
- }
- //Checks if a string is a int
- public static boolean isInt(String s) {
- try {
- Integer.parseInt(s);
- } catch (NumberFormatException nfe) {
- return false;
- }
- return true;
- }
- //Checks if a stirng is a double
- public static boolean isDouble(String s) {
- try {
- Double.parseDouble(s);
- } catch (NumberFormatException nfe) {
- return false;
- }
- return true;
- }
- //Just checks if a string is a number (int or a double)
- public static boolean isNumeric(String s) {
- if(isInt(s) || isDouble(s)) {
- return true;
- }else {
- return false;
- }
- }
- /*This is pretty useful for me when ever I need
- //to store a location in a config file instead of
- //having it all on multiple lines this makes it nice
- //and neat all on one line
- // x y z world-name
- //Format - 11:64:320:world */
- public static String locToString(Location loc){
- return loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + ":" + loc.getWorld().getName();
- }
- //This will convert the above string to a Location
- public static Location stringToLoc(String loc) {
- String[] words = loc.split("\\:");
- String x = words[0];
- String y = words[1];
- String z = words[2];
- String world = words[3];
- World wrld = Bukkit.getWorld(world);
- Location loca = new Location(wrld, Integer.parseInt(x), Integer.parseInt(y), Integer.parseInt(z));
- return loca;
- }
- //Stuff for random
- //Just returns a random num within range of the min and max
- public static int getRandomNumber(int min, int max){
- return ThreadLocalRandom.current().nextInt(min, max + 1);
- }
- //Does a random chance
- public static Boolean doRandomChance(int chance){
- int i = ThreadLocalRandom.current().nextInt(100);
- if(i < chance){
- return true;
- }else{
- return false;
- }
- }
- //Format string
- //Nice if you are displaying a number to make it more readable
- public String formatInt(int format) {
- DecimalFormat formatter = new DecimalFormat("#,###.00");
- String formatted = formatter.format(format);
- return formatted;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement