Skip to content

Commit

Permalink
Rename placeholder providers, add more placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTriassic committed Oct 6, 2024
1 parent 6ab59e5 commit a456337
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 125 deletions.
10 changes: 4 additions & 6 deletions src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.triassic.geyserdebuginfo.placeholder.modifiers.MathModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.modifiers.TextModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.ServerPlaceholderProvider;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
Expand All @@ -15,9 +16,7 @@
import com.triassic.geyserdebuginfo.manager.BossBarManager;
import com.triassic.geyserdebuginfo.manager.PlaceholderManager;
import com.triassic.geyserdebuginfo.manager.PlayerDataManager;
import com.triassic.geyserdebuginfo.placeholder.placeholders.ChunkPlaceholderProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.PositionPlaceholderProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.SessionPlaceholderProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.PlayerPlaceholderProvider;

import java.io.File;
import java.util.stream.Stream;
Expand Down Expand Up @@ -50,9 +49,8 @@ public void onPostInitialize(GeyserPreInitializeEvent event) {
this.eventBus().register(new PlayerJoinListener(this));

Stream.of(
new ChunkPlaceholderProvider(),
new PositionPlaceholderProvider(),
new SessionPlaceholderProvider()
new PlayerPlaceholderProvider(),
new ServerPlaceholderProvider()
).forEach(placeholderManager::registerProvider);

Stream.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public static class BossBarSettings {
private List<String> displayFormat = Arrays.asList(
"Geyser Debug Information",
"",
"%session_world%",
"%player_world%",
"",
"XYZ: %position_x% / %position_y% / %position_z%",
"Block: %position_x:floor% %position_y:floor% %position_z:floor% [%chunk_relative_x% %chunk_relative_y% %chunk_relative_z%]",
"Chunk: %chunk_x% %chunk_y% %chunk_z% [%chunk_global_x% %chunk_global_z% in %chunk_region_file%]",
"Facing: %position_facing% (%position_yaw% / %position_pitch%)"
"XYZ: %player_x% / %player_y% / %player_z%",
"Block: %player_x:floor% %player_y:floor% %player_z:floor% [%player_relative_x% %player_relative_y% %player_relative_z%]",
"Chunk: %player_chunk_x% %player_chunk_y% %player_chunk_z% [%player_global_x% %player_global_z% in %player__region_file%]",
"Facing: %player_facing% (%player_yaw% / %player_pitch%)"
);

public long getRefreshInterval() {
Expand Down

This file was deleted.

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;
};
}
}

This file was deleted.

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;
};
}
}

This file was deleted.

0 comments on commit a456337

Please sign in to comment.