2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2015-10-19 17:43:46 +00:00
2019-01-29 04:57:41 +00:00
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.List ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
2018-03-03 04:29:08 +00:00
import me.totalfreedom.totalfreedommod.punishments.Punishment ;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType ;
2016-03-06 15:56:15 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil ;
2018-03-03 04:29:08 +00:00
import net.pravian.aero.util.Ips ;
2016-05-12 19:40:39 +00:00
import org.apache.commons.lang3.ArrayUtils ;
2019-07-31 16:19:23 +00:00
import org.apache.commons.lang3.StringUtils ;
2016-05-12 19:40:39 +00:00
import org.bukkit.ChatColor ;
2015-10-19 17:43:46 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . BOTH )
2020-04-22 08:23:51 +00:00
@CommandParameters ( description = " Mutes a player with brute force. " , usage = " /<command> [[-s | -q] <player> [reason] | list | purge | all] " , aliases = " stfu " )
public class Command_mute extends FreedomCommand
2015-10-19 17:43:46 +00:00
{
2015-11-22 18:26:47 +00:00
2015-10-19 17:43:46 +00:00
@Override
2015-11-22 18:26:47 +00:00
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
2015-10-19 17:43:46 +00:00
{
2016-05-12 19:40:39 +00:00
if ( args . length = = 0 )
2015-10-19 17:43:46 +00:00
{
return false ;
}
2016-08-26 10:39:56 +00:00
if ( args [ 0 ] . equals ( " list " ) )
2015-10-19 17:43:46 +00:00
{
2016-03-02 19:28:01 +00:00
msg ( " Muted players: " ) ;
2015-10-19 17:43:46 +00:00
FPlayer info ;
int count = 0 ;
for ( Player mp : server . getOnlinePlayers ( ) )
{
info = plugin . pl . getPlayer ( mp ) ;
if ( info . isMuted ( ) )
{
2016-03-02 19:28:01 +00:00
msg ( " - " + mp . getName ( ) ) ;
2015-10-19 17:43:46 +00:00
count + + ;
}
}
if ( count = = 0 )
{
2016-03-02 19:28:01 +00:00
msg ( " - none " ) ;
2015-10-19 17:43:46 +00:00
}
2016-05-12 19:40:39 +00:00
return true ;
2015-10-19 17:43:46 +00:00
}
2016-05-12 19:40:39 +00:00
2016-08-26 10:39:56 +00:00
if ( args [ 0 ] . equals ( " purge " ) )
2015-10-19 17:43:46 +00:00
{
FUtil . adminAction ( sender . getName ( ) , " Unmuting all players. " , true ) ;
FPlayer info ;
int count = 0 ;
for ( Player mp : server . getOnlinePlayers ( ) )
{
info = plugin . pl . getPlayer ( mp ) ;
if ( info . isMuted ( ) )
{
info . setMuted ( false ) ;
2020-03-27 22:16:28 +00:00
mp . sendTitle ( ChatColor . RED + " You've been unmuted. " , ChatColor . YELLOW + " Be sure to follow the rules! " , 20 , 100 , 60 ) ;
2015-10-19 17:43:46 +00:00
count + + ;
}
}
2018-03-18 08:32:50 +00:00
plugin . mu . MUTED_PLAYERS . clear ( ) ;
2016-03-02 19:28:01 +00:00
msg ( " Unmuted " + count + " players. " ) ;
2016-05-12 19:40:39 +00:00
return true ;
2015-10-19 17:43:46 +00:00
}
2016-05-12 19:40:39 +00:00
2016-08-26 10:39:56 +00:00
if ( args [ 0 ] . equals ( " all " ) )
2015-10-19 17:43:46 +00:00
{
2018-03-03 04:29:08 +00:00
FUtil . adminAction ( sender . getName ( ) , " Muting all non-admins " , true ) ;
2015-10-19 17:43:46 +00:00
FPlayer playerdata ;
int counter = 0 ;
for ( Player player : server . getOnlinePlayers ( ) )
{
if ( ! plugin . al . isAdmin ( player ) )
{
2020-03-27 22:16:28 +00:00
player . sendTitle ( ChatColor . RED + " You've been muted globally. " , ChatColor . YELLOW + " Please be patient and you will be unmuted shortly. " , 20 , 100 , 60 ) ;
2015-10-19 17:43:46 +00:00
playerdata = plugin . pl . getPlayer ( player ) ;
playerdata . setMuted ( true ) ;
counter + + ;
}
}
2016-03-02 19:28:01 +00:00
msg ( " Muted " + counter + " players. " ) ;
2016-05-12 19:40:39 +00:00
return true ;
2015-10-19 17:43:46 +00:00
}
2016-05-12 19:40:39 +00:00
2016-08-26 10:39:56 +00:00
// -s option (smite)
2016-05-12 19:40:39 +00:00
boolean smite = args [ 0 ] . equals ( " -s " ) ;
2020-01-11 22:44:13 +00:00
// -q option (shadowmute)
boolean quiet = args [ 0 ] . equals ( " -q " ) ;
if ( smite | | quiet )
2015-10-19 17:43:46 +00:00
{
2016-05-12 19:40:39 +00:00
args = ArrayUtils . subarray ( args , 1 , args . length ) ;
2016-08-26 10:39:56 +00:00
if ( args . length < 1 )
{
return false ;
}
2016-05-12 19:40:39 +00:00
}
2015-10-19 17:43:46 +00:00
2016-05-12 19:40:39 +00:00
final Player player = getPlayer ( args [ 0 ] ) ;
if ( player = = null )
{
sender . sendMessage ( FreedomCommand . PLAYER_NOT_FOUND ) ;
return true ;
}
String reason = null ;
if ( args . length > 1 )
{
reason = StringUtils . join ( args , " " , 1 , args . length ) ;
}
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2020-04-22 08:23:51 +00:00
if ( plugin . al . isAdmin ( player ) )
2016-05-12 19:40:39 +00:00
{
2020-04-22 08:23:51 +00:00
msg ( player . getName ( ) + " is an admin, and can't be muted. " ) ;
return true ;
2016-05-12 19:40:39 +00:00
}
2015-10-19 17:43:46 +00:00
2020-04-22 08:23:51 +00:00
if ( ! playerdata . isMuted ( ) )
{
2020-01-11 22:44:13 +00:00
if ( quiet )
{
playerdata . setMuted ( true ) ;
playerdata . setQuietMuted ( true ) ;
msg ( " Muted " + player . getName ( ) + " quietly " ) ;
return true ;
}
2016-05-12 19:40:39 +00:00
FUtil . adminAction ( sender . getName ( ) , " Muting " + player . getName ( ) , true ) ;
playerdata . setMuted ( true ) ;
if ( smite )
2015-10-19 17:43:46 +00:00
{
2017-12-23 04:07:36 +00:00
Command_smite . smite ( sender , player , reason ) ;
2016-05-12 19:40:39 +00:00
}
2015-10-19 17:43:46 +00:00
2018-03-03 04:29:08 +00:00
msg ( player , " You have been muted by " + ChatColor . YELLOW + sender . getName ( ) , ChatColor . RED ) ;
2020-03-27 22:16:28 +00:00
player . sendTitle ( ChatColor . RED + " You've been muted. " , ChatColor . YELLOW + " Be sure to follow the rules! " , 20 , 100 , 60 ) ;
2018-03-03 04:29:08 +00:00
if ( reason ! = null )
{
2020-04-22 08:23:51 +00:00
msg ( player , ChatColor . RED + " Reason: " + ChatColor . YELLOW + reason ) ;
2018-03-03 04:29:08 +00:00
}
2016-05-12 19:40:39 +00:00
msg ( " Muted " + player . getName ( ) ) ;
2015-10-19 17:43:46 +00:00
2018-03-03 04:34:43 +00:00
plugin . pul . logPunishment ( new Punishment ( player . getName ( ) , Ips . getIp ( player ) , sender . getName ( ) , PunishmentType . MUTE , reason ) ) ;
2015-10-19 17:43:46 +00:00
}
2020-04-22 08:23:51 +00:00
else
{
msg ( ChatColor . RED + " That player is already muted. " ) ;
}
2015-10-19 17:43:46 +00:00
return true ;
}
2019-01-29 04:57:41 +00:00
@Override
public List < String > getTabCompleteOptions ( CommandSender sender , Command command , String alias , String [ ] args )
{
if ( ! plugin . al . isAdmin ( sender ) )
{
return null ;
}
if ( args . length = = 1 )
{
List < String > arguments = new ArrayList < > ( ) ;
arguments . addAll ( FUtil . getPlayerList ( ) ) ;
arguments . addAll ( Arrays . asList ( " list " , " purge " , " all " ) ) ;
return arguments ;
}
return Collections . emptyList ( ) ;
}
2015-10-19 17:43:46 +00:00
}