2020-03-08 21:00:58 +01:00
package me.libraryaddict.disguise.commands.undisguise ;
import me.libraryaddict.disguise.DisguiseAPI ;
import me.libraryaddict.disguise.utilities.LibsPremium ;
import me.libraryaddict.disguise.utilities.translations.LibsMsg ;
import org.bukkit.ChatColor ;
2020-07-31 06:29:55 +02:00
import org.bukkit.Location ;
import org.bukkit.command.BlockCommandSender ;
2020-03-08 21:00:58 +01:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Entity ;
import org.bukkit.entity.Player ;
public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30 ;
public UndisguiseRadiusCommand ( int maxRadius ) {
this . maxRadius = maxRadius ;
}
private boolean isNumeric ( String string ) {
try {
Integer . parseInt ( string ) ;
return true ;
}
catch ( Exception ex ) {
return false ;
}
}
@Override
public boolean onCommand ( CommandSender sender , Command cmd , String label , String [ ] args ) {
if ( sender instanceof Player & & ! sender . isOp ( ) & &
( ! LibsPremium . isPremium ( ) | | LibsPremium . getPaidInformation ( ) = = LibsPremium . getPluginInformation ( ) ) ) {
2020-08-07 07:47:17 +02:00
sender . sendMessage ( ChatColor . RED + " This is the free version of Lib's Disguises, player commands are limited to console and Operators only! Purchase the plugin for non-admin usage! " ) ;
2020-03-08 21:00:58 +01:00
return true ;
}
if ( sender . getName ( ) . equals ( " CONSOLE " ) ) {
2020-07-03 14:44:22 +02:00
LibsMsg . NO_CONSOLE . send ( sender ) ;
2020-03-08 21:00:58 +01:00
return true ;
}
if ( sender . hasPermission ( " libsdisguises.undisguiseradius " ) ) {
int radius = maxRadius ;
if ( args . length > 0 ) {
if ( ! isNumeric ( args [ 0 ] ) ) {
2020-07-03 14:44:22 +02:00
LibsMsg . NOT_NUMBER . send ( sender , args [ 0 ] ) ;
2020-03-08 21:00:58 +01:00
return true ;
}
radius = Integer . parseInt ( args [ 0 ] ) ;
if ( radius > maxRadius ) {
2020-07-03 14:44:22 +02:00
LibsMsg . LIMITED_RADIUS . send ( sender , maxRadius ) ;
2020-03-08 21:00:58 +01:00
radius = maxRadius ;
}
}
2020-07-31 06:29:55 +02:00
Location center ;
if ( sender instanceof Player ) {
center = ( ( Player ) sender ) . getLocation ( ) ;
} else {
center = ( ( BlockCommandSender ) sender ) . getBlock ( ) . getLocation ( ) . add ( 0 . 5 , 0 , 0 . 5 ) ;
}
2020-03-08 21:00:58 +01:00
int disguisedEntitys = 0 ;
2020-07-31 06:29:55 +02:00
for ( Entity entity : center . getWorld ( ) . getNearbyEntities ( center , radius , radius , radius ) ) {
2020-03-08 21:00:58 +01:00
if ( entity = = sender ) {
continue ;
}
2020-07-31 06:29:55 +02:00
2020-03-08 21:00:58 +01:00
if ( DisguiseAPI . isDisguised ( entity ) ) {
DisguiseAPI . undisguiseToAll ( entity ) ;
disguisedEntitys + + ;
}
}
2020-07-03 14:44:22 +02:00
LibsMsg . UNDISRADIUS . send ( sender , disguisedEntitys ) ;
2020-03-08 21:00:58 +01:00
} else {
2020-07-03 14:44:22 +02:00
LibsMsg . NO_PERM . send ( sender ) ;
2020-03-08 21:00:58 +01:00
}
return true ;
}
}