-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteTeamCommand.java
49 lines (43 loc) · 1.99 KB
/
DeleteTeamCommand.java
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
package me.bretmounet.scavengerhunt;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteTeamCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Connection connection = Scavengerhunt.connection;
if (sender instanceof Player) {
Player player = (Player) sender;
if (player.hasPermission("delete")){
if (args.length != 0) {
String teamName = args[0];
try {
Statement statement = connection.createStatement();
TeamManager.getTeamNames();
if (TeamManager.teamNames.contains(teamName)) {
String sql = "DROP TABLE " + teamName + "";
statement.executeUpdate(sql);
TeamManager.removePlayerFromTeam(teamName, player);
TeamManager.deleteTeam(teamName);
player.sendMessage(ChatColor.GREEN + "Team Deleted.");
} else if (!TeamManager.teamNames.contains(teamName)) {
player.sendMessage(ChatColor.RED + "Error: Team Not Found.");
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}else {
player.sendMessage(ChatColor.RED + "Error: Missing Argument /delete <Team Name>");
}
}else {
player.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
}
}
return true;
}
}