mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-26 08:51:47 +01:00
Block place supported
This commit is contained in:
parent
84ad01d775
commit
3d986c47fa
2 changed files with 120 additions and 2 deletions
|
@ -0,0 +1,107 @@
|
|||
package org.geysermc.connector.metrics;
|
||||
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.SentryClient;
|
||||
import io.sentry.SentryClientFactory;
|
||||
import io.sentry.context.Context;
|
||||
import io.sentry.event.BreadcrumbBuilder;
|
||||
import io.sentry.event.UserBuilder;
|
||||
|
||||
public class SentryMetrics {
|
||||
private static SentryClient sentry;
|
||||
|
||||
public static void init() {
|
||||
/*
|
||||
It is recommended that you use the DSN detection system, which
|
||||
will check the environment variable "SENTRY_DSN", the Java
|
||||
System Property "sentry.dsn", or the "sentry.properties" file
|
||||
in your classpath. This makes it easier to provide and adjust
|
||||
your DSN without needing to change your code. See the configuration
|
||||
page for more information.
|
||||
*/
|
||||
Sentry.init();
|
||||
|
||||
// You can also manually provide the DSN to the ``init`` method.
|
||||
Sentry.init();
|
||||
|
||||
/*
|
||||
It is possible to go around the static ``Sentry`` API, which means
|
||||
you are responsible for making the SentryClient instance available
|
||||
to your code.
|
||||
*/
|
||||
sentry = SentryClientFactory.sentryClient();
|
||||
|
||||
SentryMetrics metrics = new SentryMetrics();
|
||||
metrics.logWithStaticAPI();
|
||||
metrics.logWithInstanceAPI();
|
||||
}
|
||||
|
||||
/**
|
||||
* An example method that throws an exception.
|
||||
*/
|
||||
void unsafeMethod() {
|
||||
throw new UnsupportedOperationException("You shouldn't call this!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Examples using the (recommended) static API.
|
||||
*/
|
||||
void logWithStaticAPI() {
|
||||
// Note that all fields set on the context are optional. Context data is copied onto
|
||||
// all future events in the current context (until the context is cleared).
|
||||
|
||||
// Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
new BreadcrumbBuilder().setMessage("User made an action").build()
|
||||
);
|
||||
|
||||
// Set the user in the current context.
|
||||
Sentry.getContext().setUser(
|
||||
new UserBuilder().setEmail("hello@sentry.io").build()
|
||||
);
|
||||
|
||||
// Add extra data to future events in this context.
|
||||
Sentry.getContext().addExtra("extra", "thing");
|
||||
|
||||
// Add an additional tag to future events in this context.
|
||||
Sentry.getContext().addTag("tagName", "tagValue");
|
||||
|
||||
/*
|
||||
This sends a simple event to Sentry using the statically stored instance
|
||||
that was created in the ``main`` method.
|
||||
*/
|
||||
Sentry.capture("This is a test");
|
||||
|
||||
try {
|
||||
unsafeMethod();
|
||||
} catch (Exception e) {
|
||||
// This sends an exception event to Sentry using the statically stored instance
|
||||
// that was created in the ``main`` method.
|
||||
Sentry.capture(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Examples that use the SentryClient instance directly.
|
||||
*/
|
||||
void logWithInstanceAPI() {
|
||||
// Retrieve the current context.
|
||||
Context context = sentry.getContext();
|
||||
|
||||
// Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
|
||||
context.recordBreadcrumb(new BreadcrumbBuilder().setMessage("User made an action").build());
|
||||
|
||||
// Set the user in the current context.
|
||||
context.setUser(new UserBuilder().setEmail("geyser.project@gmail.com").build());
|
||||
|
||||
// This sends a simple event to Sentry.
|
||||
sentry.sendMessage("This is a test");
|
||||
|
||||
try {
|
||||
unsafeMethod();
|
||||
} catch (Exception e) {
|
||||
// This sends an exception event to Sentry.
|
||||
sentry.sendException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,11 +25,14 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.bedrock;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
|
@ -44,6 +47,9 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
if (entity == null)
|
||||
return;
|
||||
|
||||
Vector3i vector = packet.getBlockPosition();
|
||||
Position position = new Position(vector.getX(), vector.getY(), vector.getZ());
|
||||
|
||||
switch (packet.getAction()) {
|
||||
case RESPAWN:
|
||||
// Don't put anything here as respawn is already handled
|
||||
|
@ -71,14 +77,19 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
session.getDownstream().getSession().send(stopSprintPacket);
|
||||
break;
|
||||
case DROP_ITEM:
|
||||
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(),
|
||||
packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
|
||||
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
||||
session.getDownstream().getSession().send(dropItemPacket);
|
||||
break;
|
||||
case STOP_SLEEP:
|
||||
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED);
|
||||
session.getDownstream().getSession().send(stopSleepingPacket);
|
||||
break;
|
||||
case BLOCK_INTERACT:
|
||||
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position,
|
||||
BlockFace.values()[packet.getFace()],
|
||||
Hand.MAIN_HAND, 0, 0, 0, false);
|
||||
|
||||
session.getDownstream().getSession().send(blockPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue