Skip to content

Commit

Permalink
Add a theoretically more trustworthy port getter via NMS for server.p…
Browse files Browse the repository at this point in the history
…ort tag
  • Loading branch information
mcmonkey4eva committed Jan 9, 2017
1 parent f511908 commit 7cee530
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
Expand Up @@ -109,4 +109,6 @@ public static JavaPlugin getJavaPlugin() {
public abstract void enablePacketInterception(PacketHandler packetHandler);

public abstract CompoundTag createCompoundTag(Map<String, Tag> value);

public abstract int getPort();
}
Expand Up @@ -1041,7 +1041,7 @@ else if (attribute.startsWith("recent_tps")) {
// Returns the port that the server is running on.
// -->
else if (attribute.startsWith("port")) {
event.setReplaced(new Element(Bukkit.getServer().getPort()).getAttribute(attribute.fulfill(1)));
event.setReplaced(new Element(NMSHandler.getInstance().getPort()).getAttribute(attribute.fulfill(1)));
}

// TODO: Add everything else from Bukkit.getServer().*
Expand Down
Expand Up @@ -188,6 +188,11 @@ public PlayerProfile fillPlayerProfile(PlayerProfile playerProfile) {
return null;
}

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().P();
}

@Override
public PlayerProfile getPlayerProfile(Player player) {
GameProfile gameProfile = ((CraftPlayer) player).getProfile();
Expand Down
Expand Up @@ -188,6 +188,11 @@ public PlayerProfile fillPlayerProfile(PlayerProfile playerProfile) {
return null;
}

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().P();
}

@Override
public PlayerProfile getPlayerProfile(Player player) {
GameProfile gameProfile = ((CraftPlayer) player).getProfile();
Expand Down
Expand Up @@ -59,6 +59,11 @@ public double[] getRecentTps() {
return ((CraftServer) Bukkit.getServer()).getServer().recentTps;
}

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().R();
}

@Override
public AnimationHelper getAnimationHelper() {
return animationHelper;
Expand Down
Expand Up @@ -49,6 +49,11 @@ public class Handler_v1_9_R2 extends NMSHandler {

private final ProfileEditor profileEditor = new ProfileEditor_v1_9_R2();

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().P();
}

@Override
public Thread getMainThread() {
return ((CraftServer) Bukkit.getServer()).getServer().primaryThread;
Expand Down

0 comments on commit 7cee530

Please sign in to comment.