working version
This commit is contained in:
@@ -31,7 +31,7 @@ public class Main extends JavaPlugin
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
|
this.tfaHandler.abortAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommands()
|
private void registerCommands()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class TFACommand implements CommandExecutor, TabCompleter
|
|||||||
private TFAHandler th;
|
private TFAHandler th;
|
||||||
private final Map<String, String[]> TAB_COMPLETE_MAP = new HashMap<>();
|
private final Map<String, String[]> TAB_COMPLETE_MAP = new HashMap<>();
|
||||||
{
|
{
|
||||||
TAB_COMPLETE_MAP.put("", new String[]{"add", "remove", "<code>"});
|
TAB_COMPLETE_MAP.put("", new String[]{"activate", "remove", "<code>"});
|
||||||
TAB_COMPLETE_MAP.put(":remove", new String[]{"[player]"});
|
TAB_COMPLETE_MAP.put(":remove", new String[]{"[player]"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class TFACommand implements CommandExecutor, TabCompleter
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (args.length >= 1 && args[0].equalsIgnoreCase("add"))
|
else if (args.length >= 1 && args[0].equalsIgnoreCase("activate"))
|
||||||
{
|
{
|
||||||
if (!player.hasPermission("2fa.activate"))
|
if (!player.hasPermission("2fa.activate"))
|
||||||
{
|
{
|
||||||
@@ -100,20 +100,25 @@ public class TFACommand implements CommandExecutor, TabCompleter
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String secret = th.getKey(player.getUniqueId());
|
player.sendMessage("Confirm the activation by typing /2fa <code>.");
|
||||||
String pCode = StringUtils.join(args);
|
return true;
|
||||||
if (th.matchCode(secret, pCode))
|
}
|
||||||
{
|
}
|
||||||
th.creatingSuccess(player);
|
else if (args.length >= 1)
|
||||||
player.sendMessage("Successfully activated two-factor authentication.");
|
{
|
||||||
return true;
|
String secret = th.getKey(player.getUniqueId());
|
||||||
}
|
String pCode = StringUtils.join(args);
|
||||||
else
|
if (th.matchCode(secret, pCode))
|
||||||
{
|
{
|
||||||
th.creatingFailed(player);
|
th.creatingSuccess(player);
|
||||||
player.sendMessage("That code is incorrect, aborting.");
|
player.sendMessage("Successfully activated two-factor authentication.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
th.creatingFailed(player);
|
||||||
|
player.sendMessage("That code is incorrect, aborting.");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import eu.oskar3123.spigot2fa.Main;
|
|||||||
import eu.oskar3123.spigot2fa.map.QRMapRenderer;
|
import eu.oskar3123.spigot2fa.map.QRMapRenderer;
|
||||||
import eu.oskar3123.spigot2fa.tfa.TFA;
|
import eu.oskar3123.spigot2fa.tfa.TFA;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -28,6 +29,19 @@ public class TFAHandler
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void abortAll()
|
||||||
|
{
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (!isInProcess.containsKey(player.getUniqueId()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
isInProcess.remove(player.getUniqueId());
|
||||||
|
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean shouldBypassCode(Player player)
|
public boolean shouldBypassCode(Player player)
|
||||||
{
|
{
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
@@ -94,6 +108,7 @@ public class TFAHandler
|
|||||||
public void creatingFailed(Player player)
|
public void creatingFailed(Player player)
|
||||||
{
|
{
|
||||||
remove(player.getUniqueId());
|
remove(player.getUniqueId());
|
||||||
|
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchCode(String secret, String code)
|
public boolean matchCode(String secret, String code)
|
||||||
@@ -147,6 +162,9 @@ public class TFAHandler
|
|||||||
mapMeta.setMapId(view.getId());
|
mapMeta.setMapId(view.getId());
|
||||||
map.setItemMeta(mapMeta);
|
map.setItemMeta(mapMeta);
|
||||||
player.getInventory().setItemInMainHand(map);
|
player.getInventory().setItemInMainHand(map);
|
||||||
|
Location loc = player.getLocation();
|
||||||
|
loc.setPitch(90f);
|
||||||
|
player.teleport(loc);
|
||||||
player.sendMap(view);
|
player.sendMap(view);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public class AuthListener implements Listener
|
|||||||
{
|
{
|
||||||
if (plugin.tfaHandler.shouldBypassCode(event.getPlayer()))
|
if (plugin.tfaHandler.shouldBypassCode(event.getPlayer()))
|
||||||
{
|
{
|
||||||
event.getPlayer().sendMessage("bypassed 2fa check");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
@@ -77,7 +76,7 @@ public class AuthListener implements Listener
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean correct = plugin.tfaHandler.matchCode(event.getPlayer(), event.getMessage());
|
boolean correct = plugin.tfaHandler.matchCode(event.getPlayer(), event.getMessage().replace(" ", ""));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (!correct)
|
if (!correct)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ authors: [oskar3123]
|
|||||||
main: eu.oskar3123.spigot2fa.Main
|
main: eu.oskar3123.spigot2fa.Main
|
||||||
commands:
|
commands:
|
||||||
2fa:
|
2fa:
|
||||||
usage: '/<command> add/remove/<code>'
|
usage: '/<command> activate/remove/<code>'
|
||||||
description: 'Two-factor authorization command'
|
description: 'Two-factor authorization command'
|
||||||
|
|||||||
Reference in New Issue
Block a user