Guest User

Untitled

a guest
Apr 17th, 2014
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. public class NoChunks extends JavaPlugin {
  4.  
  5. private MyThread thread;
  6.  
  7. @Override
  8. public void onDisable() {
  9. thread.isRunning = false;
  10.  
  11. while(thread.isAlive()) {}
  12.  
  13. System.out.println("[NotLag] Disabled");
  14. getServer().getScheduler().cancelTasks(this);
  15. }
  16.  
  17. @Override
  18. public void onEnable() {
  19. thread = new MyThread();
  20. System.out.println("[NotLag] Enabled");
  21. getServer().getPluginManager().registerEvents(new MyListener(), this);
  22.  
  23. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  24. public void run() {
  25. for(World world : getServer().getWorlds()) {
  26. if(world.getPlayers().size() == 0) {
  27. for(Chunk c : world.getLoadedChunks())
  28. if(c.getWorld().getPlayers().size() == 0)
  29. world.unloadChunk(c);
  30. } else {
  31. // No longer remove the entities
  32. //for(Chunk c : world.getLoadedChunks()) {
  33. // Entity[] elist = c.getEntities();
  34. // for(int i=0; (i<elist.length && i<3); i++)
  35. // if(!(elist[i] instanceof Player))
  36. // elist[i].remove();
  37. //}
  38. }
  39. }
  40. }
  41. }, 200, 200);
  42. // Every tick?
  43. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  44. public void run() {
  45. thread.ticks++;
  46. }
  47. }, 1, 1);
  48. thread.start();
  49. }
  50.  
  51.  
  52. class MyListener implements Listener {
  53.  
  54. @Override
  55. public int hashCode() {
  56. return 0;
  57. }
  58.  
  59. @EventHandler(priority = EventPriority.LOWEST)
  60. public void onWorldInit(WorldInitEvent event) {
  61. World world = event.getWorld();
  62. world.setKeepSpawnInMemory(false);
  63. }
  64. }
  65.  
  66. class MyThread extends Thread {
  67.  
  68. public boolean isRunning = true;
  69.  
  70. public int ticks = 0;
  71.  
  72. public int runs = 0;
  73.  
  74. ArrayList<Double> tpsList = new ArrayList<Double>();
  75.  
  76. public void run() {
  77. ticks = 0;
  78. while(isRunning) {
  79. // Sleep for 10 seconds
  80. try {
  81. for(int i=0; i<100 && isRunning; i++)
  82. sleep(100);
  83. } catch (InterruptedException e) {
  84. e.printStackTrace();
  85. }
  86. // Count the number of ticks
  87. double ticks = 0.0+this.ticks;
  88. double amount = ticks/10;
  89. tpsList.add(amount);
  90. this.ticks = 0;
  91. // Clear the tpsList every so often
  92. if(tpsList.size() > 6)
  93. tpsList.remove(0);
  94. }
  95. }
  96.  
  97. }
RAW Paste Data