forked from PaperMC/Velocity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/upstream/dev/3.0.0' into d…
…ev/3.0.0 # Conflicts: # .github/workflows/gradle.yml # proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java # proxy/src/main/resources/default-velocity.toml
- Loading branch information
Showing
97 changed files
with
2,068 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
api/src/main/java/com/velocitypowered/api/command/CommandResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2020-2021 Velocity Contributors | ||
* | ||
* The Velocity API is licensed under the terms of the MIT License. For more details, | ||
* reference the LICENSE file in the api top-level directory. | ||
*/ | ||
|
||
package com.velocitypowered.api.command; | ||
|
||
/** | ||
* The result of a command invocation attempt. | ||
*/ | ||
public enum CommandResult { | ||
/** | ||
* The command was successfully executed by the proxy. | ||
*/ | ||
EXECUTED, | ||
/** | ||
* The command was forwarded to the backend server. | ||
* The command may be successfully executed or not | ||
*/ | ||
FORWARDED, | ||
/** | ||
* The provided command input contained syntax errors. | ||
*/ | ||
SYNTAX_ERROR, | ||
/** | ||
* An unexpected exception occurred while executing the command in the proxy. | ||
*/ | ||
EXCEPTION | ||
} |
82 changes: 82 additions & 0 deletions
82
api/src/main/java/com/velocitypowered/api/event/command/PostCommandInvocationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2020-2023 Velocity Contributors | ||
* | ||
* The Velocity API is licensed under the terms of the MIT License. For more details, | ||
* reference the LICENSE file in the api top-level directory. | ||
*/ | ||
|
||
package com.velocitypowered.api.event.command; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.velocitypowered.api.command.CommandResult; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* This event is fired when velocity executed a command. This event is called after the event | ||
* is handled. | ||
* | ||
* <p>Commands can be cancelled or forwarded to backend servers in {@link CommandExecuteEvent}. | ||
* This will prevent firing this event.</p> | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
public final class PostCommandInvocationEvent { | ||
|
||
private final CommandSource commandSource; | ||
private final String command; | ||
private final CommandResult result; | ||
|
||
/** | ||
* Constructs a PostCommandInvocationEvent. | ||
* | ||
* @param commandSource the source executing the command | ||
* @param command the command being executed without first slash | ||
* @param result the result of this command | ||
*/ | ||
public PostCommandInvocationEvent( | ||
final @NotNull CommandSource commandSource, | ||
final @NotNull String command, | ||
final @NotNull CommandResult result | ||
) { | ||
this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); | ||
this.command = Preconditions.checkNotNull(command, "command"); | ||
this.result = Preconditions.checkNotNull(result, "result"); | ||
} | ||
|
||
/** | ||
* Get the source of this executed command. | ||
* | ||
* @return the source | ||
*/ | ||
public @NotNull CommandSource getCommandSource() { | ||
return commandSource; | ||
} | ||
|
||
/** | ||
* Gets the original command line executed without the first slash. | ||
* | ||
* @return the original command | ||
* @see CommandExecuteEvent#getCommand() | ||
*/ | ||
public @NotNull String getCommand() { | ||
return command; | ||
} | ||
|
||
/** | ||
* Returns the result of the command execution. | ||
* | ||
* @return the execution result | ||
*/ | ||
public @NotNull CommandResult getResult() { | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PostCommandInvocationEvent{" | ||
+ "commandSource=" + commandSource | ||
+ ", command=" + command | ||
+ '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
api/src/main/java/com/velocitypowered/api/event/connection/PreTransferEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (C) 2024 Velocity Contributors | ||
* | ||
* The Velocity API is licensed under the terms of the MIT License. For more details, | ||
* reference the LICENSE file in the api top-level directory. | ||
*/ | ||
|
||
package com.velocitypowered.api.event.connection; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.velocitypowered.api.event.ResultedEvent; | ||
import com.velocitypowered.api.event.annotation.AwaitingEvent; | ||
import com.velocitypowered.api.proxy.Player; | ||
import java.net.InetSocketAddress; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* This event is executed before sending a player to another host, | ||
* either by the backend server or by a plugin using | ||
* the {@link Player#transferToHost(InetSocketAddress)} method. | ||
*/ | ||
@AwaitingEvent | ||
@ApiStatus.Experimental | ||
public final class PreTransferEvent implements ResultedEvent<PreTransferEvent.TransferResult> { | ||
private final InetSocketAddress originalAddress; | ||
private final Player player; | ||
private TransferResult result = TransferResult.ALLOWED; | ||
|
||
public PreTransferEvent(final Player player, final InetSocketAddress address) { | ||
this.player = requireNonNull(player); | ||
this.originalAddress = requireNonNull(address); | ||
} | ||
|
||
public Player player() { | ||
return this.player; | ||
} | ||
|
||
public InetSocketAddress originalAddress() { | ||
return this.originalAddress; | ||
} | ||
|
||
@Override | ||
public TransferResult getResult() { | ||
return this.result; | ||
} | ||
|
||
@Override | ||
public void setResult(final TransferResult result) { | ||
requireNonNull(result); | ||
this.result = result; | ||
} | ||
|
||
/** | ||
* Transfer Result of a player to another host. | ||
*/ | ||
public static class TransferResult implements ResultedEvent.Result { | ||
private static final TransferResult ALLOWED = new TransferResult(true, null); | ||
private static final TransferResult DENIED = new TransferResult(false, null); | ||
|
||
private final InetSocketAddress address; | ||
private final boolean allowed; | ||
|
||
private TransferResult(final boolean allowed, final InetSocketAddress address) { | ||
this.address = address; | ||
this.allowed = allowed; | ||
} | ||
|
||
public static TransferResult allowed() { | ||
return ALLOWED; | ||
} | ||
|
||
public static TransferResult denied() { | ||
return DENIED; | ||
} | ||
|
||
/** | ||
* Sets the result of transfer to a specific host. | ||
* | ||
* @param address the address specified | ||
* @return a new TransferResult | ||
*/ | ||
public static TransferResult transferTo(final InetSocketAddress address) { | ||
requireNonNull(address); | ||
|
||
return new TransferResult(true, address); | ||
} | ||
|
||
@Override | ||
public boolean isAllowed() { | ||
return this.allowed; | ||
} | ||
|
||
@Nullable | ||
public InetSocketAddress address() { | ||
return this.address; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
api/src/main/java/com/velocitypowered/api/network/HandshakeIntent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2024 Velocity Contributors | ||
* | ||
* The Velocity API is licensed under the terms of the MIT License. For more details, | ||
* reference the LICENSE file in the api top-level directory. | ||
*/ | ||
|
||
package com.velocitypowered.api.network; | ||
|
||
/** | ||
* Represents the ClientIntent of a client in the Handshake state. | ||
*/ | ||
public enum HandshakeIntent { | ||
STATUS(1), | ||
LOGIN(2), | ||
TRANSFER(3); | ||
|
||
private final int id; | ||
|
||
HandshakeIntent(int id) { | ||
this.id = id; | ||
} | ||
|
||
public int id() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Obtain the HandshakeIntent by ID. | ||
* | ||
* @param id the intent id | ||
* @return the HandshakeIntent desired | ||
*/ | ||
public static HandshakeIntent getById(int id) { | ||
return switch (id) { | ||
case 1 -> STATUS; | ||
case 2 -> LOGIN; | ||
case 3 -> TRANSFER; | ||
default -> null; | ||
}; | ||
} | ||
} |
Oops, something went wrong.