2017-12-29 18:12:47 +00:00
package me.totalfreedom.totalfreedommod.command ;
import me.totalfreedom.totalfreedommod.admin.Admin ;
import me.totalfreedom.totalfreedommod.config.ConfigEntry ;
2018-03-24 15:41:45 +00:00
import me.totalfreedom.totalfreedommod.discord.Discord ;
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 ;
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
2017-12-29 18:12:47 +00:00
import java.util.Date ;
2018-03-24 15:41:45 +00:00
import java.util.Random ;
2017-12-29 18:12:47 +00:00
@CommandPermissions ( level = Rank . IMPOSTOR , source = SourceType . ONLY_IN_GAME )
@CommandParameters ( description = " Sends a verification code to the player, or the player can input the sent code. " , usage = " /<command> [code] " )
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-03-25 01:41:51 +00:00
if ( ! plugin . dc . enabled )
{
2017-12-29 18:12:47 +00:00
msg ( " The discord verification system is currently disabled " , ChatColor . RED ) ;
return true ;
}
2018-03-24 15:41:45 +00:00
2018-03-25 01:41:51 +00:00
if ( ! plugin . al . isAdminImpostor ( playerSender ) & & ! plugin . pv . isPlayerImpostor ( playerSender ) )
{
2017-12-29 18:12:47 +00:00
msg ( " You are not an imposter, therefore you do not need to verify. " , ChatColor . RED ) ;
return true ;
}
2018-03-24 15:41:45 +00:00
String discordId = " " ;
2018-03-25 01:41:51 +00:00
if ( plugin . al . isAdminImpostor ( playerSender ) )
{
2018-03-24 15:41:45 +00:00
Admin admin = plugin . al . getEntryByName ( playerSender . getName ( ) ) ;
2018-03-25 01:41:51 +00:00
if ( admin . getDiscordID ( ) = = null )
{
2018-03-24 15:41:45 +00:00
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 ( ) ;
2018-03-25 01:41:51 +00:00
}
else
{
if ( plugin . pv . isPlayerImpostor ( playerSender ) )
{
2018-06-01 14:13:40 +00:00
if ( plugin . pv . getVerificationPlayer ( playerSender ) . getDiscordId ( ) = = null )
2018-03-25 01:41:51 +00:00
{
2018-03-24 15:41:45 +00:00
msg ( " You do not have a discord account linked to your minecraft account, please verify the manual way. " , ChatColor . RED ) ;
return true ;
}
2018-06-01 14:13:40 +00:00
discordId = plugin . pv . getVerificationPlayer ( playerSender ) . getDiscordId ( ) ;
2018-03-24 15:41:45 +00:00
}
2017-12-29 18:12:47 +00:00
}
2018-03-24 15:41:45 +00:00
2018-03-25 01:41:51 +00:00
if ( args . length < 1 )
{
2017-12-29 18:12:47 +00:00
String code = " " ;
Random random = new Random ( ) ;
2018-03-25 01:41:51 +00:00
for ( int i = 0 ; i < 10 ; i + + )
{
2017-12-29 18:12:47 +00:00
code + = random . nextInt ( 10 ) ;
}
2018-03-24 15:41:45 +00:00
Discord . VERIFY_CODES . add ( code ) ;
Discord . 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 ( ) ;
2017-12-29 18:12:47 +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
{
2017-12-29 18:12:47 +00:00
String code = args [ 0 ] ;
2018-03-25 01:41:51 +00:00
if ( ! Discord . VERIFY_CODES . contains ( code ) )
{
2017-12-29 18:12:47 +00:00
msg ( " You have entered an invalid verification code " , ChatColor . RED ) ;
return true ;
2018-03-25 01:41:51 +00:00
}
else
{
if ( plugin . al . isAdminImpostor ( playerSender ) )
{
2018-03-24 15:41:45 +00:00
Admin admin = plugin . al . getEntryByName ( playerSender . getName ( ) ) ;
Discord . VERIFY_CODES . remove ( code ) ;
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified themself! " , ChatColor . GOLD ) ;
FUtil . adminAction ( ConfigEntry . SERVER_NAME . getString ( ) , " Readding " + admin . getName ( ) + " to the admin list " , true ) ;
2018-03-25 01:41:51 +00:00
if ( playerSender ! = null )
{
2018-03-24 15:41:45 +00:00
admin . setName ( playerSender . getName ( ) ) ;
admin . addIp ( Ips . getIp ( playerSender ) ) ;
}
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-06-01 14:13:40 +00:00
if ( playerSender ! = null )
2018-05-29 21:30:29 +00:00
{
masterBuilder . setName ( playerSender . getName ( ) ) ;
masterBuilder . addIp ( Ips . getIp ( playerSender ) ) ;
}
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 ( ) ) ;
plugin . al . save ( ) ;
plugin . al . updateTables ( ) ;
plugin . rm . updateDisplay ( playerSender ) ;
2018-03-25 01:41:51 +00:00
if ( playerSender ! = null )
{
plugin . rm . updateDisplay ( playerSender ) ;
}
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-03-25 01:41:51 +00:00
}
else
{
2018-03-24 15:41:45 +00:00
final FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
2018-03-25 01:41:51 +00:00
FUtil . bcastMsg ( playerSender . getName ( ) + " has verified themself! " , ChatColor . GOLD ) ;
if ( playerSender ! = null )
{
plugin . rm . updateDisplay ( playerSender ) ;
}
if ( fPlayer . getFreezeData ( ) . isFrozen ( ) )
{
2018-03-24 15:41:45 +00:00
fPlayer . getFreezeData ( ) . setFrozen ( false ) ;
msg ( " You have been unfrozen. " ) ;
}
plugin . pv . verifyPlayer ( playerSender ) ;
2017-12-29 18:12:47 +00:00
}
}
2018-03-24 15:41:45 +00:00
return true ;
2017-12-29 18:12:47 +00:00
}
return true ;
}
}