Skip to content

Commit 114a78a

Browse files
Feature - Auto Text Hotkey Module (#203)
* Add Auto Text Hotkey Module * Add `BLOCK_TEXT_INPUTS` boolean option * add overview * add word * Add `BLOCK_CHAT_MESSAGE_TEXT_INPUTS` option * Add `BLOCK_CHAT_MESSAGE_TEXT_INPUTS` examples --------- Co-authored-by: TrentinTheKid <[email protected]>
1 parent 6266cb7 commit 114a78a

File tree

18 files changed

+516
-0
lines changed

18 files changed

+516
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.autotexthotkey;
25+
26+
import com.lunarclient.apollo.module.ApolloModule;
27+
import com.lunarclient.apollo.module.ModuleDefinition;
28+
import com.lunarclient.apollo.option.ListOption;
29+
import com.lunarclient.apollo.option.Option;
30+
import com.lunarclient.apollo.option.SimpleOption;
31+
import io.leangen.geantyref.TypeToken;
32+
import java.util.ArrayList;
33+
import java.util.Arrays;
34+
import java.util.List;
35+
36+
/**
37+
* Represents the auto text hotkey module.
38+
*
39+
* @since 1.1.8
40+
*/
41+
@ModuleDefinition(id = "auto_text_hotkey", name = "Auto Text Hotkey")
42+
public final class AutoTextHotkeyModule extends ApolloModule {
43+
44+
/**
45+
* Block text inputs.
46+
*
47+
* @since 1.1.8
48+
*/
49+
public static final SimpleOption<Boolean> BLOCK_TEXT_INPUTS = Option.<Boolean>builder()
50+
.comment("Set to 'true' to block certain text inputs, otherwise 'false'.")
51+
.node("block-text-inputs").type(TypeToken.get(Boolean.class))
52+
.defaultValue(false).notifyClient().build();
53+
54+
/**
55+
* A list of text inputs that are blocked and cannot be used by the user.
56+
*
57+
* @since 1.1.8
58+
*/
59+
public static final ListOption<String> BLOCKED_TEXT_INPUTS = Option.<String>list()
60+
.comment("A list of text inputs that are blocked and cannot be used by the user.")
61+
.node("blocked-text-inputs").type(new TypeToken<List<String>>() {})
62+
.defaultValue(new ArrayList<>(Arrays.asList("/sellall", "/msg", "/pay")))
63+
.notifyClient().build();
64+
65+
/**
66+
* Block chat message text inputs.
67+
*
68+
* @since 1.1.8
69+
*/
70+
public static final SimpleOption<Boolean> BLOCK_CHAT_MESSAGE_TEXT_INPUTS = Option.<Boolean>builder()
71+
.comment("Set to 'true' to block chat message text inputs, otherwise 'false'.")
72+
.node("block-chat-message-text-inputs").type(TypeToken.get(Boolean.class))
73+
.defaultValue(false).notifyClient().build();
74+
75+
AutoTextHotkeyModule() {
76+
this.registerOptions(
77+
AutoTextHotkeyModule.BLOCK_TEXT_INPUTS,
78+
AutoTextHotkeyModule.BLOCKED_TEXT_INPUTS,
79+
AutoTextHotkeyModule.BLOCK_CHAT_MESSAGE_TEXT_INPUTS
80+
);
81+
}
82+
83+
@Override
84+
public boolean isClientNotify() {
85+
return true;
86+
}
87+
88+
}

bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/ApolloApiExamplePlatform.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.lunarclient.apollo.example.api.commands.debug.ApolloDebugCommand;
2929
import com.lunarclient.apollo.example.api.debug.SpamPacketDebug;
3030
import com.lunarclient.apollo.example.api.listener.ApolloPlayerApiListener;
31+
import com.lunarclient.apollo.example.api.module.AutoTextHotkeyApiExample;
3132
import com.lunarclient.apollo.example.api.module.BeamApiExample;
3233
import com.lunarclient.apollo.example.api.module.BorderApiExample;
3334
import com.lunarclient.apollo.example.api.module.ChatApiExample;
@@ -75,6 +76,7 @@ public void registerCommands() {
7576

7677
@Override
7778
public void registerModuleExamples() {
79+
this.setAutoTextHotkeyExample(new AutoTextHotkeyApiExample());
7880
this.setBeamExample(new BeamApiExample());
7981
this.setBorderExample(new BorderApiExample());
8082
this.setChatExample(new ChatApiExample());
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.api.module;
25+
26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.example.module.impl.AutoTextHotkeyExample;
28+
import com.lunarclient.apollo.module.autotexthotkey.AutoTextHotkeyModule;
29+
import com.lunarclient.apollo.option.Options;
30+
import java.util.List;
31+
32+
public class AutoTextHotkeyApiExample extends AutoTextHotkeyExample {
33+
34+
private final AutoTextHotkeyModule autoTextHotkeyModule = Apollo.getModuleManager().getModule(AutoTextHotkeyModule.class);
35+
36+
@Override
37+
public void setBlockedTextInputs(List<String> blockedTextInputs) {
38+
Options options = this.autoTextHotkeyModule.getOptions();
39+
options.set(AutoTextHotkeyModule.BLOCK_TEXT_INPUTS, true);
40+
options.set(AutoTextHotkeyModule.BLOCKED_TEXT_INPUTS, blockedTextInputs);
41+
}
42+
43+
@Override
44+
public void setBlockChatMesssageTextInputs(boolean value) {
45+
this.autoTextHotkeyModule.getOptions().set(AutoTextHotkeyModule.BLOCK_CHAT_MESSAGE_TEXT_INPUTS, value);
46+
}
47+
48+
}

bukkit-example-api/src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ api-version: 1.13
88
commands:
99
apollodebug:
1010
description: "Apollo Debug!"
11+
autotexthotkey:
12+
description: "Auto Text Hotkey!"
1113
beam:
1214
description: "Beams!"
1315
border:

bukkit-example-common/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.lunarclient.apollo.example;
2525

26+
import com.lunarclient.apollo.example.command.AutoTextHotkeyCommand;
2627
import com.lunarclient.apollo.example.command.BeamCommand;
2728
import com.lunarclient.apollo.example.command.BorderCommand;
2829
import com.lunarclient.apollo.example.command.ChatCommand;
@@ -51,6 +52,7 @@
5152
import com.lunarclient.apollo.example.command.TransferCommand;
5253
import com.lunarclient.apollo.example.command.VignetteCommand;
5354
import com.lunarclient.apollo.example.command.WaypointCommand;
55+
import com.lunarclient.apollo.example.module.impl.AutoTextHotkeyExample;
5456
import com.lunarclient.apollo.example.module.impl.BeamExample;
5557
import com.lunarclient.apollo.example.module.impl.BorderExample;
5658
import com.lunarclient.apollo.example.module.impl.ChatExample;
@@ -89,6 +91,7 @@ public abstract class ApolloExamplePlugin extends JavaPlugin {
8991
@Getter
9092
private static ApolloExamplePlugin instance;
9193

94+
private AutoTextHotkeyExample autoTextHotkeyExample;
9295
private BeamExample beamExample;
9396
private BorderExample borderExample;
9497
private ChatExample chatExample;
@@ -137,6 +140,7 @@ public void onDisable() {
137140
}
138141

139142
private void registerCommonCommands() {
143+
this.getCommand("autotexthotkey").setExecutor(new AutoTextHotkeyCommand());
140144
this.getCommand("beam").setExecutor(new BeamCommand());
141145
this.getCommand("border").setExecutor(new BorderCommand());
142146
this.getCommand("chat").setExecutor(new ChatCommand());
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.command;
25+
26+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
27+
import com.lunarclient.apollo.example.module.impl.AutoTextHotkeyExample;
28+
import java.util.Arrays;
29+
import java.util.List;
30+
import org.bukkit.command.Command;
31+
import org.bukkit.command.CommandExecutor;
32+
import org.bukkit.command.CommandSender;
33+
import org.bukkit.entity.Player;
34+
import org.jetbrains.annotations.NotNull;
35+
36+
public class AutoTextHotkeyCommand implements CommandExecutor {
37+
38+
@Override
39+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
40+
if (!(sender instanceof Player)) {
41+
sender.sendMessage("Player only!");
42+
return true;
43+
}
44+
45+
Player player = (Player) sender;
46+
47+
if (args.length < 2) {
48+
player.sendMessage("/autotexthotkey blockedTextInputs <inputs>");
49+
player.sendMessage("/autotexthotkey blockChatMessageTextInputs <true/false>");
50+
return true;
51+
}
52+
53+
AutoTextHotkeyExample autoTextHotkeyExample = ApolloExamplePlugin.getInstance().getAutoTextHotkeyExample();
54+
55+
switch (args[0].toLowerCase()) {
56+
case "blockedtextinputs": {
57+
List<String> blockedInputs = Arrays.asList(Arrays.copyOfRange(args, 1, args.length));
58+
autoTextHotkeyExample.setBlockedTextInputs(blockedInputs);
59+
60+
player.sendMessage("Blocked text inputs have been set to: " + String.join(", ", blockedInputs));
61+
break;
62+
}
63+
64+
case "blockchatmessagetextinputs": {
65+
boolean value = Boolean.parseBoolean(args[1]);
66+
autoTextHotkeyExample.setBlockChatMesssageTextInputs(value);
67+
68+
player.sendMessage("Block chat message text inputs has been set to " + value);
69+
break;
70+
}
71+
72+
default: {
73+
player.sendMessage("/autotexthotkey blockedTextInputs <inputs>");
74+
player.sendMessage("/autotexthotkey blockChatMessageTextInputs <true/false>");
75+
break;
76+
}
77+
}
78+
79+
return true;
80+
}
81+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.module.impl;
25+
26+
import com.lunarclient.apollo.example.module.ApolloModuleExample;
27+
import java.util.List;
28+
29+
public abstract class AutoTextHotkeyExample extends ApolloModuleExample {
30+
31+
public abstract void setBlockedTextInputs(List<String> blockedTextInputs);
32+
33+
public abstract void setBlockChatMesssageTextInputs(boolean value);
34+
35+
}

bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/ApolloJsonExamplePlatform.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.lunarclient.apollo.example.ApolloExamplePlugin;
2727
import com.lunarclient.apollo.example.ApolloExampleType;
2828
import com.lunarclient.apollo.example.json.listener.ApolloPlayerJsonListener;
29+
import com.lunarclient.apollo.example.json.module.AutoTextHotkeyJsonExample;
2930
import com.lunarclient.apollo.example.json.module.BeamJsonExample;
3031
import com.lunarclient.apollo.example.json.module.BorderJsonExample;
3132
import com.lunarclient.apollo.example.json.module.ChatJsonExample;
@@ -66,6 +67,7 @@ public void enable() {
6667

6768
@Override
6869
public void registerModuleExamples() {
70+
this.setAutoTextHotkeyExample(new AutoTextHotkeyJsonExample());
6971
this.setBeamExample(new BeamJsonExample());
7072
this.setBorderExample(new BorderJsonExample());
7173
this.setChatExample(new ChatJsonExample());
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.example.json.module;
25+
26+
import com.google.gson.JsonObject;
27+
import com.lunarclient.apollo.example.json.util.JsonPacketUtil;
28+
import com.lunarclient.apollo.example.json.util.JsonUtil;
29+
import com.lunarclient.apollo.example.module.impl.AutoTextHotkeyExample;
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
33+
34+
public class AutoTextHotkeyJsonExample extends AutoTextHotkeyExample {
35+
36+
@Override
37+
public void setBlockedTextInputs(List<String> blockedTextInputs) {
38+
Map<String, Object> properties = new HashMap<>();
39+
properties.put("block-text-inputs", true);
40+
properties.put("blocked-text-inputs", blockedTextInputs);
41+
42+
JsonObject message = JsonUtil.createEnableModuleObjectWithType("auto_text_hotkey", properties);
43+
JsonPacketUtil.broadcastPacket(message);
44+
}
45+
46+
@Override
47+
public void setBlockChatMesssageTextInputs(boolean value) {
48+
Map<String, Object> properties = new HashMap<>();
49+
properties.put("block-chat-message-text-inputs", value);
50+
51+
JsonObject message = JsonUtil.createEnableModuleObjectWithType("auto_text_hotkey", properties);
52+
JsonPacketUtil.broadcastPacket(message);
53+
}
54+
55+
}

bukkit-example-json/src/main/resources/plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ softdepend: [ Apollo-Bukkit ]
66
api-version: 1.13
77

88
commands:
9+
autotexthotkey:
10+
description: "Auto Text Hotkey!"
911
beam:
1012
description: "Beams!"
1113
border:

0 commit comments

Comments
 (0)