Skip to content

Commit 253b894

Browse files
[!] Fixed the file extracting error located to 'C:\Users\Administrator' on the cmd with different start path.
[+] Added Auto-Tab-Completer feature. [+] Added TerminalCommand.java and builder API for registering the terminal side commands. [+] Added ReloadCommandExecutor to reload & hot load plugins.(Hot Inject during the connection) [+] Added quit confirmation. [~] Improved code structure. [~] Optimized path fetch logic in getBaseConfigRoot() method.
1 parent 1c57283 commit 253b894

25 files changed

+293
-63
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.angellock.impl</groupId>
88
<artifactId>DolphinBot</artifactId>
9-
<version>1.2.4-Alpha-full</version>
9+
<version>1.2.4-ALPHA-full</version>
1010
<packaging>
1111
jar
1212
</packaging>

src/main/java/org/angellock/impl/AbstractRobot.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.angellock.impl.ingame.PlayerTracker;
1818
import org.angellock.impl.managers.BotManager;
1919
import org.angellock.impl.managers.ConfigManager;
20+
import org.angellock.impl.managers.TerminalCommandManager;
2021
import org.angellock.impl.plugin.Plugin;
2122
import org.angellock.impl.plugin.PluginManager;
2223
import org.angellock.impl.plugin.SessionProvider;
@@ -49,7 +50,7 @@ public abstract class AbstractRobot implements ISendable, SessionProvider, IOpti
4950
protected final int TIME_OUT;
5051
protected MinecraftProtocol minecraftProtocol;
5152
protected ConfigManager config;
52-
protected long connectDuration = 0;
53+
protected long connectDuration;
5354
protected boolean isByPassedVerification = true;
5455
protected GameMode serverGamemode = GameMode.ADVENTURE;
5556
private ChatMessageManager messageManager;
@@ -61,13 +62,15 @@ public abstract class AbstractRobot implements ISendable, SessionProvider, IOpti
6162
private String profileName;
6263
protected List<String> owners = new ArrayList<>();
6364
protected String password;
65+
protected final TerminalCommandManager commandManager = new TerminalCommandManager();
6466
protected final CommandSpec commands = new CommandSpec(this);
6567

