-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSetHomeCommand.java
More file actions
65 lines (60 loc) · 3.15 KB
/
Copy pathSetHomeCommand.java
File metadata and controls
65 lines (60 loc) · 3.15 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
58
59
60
61
62
63
64
65
package dev.hytalemodding.hyssentials.commands.home;
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.HomeManager;
import dev.hytalemodding.hyssentials.manager.RankManager;
import dev.hytalemodding.hyssentials.util.ChatUtil;
import java.util.UUID;
import javax.annotation.Nonnull;
public class SetHomeCommand extends AbstractPlayerCommand {
private final HomeManager homeManager;
private final RankManager rankManager;
private final RequiredArg<String> nameArg = this.withRequiredArg("name", "Home name", ArgTypes.STRING);
public SetHomeCommand(@Nonnull HomeManager homeManager, @Nonnull RankManager rankManager) {
super("sethome", "Set a home at your current location");
this.homeManager = homeManager;
this.rankManager = rankManager;
}
@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_HOME));
return;
}
String name = nameArg.get(context);
UUID playerUuid = playerRef.getUuid();
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();
int maxHomes = rankManager.getEffectiveMaxHomes(playerRef);
boolean success = homeManager.setHome(playerUuid, name, world, position, rotation, maxHomes);
if (success) {
context.sendMessage(ChatUtil.parse(Messages.SUCCESS_HOME_SET,
name, position.x(), position.y(), position.z(), world.getName()));
} else {
context.sendMessage(ChatUtil.parse(Messages.ERROR_MAX_HOMES_REACHED, maxHomes));
}
}
}