This commit is contained in:
35
src/main/java/de/npid7/serverlite/D7ServerLite.java
Normal file
35
src/main/java/de/npid7/serverlite/D7ServerLite.java
Normal file
@ -0,0 +1,35 @@
|
||||
package de.npid7.serverlite;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.npid7.serverlite.Helpers.Spielzeit;
|
||||
import de.npid7.serverlite.Tasks.TablistTask;
|
||||
|
||||
/*
|
||||
* d7serverlite java plugin
|
||||
*/
|
||||
public class D7ServerLite extends JavaPlugin {
|
||||
private static D7ServerLite inst;
|
||||
|
||||
private TablistTask tablistUpdater;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
inst = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
tablistUpdater = new TablistTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {}
|
||||
|
||||
public static D7ServerLite getInst() {
|
||||
return inst;
|
||||
}
|
||||
}
|
27
src/main/java/de/npid7/serverlite/Helpers/Spielzeit.java
Normal file
27
src/main/java/de/npid7/serverlite/Helpers/Spielzeit.java
Normal file
@ -0,0 +1,27 @@
|
||||
package de.npid7.serverlite.Helpers;
|
||||
|
||||
public class Spielzeit {
|
||||
public static String formatTicks(int ticks) {
|
||||
int time = ticks / 20;
|
||||
String timers = new String("");
|
||||
int day = time / 86400;
|
||||
int hours = (time % 86400) / 3600;
|
||||
int minutes = (time % 3600) / 60;
|
||||
int seconds = time % 60;
|
||||
if (time > -1 && time < 60) {
|
||||
timers = String.format("%02ds", seconds);
|
||||
} else if (time > 59 && time < 3600) {
|
||||
timers = String.format("%02dm %02ds", minutes, seconds);
|
||||
} else if (time > 3599 && time < 86400) {
|
||||
timers = String.format("%02dh %02dm %02ds", hours, minutes, seconds);
|
||||
} else if (time > 86399) {
|
||||
timers = String.format("%02dd %02dh %02dm %02ds", day, hours, minutes, seconds);
|
||||
}
|
||||
return timers;
|
||||
}
|
||||
|
||||
public static int getHours(int ticks) {
|
||||
int time = ticks / 20;
|
||||
return time / 3600;
|
||||
}
|
||||
}
|
70
src/main/java/de/npid7/serverlite/Tasks/TablistTask.java
Normal file
70
src/main/java/de/npid7/serverlite/Tasks/TablistTask.java
Normal file
@ -0,0 +1,70 @@
|
||||
package de.npid7.serverlite.Tasks;
|
||||
|
||||
import de.npid7.serverlite.D7ServerLite;
|
||||
import de.npid7.serverlite.Helpers.Spielzeit;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TablistTask {
|
||||
long lastTickNano = System.nanoTime();
|
||||
long lastSecondNano = lastTickNano;
|
||||
int ticksThisSec = 0;
|
||||
double tps = 20.0;
|
||||
double mspt = 0.0;
|
||||
double total_mspt = 0.0;
|
||||
long msptlt;
|
||||
|
||||
private void CalcTPS() {
|
||||
long now = System.nanoTime();
|
||||
double now_mspt = (now - lastTickNano) / 1000000.0;
|
||||
lastTickNano = now;
|
||||
total_mspt += now_mspt;
|
||||
if (now - lastSecondNano >= 1000000000.0) {
|
||||
tps = ticksThisSec;
|
||||
// Fake Value
|
||||
if (tps == 21)
|
||||
tps = 20;
|
||||
mspt = total_mspt / ticksThisSec;
|
||||
total_mspt = 0;
|
||||
ticksThisSec = 0;
|
||||
lastSecondNano = now;
|
||||
}
|
||||
ticksThisSec++;
|
||||
}
|
||||
|
||||
public TablistTask() {
|
||||
run();
|
||||
}
|
||||
|
||||
private void displayTablist() {
|
||||
for (Player pl : Bukkit.getServer().getOnlinePlayers()) {
|
||||
int playtime = Spielzeit.getHours(pl.getStatistic(Statistic.TOTAL_WORLD_TIME));
|
||||
String str = " Stunden";
|
||||
if (playtime == 1) {
|
||||
str = " Stunde";
|
||||
}
|
||||
pl.setPlayerListHeader(
|
||||
"\n§x§5§5§5§5§5§5§lѕ§x§5§B§5§B§5§B§lᴜ§x§6§1§6§1§6§1§lʀ§x§6§7§6§7§6§7§lᴠ§x§6§D§6§D§6§D§lɪ§x§7§3§7§3§7§3§lᴠ§x§7§9§7§9§7§9§lᴀ§x§8§0§8§0§8§0§lʟ§x§8§6§8§6§8§6§lᴘ§x§8§C§8§C§8§C§lʀ§x§9§2§9§2§9§2§lᴏ§x§9§8§9§8§9§8§lᴊ§x§9§E§9§E§9§E§lᴇ§x§A§4§A§4§A§4§lᴋ§x§A§A§A§A§A§A§lᴛ\n"
|
||||
+ "\n" + ChatColor.GRAY.toString() + "ᴅᴇɪɴ ᴘɪɴɢ" + ChatColor.DARK_GRAY.toString() + ": "
|
||||
+ ChatColor.GREEN.toString() + pl.getPing() + " " + ChatColor.GRAY.toString()
|
||||
+ "ѕᴇʀᴠᴇʀ ᴛᴘѕ" + ChatColor.DARK_GRAY.toString() + ": " + ChatColor.GREEN.toString()
|
||||
+ String.format("%.1f", tps) + "\n\n" + ChatColor.GRAY.toString() + "ѕᴘɪᴇʟᴢᴇɪᴛ"
|
||||
+ ChatColor.DARK_GRAY.toString() + ": " + ChatColor.GREEN.toString() + playtime + str
|
||||
+ "\n");
|
||||
pl.setPlayerListFooter("\n");
|
||||
}
|
||||
}
|
||||
|
||||
private void run() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CalcTPS();
|
||||
displayTablist();
|
||||
}
|
||||
}.runTaskTimer(D7ServerLite.getInst(), 0, 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user