|
42 | 42 | import net.minecraft.util.Identifier; |
43 | 43 | import net.minecraft.world.GameMode; |
44 | 44 |
|
45 | | -import java.io.IOException; |
| 45 | +import java.io.*; |
| 46 | +import java.net.*; |
46 | 47 | import java.nio.file.Files; |
47 | 48 | import java.nio.file.Path; |
48 | 49 | import java.text.SimpleDateFormat; |
@@ -119,6 +120,31 @@ public enum ScriptActionType { |
119 | 120 | ctx.value("Value") |
120 | 121 | ))), |
121 | 122 |
|
| 123 | + GET_REQUEST(builder -> builder.name("Get Webrequest") |
| 124 | + .description("Makes a get request to the internet.") |
| 125 | + .icon(Items.GRASS_BLOCK) |
| 126 | + .arg("Result", ScriptActionArgumentType.VARIABLE) |
| 127 | + .arg("Url", ScriptActionArgumentType.TEXT) |
| 128 | + .category(ScriptActionCategory.VARIABLES) |
| 129 | + .action(ctx -> { |
| 130 | + try{ |
| 131 | + StringBuilder result = new StringBuilder(); |
| 132 | + URL url = new URL(ctx.value("Url").asText()); |
| 133 | + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| 134 | + conn.setRequestMethod("GET"); |
| 135 | + try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { |
| 136 | + for (String line; (line = reader.readLine()) != null; ) { |
| 137 | + result.append(line); |
| 138 | + } |
| 139 | + } |
| 140 | + ctx.task().context().setVariable(ctx.variable("Result").name(), new ScriptTextValue(result.toString())); |
| 141 | + }catch(MalformedURLException ex){ |
| 142 | + |
| 143 | + }catch(IOException ex){ |
| 144 | + |
| 145 | + } |
| 146 | + })), |
| 147 | + |
122 | 148 | INCREMENT(builder -> builder.name("Increment") |
123 | 149 | .description("Increments a variable by a value.") |
124 | 150 | .icon(Items.GLOWSTONE_DUST) |
@@ -911,7 +937,7 @@ public enum ScriptActionType { |
911 | 937 | String text = ctx.value("Text").asText(); |
912 | 938 | ctx.task().context().setVariable(ctx.variable("Result").name(), new ScriptNumberValue(text.length())); |
913 | 939 | })), |
914 | | - |
| 940 | + |
915 | 941 | READ_FILE(builder -> builder.name("Read File") |
916 | 942 | .description("Reads a file from the scripts folder.") |
917 | 943 | .icon(Items.WRITTEN_BOOK) |
@@ -1231,7 +1257,7 @@ public enum ScriptActionType { |
1231 | 1257 | OverlayManager.getInstance().add("Unable to set text field value! (Unknown menu type)"); |
1232 | 1258 | } |
1233 | 1259 | })), |
1234 | | - |
| 1260 | + |
1235 | 1261 | RANDOM_INT(builder -> builder.name("Random Int") |
1236 | 1262 | .description("Generates a random whole number between two other numbers.") |
1237 | 1263 | .icon(Items.HOPPER) |
@@ -1266,7 +1292,7 @@ public enum ScriptActionType { |
1266 | 1292 | new ScriptNumberValue(result) |
1267 | 1293 | ); |
1268 | 1294 | })), |
1269 | | - |
| 1295 | + |
1270 | 1296 | RANDOM_NUMBER(builder -> builder.name("Random Number") |
1271 | 1297 | .description("Generates a random number between two other numbers.") |
1272 | 1298 | .icon(Items.HOPPER) |
|
0 commit comments