Advertisement
JackOUT

Untitled

Oct 26th, 2021
1,270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package games.coob.core.block;
  2.  
  3. import lombok.Getter;
  4. import org.bukkit.Location;
  5. import org.mineacademy.fo.SerializeUtil;
  6. import org.mineacademy.fo.collection.SerializedMap;
  7. import org.mineacademy.fo.model.ConfigSerializable;
  8. import org.mineacademy.fo.remain.CompMaterial;
  9.  
  10. @Getter
  11. public class BlockData implements ConfigSerializable {
  12.  
  13.     @Getter
  14.     private static final BlockData instance = new BlockData();
  15.  
  16.     private Location location;
  17.  
  18.     private CompMaterial material;
  19.  
  20.     private int level;
  21.  
  22.     public void setLevel(final int level) {
  23.         this.level = level;
  24.     }
  25.  
  26.     public void increaseLevel() {
  27.         level++;
  28.     }
  29.  
  30.     public void setLocation(final Location location) {
  31.         this.location = location;
  32.     }
  33.  
  34.     public void setMaterial(final CompMaterial material) {
  35.         this.material = material;
  36.     }
  37.  
  38.     private String toHash(final Location location, final CompMaterial material) {
  39.         return SerializeUtil.serializeLoc(location) + " | " + material;
  40.     }
  41.  
  42.     @Override
  43.     public SerializedMap serialize() {
  44.         return SerializedMap.ofArray(
  45.                 "hash", toHash(this.location, this.material),
  46.                 "Level", this.level);
  47.     }
  48.  
  49.     static BlockData deserialize(final SerializedMap map) {
  50.         final String hash = map.getString("hash");
  51.         final int level = map.getInteger("Level");
  52.  
  53.         final String[] split = hash.split(" \\| ");
  54.         final Location location = SerializeUtil.deserializeLocation(split[0]);
  55.         final CompMaterial material = CompMaterial.valueOf(split[1]);
  56.  
  57.         final BlockData blockData = new BlockData();
  58.  
  59.         blockData.setMaterial(material);
  60.         blockData.setLocation(location);
  61.         blockData.setLevel(level);
  62.  
  63.         return blockData;
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement