Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Listener
- public void EntityDestructEvent(DestructEntityEvent e){
- Entity entity = e.getTargetEntity();
- if(entity instanceof Human){
- int x,y,z;
- x = (int) entity.getLocation().getX();
- y = (int) entity.getLocation().getY();
- z = (int) entity.getLocation().getZ();
- EntitySnapshot entitySnapshot = entity.createSnapshot().withLocation(entity.getLocation());
- Optional<Chunk> chunkOptional = entity.getWorld().getChunk(x,y,z);
- if(chunkOptional.isPresent()){
- Chunk chunk = chunkOptional.get();
- Map<EntitySnapshot,Chunk> entSnapMap = new HashMap<>();
- entSnapMap.put(entitySnapshot,chunk);
- map.add(entSnapMap);
- }
- }
- }
- @Listener
- public void chunkLoadEvent(LoadChunkEvent e){
- Chunk chunk = e.getTargetChunk();
- for (int i = 0; i < map.size();i++){
- Map<EntitySnapshot,Chunk> mapwanted = map.get(i);
- for (Object preKey : mapwanted.keySet()){
- EntitySnapshot entitySnapshot = (EntitySnapshot)preKey;
- Chunk snapChunk = mapwanted.get(preKey);
- if(chunk == snapChunk){
- entitySnapshot.restore();
- map.remove(mapwanted);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement