Advertisement
Guest User

Untitled

a guest
May 4th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.95 KB | None | 0 0
  1. package org.jbls.LexManos;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.lang.reflect.Field;
  7. import java.util.Properties;
  8.  
  9.  
  10. import org.bukkit.plugin.java.*;
  11. import org.bukkit.craftbukkit.*;
  12. import net.minecraft.server.*;
  13.  
  14. public class AutoSaveStopper extends JavaPlugin {
  15.     public AutoSaveStopper() {}
  16.  
  17.     @Override
  18.     public void onEnable() {
  19.         try {
  20.             Field saveInterval = World.class.getDeclaredField("k");
  21.             saveInterval.setAccessible(true);
  22.             verifyFiles();
  23.             int time = getTime();
  24.            
  25.             for(org.bukkit.World bworld : getServer().getWorlds()){
  26.                 CraftWorld cWorld = (CraftWorld)bworld;
  27.                 World mWorld = cWorld.getHandle();
  28.                 saveInterval.setInt(mWorld, time);
  29.                
  30.                 System.out.println(String.format("[Performance Tweaks] Set auto save interval to %d in world \"%s\"", time, cWorld.getName()));
  31.             }
  32.         } catch (Exception e){
  33.             System.out.println("[Performance Tweaks]AutoSaveStopper Failed: " + e.toString());
  34.         }      
  35.     }
  36.     @Override
  37.     public void onDisable() {}
  38.        
  39.     private int getTime(){
  40.         Properties props = new Properties();
  41.         try {
  42.             props.load(new FileInputStream(new File(getDataFolder(), "tweaks.properties")));
  43.             int tmp = Integer.parseInt(props.getProperty("interval", "36000"));
  44.             System.out.println(String.format("[Performance Tweaks] Loaded Auto Save Interval: %d", tmp));
  45.             return tmp;
  46.          }catch(Exception e){}
  47.          return 3600;
  48.     }
  49.    
  50.     private void verifyFiles(){
  51.         try{
  52.             File dir = getDataFolder();
  53.             if (!dir.exists())
  54.                 dir.mkdirs();
  55.            
  56.             File pfile = new File(dir, "tweaks.properties");
  57.             if (!pfile.exists()){
  58.                 if (pfile.createNewFile()){
  59.                     Properties props = new Properties();
  60.                     props.setProperty("interval", "36000");
  61.                     props.store(new FileOutputStream(pfile), "interval = time between autosave in world ticks, {20th of a second}");
  62.                 }
  63.             }
  64.         }catch(Exception e){
  65.             System.out.println("[Performance Tweaks] Failed to verify files: " + e.toString());
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement