Skip to content

Commit 6168b58

Browse files
authored
GH-1257 Add alternative command in custom command feature. (#1257)
* Add support for executing additional commands in CustomCommand feature. * Refactor `CustomCommand` constructors to improve readability and default initialization for commands. * Revert "dependency: Update Versions.OKAERI_CONFIGS to v6.0.0-beta.27 (#1250)" This reverts commit eb307c5. * Update Okaeri Configs version to 6.0.0-beta.27
1 parent 994d475 commit 6168b58

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/customcommand/CustomCommand.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,37 @@
22

33
import com.eternalcode.multification.notice.Notice;
44
import java.io.Serializable;
5+
import java.util.Collections;
56
import java.util.List;
67

78
public class CustomCommand implements Serializable {
89

910
private String name;
1011
private List<String> aliases;
12+
private List<String> commands = Collections.emptyList();
1113
private Notice message;
1214

1315
public CustomCommand() {}
1416

1517
public CustomCommand(String name, List<String> aliases, Notice message) {
18+
this(name, aliases, message, Collections.emptyList());
19+
}
20+
21+
public CustomCommand(String name, List<String> aliases, Notice message, List<String> commands) {
1622
this.name = name;
1723
this.aliases = aliases;
1824
this.message = message;
25+
this.commands = commands;
1926
}
2027

2128
public static CustomCommand of(String commandName, List<String> aliases, Notice message) {
2229
return new CustomCommand(commandName, aliases, message);
2330
}
2431

32+
public static CustomCommand of(String commandName, List<String> aliases, Notice message, List<String> commands) {
33+
return new CustomCommand(commandName, aliases, message, commands);
34+
}
35+
2536
public String getName() {
2637
return name;
2738
}
@@ -30,6 +41,10 @@ public List<String> getAliases() {
3041
return aliases;
3142
}
3243

44+
public List<String> getCommands() {
45+
return commands;
46+
}
47+
3348
Notice getMessage() {
3449
return message;
3550
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/customcommand/CustomCommandBukkitWrapper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ public class CustomCommandBukkitWrapper extends Command {
1515

1616
private final NoticeService noticeService;
1717
private final Notice message;
18+
private final List<String> commands;
1819

1920
protected CustomCommandBukkitWrapper(
2021
@NotNull String name,
2122
@NotNull List<String> aliases,
2223
NoticeService noticeService,
23-
Notice message
24+
Notice message,
25+
List<String> commands
2426
) {
2527
super(name, EMPTY_DESCRIPTION_MESSAGE, EMPTY_USAGE_MESSAGE, aliases);
2628

2729
this.noticeService = noticeService;
2830
this.message = message;
31+
this.commands = commands;
2932
}
3033

3134
@Override
@@ -35,6 +38,11 @@ public boolean execute(@NotNull CommandSender commandSender, @NotNull String s,
3538
.sender(commandSender)
3639
.send();
3740

41+
for (String command : this.commands) {
42+
String commandToExecute = command.startsWith("/") ? command.substring(1) : command;
43+
commandSender.getServer().dispatchCommand(commandSender, commandToExecute);
44+
}
45+
3846
return true;
3947
}
4048
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/customcommand/CustomCommandConfig.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,17 @@ public class CustomCommandConfig extends AbstractConfigurationFile {
121121
"<color:#9d6eef>🗺 Live Server Map:",
122122
"<aqua>https://map.yourserver.com</aqua>",
123123
" ",
124-
"<gray>See what others are building in real time!</gray>"
124+
"<gray>See what others are building in real time!</gray>"
125125
).build()
126-
)
126+
),
127+
CustomCommand.of(
128+
"dom",
129+
List.of("chata"),
130+
Notice.builder()
131+
.chat("<green>Teleportacja do domu...</green>")
132+
.build(),
133+
List.of("home")
134+
)
127135
);
128136

129137
@Override

eternalcore-core/src/main/java/com/eternalcode/core/feature/customcommand/CustomCommandRegistry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ private void registerCustomCommand(CustomCommand customCommand) {
3939
customCommand.getName(),
4040
customCommand.getAliases(),
4141
this.noticeService,
42-
customCommand.getMessage()
42+
customCommand.getMessage(),
43+
customCommand.getCommands()
4344
);
4445

4546
this.commandMap().register(FALLBACK_PREFIX, customCommandBukkitWrapper);

0 commit comments

Comments
 (0)