turt2live

Untitled

Dec 31st, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package com.turt2live.antishare.storage;
  2.  
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.concurrent.CopyOnWriteArrayList;
  9.  
  10. import org.bukkit.GameMode;
  11. import org.bukkit.block.Block;
  12.  
  13. import com.turt2live.antishare.AntiShare;
  14. import com.turt2live.antishare.feildmaster.lib.configuration.EnhancedConfiguration;
  15. import com.turt2live.antishare.storage.BlockManager.ListComplete;
  16.  
  17. class BlockSaver implements Runnable {
  18.  
  19.     private final Map<String, List<String>> list = new HashMap<String, List<String>>();
  20.     private final AntiShare plugin = AntiShare.getInstance();
  21.     private final BlockManager blockman = plugin.getBlockManager();
  22.     private final File dir;
  23.     private final String gamemode;
  24.     private final ListComplete listType;
  25.     private boolean clear = false, load = false;
  26.     private double completed = 0;
  27.     private final int listSize;
  28.  
  29.     public BlockSaver(CopyOnWriteArrayList<Block> list, GameMode gm, File saveDir, ListComplete type){
  30.         this.dir = saveDir;
  31.         this.gamemode = gm.name();
  32.         this.listType = type;
  33.         for(Block block : list){
  34.             String fname = block.getChunk().getX() + "." + block.getChunk().getZ() + "." + block.getWorld().getName() + ".yml";
  35.             List<String> blocks = new ArrayList<String>();
  36.             if(this.list.containsKey(fname)){
  37.                 blocks = this.list.get(fname);
  38.             }
  39.             blocks.add(block.getX() + ";" + block.getY() + ";" + block.getZ() + ";" + block.getWorld().getName());
  40.             this.list.put(fname, blocks);
  41.         }
  42.         this.listSize = this.list.keySet().size();
  43.     }
  44.  
  45.     @Override
  46.     public void run(){
  47.         for(String chunk : list.keySet()){
  48.             List<String> blocks = list.get(chunk);
  49.             for(String block : blocks){
  50.                 saveBlock(dir, chunk, block);
  51.                 completed++;
  52.             }
  53.         }
  54.         blockman.markSaveAsDone(listType, this);
  55.     }
  56.  
  57.     void saveBlock(File dir, String fname, String key){
  58.         EnhancedConfiguration blocks = blockman.getFile(dir, fname);
  59.         blocks.set(key, gamemode);
  60.     }
  61.  
  62.     boolean getClear(){
  63.         return clear;
  64.     }
  65.  
  66.     boolean getLoad(){
  67.         return load;
  68.     }
  69.  
  70.     void setClear(boolean clear){
  71.         this.clear = clear;
  72.     }
  73.  
  74.     void setLoad(boolean load){
  75.         this.load = load;
  76.     }
  77.  
  78.     double getPercent(){
  79.         return (completed / listSize) * 100;
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment