diff --git a/src/main/java/net/minestom/server/command/ConsoleSender.java b/src/main/java/net/minestom/server/command/ConsoleSender.java index 75bd72ad7..90d53f940 100644 --- a/src/main/java/net/minestom/server/command/ConsoleSender.java +++ b/src/main/java/net/minestom/server/command/ConsoleSender.java @@ -3,7 +3,7 @@ package net.minestom.server.command; import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.minestom.server.permission.Permission; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -16,7 +16,7 @@ import java.util.concurrent.CopyOnWriteArraySet; * Represents the console when sending a command to the server. */ public class ConsoleSender implements CommandSender { - private static final PlainComponentSerializer PLAIN_SERIALIZER = PlainComponentSerializer.plain(); + private static final PlainTextComponentSerializer PLAIN_SERIALIZER = PlainTextComponentSerializer.plainText(); private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleSender.class); private final Set permissions = new CopyOnWriteArraySet<>(); @@ -27,7 +27,7 @@ public class ConsoleSender implements CommandSender { } @Override - public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { + public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) { // we don't use the serializer here as we just need the plain text of the message this.sendMessage(PLAIN_SERIALIZER.serialize(message)); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java index c33d24c4c..015bc503f 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java @@ -13,7 +13,7 @@ public class ResourcePackSendPacket implements ServerPacket { public String url = ""; public String hash = "0000000000000000000000000000000000000000"; // Size 40 public boolean forced; - public Component forcedMessage = Component.empty(); + public Component forcedMessage; public ResourcePackSendPacket() { } @@ -30,8 +30,11 @@ public class ResourcePackSendPacket implements ServerPacket { writer.writeSizedString(url); writer.writeSizedString(hash); writer.writeBoolean(forced); - if (forced) { + if (forcedMessage != null) { + writer.writeBoolean(true); writer.writeComponent(forcedMessage); + } else { + writer.writeBoolean(false); } } @@ -40,8 +43,12 @@ public class ResourcePackSendPacket implements ServerPacket { this.url = reader.readSizedString(); this.hash = reader.readSizedString(); this.forced = reader.readBoolean(); - if (forced) { + + final boolean hasMessage = reader.readBoolean(); + if (hasMessage) { this.forcedMessage = reader.readComponent(); + } else { + this.forcedMessage = null; } } diff --git a/src/main/java/net/minestom/server/resourcepack/ResourcePack.java b/src/main/java/net/minestom/server/resourcepack/ResourcePack.java index c0719bec0..cd10a3e47 100644 --- a/src/main/java/net/minestom/server/resourcepack/ResourcePack.java +++ b/src/main/java/net/minestom/server/resourcepack/ResourcePack.java @@ -35,10 +35,14 @@ public class ResourcePack { return new ResourcePack(url, hash); } - public static ResourcePack forced(@NotNull String url, @Nullable String hash, @NotNull Component forcedMessage) { + public static ResourcePack forced(@NotNull String url, @Nullable String hash, @Nullable Component forcedMessage) { return new ResourcePack(url, hash, true, forcedMessage); } + public static ResourcePack forced(@NotNull String url, @Nullable String hash) { + return forced(url, hash, null); + } + /** * Gets the resource pack URL. * diff --git a/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java b/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java index b1b183e77..2a3ee592c 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeBlockPosition.java @@ -28,4 +28,17 @@ public class RelativeBlockPosition extends RelativeLocation { return new BlockPosition(x, y, z); } + + @Override + public BlockPosition fromView(@Nullable Position position) { + if (!relativeX && !relativeY && !relativeZ) { + return location.clone(); + } + final Position entityPosition = position != null ? position : new Position(); + + final int x = location.getX() + (relativeX ? (int) entityPosition.getYaw() : 0); + final int z = location.getZ() + (relativeZ ? (int) entityPosition.getPitch() : 0); + + return new BlockPosition(x, 0, z); + } } diff --git a/src/main/java/net/minestom/server/utils/location/RelativeLocation.java b/src/main/java/net/minestom/server/utils/location/RelativeLocation.java index fac09b12f..259406877 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeLocation.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeLocation.java @@ -1,5 +1,6 @@ package net.minestom.server.utils.location; +import com.google.common.annotations.Beta; import net.minestom.server.entity.Entity; import net.minestom.server.utils.Position; import org.jetbrains.annotations.NotNull; @@ -22,19 +23,6 @@ public abstract class RelativeLocation { this.relativeZ = relativeZ; } - /** - * Gets the location based on the relative fields and {@code entity}. - * - * @param entity the entity to get the relative position from - * @return the location - */ - public T from(@Nullable Entity entity) { - - final Position entityPosition = entity != null ? entity.getPosition() : new Position(); - - return from(entityPosition); - } - /** * Gets the location based on the relative fields and {@code position}. * @@ -43,6 +31,26 @@ public abstract class RelativeLocation { */ public abstract T from(@Nullable Position position); + @Beta + public abstract T fromView(@Nullable Position position); + + /** + * Gets the location based on the relative fields and {@code entity}. + * + * @param entity the entity to get the relative position from + * @return the location + */ + public T from(@Nullable Entity entity) { + final Position entityPosition = entity != null ? entity.getPosition() : new Position(); + return from(entityPosition); + } + + @Beta + public T fromView(@Nullable Entity entity) { + final Position entityPosition = entity != null ? entity.getPosition() : new Position(); + return fromView(entityPosition); + } + /** * Gets if the 'x' field is relative. * diff --git a/src/main/java/net/minestom/server/utils/location/RelativeVec.java b/src/main/java/net/minestom/server/utils/location/RelativeVec.java index 42d948c84..df1c02ed9 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeVec.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeVec.java @@ -28,4 +28,17 @@ public class RelativeVec extends RelativeLocation { return new Vector(x, y, z); } + + @Override + public Vector fromView(@Nullable Position position) { + if (!relativeX && !relativeY && !relativeZ) { + return location.clone(); + } + final Position entityPosition = position != null ? position : new Position(); + + final double x = location.getX() + (relativeX ? entityPosition.getYaw() : 0); + final double z = location.getZ() + (relativeZ ? entityPosition.getPitch() : 0); + + return new Vector(x, 0, z); + } }