-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamCommand.java
More file actions
101 lines (89 loc) · 4.16 KB
/
TeamCommand.java
File metadata and controls
101 lines (89 loc) · 4.16 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package fr.dofsekai.sekonomy.commands;
import fr.dofsekai.sekonomy.Sekonomy;
import fr.dofsekai.sekonomy.managers.TeamManager;
import fr.dofsekai.sekonomy.models.Team;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
public class TeamCommand implements CommandExecutor {
private final Sekonomy plugin;
private final TeamManager teamManager;
public TeamCommand() {
plugin = Sekonomy.get();
teamManager = TeamManager.get();
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player player) {
Team team = teamManager.getTeam(player);
if (team.getLeader().equals(player)) {
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /teams <sethome | delhome | home>");
} else if (args[0].equalsIgnoreCase("sethome")) {
if (!teamManager.isSetHomeEnabled()) {
player.sendMessage(ChatColor.RED + "This command is disabled.");
return true;
}
if (team.getHome() == null) {
teamManager.setHome(player.getLocation(), team);
player.sendMessage(ChatColor.GREEN + "Your home has been defined.");
} else {
player.sendMessage(ChatColor.RED + "Your home is already defined.");
}
} else if (args[0].equalsIgnoreCase("delhome")) {
if (!teamManager.isDelHomeEnabled()) {
player.sendMessage(ChatColor.RED + "This command is disabled.");
return true;
}
if (team.getHome() != null) {
teamManager.deleteHome(team);
player.sendMessage(ChatColor.GREEN + "Your home has been deleted.");
} else {
player.sendMessage(ChatColor.RED + "No home has been defined.");
}
} else home(args, player, team);
} else if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /teams home");
} else home(args, player, team);
}
return true;
}
private void home(@NotNull String[] args, Player player, Team team) {
if (args[0].equalsIgnoreCase("home")) {
if (!teamManager.isHomeEnabled()) {
player.sendMessage(ChatColor.RED + "This command is disabled.");
return;
}
if (team.getHome() != null) {
Location initialLocation = player.getLocation().clone();
final int[] countdown = {5};
player.sendMessage(ChatColor.GOLD + "Teleportation in " + countdown[0] + ", don't move!");
new BukkitRunnable() {
@Override
public void run() {
if (player.getLocation().distance(initialLocation) > 0.1) {
player.sendMessage(ChatColor.RED + "Teleportation canceled, you moved.");
this.cancel();
return;
}
if (countdown[0] <= 1) {
player.teleport(team.getHome());
player.sendMessage(ChatColor.GREEN + "You've been teleported.");
this.cancel();
return;
}
countdown[0]--;
player.sendMessage(ChatColor.GOLD + "Teleportation in " + countdown[0]);
}
}.runTaskTimer(plugin, 20L, 20L);
} else {
player.sendMessage(ChatColor.RED + "No home has been defined.");
}
}
}
}