From 44556d788e0eee0093aa21daa1ba6df92aca4916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bro=C4=8Dko?= Date: Thu, 6 Sep 2018 10:35:17 +0200 Subject: [PATCH] ChatNotifier: finished --- src/cz/marwland/mc/core/MarwCore.java | 2 ++ .../mc/essentials/features/ChatNotifier.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/cz/marwland/mc/core/MarwCore.java b/src/cz/marwland/mc/core/MarwCore.java index 443e806..8c97fe8 100644 --- a/src/cz/marwland/mc/core/MarwCore.java +++ b/src/cz/marwland/mc/core/MarwCore.java @@ -8,6 +8,7 @@ import cz.marwland.mc.core.config.ConfigManager; import cz.marwland.mc.core.features.Base; import cz.marwland.mc.core.features.Feature; import cz.marwland.mc.essentials.features.Borders; +import cz.marwland.mc.essentials.features.ChatNotifier; public class MarwCore extends JavaPlugin { @@ -22,6 +23,7 @@ public class MarwCore extends JavaPlugin { this.addFeature(new Base(this)); this.addFeature(new Borders(this)); + this.addFeature(new ChatNotifier(this)); configManager.load(); this.features.forEach((k, v) -> v.onEnable()); diff --git a/src/cz/marwland/mc/essentials/features/ChatNotifier.java b/src/cz/marwland/mc/essentials/features/ChatNotifier.java index 23e3b76..37836d1 100644 --- a/src/cz/marwland/mc/essentials/features/ChatNotifier.java +++ b/src/cz/marwland/mc/essentials/features/ChatNotifier.java @@ -1,7 +1,13 @@ package cz.marwland.mc.essentials.features; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; + import cz.marwland.mc.core.MarwCore; import cz.marwland.mc.core.features.Feature; +import net.md_5.bungee.api.ChatColor; public class ChatNotifier extends Feature { @@ -9,4 +15,17 @@ public class ChatNotifier extends Feature { super(plugin, null); } + @EventHandler + public void onPlayerChat(AsyncPlayerChatEvent e) { + e.setCancelled(true); + for (Player p : plugin.getServer().getOnlinePlayers()) { + String msg = e.getMessage(); + if (e.getMessage().toLowerCase().contains(p.getName().toLowerCase())) { + msg = ChatColor.RED + msg; + // ActionBarAPI.sendActionBar(p, ChatColor.RED + "Byl jsi zminen v chatu", 80); + p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 3.0F); + } + p.sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), msg)); + } + } }