-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename placeholder providers, add more placeholders
- Loading branch information
1 parent
6ab59e5
commit a456337
Showing
7 changed files
with
143 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
.../java/com/triassic/geyserdebuginfo/placeholder/placeholders/ChunkPlaceholderProvider.java
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
...java/com/triassic/geyserdebuginfo/placeholder/placeholders/PlayerPlaceholderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.triassic.geyserdebuginfo.placeholder.placeholders; | ||
|
||
import com.triassic.geyserdebuginfo.placeholder.PlaceholderProvider; | ||
import com.triassic.geyserdebuginfo.util.ChunkUtil; | ||
import com.triassic.geyserdebuginfo.util.PositionUtil; | ||
import org.cloudburstmc.math.vector.Vector3f; | ||
import org.cloudburstmc.math.vector.Vector3i; | ||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class PlayerPlaceholderProvider extends PlaceholderProvider { | ||
|
||
/** | ||
* Determines the player's facing direction based on the yaw value. | ||
* Yaw is normalized to a range of [0, 360) and mapped to cardinal directions. | ||
* | ||
* @param yaw The yaw value of the player. | ||
* @return The direction the player is facing as a string. | ||
*/ | ||
private static String getFacingDirection(float yaw) { | ||
// Normalize yaw to a range of [0, 360) | ||
yaw = (yaw % 360 + 360) % 360; | ||
|
||
// Determine direction based on yaw | ||
if (yaw >= 45 && yaw < 135) { | ||
return "west (Towards negative X)"; | ||
} else if (yaw >= 135 && yaw < 225) { | ||
return "north (Towards negative Z)"; | ||
} else if (yaw >= 225 && yaw < 315) { | ||
return "east (Towards positive X)"; | ||
} else { | ||
return "south (Towards positive Z)"; | ||
} | ||
} | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return "player"; | ||
} | ||
|
||
@Override | ||
public String onRequest(final GeyserSession session, @NotNull final String params) { | ||
final SessionPlayerEntity player = session.getPlayerEntity(); | ||
final Vector3f pos = PositionUtil.adjustForPlayerOffset(player.getPosition()); | ||
final Vector3i bedPos = player.getBedPosition(); | ||
int[] relativeChunkCoords = ChunkUtil.getRelativeCoordinates(pos); | ||
|
||
return switch (params) { | ||
case "x" -> String.format("%.3f", pos.getX()); | ||
case "y" -> String.format("%.3f", pos.getY()); | ||
case "z" -> String.format("%.3f", pos.getZ()); | ||
case "yaw" -> String.format("%.1f", player.getYaw()); | ||
case "pitch" -> String.format("%.1f", player.getPitch()); | ||
case "facing" -> getFacingDirection(player.getYaw()); | ||
|
||
case "chunk_x" -> String.valueOf(session.getLastChunkPosition().getX()); | ||
case "chunk_y" -> String.valueOf(ChunkUtil.calculateChunkY(pos.getFloorY())); | ||
case "chunk_z" -> String.valueOf(session.getLastChunkPosition().getY()); | ||
case "relative_x" -> String.valueOf(relativeChunkCoords[0]); | ||
case "relative_y" -> String.valueOf(relativeChunkCoords[1]); | ||
case "relative_z" -> String.valueOf(relativeChunkCoords[2]); | ||
case "global_x" -> String.valueOf(ChunkUtil.getRelativeChunkCoordinates(pos.getX(), pos.getZ())[0]); | ||
case "global_z" -> String.valueOf(ChunkUtil.getRelativeChunkCoordinates(pos.getX(), pos.getZ())[1]); | ||
case "region_file" -> ChunkUtil.getRegionFileName(pos.getX(), pos.getZ()); | ||
|
||
case "allow_flight" -> String.valueOf(session.isCanFly()); | ||
case "gamemode" -> String.valueOf(session.getGameMode()); | ||
case "uuid" -> String.valueOf(player.getUuid()); | ||
case "locale" -> session.locale(); | ||
case "version" -> session.version(); | ||
case "ip" -> String.valueOf(session.getSocketAddress()); | ||
|
||
case "health" -> String.valueOf(player.getHealth()); | ||
case "max_health" -> String.valueOf(player.getMaxHealth()); | ||
|
||
case "world" -> String.valueOf(session.getWorldName()); | ||
case "difficulty" -> String.valueOf(session.getWorldCache().getDifficulty()); | ||
case "time" -> String.valueOf(session.getTicks()); | ||
case "view_distance" -> String.valueOf(session.getClientRenderDistance()); | ||
|
||
case "name" -> session.bedrockUsername(); | ||
case "ping" -> String.valueOf(session.ping()); | ||
case "platform" -> session.platform().toString(); | ||
|
||
default -> null; | ||
}; | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
...va/com/triassic/geyserdebuginfo/placeholder/placeholders/PositionPlaceholderProvider.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...java/com/triassic/geyserdebuginfo/placeholder/placeholders/ServerPlaceholderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.triassic.geyserdebuginfo.placeholder.placeholders; | ||
|
||
import com.triassic.geyserdebuginfo.placeholder.PlaceholderProvider; | ||
import org.geysermc.geyser.GeyserImpl; | ||
import org.geysermc.geyser.session.GeyserSession; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ServerPlaceholderProvider extends PlaceholderProvider { | ||
|
||
private final Runtime runtime = Runtime.getRuntime(); | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return "server"; | ||
} | ||
|
||
@Override | ||
public String onRequest(final GeyserSession session, @NotNull final String params) { | ||
final GeyserImpl geyser = session.getGeyser(); | ||
final int i = 1024 * 1024; // Mebibytes conversion factor (1 MiB = 1024 * 1024 bytes) | ||
|
||
return switch (params) { | ||
case "name" -> geyser.bedrockListener().serverName(); | ||
case "address" -> geyser.bedrockListener().address(); | ||
case "port" -> String.valueOf(geyser.bedrockListener().port()); | ||
case "version" -> GeyserImpl.VERSION; | ||
case "build" -> GeyserImpl.BUILD_NUMBER; | ||
case "platform" -> geyser.getPlatformType().platformName(); | ||
case "online" -> String.valueOf(geyser.onlineConnectionsCount()); | ||
case "view_distance" -> String.valueOf(session.getServerRenderDistance()); | ||
|
||
case "remote_address" -> geyser.defaultRemoteServer().address(); | ||
case "remote_port" -> String.valueOf(geyser.defaultRemoteServer().port()); | ||
case "remote_version" -> geyser.defaultRemoteServer().minecraftVersion(); | ||
case "remote_protocol" -> String.valueOf(geyser.defaultRemoteServer().protocolVersion()); | ||
case "remote_auth_type" -> geyser.defaultRemoteServer().authType().toString(); | ||
|
||
case "ram_used" -> String.valueOf((runtime.totalMemory() - runtime.freeMemory()) / i); | ||
case "ram_free" -> String.valueOf(runtime.freeMemory() / i); | ||
case "ram_total" -> String.valueOf(runtime.totalMemory() / i); | ||
case "ram_max" -> String.valueOf(runtime.maxMemory() / i); | ||
default -> null; | ||
}; | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
...ava/com/triassic/geyserdebuginfo/placeholder/placeholders/SessionPlaceholderProvider.java
This file was deleted.
Oops, something went wrong.