2019-10-27 15:45:44 +00:00
package me.rigamortis.seppuku.impl.management ;
import me.rigamortis.seppuku.Seppuku ;
import me.rigamortis.seppuku.api.command.Command ;
import me.rigamortis.seppuku.api.event.command.EventCommandLoad ;
import me.rigamortis.seppuku.api.module.Module ;
import me.rigamortis.seppuku.api.util.ReflectionUtil ;
import me.rigamortis.seppuku.api.util.StringUtil ;
2021-08-08 11:46:00 +00:00
import me.rigamortis.seppuku.api.value.Regex ;
2021-08-30 21:08:51 +00:00
import me.rigamortis.seppuku.api.value.Shader ;
2019-11-30 04:06:11 +00:00
import me.rigamortis.seppuku.api.value.Value ;
2019-10-27 15:45:44 +00:00
import me.rigamortis.seppuku.impl.command.* ;
2020-12-29 22:17:46 +00:00
import me.rigamortis.seppuku.impl.config.ModuleConfig ;
2019-12-02 01:58:25 +00:00
import net.minecraft.util.text.TextComponentString ;
2019-10-27 15:45:44 +00:00
import java.io.File ;
import java.util.ArrayList ;
2019-12-10 23:19:54 +00:00
import java.util.Comparator ;
2019-10-27 15:45:44 +00:00
import java.util.List ;
2020-11-25 20:00:59 +00:00
import java.util.logging.Level ;
2019-10-27 15:45:44 +00:00
/ * *
* Author Seth
* 4 / 16 / 2019 @ 8 : 36 AM .
* /
public final class CommandManager {
private List < Command > commandList = new ArrayList < > ( ) ;
public CommandManager ( ) {
this . commandList . add ( new HelpCommand ( ) ) ;
this . commandList . add ( new ToggleCommand ( ) ) ;
this . commandList . add ( new VClipCommand ( ) ) ;
this . commandList . add ( new HClipCommand ( ) ) ;
this . commandList . add ( new HideCommand ( ) ) ;
this . commandList . add ( new ColorCommand ( ) ) ;
this . commandList . add ( new BindCommand ( ) ) ;
2021-02-08 20:57:33 +00:00
this . commandList . add ( new XrayCommand ( ) ) ;
2019-10-27 15:45:44 +00:00
this . commandList . add ( new FriendCommand ( ) ) ;
this . commandList . add ( new PeekCommand ( ) ) ;
this . commandList . add ( new SpectateCommand ( ) ) ;
this . commandList . add ( new ModuleCommand ( ) ) ;
this . commandList . add ( new YawCommand ( ) ) ;
this . commandList . add ( new PitchCommand ( ) ) ;
this . commandList . add ( new NameCommand ( ) ) ;
this . commandList . add ( new MacroCommand ( ) ) ;
this . commandList . add ( new WaypointsCommand ( ) ) ;
this . commandList . add ( new ReloadCommand ( ) ) ;
this . commandList . add ( new UnloadCommand ( ) ) ;
this . commandList . add ( new DupeCommand ( ) ) ;
this . commandList . add ( new InvSeeCommand ( ) ) ;
this . commandList . add ( new SayCommand ( ) ) ;
this . commandList . add ( new IPCommand ( ) ) ;
this . commandList . add ( new CoordsCommand ( ) ) ;
this . commandList . add ( new ConnectCommand ( ) ) ;
this . commandList . add ( new DisconnectCommand ( ) ) ;
this . commandList . add ( new SeedCommand ( ) ) ;
this . commandList . add ( new TeleportCommand ( ) ) ;
this . commandList . add ( new IgnoreCommand ( ) ) ;
this . commandList . add ( new AutoIgnoreCommand ( ) ) ;
this . commandList . add ( new JavaScriptCommand ( ) ) ;
this . commandList . add ( new FakeChatCommand ( ) ) ;
this . commandList . add ( new EnchantCommand ( ) ) ;
this . commandList . add ( new RenameCommand ( ) ) ;
2020-05-06 17:14:29 +00:00
this . commandList . add ( new RenameModuleCommand ( ) ) ;
2019-10-27 15:45:44 +00:00
this . commandList . add ( new SpawnEggCommand ( ) ) ;
this . commandList . add ( new StackSizeCommand ( ) ) ;
this . commandList . add ( new CrashSlimeCommand ( ) ) ;
this . commandList . add ( new SignBookCommand ( ) ) ;
this . commandList . add ( new SkullCommand ( ) ) ;
this . commandList . add ( new GiveCommand ( ) ) ;
2019-12-16 00:58:07 +00:00
this . commandList . add ( new CalcStrongholdCommand ( ) ) ;
2020-12-09 03:40:39 +00:00
this . commandList . add ( new LastInvCommand ( ) ) ;
2020-12-10 04:39:14 +00:00
this . commandList . add ( new SearchCommand ( ) ) ;
2021-01-10 02:09:40 +00:00
this . commandList . add ( new PlayCommand ( ) ) ;
2021-08-09 01:23:54 +00:00
this . commandList . add ( new LocateFeatureCommand ( ) ) ;
2021-10-06 00:31:58 +00:00
this . commandList . add ( new MainMenuCommand ( ) ) ;
2022-10-02 14:26:19 +00:00
this . commandList . add ( new ConfigCommand ( ) ) ;
2023-03-31 05:56:32 +00:00
this . commandList . add ( new NukerFilterCommand ( ) ) ;
2023-05-16 05:50:39 +00:00
this . commandList . add ( new ExportCommand ( ) ) ;
this . commandList . add ( new LoadCommand ( ) ) ;
2019-10-27 15:45:44 +00:00
//create commands for every value within every module
loadValueCommands ( ) ;
//load our external commands
loadExternalCommands ( ) ;
2019-12-10 23:19:54 +00:00
2021-01-10 02:09:40 +00:00
commandList . sort ( Comparator . comparing ( Command : : getDisplayName ) ) ;
2019-10-27 15:45:44 +00:00
}
/ * *
* This is where we load custom external commands from disk
* This allows users to create their own commands and load
* them during runtime
* /
public void loadExternalCommands ( ) {
try {
2019-12-02 01:58:25 +00:00
//create a directory at "Seppuku/Commands"
final File dir = new File ( " Seppuku/Commands " ) ;
2019-10-27 15:45:44 +00:00
//if it doesnt exist create it
if ( ! dir . exists ( ) ) {
dir . mkdirs ( ) ;
}
//all jars/zip files in the dir
//loop though all classes within the jar/zip
for ( Class clazz : ReflectionUtil . getClassesEx ( dir . getPath ( ) ) ) {
if ( clazz ! = null ) {
//if we have found a class and the class inherits "Module"
if ( Command . class . isAssignableFrom ( clazz ) ) {
//create a new instance of the class
final Command command = ( Command ) clazz . newInstance ( ) ;
2020-11-25 20:00:59 +00:00
//add the class to our list of modules
this . commandList . add ( command ) ;
Seppuku . INSTANCE . getEventManager ( ) . dispatchEvent ( new EventCommandLoad ( command ) ) ;
Seppuku . INSTANCE . getLogger ( ) . log ( Level . INFO , " Found external command " + command . getDisplayName ( ) ) ;
2019-10-27 15:45:44 +00:00
}
}
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
public void loadValueCommands ( ) {
for ( final Module module : Seppuku . INSTANCE . getModuleManager ( ) . getModuleList ( ) ) {
if ( module . getValueList ( ) . size ( ) > 0 ) {
2019-11-30 07:37:20 +00:00
this . commandList . add ( new Command ( module . getDisplayName ( ) , module . getAlias ( ) , module . getDesc ( ) ! = null ? module . getDesc ( ) : " There is no description for this command " , module . toUsageTextComponent ( ) ) {
2019-10-27 15:45:44 +00:00
2019-12-02 01:58:25 +00:00
@Override
public TextComponentString getTextComponentUsage ( ) {
return module . toUsageTextComponent ( ) ;
}
2019-10-27 15:45:44 +00:00
@Override
public void exec ( String input ) {
if ( ! this . clamp ( input , 2 , 3 ) ) {
this . printUsage ( ) ;
return ;
}
final String [ ] split = input . split ( " " ) ;
2020-12-24 19:47:30 +00:00
final Value v = module . findValue ( split [ 1 ] ) ;
2019-10-27 15:45:44 +00:00
if ( v ! = null ) {
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) instanceof Boolean ) {
2019-10-27 15:45:44 +00:00
if ( split . length = = 3 ) {
if ( split [ 2 ] . equalsIgnoreCase ( " true " ) | | split [ 2 ] . equalsIgnoreCase ( " false " ) | | split [ 2 ] . equalsIgnoreCase ( " 1 " ) | | split [ 2 ] . equalsIgnoreCase ( " 0 " ) ) {
if ( split [ 2 ] . equalsIgnoreCase ( " 1 " ) ) {
2019-11-30 04:06:11 +00:00
v . setValue ( true ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247atrue " ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else if ( split [ 2 ] . equalsIgnoreCase ( " 0 " ) ) {
2019-11-30 04:06:11 +00:00
v . setValue ( false ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247cfalse " ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else {
2019-11-30 04:06:11 +00:00
v . setValue ( Boolean . parseBoolean ( split [ 2 ] ) ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to " + ( ( Boolean ) v . getValue ( ) ? " \ 247a " : " \ 247c " ) + v . getValue ( ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
}
} else {
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected true/false " ) ;
}
2019-11-30 04:06:11 +00:00
} else {
v . setValue ( ! ( ( Boolean ) v . getValue ( ) ) ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to " + ( ( Boolean ) v . getValue ( ) ? " \ 247a " : " \ 247c " ) + v . getValue ( ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
}
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) instanceof String ) {
2019-10-27 15:45:44 +00:00
if ( ! this . clamp ( input , 3 , 3 ) ) {
this . printUsage ( ) ;
return ;
}
2019-11-30 04:06:11 +00:00
v . setValue ( split [ 2 ] ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to " + split [ 2 ] ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) instanceof Number & & ! ( v . getValue ( ) instanceof Enum ) ) {
2019-10-27 15:45:44 +00:00
if ( ! this . clamp ( input , 3 , 3 ) ) {
this . printUsage ( ) ;
return ;
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) . getClass ( ) = = Float . class ) {
2019-10-27 15:45:44 +00:00
if ( StringUtil . isFloat ( split [ 2 ] ) ) {
2019-11-30 04:06:11 +00:00
v . setValue ( Float . parseFloat ( split [ 2 ] ) ) ;
2019-12-01 05:08:56 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247b " + Float . parseFloat ( split [ 2 ] ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else {
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected a number " ) ;
}
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) . getClass ( ) = = Double . class ) {
2019-10-27 15:45:44 +00:00
if ( StringUtil . isDouble ( split [ 2 ] ) ) {
2019-11-30 04:06:11 +00:00
v . setValue ( Double . parseDouble ( split [ 2 ] ) ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247b " + Double . parseDouble ( split [ 2 ] ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else {
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected a number " ) ;
}
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) . getClass ( ) = = Integer . class ) {
2019-10-27 15:45:44 +00:00
if ( StringUtil . isInt ( split [ 2 ] ) ) {
2019-11-30 04:06:11 +00:00
v . setValue ( Integer . parseInt ( split [ 2 ] ) ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247b " + Integer . parseInt ( split [ 2 ] ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else {
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected a number " ) ;
}
}
}
2019-11-30 04:06:11 +00:00
if ( v . getValue ( ) instanceof Enum ) {
2019-11-30 05:24:25 +00:00
if ( ! this . clamp ( input , 3 , 3 ) | | split [ 2 ] . matches ( " -? \\ d+( \\ . \\ d+)? " ) ) { // is a number?
2019-10-27 15:45:44 +00:00
this . printUsage ( ) ;
return ;
}
2019-11-30 04:06:11 +00:00
final int op = v . getEnum ( split [ 2 ] ) ;
2019-10-27 15:45:44 +00:00
if ( op ! = - 1 ) {
2019-11-30 05:24:25 +00:00
v . setEnumValue ( split [ 2 ] ) ;
2019-11-30 16:59:09 +00:00
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to \ 247e " + ( ( Enum ) v . getValue ( ) ) . name ( ) . toLowerCase ( ) ) ;
2020-12-29 22:17:46 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
2019-10-27 15:45:44 +00:00
} else {
2019-11-30 05:24:25 +00:00
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected a string " ) ;
2019-10-27 15:45:44 +00:00
}
}
2021-08-08 11:46:00 +00:00
if ( v . getValue ( ) instanceof Regex ) {
if ( ! this . clamp ( input , 2 , 3 ) ) {
this . printUsage ( ) ;
return ;
}
final Regex regex = ( Regex ) v . getValue ( ) ;
2021-08-30 21:08:51 +00:00
if ( split . length = = 2 | | split [ 2 ] . equals ( " " ) ) {
2021-08-08 11:46:00 +00:00
regex . setPatternString ( " " ) ;
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f cleared " ) ;
} else {
final String oldPatternString = regex . getPatternString ( ) ;
regex . setPatternString ( split [ 2 ] ) ;
if ( regex . getPattern ( ) = = null ) {
regex . setPatternString ( oldPatternString ) ;
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected a valid regular expression or an empty string " ) ;
} else {
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to " + split [ 2 ] ) ;
2021-08-30 21:08:51 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
}
}
}
if ( v . getValue ( ) instanceof Shader ) {
if ( ! this . clamp ( input , 2 , 3 ) ) {
this . printUsage ( ) ;
return ;
}
final Shader shader = ( Shader ) v . getValue ( ) ;
if ( split . length = = 2 | | split [ 2 ] . equals ( " " ) ) {
shader . setShaderID ( " " ) ;
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f unset " ) ;
} else {
final String oldShaderID = shader . getShaderID ( ) ;
shader . setShaderID ( split [ 2 ] ) ;
if ( shader . getShaderProgram ( ) = = null ) {
shader . setShaderID ( oldShaderID ) ;
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 2 ] + " \" expected an existing shader ID or an empty string " ) ;
} else {
Seppuku . INSTANCE . logChat ( module . getDisplayName ( ) + " \ 2477 " + v . getName ( ) + " \ 247f set to " + split [ 2 ] ) ;
2021-08-08 11:46:00 +00:00
Seppuku . INSTANCE . getConfigManager ( ) . save ( ModuleConfig . class ) ;
}
}
}
2019-10-27 15:45:44 +00:00
} else {
Seppuku . INSTANCE . errorChat ( " Invalid input " + " \" " + split [ 1 ] + " \" " ) ;
this . printUsage ( ) ;
}
}
} ) ;
}
}
}
/ * *
* Returns a given command based on display name or alias
*
* @param alias
* @return
* /
public Command find ( String alias ) {
for ( Command cmd : this . getCommandList ( ) ) {
for ( String s : cmd . getAlias ( ) ) {
if ( alias . equalsIgnoreCase ( s ) | | alias . equalsIgnoreCase ( cmd . getDisplayName ( ) ) ) {
return cmd ;
}
}
}
return null ;
}
/ * *
* Returns the most similar command based on display name or alias
*
* @param input
* @return
* /
public Command findSimilar ( String input ) {
Command cmd = null ;
double similarity = 0 . 0f ;
for ( Command command : this . getCommandList ( ) ) {
final double currentSimilarity = StringUtil . levenshteinDistance ( input , command . getDisplayName ( ) ) ;
if ( currentSimilarity > = similarity ) {
similarity = currentSimilarity ;
cmd = command ;
}
}
return cmd ;
}
public void unload ( ) {
2019-11-30 04:06:11 +00:00
for ( Command cmd : this . commandList ) {
2019-10-27 15:45:44 +00:00
Seppuku . INSTANCE . getEventManager ( ) . removeEventListener ( cmd ) ;
}
this . commandList . clear ( ) ;
}
public List < Command > getCommandList ( ) {
return commandList ;
}
public void setCommandList ( List < Command > commandList ) {
this . commandList = commandList ;
}
}