Skip to content

Commit f9e1a27

Browse files
Initial Commit
Signed-off-by: BuildTools <jumboofawarrior@gmail.com>
1 parent a082452 commit f9e1a27

18 files changed

Lines changed: 1056 additions & 0 deletions

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Caleb E. Warren
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Development Library
2+
3+
![Rating](https://img.shields.io/badge/Rating-1%2F5-Red)
4+
![Sauce](https://img.shields.io/badge/100%25-Spaghetti%20Code-orange)
5+
![Build Status](https://img.shields.io/badge/Passing-yellowgreen)
6+
7+
8+
Have you Ever Written Code So Good You use it again? Same, but if I did I'd put it here.
9+
10+
- jumbodinosaurs.com Support
11+
- java reflection help
12+
13+
### Gradle
14+
15+
```
16+
buildscript {
17+
repositories {
18+
jcenter()
19+
}
20+
21+
22+
}
23+
24+
25+
allprojects {
26+
repositories {
27+
jcenter()
28+
maven { url 'https://jitpack.io' }
29+
}
30+
}
31+
...
32+
33+
dependencies {
34+
compile 'com.github.WalkingLibrary:Dev-Lib:$version'
35+
36+
}
37+
38+
39+
```
40+
License
41+
----
42+
![AUR license](https://img.shields.io/badge/License-MIT-blue)
43+
44+

build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
7+
}
8+
9+
10+
allprojects {
11+
repositories {
12+
jcenter()
13+
maven { url 'https://jitpack.io' }
14+
}
15+
}
16+
17+
apply plugin: 'java'
18+
apply plugin: 'idea'
19+
apply plugin: 'maven'
20+
21+
group 'com.jumbodinosaurs'
22+
version '1.0.0'
23+
archivesBaseName = "jumsdevlib"
24+
25+
sourceCompatibility = 1.8
26+
27+
repositories {
28+
mavenCentral()
29+
}
30+
31+
dependencies {
32+
testCompile group: 'junit', name: 'junit', version: '4.12'
33+
compile 'com.github.classgraph:classgraph:fast-classpath-scanner-4.0.0-beta-10b'
34+
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
4+
import com.jumbodinosaurs.devlib.commands.exceptions.WaveringParametersException;
5+
6+
public abstract class Command
7+
{
8+
9+
public String getCommand()
10+
{
11+
return getClass().getSimpleName();
12+
}
13+
14+
public abstract MessageResponse getExecutedMessage() throws WaveringParametersException;
15+
16+
public abstract String getHelpMessage();
17+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
import com.jumbodinosaurs.devlib.commands.exceptions.WaveringParametersException;
4+
import com.jumbodinosaurs.devlib.util.ReflectionUtil;
5+
6+
import java.util.ArrayList;
7+
8+
public class CommandManager
9+
{
10+
public static MessageResponse filter(String input, boolean hasPrefix) throws WaveringParametersException
11+
{
12+
MessageResponse response = null;
13+
CommandParser parser = new CommandParser(input, hasPrefix);
14+
String command = parser.getCommand();
15+
ArrayList<Parameter> parameters = parser.getParameters();
16+
System.out.println(command);
17+
for(Command consoleCommand : getLoadedCommands())
18+
{
19+
System.out.println(consoleCommand.getCommand());
20+
if(consoleCommand.getCommand().toLowerCase().equals(command.toLowerCase().trim()))
21+
{
22+
if(consoleCommand instanceof CommandWithParameters)
23+
{
24+
((CommandWithParameters) consoleCommand).setParameters(parameters);
25+
26+
}
27+
response = consoleCommand.getExecutedMessage();
28+
}
29+
}
30+
return response;
31+
}
32+
33+
public static ArrayList<Command> getLoadedCommands()
34+
{
35+
ArrayList<Command> commands = new ArrayList<Command>();
36+
for(Class classType : ReflectionUtil.getSubClasses(Command.class))
37+
{
38+
try
39+
{
40+
commands.add((Command) classType.newInstance());
41+
}
42+
catch(IllegalAccessException e)
43+
{
44+
e.printStackTrace();
45+
}
46+
catch(InstantiationException e)
47+
{
48+
e.printStackTrace();
49+
}
50+
}
51+
System.out.println("Commands Size: " + commands.size());
52+
return commands;
53+
}
54+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
import java.util.ArrayList;
4+
5+
;
6+
7+
public class CommandParser
8+
{
9+
private ArrayList<Parameter> parameters = new ArrayList<Parameter>();
10+
private String command;
11+
12+
public CommandParser(String message, boolean hasPrefix)
13+
{
14+
String[] commandParts = message.split(" ");
15+
//Remove Prefix
16+
if(hasPrefix)
17+
{
18+
commandParts[0] = commandParts[0].substring(1);
19+
20+
}
21+
this.command = commandParts[0];
22+
for(int i = 1; i < commandParts.length; i++)
23+
{
24+
parameters.add(new Parameter(commandParts[i]));
25+
}
26+
}
27+
28+
public ArrayList<Parameter> getParameters()
29+
{
30+
return parameters;
31+
}
32+
33+
public void setParameters(ArrayList<Parameter> parameters)
34+
{
35+
this.parameters = parameters;
36+
}
37+
38+
public String getCommand()
39+
{
40+
return command;
41+
}
42+
43+
public void setCommand(String command)
44+
{
45+
this.command = command;
46+
}
47+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
import java.util.ArrayList;
4+
5+
public abstract class CommandWithParameters extends Command
6+
{
7+
private ArrayList<Parameter> parameters = new ArrayList<Parameter>();
8+
9+
public ArrayList<Parameter> getParameters()
10+
{
11+
return parameters;
12+
}
13+
14+
public void setParameters(ArrayList<Parameter> parameters)
15+
{
16+
this.parameters = parameters;
17+
}
18+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
4+
public class Help extends CommandWithParameters
5+
{
6+
@Override
7+
public MessageResponse getExecutedMessage()
8+
{
9+
MessageResponse response = null;
10+
//TODO Automate
11+
if(this.getParameters().size() > 0)
12+
{
13+
String identifier = this.getParameters().get(0).getParameter();
14+
15+
16+
for(Command command : CommandManager.getLoadedCommands())
17+
{
18+
if(command.getCommand().equals(identifier))
19+
{
20+
response = new MessageResponse(command.getHelpMessage());
21+
}
22+
}
23+
24+
if(response == null)
25+
{
26+
response = new MessageResponse("No Retention or Command Named: " + identifier);
27+
}
28+
29+
}
30+
else
31+
{
32+
String commandsToList = "Commands:";
33+
for(Command command : CommandManager.getLoadedCommands())
34+
{
35+
commandsToList += "\n" + command.getCommand();
36+
}
37+
response = new MessageResponse(commandsToList);
38+
}
39+
return response;
40+
}
41+
42+
43+
@Override
44+
public String getHelpMessage()
45+
{
46+
return "Enter " + getCommand() + " followed by a command or retention to see the help/info message for that " + "command or retention.";
47+
}
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
6+
public class MessageResponse
7+
{
8+
private String message;
9+
private ArrayList<File> attachments;
10+
11+
public MessageResponse(String message, ArrayList<File> attachments)
12+
{
13+
this.message = message;
14+
this.attachments = attachments;
15+
}
16+
17+
public MessageResponse(String message)
18+
{
19+
this.message = message;
20+
}
21+
22+
public String getMessage()
23+
{
24+
return message;
25+
}
26+
27+
public void setMessage(String message)
28+
{
29+
this.message = message;
30+
}
31+
32+
public ArrayList<File> getAttachments()
33+
{
34+
return attachments;
35+
}
36+
37+
public void setAttachments(ArrayList<File> attachments)
38+
{
39+
this.attachments = attachments;
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.jumbodinosaurs.devlib.commands;
2+
3+
public class Parameter
4+
{
5+
private String parameter;
6+
private int order;
7+
8+
public Parameter(String parameter, int order)
9+
{
10+
this.parameter = parameter;
11+
this.order = order;
12+
}
13+
14+
public Parameter(String parameter)
15+
{
16+
this.parameter = parameter;
17+
}
18+
19+
20+
public String getParameter()
21+
{
22+
return parameter;
23+
}
24+
25+
public void setParameter(String parameter)
26+
{
27+
this.parameter = parameter;
28+
}
29+
30+
public int getOrder()
31+
{
32+
return order;
33+
}
34+
35+
public void setOrder(int order)
36+
{
37+
this.order = order;
38+
}
39+
}

0 commit comments

Comments
 (0)