Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NoChunks extends JavaPlugin {
- private MyThread thread;
- @Override
- public void onDisable() {
- thread.isRunning = false;
- while(thread.isAlive()) {}
- System.out.println("[NotLag] Disabled");
- getServer().getScheduler().cancelTasks(this);
- }
- @Override
- public void onEnable() {
- thread = new MyThread();
- System.out.println("[NotLag] Enabled");
- getServer().getPluginManager().registerEvents(new MyListener(), this);
- getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- public void run() {
- for(World world : getServer().getWorlds()) {
- if(world.getPlayers().size() == 0) {
- for(Chunk c : world.getLoadedChunks())
- if(c.getWorld().getPlayers().size() == 0)
- world.unloadChunk(c);
- } else {
- // No longer remove the entities
- //for(Chunk c : world.getLoadedChunks()) {
- // Entity[] elist = c.getEntities();
- // for(int i=0; (i<elist.length && i<3); i++)
- // if(!(elist[i] instanceof Player))
- // elist[i].remove();
- //}
- }
- }
- }
- }, 200, 200);
- // Every tick?
- getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- public void run() {
- thread.ticks++;
- }
- }, 1, 1);
- thread.start();
- }
- class MyListener implements Listener {
- @Override
- public int hashCode() {
- return 0;
- }
- @EventHandler(priority = EventPriority.LOWEST)
- public void onWorldInit(WorldInitEvent event) {
- World world = event.getWorld();
- world.setKeepSpawnInMemory(false);
- }
- }
- class MyThread extends Thread {
- public boolean isRunning = true;
- public int ticks = 0;
- public int runs = 0;
- ArrayList<Double> tpsList = new ArrayList<Double>();
- public void run() {
- ticks = 0;
- while(isRunning) {
- // Sleep for 10 seconds
- try {
- for(int i=0; i<100 && isRunning; i++)
- sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- // Count the number of ticks
- double ticks = 0.0+this.ticks;
- double amount = ticks/10;
- tpsList.add(amount);
- this.ticks = 0;
- // Clear the tpsList every so often
- if(tpsList.size() > 6)
- tpsList.remove(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement