Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
* text=auto eol=lf

*.bat text eol=crlf

*.jar binary
*.png binary
*.der binary
*.dat binary
*.mca binary

*.java diff=java
*.java.peb diff=java
*.kt diff=kotlin
*.kts diff=kotlin
*.md diff=markdown

/src/autogenerated/** linguist-generated
/src/main/resources/META-INF/native-image/** linguist-generated
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CookieCommand() {
}

public static class Store extends Command {
private final Argument<Key> keyArg = ArgumentType.ResourceLocation("key");
private final Argument<Key> keyArg = ArgumentType.Key("key");
private final Argument<String[]> valueArg = ArgumentType.StringArray("value");

public Store() {
Expand All @@ -40,7 +40,7 @@ private void store(CommandSender sender, CommandContext context) {
}

public static class Fetch extends Command {
private final Argument<Key> keyArg = ArgumentType.ResourceLocation("key");
private final Argument<Key> keyArg = ArgumentType.Key("key");

public Fetch() {
super("fetch");
Expand Down
224 changes: 112 additions & 112 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import net.minestom.server.command.builder.arguments.minecraft.ArgumentFloatRange;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentIntRange;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentItemStack;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentKey;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentNbtCompoundTag;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentNbtTag;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentResource;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentResourceLocation;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentResourceOrTag;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentTeamColor;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentTime;
Expand All @@ -31,7 +31,7 @@
* <p>
* Please see the specific class documentation for further info.
*/
public class ArgumentType {

Check failure on line 34 in src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java

View workflow job for this annotation

GitHub Actions / Binary Compatibility

Public/protected method removed or signature changed: net/minestom/server/command/builder/arguments/ArgumentType#ResourceLocation(Ljava/lang/String;)Lnet/minestom/server/command/builder/arguments/minecraft/ArgumentResourceLocation;

/**
* Creates a new {@link ArgumentLiteral}.
Expand Down Expand Up @@ -183,12 +183,12 @@
}

/**
* Creates a new {@link ArgumentResourceLocation}.
* Creates a new {@link ArgumentKey}.
*
* @see ArgumentResourceLocation
* @see ArgumentKey
*/
public static ArgumentResourceLocation ResourceLocation(String id) {
return new ArgumentResourceLocation(id);
public static ArgumentKey Key(String id) {
return new ArgumentKey(id);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;

/**
* Represents a resource location (namespaced identifier) value.
* Represents a {@link Key} value.
* <p>
* Example: {@code minecraft:air}
* </p>
*/
public class ArgumentResourceLocation extends Argument<Key> {
public class ArgumentKey extends Argument<Key> {

public static final int PARSE_ERROR = 1;

public ArgumentResourceLocation(String id) {
public ArgumentKey(String id) {
super(id);
}

@Override
public Key parse(CommandSender sender, @KeyPattern String input) throws ArgumentSyntaxException {
if (!Key.parseable(input))
throw new ArgumentSyntaxException("Invalid resource location", input, PARSE_ERROR);
throw new ArgumentSyntaxException("Invalid key", input, PARSE_ERROR);

return Key.key(input);
}
Expand All @@ -36,6 +36,6 @@ public ArgumentParserType parser() {

@Override
public String toString() {
return String.format("ResourceLocation<%s>", getId());
return String.format("Key<%s>", getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import net.minestom.server.command.builder.arguments.minecraft.ArgumentFloatRange;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentIntRange;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentItemStack;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentKey;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentNbtCompoundTag;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentNbtTag;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentResourceLocation;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentTeamColor;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentTime;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentUUID;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class ArgumentParser {
ARGUMENT_FUNCTION_MAP.put("color", ArgumentTeamColor::new);
ARGUMENT_FUNCTION_MAP.put("time", ArgumentTime::new);
ARGUMENT_FUNCTION_MAP.put("particle", ArgumentParticle::new);
ARGUMENT_FUNCTION_MAP.put("resourcelocation", ArgumentResourceLocation::new);
ARGUMENT_FUNCTION_MAP.put("key", ArgumentKey::new);
ARGUMENT_FUNCTION_MAP.put("entitytype", ArgumentEntityType::new);
ARGUMENT_FUNCTION_MAP.put("blockstate", ArgumentBlockState::new);
ARGUMENT_FUNCTION_MAP.put("intrange", ArgumentIntRange::new);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/minestom/server/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -200,6 +201,8 @@ public class Player extends LivingEntity implements CommandSender, HoverEventSou
private PlayerSkin skin;

private @Nullable Instance pendingInstance = null;
// Counts the calls to setInstance, so a spawn waiting for chunks knows when a later call replaces it
private final AtomicInteger instanceRequests = new AtomicInteger();
private int dimensionTypeId;
private volatile GameMode gameMode;
private WorldPos deathLocation;
Expand Down Expand Up @@ -671,6 +674,9 @@ public void sendPacketToViewersAndSelf(SendablePacket packet) {
* <p>
* Be aware that because chunk operations are expensive,
* it is possible for this method to be non-blocking when retrieving chunks is required.
* <p>
* A future that waits for chunks completes with a {@link CancellationException} when a later call to this method
* replaces it, and the player stays wherever that later call moves it.
*
* @param instance the new player instance
* @param spawnPosition the new position of the player
Expand All @@ -681,6 +687,7 @@ public CompletableFuture<Void> setInstance(Instance instance, Pos spawnPosition)
Check.argCondition(instance.process() != process(), "Instance belongs to another process");
final Instance currentInstance = this.instance;
Check.argCondition(currentInstance == instance, "Instance should be different than the current one");
final int request = instanceRequests.incrementAndGet();
if (SharedInstance.areLinked(currentInstance, instance) && spawnPosition.sameChunk(this.position)) {
// The player already has the good version of all the chunks.
// We just need to refresh his entity viewing list and add him to the instance
Expand Down Expand Up @@ -731,6 +738,10 @@ public Void join() {
var _ = CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new))
.thenRun(() -> {
scheduler.scheduleNextProcess(() -> {
if (instanceRequests.get() != request) {
future.completeExceptionally(new CancellationException("Another setInstance call replaced this one"));
return;
}
runnable.accept(instance);
future.complete(null);
});
Expand Down
Loading
Loading