From 46e7d4786cc16ec37c141eba5f7753a4944c6e5f Mon Sep 17 00:00:00 2001 From: thematdev Date: Sun, 17 Mar 2019 21:31:42 +0300 Subject: [PATCH] Removed shit from code and added handle for incorrect usage of cmds. #5.0.1 --- config.yml | 8 +++--- src/ru/thematdev/cm/auto/AutoMessage.java | 25 ++++++++++++------- src/ru/thematdev/cm/command/ChatExecutor.java | 9 ++++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/config.yml b/config.yml index 3646db2..b9ea51b 100644 --- a/config.yml +++ b/config.yml @@ -13,10 +13,10 @@ auto: delay: 10 messages: - icon: 'minecraft:diamond' - header: '228' - footer: '228' + header: 'Привет!' + footer: 'Спасибо, что играешь на сервере Infinity!' - icon: 'minecraft:gold_ingot' - header: 'gay' - footer: 'gay' + header: 'Тех.поддержка' + footer: 'vk.com/thematdev' permission: true \ No newline at end of file diff --git a/src/ru/thematdev/cm/auto/AutoMessage.java b/src/ru/thematdev/cm/auto/AutoMessage.java index 3e0d5b7..e4aa332 100644 --- a/src/ru/thematdev/cm/auto/AutoMessage.java +++ b/src/ru/thematdev/cm/auto/AutoMessage.java @@ -24,16 +24,23 @@ public AutoMessage() { configuration = new Configuration(); configuration.getConfig().getConfigurationSection("auto.notifications.chat").getKeys(false).forEach(node -> chatNotifications.add(configuration.getChatNotificationByNode(node))); - for (String node : configuration.config.getConfigurationSection("auto.notifications.advancement").getKeys(false)) { - plugin.getLogger().info("123"); - AdvancementNotification notification = new AdvancementNotification(node, - configuration.config.getDouble(configuration.getAdvSection() + "." + node + ".delay"), - configuration.config.getMapList(configuration.getAdvSection() + "." + node + ".messages"), - configuration.config.getBoolean(configuration.getAdvSection() + "." + node + ".permission")); - advancementNotifications.add(notification); - - } + configuration.getConfig().getConfigurationSection("auto.notifications.advancement").getKeys(false).forEach(node -> advancementNotifications.add(configuration.getAdvancementNotificationByNode(node))); } + + public void cancelAll() { + chatNotifications.forEach(ChatNotification::cancel); + advancementNotifications.forEach(AdvancementNotification::cancel); + } + + public void startAll() { + chatNotifications.forEach(ChatNotification::start); + advancementNotifications.forEach(AdvancementNotification::start); + } + + public void restartAll() { + cancelAll(); + startAll(); + } } diff --git a/src/ru/thematdev/cm/command/ChatExecutor.java b/src/ru/thematdev/cm/command/ChatExecutor.java index 14f2edc..2f36e04 100644 --- a/src/ru/thematdev/cm/command/ChatExecutor.java +++ b/src/ru/thematdev/cm/command/ChatExecutor.java @@ -24,9 +24,12 @@ public ChatExecutor(Main plugin) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) return false; if (args.length < 1) return false; - CommandEnum command = CommandEnum.valueOf(args[0]); - command.call((Player) sender, plugin); - + try { + CommandEnum command = CommandEnum.valueOf(args[0]); + command.call((Player) sender, plugin); + } catch (Exception e) { + Utils.sendMessage((Player) sender, "&4Неккоректное использование команды!"); + } return true; }