Check twofactor status instead of interact events

This commit is contained in:
cnr 2017-01-14 01:29:37 -06:00
parent babc72a87c
commit 5ba3fac58c
8 changed files with 34 additions and 25 deletions

View File

@ -7,7 +7,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
@ -17,6 +16,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
@ -36,9 +36,11 @@ import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.mount.MountManager; import mineplex.core.mount.MountManager;
import mineplex.core.pet.PetManager; import mineplex.core.pet.PetManager;
import mineplex.core.treasure.TreasureManager; import mineplex.core.treasure.TreasureManager;
import mineplex.core.twofactor.TwoFactorAuth;
public class CosmeticManager extends MiniPlugin public class CosmeticManager extends MiniPlugin
{ {
private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class);
private InventoryManager _inventoryManager; private InventoryManager _inventoryManager;
private GadgetManager _gadgetManager; private GadgetManager _gadgetManager;
private MountManager _mountManager; private MountManager _mountManager;
@ -136,7 +138,7 @@ public class CosmeticManager extends MiniPlugin
@EventHandler @EventHandler
public void openShop(PlayerInteractEvent event) public void openShop(PlayerInteractEvent event)
{ {
if (event.useItemInHand() == Event.Result.DENY || !_showInterface) if (_twofactor.isAuthenticating(event.getPlayer()))
return; return;
if (event.hasItem() && event.getItem().getType() == Material.CHEST) if (event.hasItem() && event.getItem().getType() == Material.CHEST)

View File

@ -8,7 +8,6 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
@ -19,6 +18,7 @@ import org.bukkit.scheduler.BukkitTask;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import mineplex.core.Managers;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -34,6 +34,7 @@ import mineplex.core.party.rediscommands.PartyTransferResponse;
import mineplex.core.portal.Intent; import mineplex.core.portal.Intent;
import mineplex.core.portal.events.GenericServerTransferEvent; import mineplex.core.portal.events.GenericServerTransferEvent;
import mineplex.core.portal.events.ServerTransferEvent; import mineplex.core.portal.events.ServerTransferEvent;
import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.utils.UtilGameProfile; import mineplex.core.utils.UtilGameProfile;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.MinecraftServer;
@ -43,6 +44,7 @@ import mineplex.serverdata.data.MinecraftServer;
*/ */
public class PartyJoinManager implements Listener public class PartyJoinManager implements Listener
{ {
private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class);
private final PartyManager _plugin; private final PartyManager _plugin;
private final int _maxPlayers; private final int _maxPlayers;
@ -344,7 +346,7 @@ public class PartyJoinManager implements Listener
@EventHandler @EventHandler
public void onClick(PlayerInteractEvent event) public void onClick(PlayerInteractEvent event)
{ {
if (event.useItemInHand() == Event.Result.DENY) if (_twofactor.isAuthenticating(event.getPlayer()))
{ {
return; return;
} }

View File

@ -75,6 +75,7 @@ import mineplex.core.titles.tracks.Track;
import mineplex.core.titles.tracks.TrackFormat; import mineplex.core.titles.tracks.TrackFormat;
import mineplex.core.titles.tracks.TrackManager; import mineplex.core.titles.tracks.TrackManager;
import mineplex.core.titles.tracks.TrackTier; import mineplex.core.titles.tracks.TrackTier;
import mineplex.core.twofactor.TwoFactorAuth;
/** /**
* This manager handles displaying titles above a player's head, as well as their tracks * This manager handles displaying titles above a player's head, as well as their tracks
@ -97,6 +98,7 @@ public class Titles extends MiniDbClientPlugin<TitleData> implements IPacketHand
private final TitlesRepository _titlesRepository = new TitlesRepository(); private final TitlesRepository _titlesRepository = new TitlesRepository();
private final GadgetManager _gadgetManager = require(GadgetManager.class); private final GadgetManager _gadgetManager = require(GadgetManager.class);
private final TwoFactorAuth _twofactor = require(TwoFactorAuth.class);
private final BaseComponent[] CLICK_ENABLE_TRACK = new ComponentBuilder("") private final BaseComponent[] CLICK_ENABLE_TRACK = new ComponentBuilder("")
.append("Click to enable this track") .append("Click to enable this track")
@ -175,10 +177,10 @@ public class Titles extends MiniDbClientPlugin<TitleData> implements IPacketHand
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler
public void onInteract(PlayerInteractEvent event) public void onInteract(PlayerInteractEvent event)
{ {
if (event.getItem() != null && UtilEvent.isAction(event, UtilEvent.ActionType.R)) if (!_twofactor.isAuthenticating(event.getPlayer()) && event.getItem() != null && UtilEvent.isAction(event, UtilEvent.ActionType.R))
{ {
boolean cancel = false; boolean cancel = false;

View File

@ -81,6 +81,11 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
}); });
} }
public boolean isAuthenticating(Player player)
{
return authenticating.contains(player.getUniqueId()) || setupData.containsKey(player.getUniqueId());
}
private void setup2FA(Player player) private void setup2FA(Player player)
{ {
String secret = authenticator.createCredentials().getKey(); String secret = authenticator.createCredentials().getKey();
@ -243,7 +248,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onClick(InventoryClickEvent event) public void onClick(InventoryClickEvent event)
{ {
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -253,7 +258,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onDrag(InventoryDragEvent event) public void onDrag(InventoryDragEvent event)
{ {
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -263,7 +268,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onDrop(PlayerDropItemEvent event) public void onDrop(PlayerDropItemEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -273,7 +278,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onInteract(PlayerInteractEvent event) public void onInteract(PlayerInteractEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -283,7 +288,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onInteractWithEntity(PlayerInteractEntityEvent event) public void onInteractWithEntity(PlayerInteractEntityEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -293,7 +298,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onCommand(PlayerCommandPreprocessEvent event) public void onCommand(PlayerCommandPreprocessEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
event.setMessage("/"); event.setMessage("/");
event.setCancelled(true); event.setCancelled(true);
@ -304,7 +309,7 @@ public class TwoFactorAuth extends MiniClientPlugin<TwoFactorData>
public void onMove(PlayerMoveEvent event) public void onMove(PlayerMoveEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (setupData.containsKey(player.getUniqueId()) || authenticating.contains(player.getUniqueId())) if (isAuthenticating(player))
{ {
if (Recharge.Instance.use(player, "two-factor message cooldown", 3000L, false, false)) if (Recharge.Instance.use(player, "two-factor message cooldown", 3000L, false, false))
{ {

View File

@ -23,7 +23,6 @@ import org.bukkit.entity.Creature;
import org.bukkit.entity.Egg; import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -119,6 +118,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.thank.ThankManager; import mineplex.core.thank.ThankManager;
import mineplex.core.treasure.TreasureLocation; import mineplex.core.treasure.TreasureLocation;
import mineplex.core.treasure.TreasureManager; import mineplex.core.treasure.TreasureManager;
import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.valentines.ValentinesGiftManager;
@ -156,6 +156,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
private Punish _punishManager; private Punish _punishManager;
private IncognitoManager _incognito; private IncognitoManager _incognito;
private BonusManager _bonusManager; private BonusManager _bonusManager;
private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class);
private Location _spawn; private Location _spawn;
private int _scoreboardTick = 0; private int _scoreboardTick = 0;
@ -969,7 +970,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
@EventHandler @EventHandler
public void openProfile(PlayerInteractEvent event) public void openProfile(PlayerInteractEvent event)
{ {
if(event.useItemInHand() == Event.Result.DENY || event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM) if(_twofactor.isAuthenticating(event.getPlayer()) || event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM)
return; return;
new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager).openInventory();; new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager).openInventory();;

View File

@ -21,7 +21,6 @@ import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -112,6 +111,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.thank.ThankManager; import mineplex.core.thank.ThankManager;
import mineplex.core.titles.Titles; import mineplex.core.titles.Titles;
import mineplex.core.treasure.TreasureManager; import mineplex.core.treasure.TreasureManager;
import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.valentines.ValentinesGiftManager;
@ -175,6 +175,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
// private HalloweenSpookinessManager _halloweenManager; // private HalloweenSpookinessManager _halloweenManager;
// private TrickOrTreatManager _trickOrTreatManager; // private TrickOrTreatManager _trickOrTreatManager;
private MavericksManager _mavericksManager; private MavericksManager _mavericksManager;
private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class);
private Location _spawn; private Location _spawn;
@ -976,7 +977,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
@EventHandler @EventHandler
public void openProfile(PlayerInteractEvent event) public void openProfile(PlayerInteractEvent event)
{ {
if (event.useItemInHand() == Event.Result.DENY || event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM) if (_twofactor.isAuthenticating(event.getPlayer()) || event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM)
return; return;
new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager, _personalServerManager).openInventory(); new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager, _personalServerManager).openInventory();

View File

@ -14,7 +14,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.EntityPortalEnterEvent;
@ -26,6 +25,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
@ -48,6 +48,7 @@ import mineplex.core.portal.Intent;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.shop.ShopBase; import mineplex.core.shop.ShopBase;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.HubManager; import mineplex.hub.HubManager;
@ -78,6 +79,7 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
private ServerStatusManager _statusManager; private ServerStatusManager _statusManager;
private HubManager _hubManager; private HubManager _hubManager;
private BoosterManager _boosterManager; private BoosterManager _boosterManager;
private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class);
private NautHashMap<String, Long> _queueCooldowns = new NautHashMap<String, Long>(); private NautHashMap<String, Long> _queueCooldowns = new NautHashMap<String, Long>();
private NautHashMap<String, HashSet<ServerInfo>> _serverKeyInfoMap = new NautHashMap<String, HashSet<ServerInfo>>(); private NautHashMap<String, HashSet<ServerInfo>> _serverKeyInfoMap = new NautHashMap<String, HashSet<ServerInfo>>();
@ -203,7 +205,7 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
@EventHandler @EventHandler
public void playerInteract(PlayerInteractEvent event) public void playerInteract(PlayerInteractEvent event)
{ {
if (event.useItemInHand() == Event.Result.DENY) if (_twofactor.isAuthenticating(event.getPlayer()))
{ {
return; return;
} }

View File

@ -6,7 +6,6 @@ import java.util.Iterator;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -86,11 +85,6 @@ public class TutorialManager extends MiniPlugin
@EventHandler @EventHandler
public void InteractCancel(PlayerInteractEvent event) public void InteractCancel(PlayerInteractEvent event)
{ {
if (event.useItemInHand() == Event.Result.DENY)
{
return;
}
if (InTutorial(event.getPlayer())) if (InTutorial(event.getPlayer()))
event.setCancelled(true); event.setCancelled(true);
} }