Skip to content

Commit 87279a6

Browse files
authored
Merge pull request #194 from HytaleModding/player-ecs-refactor
refactor: update command docs to use the correct class
2 parents c4b5faf + 8ded4c7 commit 87279a6

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

content/docs/en/guides/plugin/creating-commands.mdx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,40 @@ description: "Learn how to create custom commands for your Hytale mod."
44
authors:
55
- name: "Neil Revin"
66
link: "https://itsneil.dev"
7+
- name: "oskarscot"
8+
link: "https://oskar.scot"
79
---
810

911
In this guide, you will learn how to create custom commands for your Hytale mod.
1012

11-
## The `CommandBase` Class
13+
## The `AbstractPlayerCommand` Class
1214

13-
To create a command, you can extend the `CommandBase` class. You need to provide a constructor that calls the superclass constructor with the command name, description, and whether the command requires confirmation (--confirm while running the command).
15+
To create a command, you can extend the `AbstractPlayerCommand` class. You need to provide a constructor that calls the `BaseCommand` constructor with the command name, description, and whether the command requires confirmation (--confirm while running the command).
1416

15-
You can override the `executeSync` function to implement the command's behavior. Here is an example of a simple command that sends a message to the command sender:
17+
You can override the `execute` function to implement the command's behavior. It gives you access to the CommandContext which is always a player in this case, the EntityStore, the Reference store, the player reference as well as the World in which the command is being executed.
18+
It's important to know that `AbstractPlayerCommand` extends `AbstractAsyncCommand` meaning that commands do not execute on the main server thread.
1619

17-
```java
18-
public class ExampleCommand extends CommandBase {
20+
You can use the `Store` along with the `Ref` to access all entity components like the `Player` component, `UUIDComponent` or `TransformComponent`.
1921

20-
public ExampleCommand() {
21-
super("example", "A example command", false);
22-
}
2322

24-
@Override
25-
protected void executeSync(@Nonnull CommandContext context) {
26-
context.sendMessage(Message.raw("Hello from ExampleCommand!"));
27-
}
23+
```java
24+
public class ExampleCommand extends AbstractPlayerCommand {
25+
26+
public ExampleCommand() {
27+
super("test", "Super test command!");
28+
}
29+
30+
@Override
31+
protected void execute(@Nonnull CommandContext commandContext, @Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> ref, @Nonnull PlayerRef playerRef, @Nonnull World world) {
32+
Player player = store.getComponent(ref, Player.getComponentType()); // also a component
33+
UUIDComponent component = store.getComponent(ref, UUIDComponent.getComponentType());
34+
TransformComponent transform = store.getComponent(ref, TransformComponent.getComponentType());
35+
player.sendMessage(Message.raw("Player#getUuid() : " + player.getUuid())); // returns UUID from UUIDComponent
36+
player.sendMessage(Message.raw("UUIDComponent : " + component.getUuid()));
37+
player.sendMessage(Message.raw("equal : " + player.getUuid().equals(component.getUuid()))); // they're both the same
38+
player.sendMessage(Message.raw("Transform : " + transform.getPosition()));
39+
}
40+
2841
}
2942
```
3043

0 commit comments

Comments
 (0)