NullValkyrie

Minecraft 1.19 multipurpose plugin for spigot servers with a lot of features where most modern servers have.
git clone https://codeberg.org/night0721/NullValkyrie
Log | Files | Refs | README | LICENSE

Util.java (1379B)


      1 package me.night.nullvalkyrie.util;
      2 
      3 import org.bukkit.ChatColor;
      4 
      5 import java.lang.reflect.Field;
      6 
      7 public class Util {
      8     public static String centerText(String text, int lineLength) {
      9         StringBuilder builder = new StringBuilder();
     10         char space = ' ';
     11         int distance = (lineLength - text.length()) / 2;
     12         String repeat = String.valueOf(space).repeat(Math.max(0, distance));
     13         builder.append(repeat);
     14         builder.append(text);
     15         builder.append(repeat);
     16         return builder.toString();
     17     }
     18 
     19     public static String color(String string) {
     20         return ChatColor.translateAlternateColorCodes('&', string);
     21     }
     22 
     23     public static String capitalize(String str) {
     24         if (str == null || str.length() == 0) return str;
     25         return str.substring(0, 1).toUpperCase() + str.substring(1);
     26     }
     27 
     28     public static Object getFieldValue(Object instance, String fieldName) throws Exception {
     29         Field field = instance.getClass().getDeclaredField(fieldName);
     30         field.setAccessible(true);
     31         return field.get(instance);
     32     }
     33 
     34     public static void setFieldValue(Object instance, String fieldName, Object value) throws Exception {
     35         Field field = instance.getClass().getDeclaredField(fieldName);
     36         field.setAccessible(true);
     37         field.set(instance, value);
     38     }
     39 }