mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Merge branch 'master' into new-block-api
This commit is contained in:
commit
13a64c7315
@ -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<Permission> 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));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -28,4 +28,17 @@ public class RelativeBlockPosition extends RelativeLocation<BlockPosition> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<T> {
|
||||
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<T> {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -28,4 +28,17 @@ public class RelativeVec extends RelativeLocation<Vector> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user