Skip to content

Commit

Permalink
Backport player ping api
Browse files Browse the repository at this point in the history
Backport player ping api
  • Loading branch information
HaHaWTH authored Dec 31, 2024
2 parents 36bd1d5 + a4d1e68 commit 8ab3b59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/catserver/api/annotation/Backported.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package catserver.api.annotation;

import java.lang.annotation.*;

/**
* Indicates that the annotated api method is backported from a newer version of Minecraft.
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Backported {
String from() default "";
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.destroystokyo.paper.event.server;

import catserver.api.annotation.Backported;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Called when the server has finished ticking the main loop
*/
@Backported(from = "1.13.2")
public class ServerTickEndEvent extends Event {

private static final HandlerList HANDLER_LIST = new HandlerList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.destroystokyo.paper.event.server;

import catserver.api.annotation.Backported;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

@Backported(from = "1.13.2")
public class ServerTickStartEvent extends Event {

private static final HandlerList HANDLER_LIST = new HandlerList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,13 @@ public org.bukkit.advancement.AdvancementProgress getAdvancementProgress(org.buk
return new CraftAdvancementProgress(craft, data, progress);
}

// CatRoom start - Backport APIs
@Override
public int getPing() {
return this.getHandle().ping;
}
// CatRoom end - Backport APIs

@Override
public String getLocale() {
return getHandle().language;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/bukkit/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,24 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
*/
public AdvancementProgress getAdvancementProgress(Advancement advancement);

// CatRoom start - Backport APIs
/**
* Gets the player's estimated ping in milliseconds.
*
* In Vanilla this value represents a weighted average of the response time
* to application layer ping packets sent. This value does not represent the
* network round trip time and as such may have less granularity and be
* impacted by other sources. For these reasons it <b>should not</b> be used
* for anti-cheat purposes. Its recommended use is only as a
* <b>qualitative</b> indicator of connection quality (Vanilla uses it for
* this purpose in the tab list).
*
* @return player ping
*/
@catserver.api.annotation.Backported(from = "1.17")
public int getPing();
// CatRoom end - Backport APIs

/**
* Gets the player's current locale.
*
Expand Down

0 comments on commit 8ab3b59

Please sign in to comment.