6668
public AbstractRobot(ConfigManager configManager, PluginManager pluginManager){
6769
this.config = configManager;
6870
String playerName = this.config.getConfigValue("username");
6971
String serverAddress = this.config.getConfigValue("server");
7072
int serverPort = Integer.parseInt(this.config.getConfigValue("port"));
73+
this.connectDuration = Long.parseLong(this.config.getConfigValue("reconnect-delay"));
7174
this.password = this.config.getConfigValue("password");
7275

7376
this.pluginManager = pluginManager;
@@ -116,6 +119,10 @@ public AbstractRobot buildProtocol(){
116119
return this;
117120
}
118121

122+
public TerminalCommandManager getCommandManager() {
123+
return commandManager;
124+
}
125+
119126
public BotManager getBotManager() {
120127
return botManager;
121128
}

src/main/java/org/angellock/impl/Start.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121

2222
public class Start {
2323
private static final Logger log = LoggerFactory.getLogger(Start.class);
24-
private static final String ARCHIVE_VERSION = AnsiEscapes.shiftVersionTags(Optional.ofNullable(Start.class.getPackage().getImplementationVersion()).orElse("LATEST"));
25-
private static final boolean win32 = System.getProperty("os.name").toLowerCase().contains("windows");
24+
private static final String ARCHIVE_VERSION = AnsiEscapes.shiftVersionTags(Optional
25+
.ofNullable(Start.class
26+
.getPackage()
27+
.getImplementationVersion()
28+
).orElse("LATEST"));
29+
private static final boolean win32 = System
30+
.getProperty("os.name")
31+
.toLowerCase()
32+
.contains("windows");
2633
private static GUIWindowManager guiManager;
2734
public static void main(String[] args) {
2835
OptionParser optionParser = new OptionParser();
@@ -48,7 +55,10 @@ public static void main(String[] args) {
4855
log.warn(ConsoleTokens.colorizeText("&6Omitted option arguments " + badOptions));
4956
}
5057

51-
String defaultConfigPath = Optional.ofNullable(parsedOption.valueOf(configFile)).orElse("Not-Set");
58+
String defaultConfigPath = Optional
59+
.ofNullable(parsedOption.valueOf(configFile))
60+
.orElse("not-set");
61+
5262
if (Files.exists(Paths.get(defaultConfigPath))) {
5363
log.info(ConsoleTokens.colorizeText("&dThe default config file path was specified: &5&l" + defaultConfigPath));
5464
} else {
@@ -58,15 +68,16 @@ public static void main(String[] args) {
5868
@Nullable String profiles = (parsedOption.valueOf(profilesArg));
5969

6070
ConfigManager config = new ConfigManager(parsedOption, defaultConfigPath);
61-
BotManager botManager = new BotManager(defaultConfigPath, ".json", config).globalPluginManager(parsedOption.valueOf(pluginDir)).loadProfiles(profiles);
71+
BotManager botManager = new BotManager(defaultConfigPath, ".json", config)
72+
.globalPluginManager(parsedOption.valueOf(pluginDir))
73+
.loadProfiles(profiles);
6274

6375
if (parsedOption.has("gui")){
6476
guiManager = new GUIWindowManager(botManager);
6577
guiManager.startGUI();
6678
} else {
6779
AnsiEscapes.printArt(ARCHIVE_VERSION);
6880
config.printConfigSpec();
69-
7081
log.info(ConsoleTokens.colorizeText("&8Loading bots..."));
7182
botManager.startAll();
7283
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.angellock.impl.commands;
2+
3+
public abstract class AbstractBuilder<T> {
4+
protected String commandName = "";
5+
protected String description;
6+
7+
protected String[] aliases = new String[0];
8+
9+
public AbstractBuilder<T> withDescription(String description){
10+
this.description = description;
11+
return this;
12+
}
13+
14+
public AbstractBuilder<T> withAliases(String[] aliases){
15+
this.aliases = aliases;
16+
return this;
17+
}
18+
19+
public abstract T build(ICommandAction action);
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.angellock.impl.commands;
2+
3+
public abstract class AbstractCommand {
4+
protected final String name;
5+
protected ICommandAction action;
6+
protected String description;
7+
protected String[] aliases;
8+
9+
public AbstractCommand(String name, ICommandAction action) {
10+
this.name = name;
11+
this.action = action;
12+
this.aliases = new String[0];
13+
}
14+
15+
public AbstractCommand(String name, ICommandAction action, String[] aliases) {
16+
this.name = name;
17+
this.action = action;
18+
this.aliases = aliases;
19+
}
20+
21+
public void setDescription(String description) {
22+
this.description = description;
23+
}
24+
25+
public void setAliases(String[] aliases) {
26+
this.aliases = aliases;
27+
}
28+
29+
public String[] getAliases() {
30+
return aliases;
31+
}
32+
33+
public String getDescription() {
34+
return description;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public abstract boolean activate(CommandResponse entity);
42+
}

src/main/java/org/angellock/impl/commands/Command.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,24 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public class Command {
7-
private final String name;
6+
public class Command extends AbstractCommand {
7+
88
private final List<String> users = new ArrayList<>();
9-
private ICommandAction action;
109

1110
public Command(String name, ICommandAction action, List<String> users) {
12-
this.name = name;
11+
super(name, action);
1312
this.users.addAll(users);
14-
this.action = action;
1513
}
1614

1715
public List<String> getUsers(){
1816
return this.users;
1917
}
2018

21-
public String getName() {
22-
return name;
23-
}
24-
2519
public void setAction(ICommandAction action){
2620
this.action = action;
2721
}
2822

23+
@Override
2924
public boolean activate(CommandResponse entity){
3025
if (users.contains(entity.getSender()) || users.isEmpty()) {
3126
this.action.onCommand(entity);

src/main/java/org/angellock/impl/commands/CommandBuilder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public class CommandBuilder {
7-
private String commandName = "";
6+
public class CommandBuilder extends AbstractBuilder<Command> {
87
private List<String> users = new ArrayList<>();
98

109
public CommandBuilder withName(String cmdName){
@@ -17,7 +16,11 @@ public CommandBuilder allowedUsers(List<String> users) {
1716
return this;
1817
}
1918

19+
@Override
2020
public Command build(ICommandAction action) {
21-
return new Command(this.commandName, action, this.users);
21+
Command command = new Command(this.commandName, action, this.users);
22+
command.setDescription(this.description);
23+
command.setAliases(this.aliases);
24+
return command;
2225
}
2326
}

src/main/java/org/angellock/impl/commands/CommandResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public void setSender(String sender) {
3030
}
3131

3232
public boolean isInvalid(){
33-
return (this.sender == null || this.commandName == null);
33+
return (this.sender == null && this.commandName == null);
34+
}
35+
36+
public boolean isFromTerminal(){
37+
return this.sender == null;
3438
}
3539
}

src/main/java/org/angellock/impl/commands/CommandSpec.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ public void register(Command command){
2525

2626
public @Nullable Command getCommand(String commandName) {
2727
String standardizedCommand = commandName.toLowerCase();
28-
// log.info(standardizedCommand);
29-
// for (String command: registeredCommands.keySet()){
30-
// if (standardizedCommand.startsWith(command)){
3128
return this.registeredCommands.get(standardizedCommand);
32-
// }
33-
// }
34-
// return null;
3529
}
3630

3731
public void executeCommand(CommandResponse response) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.angellock.impl.commands;
22
@FunctionalInterface
33
public interface ICommandAction {
4-
public void onCommand(CommandResponse responseEntity);
4+
void onCommand(CommandResponse responseEntity);
55
}

0 commit comments

Comments
 (0)