forked from Maxlego08/zEssentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandDelHome.java
More file actions
56 lines (46 loc) · 2.08 KB
/
Copy pathCommandDelHome.java
File metadata and controls
56 lines (46 loc) · 2.08 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
package fr.maxlego08.essentials.commands.commands.home;
import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.home.Home;
import fr.maxlego08.essentials.api.home.HomeManager;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.module.modules.HomeModule;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
import org.bukkit.entity.Player;
import java.util.ArrayList;
public class CommandDelHome extends VCommand {
public CommandDelHome(EssentialsPlugin plugin) {
super(plugin);
this.setModule(HomeModule.class);
this.setPermission(Permission.ESSENTIALS_DEL_HOME);
this.setDescription(Message.DESCRIPTION_DEL_HOME);
this.addRequireArg("name", (sender, args) -> {
if (sender instanceof Player player) {
User user = plugin.getUser(player.getUniqueId());
if (user != null) return user.getHomes().stream().map(Home::getName).toList();
}
return new ArrayList<>();
});
}
@Override
protected CommandResultType perform(EssentialsPlugin plugin) {
String homeName = this.argAsString(0);
HomeManager homeManager = plugin.getHomeManager();
// For /delhome Maxlego08:<home name>
if (homeName.contains(":") && hasPermission(sender, Permission.ESSENTIALS_SET_HOME_OTHER)) {
String[] values = homeName.split(":", 2);
String username = values[0];
String home = values[1];
homeManager.deleteHome(this.sender, username, home);
return CommandResultType.DEFAULT;
}
if (homeManager.isHomeDeleteConfirm()) {
message(user, Message.COMMAND_HOME_DELETE_CONFIRM, "%name%", homeName);
return CommandResultType.SUCCESS;
}
homeManager.deleteHome(this.player, this.user, homeName);
return CommandResultType.SUCCESS;
}
}