Advertisement
Guest User

Untitled

a guest
Mar 28th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. @Listener
  2. public void EntityDestructEvent(DestructEntityEvent e){
  3. Entity entity = e.getTargetEntity();
  4.  
  5. if(entity instanceof Human){
  6.  
  7. int x,y,z;
  8.  
  9. x = (int) entity.getLocation().getX();
  10. y = (int) entity.getLocation().getY();
  11. z = (int) entity.getLocation().getZ();
  12.  
  13.  
  14. EntitySnapshot entitySnapshot = entity.createSnapshot().withLocation(entity.getLocation());
  15. Optional<Chunk> chunkOptional = entity.getWorld().getChunk(x,y,z);
  16.  
  17. if(chunkOptional.isPresent()){
  18. Chunk chunk = chunkOptional.get();
  19.  
  20. Map<EntitySnapshot,Chunk> entSnapMap = new HashMap<>();
  21. entSnapMap.put(entitySnapshot,chunk);
  22.  
  23. map.add(entSnapMap);
  24.  
  25. }
  26.  
  27. }
  28.  
  29.  
  30. }
  31.  
  32.  
  33. @Listener
  34. public void chunkLoadEvent(LoadChunkEvent e){
  35.  
  36. Chunk chunk = e.getTargetChunk();
  37.  
  38. for (int i = 0; i < map.size();i++){
  39.  
  40. Map<EntitySnapshot,Chunk> mapwanted = map.get(i);
  41.  
  42. for (Object preKey : mapwanted.keySet()){
  43.  
  44. EntitySnapshot entitySnapshot = (EntitySnapshot)preKey;
  45.  
  46. Chunk snapChunk = mapwanted.get(preKey);
  47.  
  48. if(chunk == snapChunk){
  49. entitySnapshot.restore();
  50. map.remove(mapwanted);
  51. }
  52.  
  53. }
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement