Skip to content

Commit

Permalink
Add get_player_ping()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jul 3, 2024
1 parent 90e2d60 commit ace9b67
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,6 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye
void respawn();

void sendEquipmentChange(MCLivingEntity entity, MCEquipmentSlot slot, MCItemStack item);

int getPing();
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,4 +848,9 @@ public void sendEquipmentChange(MCLivingEntity entity, MCEquipmentSlot slot, MCI
// probably before 1.18, which is unsupported
}
}

@Override
public int getPing() {
return p.getPing();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7173,7 +7173,8 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREBadEntityException.class};
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREBadEntityException.class,
CREFormatException.class};
}

@Override
Expand All @@ -7191,4 +7192,48 @@ public Boolean runAsync() {
return false;
}
}

@api
public static class get_player_ping extends AbstractFunction {

public String getName() {
return "get_player_ping";
}

public Integer[] numArgs() {
return new Integer[]{0, 1};
}

public String docs() {
return "int {[player]} Returns a player's average response time to ping packets in milliseconds."
+ " This is an indicator of the quality of the player's connection, as represented in the tab list.";
}

public Construct exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
MCPlayer p;
if(args.length == 1) {
p = Static.GetPlayer(args[0].val(), t);
} else {
p = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
Static.AssertPlayerNonNull(p, t);
}
return new CInt(p.getPing(), t);
}

public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class};
}

public Version since() {
return MSVersion.V3_3_5;
}

public boolean isRestricted() {
return false;
}

public Boolean runAsync() {
return false;
}
}
}

0 comments on commit ace9b67

Please sign in to comment.