Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. Main:
  2.  
  3. package me.William.TigerTPS;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9. public class Main extends JavaPlugin {
  10.  
  11. @Override
  12. public void onEnable() {
  13. this.getCommand("ttps").setExecutor(new TpsCommand());
  14. this.getCommand("tpup").setExecutor(new TpupCommand());
  15. getServer().getPluginManager().registerEvents(new LoginListener(), this);
  16. getServer().getPluginManager().registerEvents(new BreakBlockListener(), this);
  17. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
  18. }
  19.  
  20. @Override
  21. public void onDisable() {
  22. getServer().getScheduler().cancelTasks(this);
  23. }
  24. }
  25.  
  26.  
  27. TpsCommand:
  28.  
  29. package me.William.TigerTPS;
  30.  
  31. import org.bukkit.ChatColor;
  32. import org.bukkit.command.Command;
  33. import org.bukkit.command.CommandExecutor;
  34. import org.bukkit.command.CommandSender;
  35.  
  36. public class TpsCommand implements CommandExecutor {
  37. @Override
  38. public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
  39. if (command.getName().equalsIgnoreCase("ttps")) {
  40. commandSender.sendMessage(ChatColor.AQUA + "TPS: " + ChatColor.GOLD + Lag.getTPS() );
  41. return true;
  42. }
  43. return false;
  44. }
  45. }
  46.  
  47. TpupCommand:
  48.  
  49. package me.William.TigerTPS;
  50.  
  51. import org.bukkit.ChatColor;
  52. import org.bukkit.command.Command;
  53. import org.bukkit.command.CommandExecutor;
  54. import org.bukkit.command.CommandSender;
  55.  
  56. public class TpsCommand implements CommandExecutor {
  57. @Override
  58. public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
  59. if (command.getName().equalsIgnoreCase("ttps")) {
  60. commandSender.sendMessage(ChatColor.AQUA + "TPS: " + ChatColor.GOLD + Lag.getTPS() );
  61. return true;
  62. }
  63. return false;
  64. }
  65. }
  66.  
  67. Lag:
  68.  
  69. package me.William.TigerTPS;
  70.  
  71. public class Lag
  72. implements Runnable
  73. {
  74. public static int TICK_COUNT= 0;
  75. public static long[] TICKS= new long[600];
  76. public static long LAST_TICK= 0L;
  77.  
  78. public static double getTPS()
  79. {
  80. return getTPS(100);
  81. }
  82.  
  83. public static double getTPS(int ticks)
  84. {
  85. if (TICK_COUNT< ticks) {
  86. return 20.0D;
  87. }
  88. int target = (TICK_COUNT- 1 - ticks) % TICKS.length;
  89. long elapsed = System.currentTimeMillis() - TICKS[target];
  90.  
  91. return ticks / (elapsed / 1000.0D);
  92. }
  93.  
  94. public static long getElapsed(int tickID)
  95. {
  96. if (TICK_COUNT- tickID >= TICKS.length)
  97. {
  98. }
  99.  
  100. long time = TICKS[(tickID % TICKS.length)];
  101. return System.currentTimeMillis() - time;
  102. }
  103.  
  104. public void run()
  105. {
  106. TICKS[(TICK_COUNT% TICKS.length)] = System.currentTimeMillis();
  107.  
  108. TICK_COUNT+= 1;
  109. }
  110. }
  111.  
  112. plugin.yml:
  113.  
  114. name: TigerTPS
  115. main: me.William.TigerTPS.Main
  116. version: 1.0.0
  117. authors:
  118. - Taogrin
  119. - William
  120. commands:
  121. ttps:
  122. description: a
  123. tpup:
  124. description: a
  125.  
  126. LoginListener:
  127.  
  128. package me.William.TigerTPS;
  129.  
  130. import org.bukkit.ChatColor;
  131. import org.bukkit.event.EventHandler;
  132. import org.bukkit.event.Listener;
  133. import org.bukkit.event.player.PlayerJoinEvent;
  134. import org.bukkit.event.player.PlayerQuitEvent;
  135.  
  136. public class LoginListener implements Listener {
  137. @EventHandler
  138. public void onJoin(PlayerJoinEvent event) {
  139. String message = ChatColor.DARK_GRAY + "Player " + ChatColor.RED + event.getPlayer().getName() + ChatColor.DARK_GRAY + " is joined whe server :)";
  140. event.setJoinMessage(message);
  141. }
  142. @EventHandler
  143. public void onQuit(PlayerQuitEvent event) {
  144. String message = ChatColor.DARK_GRAY + "Player " + ChatColor.RED + event.getPlayer().getName() + ChatColor.DARK_GRAY + " left the server :(";
  145. event.setQuitMessage(message);
  146. }
  147.  
  148. }
  149.  
  150. breakBlockEventListener:
  151.  
  152. package me.William.TigerTPS;
  153.  
  154. import org.bukkit.ChatColor;
  155. import org.bukkit.event.EventHandler;
  156. import org.bukkit.event.Listener;
  157. import org.bukkit.event.block.BlockBreakEvent;
  158.  
  159. public class BreakBlockListener implements Listener {
  160. @EventHandler
  161. public void onBlockBreak(BlockBreakEvent event){
  162. if (!event.getPlayer().hasPermission("test")) {
  163. event.setCancelled(true);
  164. event.getPlayer().sendMessage(ChatColor.RED + "You dont have permissions to break block's!!!");
  165. }
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement