-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetRadiusCommand.java
More file actions
50 lines (37 loc) · 2.06 KB
/
SetRadiusCommand.java
File metadata and controls
50 lines (37 loc) · 2.06 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
package net.onelitefeather.labyrinth.commands;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.onelitefeather.labyrinth.Labyrinth;
import net.onelitefeather.labyrinth.service.api.ValidationService;
import net.onelitefeather.labyrinth.utils.Constants;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.incendo.cloud.annotations.Argument;
import org.incendo.cloud.annotations.Command;
import org.incendo.cloud.annotations.Permission;
import org.jetbrains.annotations.NotNull;
@Command("labyrinth")
public record SetRadiusCommand(Labyrinth labyrinth, ValidationService validationService) {
@Command("setradius <zone>")
@Permission("labyrinth.setup.setradius")
public void setRadius(@NotNull Player player, @Argument(value = "zone", suggestions = "zones") String zone) {
if (validationService.validateZoneInput(player, zone)) {
Location playerLabyrinthCenterLocation = player.getLocation();
// This playerLabyrinthCenterLocation needs to have the Y axis to be 0, in order to do a cylindric region.
// We only care about the x and z axis.
playerLabyrinthCenterLocation.setY(0);
Location location = labyrinth.getConfig().getLocation(Constants.CONFIG_ZONE_CENTER_PATH.formatted(zone));
if (location == null) return;
labyrinth.getConfig().set(Constants.CONFIG_ZONE_RADIUS_PATH.formatted(zone), playerLabyrinthCenterLocation.distance(location));
labyrinth.saveConfig();
var message = MiniMessage.miniMessage().deserialize(Constants.SET_RADIUS_MESSAGE,
Placeholder.unparsed("zone", zone),
Placeholder.component("prefix", Constants.PREFIX));
player.sendMessage(message);
} else {
var message = MiniMessage.miniMessage().deserialize(Constants.ZONE_INVALID_MESSAGE,
Placeholder.component("prefix", Constants.PREFIX));
player.sendMessage(message);
}
}
}