[text] opinion

Viewer

  1. public class CurrencyUser {
  2.  
  3.     private final UUID player;
  4.  
  5.     private EconomyData economyData;
  6.     private TestData testData;
  7.  
  8.     public CurrencyUser(UUID player) {
  9.         this.player = player;
  10.  
  11.         this.economyData = new EconomyData(this.player);
  12.     }
  13.  
  14.     /**
  15.      * Initializes the data fields to make all of them assigned to a non-null value
  16.      * (ONLY EXECUTE ON STARTUP)
  17.      */
  18.     @SneakyThrows
  19.     public void initialize() {
  20.         for (Field field : getClass().getDeclaredFields()) {
  21.             field.setAccessible(true);
  22.  
  23.             if (!Data.class.isAssignableFrom(field.getType())) {
  24.                 continue;
  25.             }
  26.  
  27.             if (field.get(this) != null) {
  28.                 continue;
  29.             }
  30.  
  31.             field.set(this, field.getType().getDeclaredConstructor(UUID.class).newInstance(this.player));
  32.             field.setAccessible(false);
  33.         }
  34.     }
  35. }
  36.  

Editor

You can edit this paste and save as new:


File Description
  • opinion
  • Paste Code
  • 16 Oct-2021
  • 936 Bytes
You can Share it: