2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command ;
2018-03-24 15:41:45 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData ;
2018-03-24 15:41:45 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
import net.pravian.aero.util.Ips ;
import org.bukkit.ChatColor ;
2017-12-29 18:12:47 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2018-06-01 14:13:40 +00:00
2018-08-01 05:58:38 +00:00
@CommandPermissions ( level = Rank . IMPOSTOR , source = SourceType . BOTH )
2018-08-01 07:08:06 +00:00
@CommandParameters ( description = " Sends a verification code to the player, or the player can input the sent code. Admins can manually verify a player impostor. " , usage = " /<command> <code | <playername>> " )
2018-03-25 01:41:51 +00:00
public class Command_verify extends FreedomCommand
{
2017-12-29 18:12:47 +00:00
@Override
2018-03-25 01:41:51 +00:00
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
2018-03-24 15:41:45 +00:00
2020-06-30 07:25:38 +00:00
if ( ! plugin . dc . enabled )
2018-03-25 01:41:51 +00:00
{
2020-06-30 07:25:38 +00:00
msg ( " The Discord verification system is currently disabled " , ChatColor . RED ) ;
2018-08-01 05:58:38 +00:00
return true ;
2018-03-25 01:41:51 +00:00
}
2020-06-30 07:25:38 +00:00
if ( senderIsConsole )
2018-03-25 01:41:51 +00:00
{
2020-06-30 07:25:38 +00:00
msg ( " /manuallyverify <playername> " , ChatColor . WHITE ) ;
return true ;
}
2019-11-27 05:39:30 +00:00
2020-06-30 07:25:38 +00:00
if ( ! plugin . pl . isImposter ( playerSender ) )
{
msg ( " You are not an impostor, therefore you do not need to verify. " , ChatColor . RED ) ;
return true ;
}
2018-08-01 07:08:06 +00:00
2020-06-30 07:25:38 +00:00
PlayerData playerData = plugin . pl . getData ( playerSender ) ;
String discordId = playerData . getDiscordID ( ) ;
if ( playerData . getDiscordID ( ) = = null )
{
msg ( " You do not have a Discord account linked to your Minecraft account, please verify the manual way. " , ChatColor . RED ) ;
return true ;
}
if ( args . length = = 0 )
{
String code = plugin . dc . generateCode ( 10 ) ;
plugin . dc . addVerificationCode ( code , playerData ) ;
plugin . dc . bot . getUserById ( discordId ) . openPrivateChannel ( ) . complete ( ) . sendMessage ( " A user with the IP ` " + Ips . getIp ( playerSender ) + " ` has sent a verification request. Please run the following in-game command: `/verify " + code + " ` " ) . complete ( ) ;
msg ( " A verification code has been sent to your account, please copy the code and run /verify <code> " , ChatColor . GREEN ) ;
return true ;
}
2018-08-01 05:58:38 +00:00
2020-06-30 07:25:38 +00:00
String code = args [ 0 ] ;
String backupCode = null ;
2018-08-01 05:58:38 +00:00
2020-06-30 07:25:38 +00:00
if ( plugin . pl . isImposter ( playerSender ) )
{
PlayerData mapPlayer = plugin . dc . getVerificationCodes ( ) . get ( code ) ;
if ( mapPlayer = = null )
2020-01-25 06:27:16 +00:00
{
2020-06-30 07:25:38 +00:00
if ( ! playerData . getBackupCodes ( ) . contains ( plugin . dc . getMD5 ( code ) ) )
2020-01-25 06:27:16 +00:00
{
2020-06-30 07:25:38 +00:00
msg ( " You have entered an invalid verification code " , ChatColor . RED ) ;
2020-01-25 06:27:16 +00:00
return true ;
}
2020-06-30 07:25:38 +00:00
else
2018-08-01 05:58:38 +00:00
{
2020-06-30 07:25:38 +00:00
backupCode = plugin . dc . getMD5 ( code ) ;
2018-08-01 05:58:38 +00:00
}
}
2020-06-30 07:25:38 +00:00
else
2018-03-25 01:41:51 +00:00
{
2020-06-30 07:25:38 +00:00
plugin . dc . removeVerificationCode ( code ) ;
2018-03-24 15:41:45 +00:00
}
2020-06-30 07:25:38 +00:00
final FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
if ( fPlayer . getFreezeData ( ) . isFrozen ( ) )
2018-03-25 01:41:51 +00:00
{
2020-06-30 07:25:38 +00:00
fPlayer . getFreezeData ( ) . setFrozen ( false ) ;
msg ( " You have been unfrozen. " ) ;
2017-12-29 18:12:47 +00:00
}
2020-06-30 07:25:38 +00:00
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified! " , ChatColor . GOLD ) ;
playerSender . setOp ( true ) ;
plugin . pl . verify ( playerSender , backupCode ) ;
return true ;
2017-12-29 18:12:47 +00:00
}
return true ;
}
}