From dda8c31780dae428569b5a23444abb79f2e7b13b Mon Sep 17 00:00:00 2001 From: cnaude Date: Thu, 15 Jun 2017 21:16:10 -0700 Subject: [PATCH] IRCMessageEvent now obeys cancel orders. --- .../cnaude/purpleirc/CommandQueueWatcher.java | 4 +- .../GameListeners/IRCMessageListener.java | 4 ++ .../cnaude/purpleirc/Hooks/VanishHook.java | 5 +- .../purpleirc/Hooks/VanishNoPacketHook.java | 56 +++++++++++++++++++ .../java/com/cnaude/purpleirc/PurpleIRC.java | 11 ++-- 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/cnaude/purpleirc/Hooks/VanishNoPacketHook.java diff --git a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java index d29eb3e..f2f037b 100644 --- a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java +++ b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java @@ -86,9 +86,7 @@ public class CommandQueueWatcher { plugin.logError("Error running command: " + ce.getMessage()); } IRCCommandEvent event = new IRCCommandEvent(ircCommand); - if (!event.isCancelled()) { - plugin.getServer().getPluginManager().callEvent(event); - } + plugin.getServer().getPluginManager().callEvent(event); } } diff --git a/src/main/java/com/cnaude/purpleirc/GameListeners/IRCMessageListener.java b/src/main/java/com/cnaude/purpleirc/GameListeners/IRCMessageListener.java index dc91512..2036382 100644 --- a/src/main/java/com/cnaude/purpleirc/GameListeners/IRCMessageListener.java +++ b/src/main/java/com/cnaude/purpleirc/GameListeners/IRCMessageListener.java @@ -45,6 +45,10 @@ public class IRCMessageListener implements Listener { */ @EventHandler public void onIRCMessageEvent(IRCMessageEvent event) { + if (event.isCancelled()) { + plugin.logDebug("onIRCMessageEvent cancelled"); + return; + } String permission = event.getPermission(); String message = event.getMessage(); Player player = event.getPlayer(); diff --git a/src/main/java/com/cnaude/purpleirc/Hooks/VanishHook.java b/src/main/java/com/cnaude/purpleirc/Hooks/VanishHook.java index 8623a7a..d320afb 100644 --- a/src/main/java/com/cnaude/purpleirc/Hooks/VanishHook.java +++ b/src/main/java/com/cnaude/purpleirc/Hooks/VanishHook.java @@ -19,6 +19,7 @@ package com.cnaude.purpleirc.Hooks; import com.cnaude.purpleirc.PurpleIRC; import org.bukkit.entity.Player; import org.bukkit.metadata.MetadataValue; +import org.kitteh.vanish.staticaccess.VanishNoPacket; /** * @@ -45,10 +46,12 @@ public class VanishHook { // Try SuperVanish first if (plugin.superVanishHook != null) { return plugin.superVanishHook.isVanished(player); + } else if (plugin.vanishNoPacketHook != null) { + return plugin.vanishNoPacketHook.isVanished(player); } else { // Fallback to other Vanish if (player.hasMetadata("vanished")) { - plugin.logDebug("Player " + player.getName() + " has vanished metadata."); + plugin.logDebug("Player " + player.getName() + " has vanished metadata" + player.getMetadata("vanished").get(0).asString()); MetadataValue md = player.getMetadata("vanished").get(0); if (md.asBoolean()) { plugin.logDebug("Player " + player.getName() + " is vanished."); diff --git a/src/main/java/com/cnaude/purpleirc/Hooks/VanishNoPacketHook.java b/src/main/java/com/cnaude/purpleirc/Hooks/VanishNoPacketHook.java new file mode 100644 index 0000000..1c4142b --- /dev/null +++ b/src/main/java/com/cnaude/purpleirc/Hooks/VanishNoPacketHook.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 cnaude + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.cnaude.purpleirc.Hooks; + +import com.cnaude.purpleirc.PurpleIRC; +import org.bukkit.entity.Player; +import org.kitteh.vanish.staticaccess.VanishNoPacket; +import org.kitteh.vanish.staticaccess.VanishNotLoadedException; + +/** + * + * @author cnaude + */ +public class VanishNoPacketHook { + + private final PurpleIRC plugin; + + /** + * + * @param plugin the PurpleIRC plugin + */ + public VanishNoPacketHook(PurpleIRC plugin) { + this.plugin = plugin; + } + + + public boolean isVanished(Player player) { + try { + if (VanishNoPacket.isVanished(player.getName())) { + plugin.logDebug("Player " + player.getName() + " is vanished."); + return true; + } else { + plugin.logDebug("Player " + player.getName() + " is NOT vanished."); + return false; + } + } catch (VanishNotLoadedException ex) { + plugin.logError("VanishNoPacketHook: " + ex.getMessage()); + return false; + } + } + +} diff --git a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java index d94e911..da51709 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java @@ -63,6 +63,7 @@ import com.cnaude.purpleirc.Hooks.ShortifyHook; import com.cnaude.purpleirc.Hooks.SuperVanishHook; import com.cnaude.purpleirc.Hooks.TownyChatHook; import com.cnaude.purpleirc.Hooks.VanishHook; +import com.cnaude.purpleirc.Hooks.VanishNoPacketHook; import com.cnaude.purpleirc.Hooks.VaultHook; import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap; import com.cnaude.purpleirc.Utilities.ChatTokenizer; @@ -224,6 +225,7 @@ public class PurpleIRC extends JavaPlugin { public VaultHook vaultHelpers; public VanishHook vanishHook; public SuperVanishHook superVanishHook; + public VanishNoPacketHook vanishNoPacketHook; private YamlConfiguration heroConfig; private final File cacheFile; private final File uuidCacheFile; @@ -1726,6 +1728,7 @@ public class PurpleIRC extends JavaPlugin { if (isPluginEnabled(PL_VANISHNOPACKET)) { hookList.add(hookFormat(PL_VANISHNOPACKET, true)); getServer().getPluginManager().registerEvents(new VanishNoPacketListener(this), this); + vanishNoPacketHook = new VanishNoPacketHook(this); } else { hookList.add(hookFormat(PL_VANISHNOPACKET, false)); } @@ -1815,16 +1818,12 @@ public class PurpleIRC extends JavaPlugin { public void broadcastToGame(final String message, final String channel, final String permission) { IRCMessageEvent event = new IRCMessageEvent(message, channel, permission); - if (!event.isCancelled()) { - getServer().getPluginManager().callEvent(event); - } + getServer().getPluginManager().callEvent(event); } public void broadcastToPlayer(final String message, final String channel, final String permission, final Player player) { IRCMessageEvent event = new IRCMessageEvent(message, channel, permission, player); - if (!event.isCancelled()) { - getServer().getPluginManager().callEvent(event); - } + getServer().getPluginManager().callEvent(event); } /**