Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jbls.LexManos;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.lang.reflect.Field;
- import java.util.Properties;
- import org.bukkit.plugin.java.*;
- import org.bukkit.craftbukkit.*;
- import net.minecraft.server.*;
- public class AutoSaveStopper extends JavaPlugin {
- public AutoSaveStopper() {}
- @Override
- public void onEnable() {
- try {
- Field saveInterval = World.class.getDeclaredField("k");
- saveInterval.setAccessible(true);
- verifyFiles();
- int time = getTime();
- for(org.bukkit.World bworld : getServer().getWorlds()){
- CraftWorld cWorld = (CraftWorld)bworld;
- World mWorld = cWorld.getHandle();
- saveInterval.setInt(mWorld, time);
- System.out.println(String.format("[Performance Tweaks] Set auto save interval to %d in world \"%s\"", time, cWorld.getName()));
- }
- } catch (Exception e){
- System.out.println("[Performance Tweaks]AutoSaveStopper Failed: " + e.toString());
- }
- }
- @Override
- public void onDisable() {}
- private int getTime(){
- Properties props = new Properties();
- try {
- props.load(new FileInputStream(new File(getDataFolder(), "tweaks.properties")));
- int tmp = Integer.parseInt(props.getProperty("interval", "36000"));
- System.out.println(String.format("[Performance Tweaks] Loaded Auto Save Interval: %d", tmp));
- return tmp;
- }catch(Exception e){}
- return 3600;
- }
- private void verifyFiles(){
- try{
- File dir = getDataFolder();
- if (!dir.exists())
- dir.mkdirs();
- File pfile = new File(dir, "tweaks.properties");
- if (!pfile.exists()){
- if (pfile.createNewFile()){
- Properties props = new Properties();
- props.setProperty("interval", "36000");
- props.store(new FileOutputStream(pfile), "interval = time between autosave in world ticks, {20th of a second}");
- }
- }
- }catch(Exception e){
- System.out.println("[Performance Tweaks] Failed to verify files: " + e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement