-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidationServiceImpl.java
More file actions
37 lines (31 loc) · 1.36 KB
/
ValidationServiceImpl.java
File metadata and controls
37 lines (31 loc) · 1.36 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
package net.onelitefeather.labyrinth.service.impl;
import net.kyori.adventure.text.Component;
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.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.regex.Matcher;
public final class ValidationServiceImpl implements ValidationService {
private final Labyrinth labyrinth;
public ValidationServiceImpl(Labyrinth labyrinth) {
this.labyrinth = labyrinth;
}
@Override
public boolean validateZoneInput(@NotNull Player player, @NotNull String zone) {
if (!labyrinth.getConfig().isSet(Constants.CONFIG_ZONE_PATH.formatted(zone))) {
player.sendMessage(MiniMessage.miniMessage().deserialize(
"Zone <zone> could not be found!", Placeholder.unparsed("zone", zone)));
return false;
}
Matcher matcher = Constants.PATTERN.matcher(zone);
boolean notMatches = !(matcher.matches());
if (notMatches) {
player.sendMessage(Component.text("Only characters without symbols are allowed"));
return false;
}
return true;
}
}