1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
package de.hype.bbsentials.client;
import com.mojang.brigadier.arguments.StringArgumentType;
import de.hype.bbsentials.api.Options;
import de.hype.bbsentials.chat.Chat;
import de.hype.bbsentials.client.Commands.CommandsOLD;
import de.hype.bbsentials.communication.BBsentialConnection;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.command.CommandSource;
import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static de.hype.bbsentials.chat.Chat.*;
public class BBsentials implements ClientModInitializer {
private boolean initialised = false;
public static Config config;
public static BBsentialConnection bbserver;
public static CommandsOLD coms;
public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000);
/**
* Runs the mod initializer on the client environment.
*/
@Override
public void onInitializeClient() {
ClientPlayConnectionEvents.JOIN.register((a, b, c) -> {
if (!initialised) {
config = Config.load();
Options.setGamma(10);
Chat chat = new Chat();
if (Config.isBingoTime() || config.overrideBingoTime()) {
connectToBBserver();
}
initialised = true;
}
}
);
KeyBinding promptKeyBind = new KeyBinding("Chat Prompt Yes / Open Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "BBsentials");
KeyBindingHelper.registerKeyBinding(promptKeyBind);
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (promptKeyBind.wasPressed()) {
if (config.getLastChatPromptAnswer() != null) {
if (config.isDetailedDevModeEnabled()){
Chat.sendPrivateMessageToSelf(config.getLastChatPromptAnswer());}
MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(config.getLastChatPromptAnswer());
}
config.setLastChatPromptAnswer(null);
}
});
}
public static Config getConfig() {
return config;
}
public static void connectToBBserver() {
if (bbserver != null) {
bbserver.sendHiddenMessage("exit");
}
bbserver = new BBsentialConnection();
bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message));
bbserver.connect(config.getBBServerURL(), 5000);
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
dispatcher.register(ClientCommandManager.literal("bbi")
.then(ClientCommandManager.literal("reconnect")
.executes((context) -> {
connectToBBserver();
return 1;
}))
.then(ClientCommandManager.literal("config")
.then(ClientCommandManager.argument("category", StringArgumentType.string())
.suggests((context, builder) -> {
// Provide tab-completion options for config subfolder
return CommandSource.suggestMatching(new String[]{"save", "reset", "load"}, builder);
}).executes((context) -> {
String category = StringArgumentType.getString(context, "category");
switch (category) {
case "save":
getConfig().save();
sendPrivateMessageToSelf(Formatting.GREEN + "Saved config successfully");
break;
case "load":
BBsentials.config = Config.load();
break;
case "reset":
// Reset logic here
break;
}
return 1;
}))
.then(ClientCommandManager.literal("set-value")
.then(ClientCommandManager.argument("className", StringArgumentType.string())
.suggests((context, builder) -> {
// Provide tab-completion options for classes
ArrayList<String> classNames = new ArrayList<>();
classNames.add("Config");
// Replace with your own logic to retrieve class names
return CommandSource.suggestMatching(classNames, builder);
})
.then(ClientCommandManager.argument("variableName", StringArgumentType.string())
.suggests((context, builder) -> {
// Provide tab-completion options for variable names
List<String> variableNames;
variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
return CommandSource.suggestMatching(variableNames, builder);
})
.then(ClientCommandManager.argument("variableValue", StringArgumentType.string())
.executes((context) -> {
// Handle "variableName" and "variableValue" logic here
String variableName = StringArgumentType.getString(context, "variableName");
String variableValue = StringArgumentType.getString(context, "variableValue");
try {
if (!variableName.toLowerCase().contains("dev")||config.hasBBRoles("dev")){
setVariableValue(getConfig(), variableName, variableValue);}
getConfig().save();
} catch (ClassNotFoundException | NoSuchFieldException |
IllegalAccessException |
InstantiationException |
InvocationTargetException |
NoSuchMethodException e) {
Chat.sendPrivateMessageToSelf("§cInvalid variable or value");
}
return 1;
})))))
.then(ClientCommandManager.literal("get-value")
.then(ClientCommandManager.argument("className", StringArgumentType.string())
.suggests((context, builder) -> {
// Provide tab-completion options for classes
ArrayList<String> classNames = new ArrayList<>();
classNames.add("Config");
// Replace with your own logic to retrieve class names
return CommandSource.suggestMatching(classNames, builder);
})
.then(ClientCommandManager.argument("variableName", StringArgumentType.string())
.suggests((context, builder) -> {
// Provide tab-completion options for variable names
List<String> variableNames;
variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
return CommandSource.suggestMatching(variableNames, builder);
})
.executes((context) -> {
// Handle "variableName" and "variableValue" logic here
String variableName = StringArgumentType.getString(context, "variableName");
try {
Chat.getVariableValue(getConfig(), variableName);
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}))).executes((context) -> {
// Handle the case when "config" argument is not provided
// ...
return 1;
})))
);
}); //bbi}
executionService.scheduleAtFixedRate(new DebugThread(),0,20, TimeUnit.SECONDS);
}
public static void refreshCommands() {
coms = new CommandsOLD();
}
}
|