mirror of https://github.com/Minestom/Minestom.git
Update to Java 17 (#462)
This commit is contained in:
parent
85d9256fa8
commit
b308ce5baa
|
@ -11,10 +11,10 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Run java checkstyle
|
- name: Run java checkstyle
|
||||||
uses: nikitasavinov/checkstyle-action@0.3.1
|
uses: nikitasavinov/checkstyle-action@0.3.1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -11,10 +11,10 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Build javadoc
|
- name: Build javadoc
|
||||||
run: gradle javadoc
|
run: gradle javadoc
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 16
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v2
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt'
|
distribution: 'zulu'
|
||||||
java-version: 16
|
java-version: 17
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Setup gradle cache
|
- name: Setup gradle cache
|
||||||
|
|
|
@ -3,14 +3,14 @@ import org.gradle.internal.os.OperatingSystem
|
||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.5.21'
|
id 'org.jetbrains.kotlin.jvm' version '1.5.31'
|
||||||
id 'checkstyle'
|
id 'checkstyle'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'net.minestom.server'
|
group 'net.minestom.server'
|
||||||
version '1.0'
|
version '1.0'
|
||||||
|
|
||||||
sourceCompatibility = 11
|
sourceCompatibility = 17
|
||||||
project.ext.lwjglVersion = "3.2.3"
|
project.ext.lwjglVersion = "3.2.3"
|
||||||
|
|
||||||
switch (OperatingSystem.current()) {
|
switch (OperatingSystem.current()) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ plugins {
|
||||||
group 'net.minestom.server'
|
group 'net.minestom.server'
|
||||||
version '1.0'
|
version '1.0'
|
||||||
|
|
||||||
sourceCompatibility = 1.11
|
sourceCompatibility = 17
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass.set("net.minestom.codegen.Generators")
|
mainClass.set("net.minestom.codegen.Generators")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
mcVersion = 1.17
|
mcVersion = 1.17
|
||||||
|
|
||||||
asmVersion=9.2
|
asmVersion=9.2
|
||||||
mixinVersion=0.8.3
|
mixinVersion=0.8.4
|
||||||
hephaistosVersion=v1.1.8
|
hephaistosVersion=v1.1.8
|
||||||
kotlinVersion=1.5.21
|
kotlinVersion=1.5.31
|
||||||
adventureVersion=4.8.1
|
adventureVersion=4.8.1
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-rc-2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
jdk:
|
before_install:
|
||||||
- openjdk11
|
- source "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||||
|
- sdk update
|
||||||
|
- sdk install java 17-open
|
||||||
|
- sdk use java 17-open
|
|
@ -148,54 +148,28 @@ public class CollisionUtils {
|
||||||
@NotNull Pos currentPosition, @NotNull Pos newPosition) {
|
@NotNull Pos currentPosition, @NotNull Pos newPosition) {
|
||||||
final WorldBorder worldBorder = instance.getWorldBorder();
|
final WorldBorder worldBorder = instance.getWorldBorder();
|
||||||
final WorldBorder.CollisionAxis collisionAxis = worldBorder.getCollisionAxis(newPosition);
|
final WorldBorder.CollisionAxis collisionAxis = worldBorder.getCollisionAxis(newPosition);
|
||||||
switch (collisionAxis) {
|
return switch (collisionAxis) {
|
||||||
case NONE:
|
case NONE ->
|
||||||
// Apply velocity + gravity
|
// Apply velocity + gravity
|
||||||
return newPosition;
|
newPosition;
|
||||||
case BOTH:
|
case BOTH ->
|
||||||
// Apply Y velocity/gravity
|
// Apply Y velocity/gravity
|
||||||
return new Pos(currentPosition.x(), newPosition.y(), currentPosition.z());
|
new Pos(currentPosition.x(), newPosition.y(), currentPosition.z());
|
||||||
case X:
|
case X ->
|
||||||
// Apply Y/Z velocity/gravity
|
// Apply Y/Z velocity/gravity
|
||||||
return new Pos(currentPosition.x(), newPosition.y(), newPosition.z());
|
new Pos(currentPosition.x(), newPosition.y(), newPosition.z());
|
||||||
case Z:
|
case Z ->
|
||||||
// Apply X/Y velocity/gravity
|
// Apply X/Y velocity/gravity
|
||||||
return new Pos(newPosition.x(), newPosition.y(), currentPosition.z());
|
new Pos(newPosition.x(), newPosition.y(), currentPosition.z());
|
||||||
}
|
};
|
||||||
throw new IllegalStateException("Something weird happened...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PhysicsResult {
|
public record PhysicsResult(Pos newPosition,
|
||||||
private final Pos newPosition;
|
Vec newVelocity,
|
||||||
private final Vec newVelocity;
|
boolean isOnGround) {
|
||||||
private final boolean isOnGround;
|
|
||||||
|
|
||||||
public PhysicsResult(Pos newPosition, Vec newVelocity, boolean isOnGround) {
|
|
||||||
this.newPosition = newPosition;
|
|
||||||
this.newVelocity = newVelocity;
|
|
||||||
this.isOnGround = isOnGround;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pos newPosition() {
|
|
||||||
return newPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec newVelocity() {
|
|
||||||
return newVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOnGround() {
|
|
||||||
return isOnGround;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class StepResult {
|
private record StepResult(Vec newPosition,
|
||||||
private final Vec newPosition;
|
boolean foundCollision) {
|
||||||
private final boolean foundCollision;
|
|
||||||
|
|
||||||
public StepResult(Vec newPosition, boolean foundCollision) {
|
|
||||||
this.newPosition = newPosition;
|
|
||||||
this.foundCollision = foundCollision;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ import java.util.function.DoubleUnaryOperator;
|
||||||
* Can either be a {@link Pos} or {@link Vec}.
|
* Can either be a {@link Pos} or {@link Vec}.
|
||||||
* Interface will become {@code sealed} in the future.
|
* Interface will become {@code sealed} in the future.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface Point permits Vec, Pos {
|
||||||
public interface Point {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the X coordinate.
|
* Gets the X coordinate.
|
||||||
|
@ -176,22 +175,14 @@ public interface Point {
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
default @NotNull Point relative(@NotNull BlockFace face) {
|
default @NotNull Point relative(@NotNull BlockFace face) {
|
||||||
switch (face) {
|
return switch (face) {
|
||||||
case BOTTOM:
|
case BOTTOM -> sub(0, 1, 0);
|
||||||
return sub(0, 1, 0);
|
case TOP -> add(0, 1, 0);
|
||||||
case TOP:
|
case NORTH -> sub(0, 0, 1);
|
||||||
return add(0, 1, 0);
|
case SOUTH -> add(0, 0, 1);
|
||||||
case NORTH:
|
case WEST -> sub(1, 0, 0);
|
||||||
return sub(0, 0, 1);
|
case EAST -> add(1, 0, 0);
|
||||||
case SOUTH:
|
};
|
||||||
return add(0, 0, 1);
|
|
||||||
case WEST:
|
|
||||||
return sub(1, 0, 0);
|
|
||||||
case EAST:
|
|
||||||
return add(1, 0, 0);
|
|
||||||
default: // should never be called
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,6 @@ import net.minestom.server.utils.MathUtils;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.DoubleUnaryOperator;
|
import java.util.function.DoubleUnaryOperator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,18 +12,11 @@ import java.util.function.DoubleUnaryOperator;
|
||||||
* <p>
|
* <p>
|
||||||
* To become record and primitive.
|
* To become record and primitive.
|
||||||
*/
|
*/
|
||||||
public final class Pos implements Point {
|
public record Pos(double x, double y, double z, float yaw, float pitch) implements Point {
|
||||||
public static final Pos ZERO = new Pos(0, 0, 0);
|
public static final Pos ZERO = new Pos(0, 0, 0);
|
||||||
|
|
||||||
private final double x, y, z;
|
public Pos {
|
||||||
private final float yaw, pitch;
|
yaw = fixYaw(yaw);
|
||||||
|
|
||||||
public Pos(double x, double y, double z, float yaw, float pitch) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.yaw = fixYaw(yaw);
|
|
||||||
this.pitch = pitch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos(double x, double y, double z) {
|
public Pos(double x, double y, double z) {
|
||||||
|
@ -47,8 +39,7 @@ public final class Pos implements Point {
|
||||||
* @return the converted position
|
* @return the converted position
|
||||||
*/
|
*/
|
||||||
public static @NotNull Pos fromPoint(@NotNull Point point) {
|
public static @NotNull Pos fromPoint(@NotNull Point point) {
|
||||||
if (point instanceof Pos)
|
if (point instanceof Pos pos) return pos;
|
||||||
return (Pos) point;
|
|
||||||
return new Pos(point.x(), point.y(), point.z());
|
return new Pos(point.x(), point.y(), point.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,34 +284,6 @@ public final class Pos implements Point {
|
||||||
return new Vec(x, y, z);
|
return new Vec(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Pos pos = (Pos) o;
|
|
||||||
return Double.compare(pos.x, x) == 0 &&
|
|
||||||
Double.compare(pos.y, y) == 0 &&
|
|
||||||
Double.compare(pos.z, z) == 0 &&
|
|
||||||
Float.compare(pos.yaw, yaw) == 0 &&
|
|
||||||
Float.compare(pos.pitch, pitch) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(x, y, z, yaw, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Pos{" +
|
|
||||||
"x=" + x +
|
|
||||||
", y=" + y +
|
|
||||||
", z=" + z +
|
|
||||||
", yaw=" + yaw +
|
|
||||||
", pitch=" + pitch +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Operator {
|
public interface Operator {
|
||||||
@NotNull Pos apply(double x, double y, double z, float yaw, float pitch);
|
@NotNull Pos apply(double x, double y, double z, float yaw, float pitch);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import net.minestom.server.utils.MathUtils;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.DoubleUnaryOperator;
|
import java.util.function.DoubleUnaryOperator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,27 +12,12 @@ import java.util.function.DoubleUnaryOperator;
|
||||||
* <p>
|
* <p>
|
||||||
* To become record and primitive.
|
* To become record and primitive.
|
||||||
*/
|
*/
|
||||||
public final class Vec implements Point {
|
public record Vec(double x, double y, double z) implements Point {
|
||||||
public static final Vec ZERO = new Vec(0);
|
public static final Vec ZERO = new Vec(0);
|
||||||
public static final Vec ONE = new Vec(1);
|
public static final Vec ONE = new Vec(1);
|
||||||
|
|
||||||
public static final double EPSILON = 0.000001;
|
public static final double EPSILON = 0.000001;
|
||||||
|
|
||||||
private final double x, y, z;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new vec with the 3 coordinates set.
|
|
||||||
*
|
|
||||||
* @param x the X coordinate
|
|
||||||
* @param y the Y coordinate
|
|
||||||
* @param z the Z coordinate
|
|
||||||
*/
|
|
||||||
public Vec(double x, double y, double z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new vec with the [x;z] coordinates set. Y is set to 0.
|
* Creates a new vec with the [x;z] coordinates set. Y is set to 0.
|
||||||
*
|
*
|
||||||
|
@ -61,8 +45,7 @@ public final class Vec implements Point {
|
||||||
* @return the converted vector
|
* @return the converted vector
|
||||||
*/
|
*/
|
||||||
public static @NotNull Vec fromPoint(@NotNull Point point) {
|
public static @NotNull Vec fromPoint(@NotNull Point point) {
|
||||||
if (point instanceof Vec)
|
if (point instanceof Vec vec) return vec;
|
||||||
return (Vec) point;
|
|
||||||
return new Vec(point.x(), point.y(), point.z());
|
return new Vec(point.x(), point.y(), point.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,28 +485,6 @@ public final class Vec implements Point {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Vec vec = (Vec) o;
|
|
||||||
return Double.compare(vec.x, x) == 0 && Double.compare(vec.y, y) == 0 && Double.compare(vec.z, z) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Vec{" +
|
|
||||||
"x=" + x +
|
|
||||||
", y=" + y +
|
|
||||||
", z=" + z +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Operator {
|
public interface Operator {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1257,9 +1257,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
final Chunk newChunk = instance.getChunk(newChunkX, newChunkZ);
|
final Chunk newChunk = instance.getChunk(newChunkX, newChunkZ);
|
||||||
Check.notNull(newChunk, "The entity {0} tried to move in an unloaded chunk at {1}", getEntityId(), newPosition);
|
Check.notNull(newChunk, "The entity {0} tried to move in an unloaded chunk at {1}", getEntityId(), newPosition);
|
||||||
instance.UNSAFE_switchEntityChunk(this, currentChunk, newChunk);
|
instance.UNSAFE_switchEntityChunk(this, currentChunk, newChunk);
|
||||||
if (this instanceof Player) {
|
if (this instanceof Player player) {
|
||||||
// Refresh player view
|
// Refresh player view
|
||||||
final Player player = (Player) this;
|
|
||||||
player.refreshVisibleChunks(newChunk);
|
player.refreshVisibleChunks(newChunk);
|
||||||
player.refreshVisibleEntities(newChunk);
|
player.refreshVisibleEntities(newChunk);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,13 @@ package net.minestom.server.entity;
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.registry.Registry;
|
import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface EntityType extends ProtocolObject, EntityTypes permits EntityTypeImpl {
|
||||||
public interface EntityType extends ProtocolObject, EntityTypes {
|
|
||||||
/**
|
/**
|
||||||
* Returns the entity registry.
|
* Returns the entity registry.
|
||||||
*
|
*
|
||||||
|
|
|
@ -34,20 +34,13 @@ public enum EquipmentSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquipmentSlot fromAttributeSlot(@NotNull AttributeSlot attributeSlot) {
|
public static EquipmentSlot fromAttributeSlot(@NotNull AttributeSlot attributeSlot) {
|
||||||
switch (attributeSlot) {
|
return switch (attributeSlot) {
|
||||||
case MAINHAND:
|
case MAINHAND -> MAIN_HAND;
|
||||||
return MAIN_HAND;
|
case OFFHAND -> OFF_HAND;
|
||||||
case OFFHAND:
|
case FEET -> BOOTS;
|
||||||
return OFF_HAND;
|
case LEGS -> LEGGINGS;
|
||||||
case FEET:
|
case CHEST -> CHESTPLATE;
|
||||||
return BOOTS;
|
case HEAD -> HELMET;
|
||||||
case LEGS:
|
};
|
||||||
return LEGGINGS;
|
|
||||||
case CHEST:
|
|
||||||
return CHESTPLATE;
|
|
||||||
case HEAD:
|
|
||||||
return HELMET;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Something weird happened");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,49 +291,28 @@ public class Metadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Value<T> getCorrespondingNewEmptyValue(int type) {
|
private static <T> Value<T> getCorrespondingNewEmptyValue(int type) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case TYPE_BYTE:
|
case TYPE_BYTE -> (Value<T>) Byte((byte) 0);
|
||||||
return (Value<T>) Byte((byte) 0);
|
case TYPE_VARINT -> (Value<T>) VarInt(0);
|
||||||
case TYPE_VARINT:
|
case TYPE_FLOAT -> (Value<T>) Float(0);
|
||||||
return (Value<T>) VarInt(0);
|
case TYPE_STRING -> (Value<T>) String("");
|
||||||
case TYPE_FLOAT:
|
case TYPE_CHAT -> (Value<T>) Chat(Component.empty());
|
||||||
return (Value<T>) Float(0);
|
case TYPE_OPTCHAT -> (Value<T>) OptChat(null);
|
||||||
case TYPE_STRING:
|
case TYPE_SLOT -> (Value<T>) Slot(ItemStack.AIR);
|
||||||
return (Value<T>) String("");
|
case TYPE_BOOLEAN -> (Value<T>) Boolean(false);
|
||||||
case TYPE_CHAT:
|
case TYPE_ROTATION -> (Value<T>) Rotation(Vec.ZERO);
|
||||||
return (Value<T>) Chat(Component.empty());
|
case TYPE_POSITION -> (Value<T>) Position(Vec.ZERO);
|
||||||
case TYPE_OPTCHAT:
|
case TYPE_OPTPOSITION -> (Value<T>) OptPosition(null);
|
||||||
return (Value<T>) OptChat(null);
|
case TYPE_DIRECTION -> (Value<T>) Direction(Direction.DOWN);
|
||||||
case TYPE_SLOT:
|
case TYPE_OPTUUID -> (Value<T>) OptUUID(null);
|
||||||
return (Value<T>) Slot(ItemStack.AIR);
|
case TYPE_OPTBLOCKID -> (Value<T>) OptBlockID(null);
|
||||||
case TYPE_BOOLEAN:
|
case TYPE_NBT -> (Value<T>) NBT(new NBTEnd());
|
||||||
return (Value<T>) Boolean(false);
|
case TYPE_PARTICLE -> throw new UnsupportedOperationException();
|
||||||
case TYPE_ROTATION:
|
case TYPE_VILLAGERDATA -> (Value<T>) VillagerData(0, 0, 0);
|
||||||
return (Value<T>) Rotation(Vec.ZERO);
|
case TYPE_OPTVARINT -> (Value<T>) OptVarInt(null);
|
||||||
case TYPE_POSITION:
|
case TYPE_POSE -> (Value<T>) Pose(Entity.Pose.STANDING);
|
||||||
return (Value<T>) Position(Vec.ZERO);
|
default -> throw new UnsupportedOperationException();
|
||||||
case TYPE_OPTPOSITION:
|
};
|
||||||
return (Value<T>) OptPosition(null);
|
|
||||||
case TYPE_DIRECTION:
|
|
||||||
return (Value<T>) Direction(Direction.DOWN);
|
|
||||||
case TYPE_OPTUUID:
|
|
||||||
return (Value<T>) OptUUID(null);
|
|
||||||
case TYPE_OPTBLOCKID:
|
|
||||||
return (Value<T>) OptBlockID(null);
|
|
||||||
case TYPE_NBT:
|
|
||||||
return (Value<T>) NBT(new NBTEnd());
|
|
||||||
case TYPE_PARTICLE:
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
case TYPE_VILLAGERDATA:
|
|
||||||
return (Value<T>) VillagerData(0, 0, 0);
|
|
||||||
case TYPE_OPTVARINT:
|
|
||||||
return (Value<T>) OptVarInt(null);
|
|
||||||
case TYPE_POSE:
|
|
||||||
return (Value<T>) Pose(Entity.Pose.STANDING);
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Value<T> read(int type, BinaryReader reader) {
|
private static <T> Value<T> read(int type, BinaryReader reader) {
|
||||||
|
|
|
@ -23,8 +23,7 @@ import java.util.function.Predicate;
|
||||||
*
|
*
|
||||||
* @param <T> The event type accepted by this node
|
* @param <T> The event type accepted by this node
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface EventNode<T extends Event> permits EventNodeImpl {
|
||||||
public interface EventNode<T extends Event> {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an event node which accepts any event type with no filtering.
|
* Creates an event node which accepts any event type with no filtering.
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
class EventNodeImpl<T extends Event> implements EventNode<T> {
|
non-sealed class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||||
private static final Object GLOBAL_CHILD_LOCK = new Object();
|
private static final Object GLOBAL_CHILD_LOCK = new Object();
|
||||||
|
|
||||||
private final Map<Class<? extends T>, Handle<T>> handleMap = new ConcurrentHashMap<>();
|
private final Map<Class<? extends T>, Handle<T>> handleMap = new ConcurrentHashMap<>();
|
||||||
|
@ -259,7 +259,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
||||||
final Set<Consumer<T>> bindingConsumers = new CopyOnWriteArraySet<>();
|
final Set<Consumer<T>> bindingConsumers = new CopyOnWriteArraySet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class Handle<E extends Event> implements ListenerHandle<E> {
|
static final class Handle<E extends Event> implements ListenerHandle<E> {
|
||||||
private final EventNodeImpl<E> node;
|
private final EventNodeImpl<E> node;
|
||||||
private final Class<E> eventType;
|
private final Class<E> eventType;
|
||||||
private Consumer<E> listener = null;
|
private Consumer<E> listener = null;
|
||||||
|
|
|
@ -12,8 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
* @param <E> the event type
|
* @param <E> the event type
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface ListenerHandle<E extends Event> permits EventNodeImpl.Handle {
|
||||||
public interface ListenerHandle<E extends Event> {
|
|
||||||
/**
|
/**
|
||||||
* Calls the given event.
|
* Calls the given event.
|
||||||
* Will try to fast exit the execution when possible if {@link #hasListener()} return {@code false}.
|
* Will try to fast exit the execution when possible if {@link #hasListener()} return {@code false}.
|
||||||
|
|
|
@ -5,7 +5,10 @@ import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
import net.minestom.server.tag.TagReadable;
|
import net.minestom.server.tag.TagReadable;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.*;
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -19,8 +22,7 @@ import java.util.function.BiPredicate;
|
||||||
* <p>
|
* <p>
|
||||||
* Implementations are expected to be immutable.
|
* Implementations are expected to be immutable.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface Block extends ProtocolObject, TagReadable, Blocks permits BlockImpl {
|
||||||
public interface Block extends ProtocolObject, TagReadable, Blocks {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new block with the the property {@code property} sets to {@code value}.
|
* Creates a new block with the the property {@code property} sets to {@code value}.
|
||||||
|
|
|
@ -23,20 +23,13 @@ public enum BlockFace {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockFace getOppositeFace() {
|
public BlockFace getOppositeFace() {
|
||||||
switch(this) {
|
return switch (this) {
|
||||||
case BOTTOM:
|
case BOTTOM -> TOP;
|
||||||
return TOP;
|
case TOP -> BOTTOM;
|
||||||
case TOP:
|
case NORTH -> SOUTH;
|
||||||
return BOTTOM;
|
case SOUTH -> NORTH;
|
||||||
case NORTH:
|
case WEST -> EAST;
|
||||||
return SOUTH;
|
case EAST -> WEST;
|
||||||
case SOUTH:
|
};
|
||||||
return NORTH;
|
|
||||||
case WEST:
|
|
||||||
return EAST;
|
|
||||||
case EAST:
|
|
||||||
return WEST;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,12 +82,8 @@ public interface BlockHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object forwarded to {@link #onPlace(Placement)}.
|
* Represents an object forwarded to {@link #onPlace(Placement)}.
|
||||||
* <p>
|
|
||||||
* Will in the future rely on sealed classes (https://openjdk.java.net/jeps/409)
|
|
||||||
* and record pattern for the implementations (https://openjdk.java.net/jeps/405).
|
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
sealed class Placement permits PlayerPlacement {
|
||||||
class Placement {
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Instance instance;
|
private final Instance instance;
|
||||||
private final Point blockPosition;
|
private final Point blockPosition;
|
||||||
|
@ -155,8 +151,7 @@ public interface BlockHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
sealed class Destroy permits PlayerDestroy {
|
||||||
class Destroy {
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Instance instance;
|
private final Instance instance;
|
||||||
private final Point blockPosition;
|
private final Point blockPosition;
|
||||||
|
@ -195,8 +190,7 @@ public interface BlockHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
final class Interaction {
|
||||||
class Interaction {
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Instance instance;
|
private final Instance instance;
|
||||||
private final Point blockPosition;
|
private final Point blockPosition;
|
||||||
|
@ -233,8 +227,7 @@ public interface BlockHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
final class Touch {
|
||||||
class Touch {
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Instance instance;
|
private final Instance instance;
|
||||||
private final Point blockPosition;
|
private final Point blockPosition;
|
||||||
|
@ -265,8 +258,7 @@ public interface BlockHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
final class Tick {
|
||||||
class Tick {
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Instance instance;
|
private final Instance instance;
|
||||||
private final Point blockPosition;
|
private final Point blockPosition;
|
||||||
|
|
|
@ -7,7 +7,6 @@ import net.minestom.server.tag.Tag;
|
||||||
import net.minestom.server.tag.TagHandler;
|
import net.minestom.server.tag.TagHandler;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
@ -21,8 +20,8 @@ import java.util.function.UnaryOperator;
|
||||||
/**
|
/**
|
||||||
* Represents an inventory where items can be modified/retrieved.
|
* Represents an inventory where items can be modified/retrieved.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
public sealed abstract class AbstractInventory implements InventoryClickHandler, TagHandler
|
||||||
public abstract class AbstractInventory implements InventoryClickHandler, TagHandler {
|
permits Inventory, PlayerInventory {
|
||||||
|
|
||||||
private final int size;
|
private final int size;
|
||||||
protected final ItemStack[] itemStacks;
|
protected final ItemStack[] itemStacks;
|
||||||
|
|
|
@ -48,13 +48,10 @@ public interface EquipmentHandler {
|
||||||
* @return the {@link ItemStack} in {@code hand}
|
* @return the {@link ItemStack} in {@code hand}
|
||||||
*/
|
*/
|
||||||
default @NotNull ItemStack getItemInHand(@NotNull Player.Hand hand) {
|
default @NotNull ItemStack getItemInHand(@NotNull Player.Hand hand) {
|
||||||
switch (hand) {
|
return switch (hand) {
|
||||||
case MAIN:
|
case MAIN -> getItemInMainHand();
|
||||||
return getItemInMainHand();
|
case OFF -> getItemInOffHand();
|
||||||
case OFF:
|
};
|
||||||
return getItemInOffHand();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Something weird happened");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,13 +62,8 @@ public interface EquipmentHandler {
|
||||||
*/
|
*/
|
||||||
default void setItemInHand(@NotNull Player.Hand hand, @NotNull ItemStack stack) {
|
default void setItemInHand(@NotNull Player.Hand hand, @NotNull ItemStack stack) {
|
||||||
switch (hand) {
|
switch (hand) {
|
||||||
case MAIN:
|
case MAIN -> setItemInMainHand(stack);
|
||||||
setItemInMainHand(stack);
|
case OFF -> setItemInOffHand(stack);
|
||||||
break;
|
|
||||||
|
|
||||||
case OFF:
|
|
||||||
setItemInOffHand(stack);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,45 +130,24 @@ public interface EquipmentHandler {
|
||||||
* @return the equipment {@link ItemStack}
|
* @return the equipment {@link ItemStack}
|
||||||
*/
|
*/
|
||||||
default @NotNull ItemStack getEquipment(@NotNull EquipmentSlot slot) {
|
default @NotNull ItemStack getEquipment(@NotNull EquipmentSlot slot) {
|
||||||
switch (slot) {
|
return switch (slot) {
|
||||||
case MAIN_HAND:
|
case MAIN_HAND -> getItemInMainHand();
|
||||||
return getItemInMainHand();
|
case OFF_HAND -> getItemInOffHand();
|
||||||
case OFF_HAND:
|
case HELMET -> getHelmet();
|
||||||
return getItemInOffHand();
|
case CHESTPLATE -> getChestplate();
|
||||||
case HELMET:
|
case LEGGINGS -> getLeggings();
|
||||||
return getHelmet();
|
case BOOTS -> getBoots();
|
||||||
case CHESTPLATE:
|
};
|
||||||
return getChestplate();
|
|
||||||
case LEGGINGS:
|
|
||||||
return getLeggings();
|
|
||||||
case BOOTS:
|
|
||||||
return getBoots();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Something weird happened");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setEquipment(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) {
|
default void setEquipment(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case MAIN_HAND:
|
case MAIN_HAND -> setItemInMainHand(itemStack);
|
||||||
setItemInMainHand(itemStack);
|
case OFF_HAND -> setItemInOffHand(itemStack);
|
||||||
break;
|
case HELMET -> setHelmet(itemStack);
|
||||||
case OFF_HAND:
|
case CHESTPLATE -> setChestplate(itemStack);
|
||||||
setItemInOffHand(itemStack);
|
case LEGGINGS -> setLeggings(itemStack);
|
||||||
break;
|
case BOOTS -> setBoots(itemStack);
|
||||||
case HELMET:
|
|
||||||
setHelmet(itemStack);
|
|
||||||
break;
|
|
||||||
case CHESTPLATE:
|
|
||||||
setChestplate(itemStack);
|
|
||||||
break;
|
|
||||||
case LEGGINGS:
|
|
||||||
setLeggings(itemStack);
|
|
||||||
break;
|
|
||||||
case BOOTS:
|
|
||||||
setBoots(itemStack);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Something weird happened");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
* You can create one with {@link Inventory#Inventory(InventoryType, String)} or by making your own subclass.
|
* You can create one with {@link Inventory#Inventory(InventoryType, String)} or by making your own subclass.
|
||||||
* It can then be opened using {@link Player#openInventory(Inventory)}.
|
* It can then be opened using {@link Player#openInventory(Inventory)}.
|
||||||
*/
|
*/
|
||||||
public class Inventory extends AbstractInventory implements Viewable {
|
public non-sealed class Inventory extends AbstractInventory implements Viewable {
|
||||||
|
|
||||||
// incremented each time an inventory is created (used in the window packets)
|
// incremented each time an inventory is created (used in the window packets)
|
||||||
private static byte LAST_INVENTORY_ID;
|
private static byte LAST_INVENTORY_ID;
|
||||||
|
|
|
@ -5,7 +5,6 @@ import net.minestom.server.event.EventDispatcher;
|
||||||
import net.minestom.server.event.inventory.InventoryClickEvent;
|
import net.minestom.server.event.inventory.InventoryClickEvent;
|
||||||
import net.minestom.server.inventory.click.ClickType;
|
import net.minestom.server.inventory.click.ClickType;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,8 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
* <p>
|
* <p>
|
||||||
* See https://wiki.vg/Protocol#Click_Window for more information.
|
* See https://wiki.vg/Protocol#Click_Window for more information.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface InventoryClickHandler permits AbstractInventory {
|
||||||
public interface InventoryClickHandler {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a {@link Player} left click in the inventory. Can also be to drop the cursor item
|
* Called when a {@link Player} left click in the inventory. Can also be to drop the cursor item
|
||||||
|
|
|
@ -18,7 +18,7 @@ import static net.minestom.server.utils.inventory.PlayerInventoryUtils.*;
|
||||||
/**
|
/**
|
||||||
* Represents the inventory of a {@link Player}, retrieved with {@link Player#getInventory()}.
|
* Represents the inventory of a {@link Player}, retrieved with {@link Player#getInventory()}.
|
||||||
*/
|
*/
|
||||||
public class PlayerInventory extends AbstractInventory implements EquipmentHandler {
|
public non-sealed class PlayerInventory extends AbstractInventory implements EquipmentHandler {
|
||||||
public static final int INVENTORY_SIZE = 46;
|
public static final int INVENTORY_SIZE = 46;
|
||||||
public static final int INNER_INVENTORY_SIZE = 36;
|
public static final int INNER_INVENTORY_SIZE = 36;
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,13 @@ package net.minestom.server.item;
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.registry.Registry;
|
import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface Enchantment extends ProtocolObject, Enchantments permits EnchantmentImpl {
|
||||||
public interface Enchantment extends ProtocolObject, Enchantments {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the enchantment registry.
|
* Returns the enchantment registry.
|
||||||
|
|
|
@ -4,15 +4,13 @@ import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.registry.Registry;
|
import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface Material extends ProtocolObject, Materials permits MaterialImpl {
|
||||||
public interface Material extends ProtocolObject, Materials {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the material registry.
|
* Returns the material registry.
|
||||||
|
|
|
@ -15,12 +15,8 @@ public class AnimationListener {
|
||||||
PlayerHandAnimationEvent handAnimationEvent = new PlayerHandAnimationEvent(player, hand);
|
PlayerHandAnimationEvent handAnimationEvent = new PlayerHandAnimationEvent(player, hand);
|
||||||
EventDispatcher.callCancellable(handAnimationEvent, () -> {
|
EventDispatcher.callCancellable(handAnimationEvent, () -> {
|
||||||
switch (hand) {
|
switch (hand) {
|
||||||
case MAIN:
|
case MAIN -> player.swingMainHand();
|
||||||
player.swingMainHand();
|
case OFF -> player.swingOffHand();
|
||||||
break;
|
|
||||||
case OFF:
|
|
||||||
player.swingOffHand();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ public enum ChatMessageType {
|
||||||
* @return the chat message type
|
* @return the chat message type
|
||||||
*/
|
*/
|
||||||
public static @NotNull ChatMessageType fromPacketID(int id) {
|
public static @NotNull ChatMessageType fromPacketID(int id) {
|
||||||
switch (id) {
|
return switch (id) {
|
||||||
case 0: return FULL;
|
case 0 -> FULL;
|
||||||
case 1: return SYSTEM;
|
case 1 -> SYSTEM;
|
||||||
case 2: return NONE;
|
case 2 -> NONE;
|
||||||
default: throw new IllegalArgumentException("id must be between 0-2 (inclusive)");
|
default -> throw new IllegalArgumentException("id must be between 0-2 (inclusive)");
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,10 @@ public enum ChatPosition {
|
||||||
* @return the position
|
* @return the position
|
||||||
*/
|
*/
|
||||||
public static @NotNull ChatPosition fromMessageType(@NotNull MessageType messageType) {
|
public static @NotNull ChatPosition fromMessageType(@NotNull MessageType messageType) {
|
||||||
switch (messageType) {
|
return switch (messageType) {
|
||||||
case CHAT: return CHAT;
|
case CHAT -> CHAT;
|
||||||
case SYSTEM: return SYSTEM_MESSAGE;
|
case SYSTEM -> SYSTEM_MESSAGE;
|
||||||
}
|
};
|
||||||
throw new IllegalArgumentException("Cannot get position from message type!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,11 +68,11 @@ public enum ChatPosition {
|
||||||
* @return the chat position
|
* @return the chat position
|
||||||
*/
|
*/
|
||||||
public static @NotNull ChatPosition fromPacketID(byte id) {
|
public static @NotNull ChatPosition fromPacketID(byte id) {
|
||||||
switch (id) {
|
return switch (id) {
|
||||||
case 0: return CHAT;
|
case 0 -> CHAT;
|
||||||
case 1: return SYSTEM_MESSAGE;
|
case 1 -> SYSTEM_MESSAGE;
|
||||||
case 2: return GAME_INFO;
|
case 2 -> GAME_INFO;
|
||||||
default: throw new IllegalArgumentException("id must be between 0-2 (inclusive)");
|
default -> throw new IllegalArgumentException("id must be between 0-2 (inclusive)");
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,26 +11,7 @@ import java.nio.ByteBuffer;
|
||||||
* Can be used if you want to send the exact same buffer to multiple clients without processing it more than once.
|
* Can be used if you want to send the exact same buffer to multiple clients without processing it more than once.
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public final class FramedPacket {
|
public record FramedPacket(int packetId,
|
||||||
private final int packetId;
|
@NotNull ByteBuffer body,
|
||||||
private final ByteBuffer body;
|
@NotNull ServerPacket packet) {
|
||||||
private final ServerPacket packet;
|
|
||||||
|
|
||||||
public FramedPacket(int packetId, @NotNull ByteBuffer body, @NotNull ServerPacket packet) {
|
|
||||||
this.packetId = packetId;
|
|
||||||
this.body = body;
|
|
||||||
this.packet = packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int packetId() {
|
|
||||||
return packetId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ByteBuffer body() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ServerPacket packet() {
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.minestom.server.network.packet.client.play;
|
package net.minestom.server.network.packet.client.play;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||||
import net.minestom.server.utils.Rotation;
|
import net.minestom.server.utils.Rotation;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import net.minestom.server.coordinate.Vec;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ClientUpdateStructureBlockPacket extends ClientPlayPacket {
|
public class ClientUpdateStructureBlockPacket extends ClientPlayPacket {
|
||||||
|
@ -90,32 +90,22 @@ public class ClientUpdateStructureBlockPacket extends ClientPlayPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toRestrictedRotation(Rotation rotation) {
|
private int toRestrictedRotation(Rotation rotation) {
|
||||||
switch (rotation) {
|
return switch (rotation) {
|
||||||
case NONE:
|
case NONE -> 0;
|
||||||
return 0;
|
case CLOCKWISE -> 1;
|
||||||
case CLOCKWISE:
|
case FLIPPED -> 2;
|
||||||
return 1;
|
case COUNTER_CLOCKWISE -> 3;
|
||||||
case FLIPPED:
|
default -> throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||||
return 2;
|
};
|
||||||
case COUNTER_CLOCKWISE:
|
|
||||||
return 3;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rotation fromRestrictedRotation(int rotation) {
|
private Rotation fromRestrictedRotation(int rotation) {
|
||||||
switch (rotation) {
|
return switch (rotation) {
|
||||||
case 0:
|
case 0 -> Rotation.NONE;
|
||||||
return Rotation.NONE;
|
case 1 -> Rotation.CLOCKWISE;
|
||||||
case 1:
|
case 2 -> Rotation.FLIPPED;
|
||||||
return Rotation.CLOCKWISE;
|
case 3 -> Rotation.COUNTER_CLOCKWISE;
|
||||||
case 2:
|
default -> throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||||
return Rotation.FLIPPED;
|
};
|
||||||
case 3:
|
|
||||||
return Rotation.COUNTER_CLOCKWISE;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,7 @@ public final class Server {
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public void init(SocketAddress address) throws IOException {
|
public void init(SocketAddress address) throws IOException {
|
||||||
if (address instanceof InetSocketAddress) {
|
if (address instanceof InetSocketAddress inetSocketAddress) {
|
||||||
InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
|
|
||||||
this.address = inetSocketAddress.getHostString();
|
this.address = inetSocketAddress.getHostString();
|
||||||
this.port = inetSocketAddress.getPort();
|
this.port = inetSocketAddress.getPort();
|
||||||
} // TODO unix domain support
|
} // TODO unix domain support
|
||||||
|
|
|
@ -2,14 +2,12 @@ package net.minestom.server.particle;
|
||||||
|
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface Particle extends ProtocolObject, Particles permits ParticleImpl {
|
||||||
public interface Particle extends ProtocolObject, Particles {
|
|
||||||
|
|
||||||
static @NotNull Collection<@NotNull Particle> values() {
|
static @NotNull Collection<@NotNull Particle> values() {
|
||||||
return ParticleImpl.values();
|
return ParticleImpl.values();
|
||||||
|
|
|
@ -3,15 +3,13 @@ package net.minestom.server.potion;
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.registry.Registry;
|
import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface PotionEffect extends ProtocolObject, PotionEffects permits PotionEffectImpl {
|
||||||
public interface PotionEffect extends ProtocolObject, PotionEffects {
|
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Registry.PotionEffectEntry registry();
|
@NotNull Registry.PotionEffectEntry registry();
|
||||||
|
|
|
@ -2,14 +2,12 @@ package net.minestom.server.potion;
|
||||||
|
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface PotionType extends ProtocolObject, PotionTypes permits PotionTypeImpl {
|
||||||
public interface PotionType extends ProtocolObject, PotionTypes {
|
|
||||||
|
|
||||||
static @NotNull Collection<@NotNull PotionType> values() {
|
static @NotNull Collection<@NotNull PotionType> values() {
|
||||||
return PotionTypeImpl.values();
|
return PotionTypeImpl.values();
|
||||||
|
|
|
@ -271,21 +271,11 @@ public final class Registry {
|
||||||
if (armorProperties != null) {
|
if (armorProperties != null) {
|
||||||
final String slot = armorProperties.getAsJsonObject().get("slot").getAsString();
|
final String slot = armorProperties.getAsJsonObject().get("slot").getAsString();
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case "feet":
|
case "feet" -> this.equipmentSlot = EquipmentSlot.BOOTS;
|
||||||
this.equipmentSlot = EquipmentSlot.BOOTS;
|
case "legs" -> this.equipmentSlot = EquipmentSlot.LEGGINGS;
|
||||||
break;
|
case "chest" -> this.equipmentSlot = EquipmentSlot.CHESTPLATE;
|
||||||
case "legs":
|
case "head" -> this.equipmentSlot = EquipmentSlot.HELMET;
|
||||||
this.equipmentSlot = EquipmentSlot.LEGGINGS;
|
default -> this.equipmentSlot = null;
|
||||||
break;
|
|
||||||
case "chest":
|
|
||||||
this.equipmentSlot = EquipmentSlot.CHESTPLATE;
|
|
||||||
break;
|
|
||||||
case "head":
|
|
||||||
this.equipmentSlot = EquipmentSlot.HELMET;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.equipmentSlot = null;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.equipmentSlot = null;
|
this.equipmentSlot = null;
|
||||||
|
|
|
@ -4,14 +4,12 @@ import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface SoundEvent extends ProtocolObject, Sound.Type, SoundEvents permits SoundEventImpl {
|
||||||
public interface SoundEvent extends ProtocolObject, Sound.Type, SoundEvents {
|
|
||||||
|
|
||||||
static @NotNull Collection<@NotNull SoundEvent> values() {
|
static @NotNull Collection<@NotNull SoundEvent> values() {
|
||||||
return SoundEventImpl.values();
|
return SoundEventImpl.values();
|
||||||
|
|
|
@ -2,14 +2,12 @@ package net.minestom.server.statistic;
|
||||||
|
|
||||||
import net.minestom.server.registry.ProtocolObject;
|
import net.minestom.server.registry.ProtocolObject;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ApiStatus.NonExtendable
|
public sealed interface StatisticType extends ProtocolObject, StatisticTypes permits StatisticTypeImpl {
|
||||||
public interface StatisticType extends ProtocolObject, StatisticTypes {
|
|
||||||
|
|
||||||
static @NotNull Collection<@NotNull StatisticType> values() {
|
static @NotNull Collection<@NotNull StatisticType> values() {
|
||||||
return StatisticTypeImpl.values();
|
return StatisticTypeImpl.values();
|
||||||
|
|
|
@ -34,23 +34,14 @@ public enum Direction {
|
||||||
return normalZ;
|
return normalZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public @NotNull Direction opposite() {
|
||||||
public Direction opposite() {
|
return switch (this) {
|
||||||
switch (this) {
|
case UP -> DOWN;
|
||||||
case UP:
|
case DOWN -> UP;
|
||||||
return DOWN;
|
case EAST -> WEST;
|
||||||
case DOWN:
|
case WEST -> EAST;
|
||||||
return UP;
|
case NORTH -> SOUTH;
|
||||||
case EAST:
|
case SOUTH -> NORTH;
|
||||||
return WEST;
|
};
|
||||||
case WEST:
|
|
||||||
return EAST;
|
|
||||||
case NORTH:
|
|
||||||
return SOUTH;
|
|
||||||
case SOUTH:
|
|
||||||
return NORTH;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,10 @@ public final class BinaryBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
final int size = buffer.remaining();
|
final int start = buffer.position();
|
||||||
// TODO jdk 13 put with index
|
final int end = buffer.limit();
|
||||||
this.nioBuffer.position(writerOffset).put(buffer);
|
final int size = end - start;
|
||||||
|
this.nioBuffer.put(writerOffset, buffer, start, size);
|
||||||
this.writerOffset += size;
|
this.writerOffset += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,13 +108,13 @@ public final class BinaryBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte[] bytes) {
|
public void writeBytes(byte[] bytes) {
|
||||||
this.nioBuffer.position(writerOffset).put(bytes);
|
this.nioBuffer.put(writerOffset, bytes);
|
||||||
this.writerOffset += bytes.length;
|
this.writerOffset += bytes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] readBytes(int length) {
|
public byte[] readBytes(int length) {
|
||||||
byte[] bytes = new byte[length];
|
byte[] bytes = new byte[length];
|
||||||
this.nioBuffer.position(readerOffset).get(bytes, 0, length);
|
this.nioBuffer.get(readerOffset, bytes);
|
||||||
this.readerOffset += length;
|
this.readerOffset += length;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,7 @@ public final class BinaryBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer asByteBuffer(int reader, int writer) {
|
public ByteBuffer asByteBuffer(int reader, int writer) {
|
||||||
return nioBuffer.position(reader).slice().limit(writer);
|
return nioBuffer.slice(reader, writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
|
@ -139,7 +140,7 @@ public final class BinaryBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writeChannel(WritableByteChannel channel) throws IOException {
|
public boolean writeChannel(WritableByteChannel channel) throws IOException {
|
||||||
var writeBuffer = asByteBuffer(readerOffset, writerOffset - readerOffset);
|
var writeBuffer = nioBuffer.slice(readerOffset, writerOffset - readerOffset);
|
||||||
final int count = channel.write(writeBuffer);
|
final int count = channel.write(writeBuffer);
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
// EOS
|
// EOS
|
||||||
|
@ -150,7 +151,7 @@ public final class BinaryBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readChannel(ReadableByteChannel channel) throws IOException {
|
public void readChannel(ReadableByteChannel channel) throws IOException {
|
||||||
final int count = channel.read(nioBuffer.position(readerOffset));
|
final int count = channel.read(nioBuffer.slice(readerOffset, capacity - readerOffset));
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
// EOS
|
// EOS
|
||||||
throw new IOException("Disconnected");
|
throw new IOException("Disconnected");
|
||||||
|
@ -167,28 +168,6 @@ public final class BinaryBuffer {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Marker {
|
public record Marker(int readerOffset, int writerOffset) {
|
||||||
private final int readerOffset, writerOffset;
|
|
||||||
|
|
||||||
private Marker(int readerOffset, int writerOffset) {
|
|
||||||
this.readerOffset = readerOffset;
|
|
||||||
this.writerOffset = writerOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int readerOffset() {
|
|
||||||
return readerOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int writerOffset() {
|
|
||||||
return writerOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Marker{" +
|
|
||||||
"readerOffset=" + readerOffset +
|
|
||||||
", writerOffset=" + writerOffset +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue