|
1 | 1 | package com.krayir5.stands.commands;
|
2 | 2 |
|
| 3 | +import java.io.File; |
| 4 | + |
3 | 5 | import org.bukkit.ChatColor;
|
4 | 6 | import org.bukkit.command.Command;
|
5 | 7 | import org.bukkit.command.CommandExecutor;
|
6 | 8 | import org.bukkit.command.CommandSender;
|
| 9 | +import org.bukkit.configuration.file.FileConfiguration; |
| 10 | +import org.bukkit.configuration.file.YamlConfiguration; |
7 | 11 | import org.bukkit.entity.Player;
|
8 | 12 | import org.bukkit.plugin.java.JavaPlugin;
|
9 | 13 |
|
10 | 14 | public class StandPCommand implements CommandExecutor {
|
11 | 15 |
|
12 | 16 | private final JavaPlugin plugin;
|
| 17 | + private final File standFile; |
13 | 18 |
|
14 |
| - public StandPCommand(JavaPlugin plugin) { |
| 19 | + public StandPCommand(JavaPlugin plugin, File standFile) { |
15 | 20 | this.plugin = plugin;
|
| 21 | + this.standFile = standFile; |
16 | 22 | }
|
17 | 23 |
|
18 | 24 | @Override
|
19 | 25 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
| 26 | + @SuppressWarnings("unused") |
| 27 | + FileConfiguration stConfig = YamlConfiguration.loadConfiguration(standFile); |
20 | 28 | Player player = (Player) sender;
|
21 |
| - if (!player.isOp() && !player.hasPermission("standp.admin")) { |
22 |
| - player.sendMessage(ChatColor.RED + "You cant use this command!"); |
| 29 | + if (!player.isOp() || !player.hasPermission("standp.admin")) { |
| 30 | + player.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); |
23 | 31 | return true;
|
24 | 32 | }
|
25 | 33 | if (args.length == 0) {
|
26 | 34 | sender.sendMessage(ChatColor.RED + "Usage: /standp <reload>");
|
27 | 35 | return true;
|
28 | 36 | }
|
| 37 | + |
29 | 38 | String subCommand = args[0].toLowerCase();
|
30 | 39 | switch (subCommand) {
|
31 | 40 | case "reload":
|
32 | 41 | plugin.reloadConfig();
|
33 |
| - sender.sendMessage(ChatColor.GREEN + "Plugin succesfully reloaded!"); |
| 42 | + if (standFile.exists()) { |
| 43 | + stConfig = YamlConfiguration.loadConfiguration(standFile); |
| 44 | + player.sendMessage(ChatColor.GREEN + "Plugin reloaded succesfully!"); |
| 45 | + }else{ |
| 46 | + player.sendMessage(ChatColor.RED + "Something went wrong! stand.yml file not found!"); |
| 47 | + } |
34 | 48 | break;
|
35 | 49 | default:
|
36 |
| - sender.sendMessage(ChatColor.RED + "Unknown subcommand: " + subCommand); |
| 50 | + player.sendMessage(ChatColor.RED + "Unknown subcommand: " + subCommand); |
37 | 51 | break;
|
38 | 52 | }
|
39 | 53 | return true;
|
40 | 54 | }
|
41 | 55 | }
|
| 56 | + |
0 commit comments