This commit is contained in:
mathiascode 2019-09-28 03:37:11 +03:00
parent fd068e2682
commit 72a164ac3e

View file

@ -19,7 +19,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener { public class Main extends JavaPlugin implements Listener {
public void onEnable() { public void onEnable() {
this.getCommand("commandspy").setExecutor(new CommandCommandSpy(this)); this.getCommand("commandspy").setExecutor(new CommandCommandSpy());
this.getServer().getPluginManager().registerEvents(this, this); this.getServer().getPluginManager().registerEvents(this, this);
} }
@ -66,24 +66,20 @@ public class Main extends JavaPlugin implements Listener {
} }
class CommandCommandSpy implements CommandExecutor { class CommandCommandSpy implements CommandExecutor {
Main main;
CommandCommandSpy(Main main) {
this.main = main;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) { if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player"); sender.sendMessage("Command has to be run by a player");
} else { } else {
final Player player = (Player) sender; final Player player = (Player) sender;
final JavaPlugin plugin = JavaPlugin.getPlugin(Main.class);
if (main.getConfig().contains(player.getUniqueId().toString())) { if (plugin.getConfig().contains(player.getUniqueId().toString())) {
main.getConfig().set(player.getUniqueId().toString(), null); plugin.getConfig().set(player.getUniqueId().toString(), null);
main.saveConfig(); plugin.saveConfig();
player.sendMessage("Successfully disabled CommandSpy"); player.sendMessage("Successfully disabled CommandSpy");
} else { } else {
main.getConfig().set(player.getUniqueId().toString(), true); plugin.getConfig().set(player.getUniqueId().toString(), true);
main.saveConfig(); plugin.saveConfig();
player.sendMessage("Successfully enabled CommandSpy"); player.sendMessage("Successfully enabled CommandSpy");
} }
} }