-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSetWarpCommand.java
More file actions
57 lines (52 loc) · 2.77 KB
/
Copy pathSetWarpCommand.java
File metadata and controls
57 lines (52 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dev.hytalemodding.hyssentials.commands.warp;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.math.vector.Rotation3f;
import org.joml.Vector3d;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import dev.hytalemodding.hyssentials.lang.Messages;
import dev.hytalemodding.hyssentials.manager.WarpManager;
import dev.hytalemodding.hyssentials.util.ChatUtil;
import dev.hytalemodding.hyssentials.util.Permissions;
import javax.annotation.Nonnull;
public class SetWarpCommand extends AbstractPlayerCommand {
private final WarpManager warpManager;
private final RequiredArg<String> nameArg = this.withRequiredArg("name", "Warp name", ArgTypes.STRING);
public SetWarpCommand(@Nonnull WarpManager warpManager) {
super("setwarp", "Set a server warp at your current location");
this.warpManager = warpManager;
this.requirePermission(Permissions.SETWARP);
}
@Override
protected boolean canGeneratePermission() {
return false;
}
@Override
protected void execute(@Nonnull CommandContext context, @Nonnull Store<EntityStore> store,
@Nonnull Ref<EntityStore> ref, @Nonnull PlayerRef playerRef, @Nonnull World world) {
if (world.getName().startsWith("instance-")) {
context.sendMessage(ChatUtil.parse(Messages.ERROR_INSTANCE_WORLD_WARP));
return;
}
String name = nameArg.get(context);
TransformComponent transform = store.getComponent(ref, TransformComponent.getComponentType());
if (transform == null) {
context.sendMessage(ChatUtil.parse(Messages.ERROR_CANNOT_GET_POSITION));
return;
}
HeadRotation headRotation = store.getComponent(ref, HeadRotation.getComponentType());
Rotation3f rotation = headRotation != null ? headRotation.getRotation() : new Rotation3f(0, 0, 0);
Vector3d position = transform.getPosition();
warpManager.setWarp(name, world, position, rotation);
context.sendMessage(ChatUtil.parse(Messages.SUCCESS_WARP_SET,
name, position.x(), position.y(), position.z(), world.getName()));
}
}