Skip to content

Commit

Permalink
fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
aabssmc committed Jun 27, 2024
1 parent b2c5183 commit 9711db9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ExprEmbedAuthor extends SimpleExpression<Author> {
return new Author[]{new Author(text, url)};
}
}
return new Author[]{null};
return new Author[]{};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ExprEmbedField extends SimpleExpression<Field> {
if (name != null && value != null){
return new Field[]{new Field(name, value, inline)};
}
return new Field[]{null};
return new Field[]{};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ExprEmbedFooter extends SimpleExpression<Footer> {
return new Footer[]{new Footer(text)};
}
}
return new Footer[]{null};
return new Footer[]{};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
this.image = (Expression<String>) container.getOptional("image", false);
this.author = (Expression<Author>) container.getOptional("author", false);
this.fields = (Expression<Field>) container.getOptional("fields", false);
this.var = (Variable<?>) container.getOptional("variable", false);
return var != null;
if (container.getOptional("variable", false) instanceof Variable<?>){
this.var = (Variable<?>) container.getOptional("variable", false);
return var != null;
} else {
Skript.error("The object expression must be a variable.");
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
this.username = (Expression<String>) container.getOptional("username", false);
this.avatar = (Expression<String>) container.getOptional("avatar", false);
this.embed = (Expression<Embed>) container.getOptional("embed", false);
this.var = (Variable<?>) container.getOptional("variable", false);
return var != null;
if (container.getOptional("variable", false) instanceof Variable<?>){
this.var = (Variable<?>) container.getOptional("variable", false);
return var != null;
} else {
Skript.error("The object expression must be a variable.");
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.CompletableFuture;

import static lol.aabss.skhttp.SkHttp.instance;

Expand Down Expand Up @@ -52,23 +53,25 @@ protected void execute(Event e) {
String name = this.name.getSingle(e);
Object urlString = this.url.getSingle(e);
if (name != null && urlString != null) {
URL url;
InputStream in;
try {
if (urlString instanceof HttpResponse<?>) {
url = ((HttpResponse<?>) urlString).uri().toURL();
} else if (urlString instanceof RequestObject) {
url = ((RequestObject) urlString).request.uri().toURL();
} else if (urlString instanceof String) {
url = new URL((String) urlString);
} else {
return;
CompletableFuture.runAsync(() -> {
URL url;
InputStream in;
try {
if (urlString instanceof HttpResponse<?>) {
url = ((HttpResponse<?>) urlString).uri().toURL();
} else if (urlString instanceof RequestObject) {
url = ((RequestObject) urlString).request.uri().toURL();
} else if (urlString instanceof String) {
url = new URL((String) urlString);
} else {
return;
}
in = url.openStream();
Files.copy(in, new File(instance.getDataFolder().getAbsolutePath(), name).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
in = url.openStream();
Files.copy(in, new File(instance.getDataFolder().getAbsolutePath(), name).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
}
}

Expand Down

0 comments on commit 9711db9

Please sign in to comment.