Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main:
- package me.William.TigerTPS;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin {
- @Override
- public void onEnable() {
- this.getCommand("ttps").setExecutor(new TpsCommand());
- this.getCommand("tpup").setExecutor(new TpupCommand());
- getServer().getPluginManager().registerEvents(new LoginListener(), this);
- getServer().getPluginManager().registerEvents(new BreakBlockListener(), this);
- Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
- }
- @Override
- public void onDisable() {
- getServer().getScheduler().cancelTasks(this);
- }
- }
- TpsCommand:
- package me.William.TigerTPS;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- public class TpsCommand implements CommandExecutor {
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
- if (command.getName().equalsIgnoreCase("ttps")) {
- commandSender.sendMessage(ChatColor.AQUA + "TPS: " + ChatColor.GOLD + Lag.getTPS() );
- return true;
- }
- return false;
- }
- }
- TpupCommand:
- package me.William.TigerTPS;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- public class TpsCommand implements CommandExecutor {
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
- if (command.getName().equalsIgnoreCase("ttps")) {
- commandSender.sendMessage(ChatColor.AQUA + "TPS: " + ChatColor.GOLD + Lag.getTPS() );
- return true;
- }
- return false;
- }
- }
- Lag:
- package me.William.TigerTPS;
- public class Lag
- implements Runnable
- {
- public static int TICK_COUNT= 0;
- public static long[] TICKS= new long[600];
- public static long LAST_TICK= 0L;
- public static double getTPS()
- {
- return getTPS(100);
- }
- public static double getTPS(int ticks)
- {
- if (TICK_COUNT< ticks) {
- return 20.0D;
- }
- int target = (TICK_COUNT- 1 - ticks) % TICKS.length;
- long elapsed = System.currentTimeMillis() - TICKS[target];
- return ticks / (elapsed / 1000.0D);
- }
- public static long getElapsed(int tickID)
- {
- if (TICK_COUNT- tickID >= TICKS.length)
- {
- }
- long time = TICKS[(tickID % TICKS.length)];
- return System.currentTimeMillis() - time;
- }
- public void run()
- {
- TICKS[(TICK_COUNT% TICKS.length)] = System.currentTimeMillis();
- TICK_COUNT+= 1;
- }
- }
- plugin.yml:
- name: TigerTPS
- main: me.William.TigerTPS.Main
- version: 1.0.0
- authors:
- - Taogrin
- - William
- commands:
- ttps:
- description: a
- tpup:
- description: a
- LoginListener:
- package me.William.TigerTPS;
- import org.bukkit.ChatColor;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- public class LoginListener implements Listener {
- @EventHandler
- public void onJoin(PlayerJoinEvent event) {
- String message = ChatColor.DARK_GRAY + "Player " + ChatColor.RED + event.getPlayer().getName() + ChatColor.DARK_GRAY + " is joined whe server :)";
- event.setJoinMessage(message);
- }
- @EventHandler
- public void onQuit(PlayerQuitEvent event) {
- String message = ChatColor.DARK_GRAY + "Player " + ChatColor.RED + event.getPlayer().getName() + ChatColor.DARK_GRAY + " left the server :(";
- event.setQuitMessage(message);
- }
- }
- breakBlockEventListener:
- package me.William.TigerTPS;
- import org.bukkit.ChatColor;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- public class BreakBlockListener implements Listener {
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event){
- if (!event.getPlayer().hasPermission("test")) {
- event.setCancelled(true);
- event.getPlayer().sendMessage(ChatColor.RED + "You dont have permissions to break block's!!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement