Skip to content

Commit

Permalink
Remove verbose logging for PlaceholderManager, fix mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTriassic committed Oct 6, 2024
1 parent a456337 commit f498c48
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 69 deletions.
20 changes: 10 additions & 10 deletions src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.triassic.geyserdebuginfo;

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;
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
import org.geysermc.geyser.api.extension.Extension;
import com.triassic.geyserdebuginfo.command.commands.ToggleCommand;
import com.triassic.geyserdebuginfo.command.commands.ReloadCommand;
import com.triassic.geyserdebuginfo.command.commands.ToggleCommand;
import com.triassic.geyserdebuginfo.config.Configuration;
import com.triassic.geyserdebuginfo.config.ConfigurationContainer;
import com.triassic.geyserdebuginfo.listener.PlayerJoinListener;
import com.triassic.geyserdebuginfo.manager.BossBarManager;
import com.triassic.geyserdebuginfo.manager.PlaceholderManager;
import com.triassic.geyserdebuginfo.manager.PlayerDataManager;
import com.triassic.geyserdebuginfo.placeholder.modifiers.MathModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.modifiers.TextModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.PlayerPlaceholderProvider;
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;
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
import org.geysermc.geyser.api.extension.Extension;

import java.io.File;
import java.util.stream.Stream;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void onPostInitialize(GeyserPreInitializeEvent event) {

loadConfig();
this.playerDataManager = new PlayerDataManager(dataFolder, this.logger(), false);
this.placeholderManager = new PlaceholderManager(logger());
this.placeholderManager = new PlaceholderManager();
this.bossBarManager = new BossBarManager(this);
this.eventBus().register(new PlayerJoinListener(this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class BossBarSettings {
"",
"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%]",
"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%)"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,23 @@

import com.triassic.geyserdebuginfo.placeholder.ModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.PlaceholderProvider;
import org.geysermc.geyser.api.extension.ExtensionLogger;
import org.geysermc.geyser.session.GeyserSession;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class PlaceholderManager {

private final ExtensionLogger logger;
private final Map<String, PlaceholderProvider> providers = new ConcurrentHashMap<>();
private final Map<String, ModifierProvider> modifiers = new ConcurrentHashMap<>();

public PlaceholderManager(
final ExtensionLogger logger
) {
this.logger = logger;
}

public void registerProvider(PlaceholderProvider provider) {
providers.put(provider.getIdentifier(), provider);
logger.info("Registered placeholder provider " + provider.getIdentifier());
}

public void registerProvider(ModifierProvider provider) {
for (String modifier : provider.getModifiers()) {
modifiers.put(modifier, provider);
logger.info("Registered modifier " + modifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,14 @@

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.EntityDefinitions;
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";
Expand All @@ -42,8 +18,7 @@ public String getIdentifier() {
@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();
final Vector3f pos = adjustForPlayerOffset(player.getPosition());
int[] relativeChunkCoords = ChunkUtil.getRelativeCoordinates(pos);

return switch (params) {
Expand Down Expand Up @@ -86,4 +61,38 @@ public String onRequest(final GeyserSession session, @NotNull final String param
default -> null;
};
}

/**
* Adjusts the y-coordinate of the given Vector3f by removing the player offset.
* The x and z coordinates remain unchanged.
*
* @param position the original position of the player as a Vector3f
* @return a new Vector3f with the y-coordinate adjusted by subtracting the PLAYER_OFFSET
*/
public static Vector3f adjustForPlayerOffset(Vector3f position) {
return Vector3f.from(position.getX(), position.getY() - EntityDefinitions.PLAYER.offset(), position.getZ()); // TODO: https://github.com/GeyserMC/Geyser/issues/5061.
}

/**
* 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)";
}
}
}
21 changes: 0 additions & 21 deletions src/main/java/com/triassic/geyserdebuginfo/util/PositionUtil.java

This file was deleted.

0 comments on commit f498c48

Please sign in to comment.