2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command ;
2018-07-31 07:01:29 +00:00
import java.util.Date ;
2017-12-29 18:12:47 +00:00
import me.totalfreedom.totalfreedommod.admin.Admin ;
import me.totalfreedom.totalfreedommod.config.ConfigEntry ;
2018-05-29 21:30:29 +00:00
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder ;
2018-03-24 15:41:45 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
2020-01-25 06:27:16 +00:00
import me.totalfreedom.totalfreedommod.playerverification.VPlayer ;
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
2018-08-01 05:58:38 +00:00
if ( args . length = = 1 & & plugin . al . isAdmin ( playerSender ) )
2018-03-25 01:41:51 +00:00
{
2018-08-01 05:58:38 +00:00
final Player player = getPlayer ( args [ 0 ] ) ;
2018-08-01 07:08:06 +00:00
if ( player = = null )
2018-08-01 05:58:38 +00:00
{
2018-08-01 07:08:06 +00:00
msg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2018-08-01 05:58:38 +00:00
return true ;
}
if ( ! plugin . pv . isPlayerImpostor ( player ) )
2018-03-25 01:41:51 +00:00
{
2018-08-01 05:58:38 +00:00
msg ( " That player is not an impostor. " ) ;
2018-03-24 15:41:45 +00:00
return true ;
}
2018-08-01 07:08:06 +00:00
FUtil . adminAction ( sender . getName ( ) , " Manually verifying player " + player . getName ( ) , false ) ;
2018-08-01 05:58:38 +00:00
player . setOp ( true ) ;
player . sendMessage ( YOU_ARE_OP ) ;
if ( plugin . pl . getPlayer ( player ) . getFreezeData ( ) . isFrozen ( ) )
{
plugin . pl . getPlayer ( player ) . getFreezeData ( ) . setFrozen ( false ) ;
2018-08-01 07:08:06 +00:00
player . sendMessage ( ChatColor . GRAY + " You have been unfrozen. " ) ;
2018-08-01 05:58:38 +00:00
}
2020-01-25 06:27:16 +00:00
plugin . pv . verifyPlayer ( player , null ) ;
2018-08-01 05:58:38 +00:00
plugin . rm . updateDisplay ( player ) ;
return true ;
2018-03-25 01:41:51 +00:00
}
else
{
2019-11-27 05:39:30 +00:00
if ( ! plugin . dc . enabled )
{
msg ( " The Discord verification system is currently disabled " , ChatColor . RED ) ;
return true ;
}
2018-08-01 07:08:06 +00:00
if ( senderIsConsole | | plugin . al . isAdmin ( playerSender ) )
2018-08-01 05:58:38 +00:00
{
msg ( " /verify <playername> " , ChatColor . WHITE ) ;
return true ;
}
2018-08-01 07:08:06 +00:00
2020-01-25 06:27:16 +00:00
if ( ! plugin . pv . isPlayerImpostor ( playerSender ) & & ! plugin . al . isAdminImpostor ( playerSender ) & & ! plugin . mbl . isMasterBuilderImpostor ( playerSender ) )
2018-08-01 05:58:38 +00:00
{
msg ( " You are not an impostor, therefore you do not need to verify. " , ChatColor . RED ) ;
return true ;
}
String discordId = " " ;
2020-01-25 06:27:16 +00:00
if ( plugin . pv . isPlayerImpostor ( playerSender ) )
{
VPlayer vPlayer = plugin . pv . getVerificationPlayer ( playerSender ) ;
if ( vPlayer . getDiscordId ( ) = = null )
{
msg ( " You do not have a Discord account linked to your Minecraft account, please verify the manual way. " , ChatColor . RED ) ;
return true ;
}
discordId = vPlayer . getDiscordId ( ) ;
}
else if ( plugin . al . isAdminImpostor ( playerSender ) )
2018-08-01 05:58:38 +00:00
{
Admin admin = plugin . al . getEntryByName ( playerSender . getName ( ) ) ;
if ( admin . getDiscordID ( ) = = null )
{
msg ( " You do not have a Discord account linked to your Minecraft account, please verify the manual way. " , ChatColor . RED ) ;
return true ;
}
discordId = admin . getDiscordID ( ) ;
}
2020-01-25 06:27:16 +00:00
else if ( plugin . mbl . isMasterBuilderImpostor ( playerSender ) )
2018-03-25 01:41:51 +00:00
{
2020-01-25 06:27:16 +00:00
MasterBuilder masterBuilder = plugin . mbl . getEntryByName ( playerSender . getName ( ) ) ;
if ( masterBuilder . getDiscordID ( ) = = null )
2018-03-25 01:41:51 +00:00
{
2018-07-30 07:23:01 +00:00
msg ( " You do not have a Discord account linked to your Minecraft account, please verify the manual way. " , ChatColor . RED ) ;
2018-03-24 15:41:45 +00:00
return true ;
}
2020-01-25 06:27:16 +00:00
discordId = masterBuilder . getDiscordID ( ) ;
2018-03-24 15:41:45 +00:00
}
2018-08-01 05:58:38 +00:00
if ( args . length < 1 )
2018-03-25 01:41:51 +00:00
{
2020-01-25 06:27:16 +00:00
String code = plugin . dc . generateCode ( 10 ) ;
if ( plugin . pv . isPlayerImpostor ( playerSender ) )
{
VPlayer vPlayer = plugin . pv . getVerificationPlayer ( playerSender ) ;
plugin . dc . addPlayerVerificationCode ( code , vPlayer ) ;
}
else if ( plugin . al . isAdminImpostor ( playerSender ) )
2018-08-01 05:58:38 +00:00
{
2020-01-25 06:27:16 +00:00
Admin admin = plugin . al . getEntryByName ( playerSender . getName ( ) ) ;
plugin . dc . addAdminVerificationCode ( code , admin ) ;
}
else if ( plugin . mbl . isMasterBuilderImpostor ( playerSender ) )
{
MasterBuilder masterBuilder = plugin . mbl . getEntryByName ( playerSender . getName ( ) ) ;
plugin . dc . addMasterBuilderVerificationCode ( code , masterBuilder ) ;
2018-08-01 05:58:38 +00:00
}
2020-01-25 06:27:16 +00:00
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 ( ) ;
2018-08-01 05:58:38 +00:00
msg ( " A verification code has been sent to your account, please copy the code and run /verify <code> " , ChatColor . GREEN ) ;
2018-03-25 01:41:51 +00:00
}
else
{
2018-08-01 05:58:38 +00:00
String code = args [ 0 ] ;
2020-01-25 06:27:16 +00:00
String backupCode = null ;
if ( plugin . pv . isPlayerImpostor ( playerSender ) )
2018-08-01 05:58:38 +00:00
{
2020-01-25 06:27:16 +00:00
VPlayer vPlayer = plugin . pv . getVerificationPlayer ( playerSender ) ;
VPlayer mapPlayer = plugin . dc . getPlayerVerificationCodes ( ) . get ( code ) ;
if ( mapPlayer = = null )
{
if ( ! vPlayer . getBackupCodes ( ) . contains ( plugin . dc . getMD5 ( code ) ) )
{
msg ( " You have entered an invalid verification code " , ChatColor . RED ) ;
return true ;
}
else
{
backupCode = plugin . dc . getMD5 ( code ) ;
}
}
else
{
plugin . dc . removePlayerVerificationCode ( code ) ;
}
final FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified! " , ChatColor . GOLD ) ;
playerSender . setOp ( true ) ;
msg ( YOU_ARE_OP ) ;
if ( fPlayer . getFreezeData ( ) . isFrozen ( ) )
{
fPlayer . getFreezeData ( ) . setFrozen ( false ) ;
msg ( " You have been unfrozen. " ) ;
}
plugin . pv . verifyPlayer ( playerSender , backupCode ) ;
2020-04-22 08:23:51 +00:00
plugin . rm . updateDisplay ( playerSender ) ;
2018-08-01 05:58:38 +00:00
return true ;
}
2020-01-25 06:27:16 +00:00
else if ( plugin . al . isAdminImpostor ( playerSender ) )
2018-03-25 01:41:51 +00:00
{
2018-03-24 15:41:45 +00:00
Admin admin = plugin . al . getEntryByName ( playerSender . getName ( ) ) ;
2020-01-25 06:27:16 +00:00
Admin mapAdmin = plugin . dc . getAdminVerificationCodes ( ) . get ( code ) ;
if ( mapAdmin = = null )
{
if ( ! admin . getBackupCodes ( ) . contains ( plugin . dc . getMD5 ( code ) ) )
{
msg ( " You have entered an invalid verification code " , ChatColor . RED ) ;
return true ;
}
else
{
backupCode = plugin . dc . getMD5 ( code ) ;
}
}
else
{
plugin . dc . removeAdminVerificationCode ( code ) ;
}
2018-07-30 07:23:01 +00:00
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified! " , ChatColor . GOLD ) ;
2018-08-01 07:08:06 +00:00
FUtil . adminAction ( ConfigEntry . SERVER_NAME . getString ( ) , " Re-adding " + admin . getName ( ) + " to the admin list " , true ) ;
2018-08-01 05:58:38 +00:00
admin . setName ( playerSender . getName ( ) ) ;
admin . addIp ( Ips . getIp ( playerSender ) ) ;
2018-05-29 21:30:29 +00:00
2020-01-25 06:27:16 +00:00
if ( backupCode ! = null )
{
admin . removeBackupCode ( backupCode ) ;
}
2018-05-29 21:30:29 +00:00
if ( ! plugin . mbl . isMasterBuilder ( playerSender ) )
{
MasterBuilder masterBuilder = null ;
for ( MasterBuilder loopMasterBuilder : plugin . mbl . getAllMasterBuilders ( ) . values ( ) )
{
if ( loopMasterBuilder . getName ( ) . equalsIgnoreCase ( playerSender . getName ( ) ) )
{
masterBuilder = loopMasterBuilder ;
break ;
}
}
if ( masterBuilder ! = null )
{
2018-08-01 05:58:38 +00:00
masterBuilder . setName ( playerSender . getName ( ) ) ;
masterBuilder . addIp ( Ips . getIp ( playerSender ) ) ;
2018-05-29 21:30:29 +00:00
masterBuilder . setLastLogin ( new Date ( ) ) ;
plugin . mbl . save ( ) ;
plugin . mbl . updateTables ( ) ;
}
}
2018-03-24 15:41:45 +00:00
admin . setActive ( true ) ;
admin . setLastLogin ( new Date ( ) ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( admin ) ;
2018-03-24 15:41:45 +00:00
plugin . al . updateTables ( ) ;
plugin . rm . updateDisplay ( playerSender ) ;
2018-07-12 22:25:18 +00:00
playerSender . setOp ( true ) ;
msg ( YOU_ARE_OP ) ;
2018-03-24 15:41:45 +00:00
final FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
2018-03-25 01:41:51 +00:00
if ( fPlayer . getFreezeData ( ) . isFrozen ( ) )
{
2018-03-24 15:41:45 +00:00
fPlayer . getFreezeData ( ) . setFrozen ( false ) ;
msg ( " You have been unfrozen. " ) ;
}
2018-08-01 05:58:38 +00:00
return true ;
2018-03-25 01:41:51 +00:00
}
2020-01-25 06:27:16 +00:00
else if ( plugin . mbl . isMasterBuilderImpostor ( playerSender ) )
2018-03-25 01:41:51 +00:00
{
2020-01-25 06:27:16 +00:00
MasterBuilder masterBuilder = plugin . mbl . getEntryByName ( playerSender . getName ( ) ) ;
MasterBuilder mapMasterBuilder = plugin . dc . getMasterBuilderVerificationCodes ( ) . get ( code ) ;
if ( mapMasterBuilder = = null )
{
if ( ! masterBuilder . getBackupCodes ( ) . contains ( plugin . dc . getMD5 ( code ) ) )
{
msg ( " You have entered an invalid verification code " , ChatColor . RED ) ;
return true ;
}
else
{
backupCode = plugin . dc . getMD5 ( code ) ;
}
}
else
{
plugin . dc . removeMasterBuilderVerificationCode ( code ) ;
}
if ( backupCode ! = null )
{
masterBuilder . removeBackupCode ( backupCode ) ;
}
2018-03-24 15:41:45 +00:00
final FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
2018-07-30 07:23:01 +00:00
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified! " , ChatColor . GOLD ) ;
2020-01-25 06:27:16 +00:00
masterBuilder . setLastLogin ( new Date ( ) ) ;
masterBuilder . addIp ( Ips . getIp ( playerSender ) ) ;
plugin . mbl . save ( ) ;
plugin . mbl . updateTables ( ) ;
2018-08-01 05:58:38 +00:00
plugin . rm . updateDisplay ( playerSender ) ;
2018-07-30 07:23:01 +00:00
playerSender . setOp ( true ) ;
msg ( YOU_ARE_OP ) ;
2018-03-25 01:41:51 +00:00
if ( fPlayer . getFreezeData ( ) . isFrozen ( ) )
{
2018-03-24 15:41:45 +00:00
fPlayer . getFreezeData ( ) . setFrozen ( false ) ;
msg ( " You have been unfrozen. " ) ;
}
2018-08-01 05:58:38 +00:00
return true ;
2017-12-29 18:12:47 +00:00
}
}
}
return true ;
}
}