Advertisement
jayhillx

StatsManager 2

Oct 22nd, 2021
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package com.jayhill.xlife.common.world.stats;
  2.  
  3. import com.jayhill.xlife.XLife;
  4. import net.minecraft.nbt.CompoundNBT;
  5. import net.minecraft.nbt.ListNBT;
  6. import net.minecraft.world.server.ServerWorld;
  7. import net.minecraft.world.storage.DimensionSavedDataManager;
  8. import net.minecraft.world.storage.WorldSavedData;
  9. import net.minecraftforge.common.util.Constants;
  10. import sun.net.www.content.text.Generic;
  11.  
  12. import javax.annotation.Nonnull;
  13. import java.util.function.Supplier;
  14.  
  15. public class StatsManager extends WorldSavedData implements Supplier<Generic> {
  16.     public static ListNBT list = new ListNBT();
  17.  
  18.     public StatsManager() {
  19.         super(XLife.MOD_ID);
  20.     }
  21.  
  22.     public void load(CompoundNBT nbt) {
  23.         nbt.getList("Players", Constants.NBT.TAG_LIST);
  24.     }
  25.  
  26.     @Nonnull
  27.     public CompoundNBT save(CompoundNBT nbt) {
  28.         nbt.put("Players", list);
  29.         return nbt;
  30.     }
  31.  
  32.     public static StatsManager onWorld(ServerWorld world) {
  33.         DimensionSavedDataManager storage = world.getDataStorage();
  34.         StatsManager saver = storage.computeIfAbsent(StatsManager::new, XLife.MOD_ID);
  35.  
  36.         storage.set(saver);
  37.         return saver;
  38.     }
  39.  
  40.     public Generic get() {
  41.         return null;
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement