diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/artifacts/KygekPingTPS_Spigot.xml b/.idea/artifacts/KygekPingTPS_Spigot.xml
new file mode 100644
index 0000000..0624cde
--- /dev/null
+++ b/.idea/artifacts/KygekPingTPS_Spigot.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/KygekPingTPS
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/spigot_api_1_16_5_R0_1_20210604_221538_95.xml b/.idea/libraries/spigot_api_1_16_5_R0_1_20210604_221538_95.xml
new file mode 100644
index 0000000..14adceb
--- /dev/null
+++ b/.idea/libraries/spigot_api_1_16_5_R0_1_20210604_221538_95.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..0548357
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6d69ef3
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/KygekPingTPS-Spigot.iml b/KygekPingTPS-Spigot.iml
new file mode 100644
index 0000000..fc9bec4
--- /dev/null
+++ b/KygekPingTPS-Spigot.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/config.yml b/src/config.yml
new file mode 100644
index 0000000..3407fd0
--- /dev/null
+++ b/src/config.yml
@@ -0,0 +1,19 @@
+---
+# KygekPingTPS configuration file
+# KygekPingTPS was made by KygekTeam
+
+# Messages configuration (Leave empty to use default messages)
+# Use "{prefix}" to display KygekPingTPS default prefix
+# Use "&" as formatting codes
+# Use "\n" to break into new line
+no-permission: ""
+player-not-found: ""
+# Use "{tps}" to display server TPS in server-tps
+server-tps: ""
+# Use "{player}" to display player name or self and "{ping}" to display player's ping in player-ping
+player-ping: ""
+
+##### DANGER ZONE #####
+# Do not change this (Only for internal use)!
+config-version: "1.0"
+#######################
\ No newline at end of file
diff --git a/src/org/kygekteam/java/kygekpingtps/Lag.java b/src/org/kygekteam/java/kygekpingtps/Lag.java
new file mode 100644
index 0000000..52f16f5
--- /dev/null
+++ b/src/org/kygekteam/java/kygekpingtps/Lag.java
@@ -0,0 +1,45 @@
+/* I couldn't find a vanilla method so this is there until we do.
+ The script is by LazyLemons on the Bukkit forums. */
+
+package org.kygekteam.java.kygekpingtps;
+
+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;
+ }
+}
diff --git a/src/org/kygekteam/java/kygekpingtps/Main.java b/src/org/kygekteam/java/kygekpingtps/Main.java
new file mode 100644
index 0000000..698dc6d
--- /dev/null
+++ b/src/org/kygekteam/java/kygekpingtps/Main.java
@@ -0,0 +1,56 @@
+package org.kygekteam.java.kygekpingtps;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+
+public class Main extends JavaPlugin {
+ @Override
+ public void onEnable() {
+ getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
+ this.saveDefaultConfig();
+ this.checkConfig();
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ this.reloadConfig();
+ switch (command.getName().toLowerCase()) {
+ case "tps":
+ new TPS(sender, this).execute();
+ break;
+ case "ping":
+ new Ping(sender, args, this).execute();
+ break;
+ }
+ return true;
+ }
+
+ private void checkConfig() {
+ if (!this.getConfig().getString("config-version").equals("1.0")) {
+ getServer().getConsoleSender().sendMessage("Your configuration file is outdated, updating the config.yml...");
+ getServer().getConsoleSender().sendMessage("The old configuration file can be found at config-old.yml");
+ this.renameConfig();
+ this.saveDefaultConfig();
+ this.reloadConfig();
+ }
+ }
+
+ private void renameConfig() {
+ File oldConfig = new File(this.getDataFolder() + "/config.yml");
+ File newConfig = new File(this.getDataFolder() + "/config-old.yml");
+
+ if (newConfig.exists()) newConfig.delete();
+
+ oldConfig.renameTo(newConfig);
+ }
+
+ public static final String PREFIX = ChatColor.YELLOW + "[KygekPingTPS] ";
+
+ public static String replace(String string) {
+ return string.replace("{prefix}", PREFIX).replace("&", "ยง");
+ }
+}
diff --git a/src/org/kygekteam/java/kygekpingtps/Ping.java b/src/org/kygekteam/java/kygekpingtps/Ping.java
new file mode 100644
index 0000000..317d880
--- /dev/null
+++ b/src/org/kygekteam/java/kygekpingtps/Ping.java
@@ -0,0 +1,53 @@
+package org.kygekteam.java.kygekpingtps;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class Ping {
+ private final CommandSender sender;
+ private final String[] args;
+ private final Main main;
+
+ public Ping(CommandSender sender, String[] args, Main main) {
+ this.sender = sender;
+ this.args = args;
+ this.main = main;
+ }
+
+ public void execute() {
+ if (!this.sender.hasPermission("kygekpingtps.ping")) {
+ String noperm = Main.replace(this.main.getConfig().getString("no-permission", ""));
+ noperm = noperm.isEmpty() ? Main.PREFIX + ChatColor.RED + "You do not have permission to use this command" : noperm;
+
+ this.sender.sendMessage(noperm);
+ return;
+ }
+
+ if (this.args.length < 1) {
+ if (!(this.sender instanceof Player)) {
+ this.sender.sendMessage(Main.PREFIX + ChatColor.WHITE + "Usage: /ping ");
+ } else {
+ String ping = Main.replace(this.main.getConfig().getString("player-ping", "")).replace("{player}", "Your").replace("{ping}", Integer.toString(((Player) sender).getPing()));
+ ping = ping.isEmpty() ? Main.PREFIX + ChatColor.GREEN + "Your current ping: " + ChatColor.AQUA + ((Player) sender).getPing() : ping;
+
+ this.sender.sendMessage(ping);
+ }
+ return;
+ }
+
+ Player player = sender.getServer().getPlayer(this.args[0]);
+ if (player == null) {
+ String notfound = Main.replace(this.main.getConfig().getString( "player-not-found", ""));
+ notfound = notfound.isEmpty() ? Main.PREFIX + ChatColor.RED + "Player was not found" : notfound;
+
+ this.sender.sendMessage(notfound);
+ return;
+ }
+
+ String ping = Main.replace(this.main.getConfig().getString("player-ping", "")).replace("{player}", player.getName()).replace("{ping}", Integer.toString(player.getPing()));
+ ping = ping.isEmpty() ? Main.PREFIX + ChatColor.GREEN + player.getName() + "'s current ping: " + ChatColor.AQUA + player.getPing() : ping;
+
+ this.sender.sendMessage(ping);
+ }
+}
diff --git a/src/org/kygekteam/java/kygekpingtps/TPS.java b/src/org/kygekteam/java/kygekpingtps/TPS.java
new file mode 100644
index 0000000..3c141dc
--- /dev/null
+++ b/src/org/kygekteam/java/kygekpingtps/TPS.java
@@ -0,0 +1,30 @@
+package org.kygekteam.java.kygekpingtps;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+public class TPS {
+ private final CommandSender sender;
+ private final Main main;
+
+ public TPS(CommandSender sender, Main main) {
+ this.sender = sender;
+ this.main = main;
+ }
+
+ public void execute() {
+ double tps = Lag.getTPS();
+
+ if (sender.hasPermission("kygekpingtps.tps")) {
+ String servertps = Main.replace(this.main.getConfig().getString("server-tps", "")).replace("{tps}", Double.toString(tps));
+ servertps = servertps.isEmpty() ? Main.PREFIX + ChatColor.GREEN + "Current server TPS: " + ChatColor.AQUA + tps : servertps;
+
+ this.sender.sendMessage(servertps);
+ } else {
+ String noperm = Main.replace(this.main.getConfig().getString("no-permission", ""));
+ noperm = noperm.isEmpty() ? Main.PREFIX + ChatColor.RED + "You do not have permission to use this command" : noperm;
+
+ this.sender.sendMessage(noperm);
+ }
+ }
+}
diff --git a/src/plugin.yml b/src/plugin.yml
new file mode 100644
index 0000000..2aff485
--- /dev/null
+++ b/src/plugin.yml
@@ -0,0 +1,33 @@
+---
+# See server TPS and a player's ping
+# Copyright (C) 2020 KygekTeam
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+name: KygekPingTPS
+version: "1.0.0"
+author: KygekTeam
+api-version: 1.16
+main: org.kygekteam.java.kygekpingtps.Main
+
+commands:
+ ping:
+ description: Current ping of a player
+ permission: kygekpingtps.ping
+ usage: "/ping [player]"
+ tps:
+ description: Current TPS of the server
+ permission: kygekpingtps.tps
+ usage: "/tps"
+ aliases: ktps
+
+permissions:
+ kygekpingtps.ping:
+ description: Permission to use /ping
+ default: true
+ kygekpingtps.tps:
+ description: Permission to use /tps
+ default: true
\ No newline at end of file