Compare commits
3 commits
d8c392c5af
...
529a61ecbb
Author | SHA1 | Date | |
---|---|---|---|
529a61ecbb | |||
9e83de33c7 | |||
47e347c4a2 |
14 changed files with 119 additions and 177 deletions
|
@ -7,10 +7,13 @@ jobs:
|
||||||
- name: Prepare for installation
|
- name: Prepare for installation
|
||||||
run: apt update
|
run: apt update
|
||||||
- name: Install JDK and other deps
|
- name: Install JDK and other deps
|
||||||
run: apt install --no-install-recommends -y openjdk-21-jdk-headless maven git nodejs curl
|
run: apt install --no-install-recommends -y openjdk-21-jdk-headless maven git nodejs curl zstd
|
||||||
|
|
||||||
- name: BuildTools for NMS
|
#- name: BuildTools for NMS
|
||||||
run: mkdir /tmp/buildtools && cd /tmp/buildtools && curl -O https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && java -jar BuildTools.jar --rev 1.21.1 --remapped && cd
|
# run: mkdir /tmp/buildtools && cd /tmp/buildtools && curl -O https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && java -jar BuildTools.jar --rev 1.21.1 --remapped && cd
|
||||||
|
|
||||||
|
- name: Download NMS
|
||||||
|
run: curl -O https://git.m724.eu/Minecon724/temporary/raw/branch/master/XRIH.tar.zst && tar -xaf XRIH.tar.zst -C ~ && rm XRIH.tar.zst
|
||||||
|
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
run: git clone https://git.m724.eu/Minecon724/tweaks724.git .
|
run: git clone https://git.m724.eu/Minecon724/tweaks724.git .
|
||||||
|
@ -19,4 +22,4 @@ jobs:
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: https://github.com/actions/upload-artifact@v3
|
uses: https://github.com/actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
path: target/tweaks-*.jar
|
path: target
|
17
README.md
17
README.md
|
@ -53,4 +53,19 @@ Sleeping doesn't skip night, but speeds it up. The more players, the faster it g
|
||||||
### Instant sleep
|
### Instant sleep
|
||||||
One can instantly skip, but only a part of the night. \
|
One can instantly skip, but only a part of the night. \
|
||||||
There's 5 players on the server. A night is 10 minutes long. \
|
There's 5 players on the server. A night is 10 minutes long. \
|
||||||
Each player can instantly skip 2 minutes of the night at any time, even if others aren't sleeping
|
Each player can instantly skip 2 minutes of the night at any time, even if others aren't sleeping
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
### /chat
|
||||||
|
Changes chatroom
|
||||||
|
|
||||||
|
### /chatmanage
|
||||||
|
`tweaks724.chatmanage` \
|
||||||
|
Manages chatroom, like create, delete etc.
|
||||||
|
|
||||||
|
### /ping
|
||||||
|
Displays your ping. **Ping is calculated by the plugin.**
|
||||||
|
|
||||||
|
### /pomodoro
|
||||||
|
`tweaks724.pomodoro` \
|
||||||
|
Manage your pomodoro. `/pom start` to start, `stop` to stop, no arguments to forward
|
|
@ -10,8 +10,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public record TweaksConfig(
|
public record TweaksConfig(
|
||||||
boolean isProtocolLib,
|
|
||||||
|
|
||||||
boolean worldborderHide,
|
boolean worldborderHide,
|
||||||
|
|
||||||
boolean brandEnabled,
|
boolean brandEnabled,
|
||||||
|
@ -56,8 +54,6 @@ public record TweaksConfig(
|
||||||
plugin.saveDefaultConfig();
|
plugin.saveDefaultConfig();
|
||||||
FileConfiguration config = plugin.getConfig();
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
|
||||||
boolean isProtocolLib = plugin.getServer().getPluginManager().getPlugin("ProtocolLib") != null;
|
|
||||||
|
|
||||||
int configVersion = config.getInt("magic number don't modify this", 0);
|
int configVersion = config.getInt("magic number don't modify this", 0);
|
||||||
RuntimeException exception = new RuntimeException("Config version is %d, expected %d".formatted(configVersion, CONFIG_VERSION));
|
RuntimeException exception = new RuntimeException("Config version is %d, expected %d".formatted(configVersion, CONFIG_VERSION));
|
||||||
if (configVersion == 0) {
|
if (configVersion == 0) {
|
||||||
|
@ -102,7 +98,6 @@ public record TweaksConfig(
|
||||||
boolean sleepInstant = config.getBoolean("sleep.instant");
|
boolean sleepInstant = config.getBoolean("sleep.instant");
|
||||||
|
|
||||||
TweaksConfig.config = new TweaksConfig(
|
TweaksConfig.config = new TweaksConfig(
|
||||||
isProtocolLib,
|
|
||||||
hideWorldBorder,
|
hideWorldBorder,
|
||||||
brandEnabled, brandText, brandShowPing, brandShowMspt,
|
brandEnabled, brandText, brandShowPing, brandShowMspt,
|
||||||
doorEnabled, doorDoubleOpen, doorKnocking,
|
doorEnabled, doorDoubleOpen, doorKnocking,
|
||||||
|
|
|
@ -52,7 +52,6 @@ public class TweaksPlugin extends JavaPlugin {
|
||||||
|
|
||||||
new PingChecker(this).init();
|
new PingChecker(this).init();
|
||||||
Objects.requireNonNull(getCommand("ping")).setExecutor(new PingCommands());
|
Objects.requireNonNull(getCommand("ping")).setExecutor(new PingCommands());
|
||||||
Objects.requireNonNull(getCommand("dkick")).setExecutor(new PingCommands());
|
|
||||||
|
|
||||||
/*if (getServer().getPluginManager().getPlugin("voicechat") != null) {
|
/*if (getServer().getPluginManager().getPlugin("voicechat") != null) {
|
||||||
new MusicPlayer(this).init();
|
new MusicPlayer(this).init();
|
||||||
|
|
35
src/main/java/eu/m724/tweaks/ping/CookiePingChecker.java
Normal file
35
src/main/java/eu/m724/tweaks/ping/CookiePingChecker.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Minecon724
|
||||||
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
|
* in the project root for the full license text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package eu.m724.tweaks.ping;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class CookiePingChecker extends BukkitRunnable {
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final NamespacedKey namespacedKey = NamespacedKey.fromString("chk_ping");
|
||||||
|
|
||||||
|
CookiePingChecker(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
this.runTaskTimerAsynchronously(plugin, 0, 40); // 2 secs
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.getServer().getOnlinePlayers().forEach(player -> {
|
||||||
|
long start = System.nanoTime();
|
||||||
|
player.retrieveCookie(namespacedKey).thenAccept(v -> {
|
||||||
|
PlayerPingStorage.submitPing(player, System.nanoTime() - start);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,14 +78,14 @@ public class F3NameListener {
|
||||||
String sep = text.isEmpty() ? "" : " | ";
|
String sep = text.isEmpty() ? "" : " | ";
|
||||||
|
|
||||||
if (showMspt) {
|
if (showMspt) {
|
||||||
double mspt = PlayerPing.getMillisPerTick();
|
double mspt = PlayerPingStorage.getMillisPerTick();
|
||||||
if (mspt > 50.05) { // mspt is at least like 50.01 because of some measuring overheads (I think)
|
if (mspt > 50.05) { // mspt is at least like 50.01 because of some measuring overheads (I think)
|
||||||
_text += sep + "%.2f mspt".formatted(mspt);
|
_text += sep + "%.2f mspt".formatted(mspt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showPing) {
|
if (showPing) {
|
||||||
_text += sep + "%.2f ms".formatted(PlayerPing.getPingMillis(player));
|
_text += sep + "%.2f ms".formatted(PlayerPingStorage.getPingMillis(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _text;
|
return _text;
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class MsptChecker extends BukkitRunnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
PlayerPing.nspt = (now - lastLoop) / 100;
|
PlayerPingStorage.submitNspt((now - lastLoop) / 100);
|
||||||
lastLoop = now;
|
lastLoop = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
package eu.m724.tweaks.ping;
|
package eu.m724.tweaks.ping;
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class PingChecker {
|
public class PingChecker {
|
||||||
|
@ -17,14 +16,7 @@ public class PingChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
new CookiePingChecker(plugin).start();
|
||||||
if (TweaksConfig.getConfig().isProtocolLib()) {
|
|
||||||
plugin.getLogger().info("Using ProtocolLib for checking ping");
|
|
||||||
new ProtocolPingChecker(plugin).start();
|
|
||||||
} else {
|
|
||||||
plugin.getLogger().info("Using Spigot for checking ping");
|
|
||||||
}
|
|
||||||
|
|
||||||
new MsptChecker().init(plugin); // TODO should this be here
|
new MsptChecker().init(plugin); // TODO should this be here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
|
|
||||||
package eu.m724.tweaks.ping;
|
package eu.m724.tweaks.ping;
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -23,33 +21,9 @@ public class PingCommands implements CommandExecutor {
|
||||||
if (command.getName().equals("ping")) {
|
if (command.getName().equals("ping")) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
BaseComponent[] component = new ComponentBuilder("Ping: ").color(ChatColor.GOLD)
|
BaseComponent[] component = new ComponentBuilder("Ping: ").color(ChatColor.GOLD)
|
||||||
.append("%.2fms".formatted(PlayerPing.getPingMillis(player))).color(ChatColor.AQUA)
|
.append("%.2fms".formatted(PlayerPingStorage.getPingMillis(player))).color(ChatColor.AQUA)
|
||||||
.create();
|
.create();
|
||||||
player.spigot().sendMessage(component);
|
player.spigot().sendMessage(component);
|
||||||
} else if (command.getName().equals("dkick")) {
|
|
||||||
if (!TweaksConfig.getConfig().isProtocolLib()) {
|
|
||||||
sender.sendMessage("This feature is not available");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length == 0) {
|
|
||||||
sender.sendMessage("Include one or more player names");
|
|
||||||
} else {
|
|
||||||
for (String name : args) {
|
|
||||||
Player player = Bukkit.getPlayer(name);
|
|
||||||
if (player == null) {
|
|
||||||
sender.sendMessage("Player %s is not online".formatted(name));
|
|
||||||
}
|
|
||||||
if (PlayerPing.kick(player)) {
|
|
||||||
if (player.getName().equals(sender.getName())) {
|
|
||||||
sender.sendMessage("Kicking yourself? Very well");
|
|
||||||
}
|
|
||||||
sender.sendMessage("Player %s will be kicked shortly".formatted(name));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("Player %s is already queued".formatted(name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2024 Minecon724
|
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
|
||||||
* in the project root for the full license text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package eu.m724.tweaks.ping;
|
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class PlayerPing {
|
|
||||||
// if protocol lib is installed we use our own checker
|
|
||||||
private static final boolean external = TweaksConfig.getConfig().isProtocolLib();
|
|
||||||
|
|
||||||
// TODO remove this feature because why
|
|
||||||
static final Set<Player> kickQueue = ConcurrentHashMap.newKeySet();
|
|
||||||
|
|
||||||
// current player latencies, in nanos
|
|
||||||
static final Map<Player, Long> pings = new ConcurrentHashMap<>();
|
|
||||||
// nanoseconds per tick
|
|
||||||
static volatile long nspt = 0L;
|
|
||||||
|
|
||||||
public static long getPingNanos(Player player) {
|
|
||||||
if (!external) {
|
|
||||||
return (long) player.getPing() * 1000000;
|
|
||||||
} else {
|
|
||||||
return pings.getOrDefault(player, -1L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getPingMillis(Player player) {
|
|
||||||
return getPingNanos(player) / 1000000.0; // a mil ns in ms
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getNanosPerTick() {
|
|
||||||
return nspt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getMillisPerTick() {
|
|
||||||
return nspt / 1000000.0; // a mil ns in ms
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean kick(Player player) {
|
|
||||||
return kickQueue.add(player);
|
|
||||||
}
|
|
||||||
}
|
|
55
src/main/java/eu/m724/tweaks/ping/PlayerPingStorage.java
Normal file
55
src/main/java/eu/m724/tweaks/ping/PlayerPingStorage.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Minecon724
|
||||||
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
|
* in the project root for the full license text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package eu.m724.tweaks.ping;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class PlayerPingStorage {
|
||||||
|
// current player latencies, in queue of nanos
|
||||||
|
private static final Map<Player, Long> pings = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<Player, Integer> pingsCount = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
// nanoseconds per tick
|
||||||
|
private static volatile long nspt = 0L;
|
||||||
|
|
||||||
|
public static long getPingNanos(Player player) {
|
||||||
|
return pings.getOrDefault(player, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getPingMillis(Player player) {
|
||||||
|
return getPingNanos(player) / 1000000.0; // a mil ns in ms
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getNanosPerTick() {
|
||||||
|
return nspt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getMillisPerTick() {
|
||||||
|
return nspt / 1000000.0; // a mil ns in ms
|
||||||
|
}
|
||||||
|
|
||||||
|
static void submitPing(Player player, long currentPing) {
|
||||||
|
int count = pingsCount.getOrDefault(player, 0);
|
||||||
|
long average = pings.getOrDefault(player, 0L);
|
||||||
|
|
||||||
|
if (count < 5) {
|
||||||
|
average = ((average * count) + currentPing) / (count + 1);
|
||||||
|
pingsCount.put(player, count + 1);
|
||||||
|
} else {
|
||||||
|
average += (currentPing - average) / 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
pings.put(player, average);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void submitNspt(long currentNspt) {
|
||||||
|
nspt = currentNspt;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2024 Minecon724
|
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
|
||||||
* in the project root for the full license text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package eu.m724.tweaks.ping;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.ListenerPriority;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import com.comphenix.protocol.wrappers.MinecraftKey;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class ProtocolPingChecker extends BukkitRunnable {
|
|
||||||
// this is in nanoseconds
|
|
||||||
private final Map<Player, Long> pending = new ConcurrentHashMap<>();
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
ProtocolPingChecker(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
|
||||||
plugin,
|
|
||||||
ListenerPriority.NORMAL,
|
|
||||||
PacketType.Play.Client.COOKIE_RESPONSE
|
|
||||||
) {
|
|
||||||
@Override
|
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
|
||||||
// below line checks, whether the first (and sole) identifier field in the packet is minecraft:chk_ping
|
|
||||||
if (event.getPacket().getMinecraftKeys().read(0).getKey().equals("chk_ping")) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
|
|
||||||
long start = pending.remove(player);
|
|
||||||
PlayerPing.pings.put(player, System.nanoTime() - start);
|
|
||||||
|
|
||||||
// gotta cancel because the server will kick
|
|
||||||
if (!PlayerPing.kickQueue.contains(player)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else {
|
|
||||||
PlayerPing.kickQueue.remove(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.runTaskTimerAsynchronously(plugin, 0, 200); // 10 secs
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.getServer().getOnlinePlayers().forEach(player -> {
|
|
||||||
// dropped packets happen so timing out a request after 30 seconds
|
|
||||||
if (System.nanoTime() - pending.getOrDefault(player, 0L) < 30000000000L) return;
|
|
||||||
pending.put(player, System.nanoTime()); // here or at the bottom? probably doesn't matter
|
|
||||||
|
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.COOKIE_REQUEST);
|
|
||||||
packet.getMinecraftKeys().write(0, new MinecraftKey("chk_ping"));
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,8 +42,8 @@ chat:
|
||||||
# Name of the default / global chatroom
|
# Name of the default / global chatroom
|
||||||
defaultName: "global"
|
defaultName: "global"
|
||||||
|
|
||||||
|
# Compass shown in a text form on the actionbar
|
||||||
compass:
|
compass:
|
||||||
# Compass will be shown in a text form
|
|
||||||
enabled: true
|
enabled: true
|
||||||
# How much points (each point is separated with a space)
|
# How much points (each point is separated with a space)
|
||||||
# I suggest making this uneven to make center... in center
|
# I suggest making this uneven to make center... in center
|
||||||
|
|
|
@ -19,9 +19,6 @@ commands:
|
||||||
aliases: [cm, crm]
|
aliases: [cm, crm]
|
||||||
ping:
|
ping:
|
||||||
description: Your ping
|
description: Your ping
|
||||||
dkick:
|
|
||||||
description: Kick a player discreetly
|
|
||||||
permission: tweaks724.dkick
|
|
||||||
pomodoro:
|
pomodoro:
|
||||||
description: Pomodoro management
|
description: Pomodoro management
|
||||||
permission: tweaks724.pomodoro
|
permission: tweaks724.pomodoro
|
||||||
|
|
Loading…
Reference in a new issue