diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82b20ac..75f3081 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Build on: push: branches: - - '1.20.2' + - '1.20.4' jobs: build: diff --git a/README.md b/README.md index 4eccbc9..8bee482 100644 --- a/README.md +++ b/README.md @@ -10,100 +10,30 @@ DFScript is a mod created for DiamondFire to allow scripting on the client. This ## About DFScript adds the ability to add new features through the added -'scripting' ability. Scripting is constructing event based code (similar to DiamondFire) inside a client side menu, with the events and actions being simple client-based activities. +'scripting' ability. Scripting is constructing event based code (similar to DiamondFire) inside a web ui, with the events and actions being simple client-based activities. -For example, a script could play a sound when the player receives a message with their name in it, or automatically add the @ character in front of sent messages. +For example, a script could play a sound when the player receives a message with their name in it, or automatically add the @ character in front of sent messages. ___ -To access the scripting menu, run `/scripts`, and a menu will appear showing all of the scripts you have installed. Here you can toggle, delete, edit and upload scripts. -*(A simple menu which can disable scripts can be accessed through the button in the top left.)* +To access the DFScript menu, run `/dfscript`, and a menu will appear showing many different options, you can then press **Installed Scripts** to view scripts you currently have installed, here you can toggle scripts on and off or press **Dashboard** to visit the scripting dashboard and create/install new scripts. +*(The same many can be accessed on the multiplayer connection screen)* -To install a script you can click 'Add' and browse through scripts that others have created, or select 'New Script' if you would like to create one yourself. +To install a script you can locate the one you wish to install via the [public directory](https://dfscript.techstreet.dev/public/) and then press **Install Script** the script will then automatically install on your client and be enabled. ## Creating Scripts +To create a new script, access the [dashboard](https://dfscript.techstreet.dev/) from here you can press the **New Script** button, and then name and version your script, it will be created and displayed in the main menu. From here, you can edit, upload and delete. -To create a new script, run `/script`, select 'Add', and 'New Script'. After naming your script, it will be created and displayed in the main menu. From here, you can edit, upload, delete, and toggle your script. - -Here is what each of these actions do: -- ![Edit icon](https://i.imgur.com/T01dmur.png) Edit: From this menu, you can add options and code to your script. -- ![Upload icon]( https://i.imgur.com/0FuRXJ1.png) Upload: Uploads the script so that others with the mod can install and use it. (They can not modify the code) -- ![Delete icon](https://i.imgur.com/Ya9xyWH.png) Delete: Deletes your script permanently. -- ![enter image description here](https://i.imgur.com/Av7lZmu.png)**/**![enter image description here](https://i.imgur.com/I8PXtvr.png) Toggle: Toggles your script on and off. When a script is off, it does not run at all. (Red means script is currently on, green means script is off) - -To edit your script, select the edit icon and a new menu will be opened. From here, you can add code, change your scripts description and add config options. - -- ![Settings Icon](https://i.imgur.com/fy9SfQP.png) From here you can write a short description about your script to tell others who may use it any important information. -You can also add config options which users can change without accessing the code. The values of these options can be used in your code. (More info [later](https://github.com/not-first/DFScript-updated-readme-/edit/1.19.2/README.md#changing-parameters)) - - - -## Interactions -**Left click** -- Use on buttons to click them -- Use to add code to your script, and to add parameters to code blocks -- Use in your script menu to edit parameters of a code block -- Use to select text box - -**Right Click** -- Use on code blocks in your script menu to bring up a small menu where you can: - - Delete the code block - - Insert code before the code block - - Insert new code after the code block -- Can also be used on buttons to click them - -**Escape** -- Use in any menu to go back to the previous menu - - **Scroll** -- Moves a menu up and down - -## Editing Scripts -*Note that it is only possible to edit code in a script you have made yourself. Any downloaded script will still be able to be deleted, toggled, and have its options changed, but the code will be inaccessible.* - -Select the 'Add' button to add code to your script. From there you can select the category, and a specific code block. There is a short description about each block if you hover over them to help you understand what they do. - -All code is set in one menu. Just like in DiamondFire, all code must start with an event. When that event is triggered, the code inside it will run from top to bottom. - -### Changing Parameters -Most code blocks need parameters inside them so they can execute properly. You can view what parameters a code blocks needs by hovering over its icon in your script menu. An asterisk after a parameter means that a value for it is not required and the code block can run without it. - -To add values for these parameters, left click on the code block you would like to edit and a menu will be brought up. Any parameters already in the code block will show. To add values, click the 'Add' button, and a new menu with a text input box will appear. -___ -This input screen has two important sections. -1. The text box. Here is where you input a number, string, name of a variable or any other type of value required. Make sure you have finished the value you would like to add to your code block before selecting a type. -2. The value type. Here is where you select what type of value you would like to add to your code block. For example, if I wanted to add a variable called 'score', I would type `score` in the text box, then click on the variable icon (magma cream). A variable named 'score' will be added to the code block. -Most value types and their icons such as a text, a number and a variable you may recognise from DiamondFire, but here are some ones you may not be familiar with: - - - Client Value: *(Requires no text input.)* Selecting this value will bring up a menu containing values related to the client, very similar to DiamondFire's game values. - Some of these can be used in any scenario, such as the number of the players selected hotbar slot, or the players main hand item. - Others can only used if the code is under a certain event, such as the last received message *(pairs with the 'OnRecieveChat' event)* or the last received sound *(pairs with the 'OnRecieveSound' event)*. - - Config Value: *(Requires no text input.)* Selecting this value will bring up a menu of all the config options you have added to your script. These will act as a variable and return a value of the option. -For example, if I had created Option 1 as a string, and the user had set it to `complete`, the config value for options 1 would return 'complete' as a string. -These can be nearly any value type, so pay attention to make sure the code block you are using supports the value type. - -*Currently, changing the order and contents of added parameters is not supported, so you will have to delete and redo if you make a mistake.* ## Disabling Scripts - !! -Sometimes when you are creating a script, you may accidentally make your client complete actions which are against DiamondFire rules, such as making your client spam, or other similar actions. If this is the case, immediately leave the server. In the top left if your multiplayer screen, there will be a button button (![Scripts icon]( https://i.imgur.com/Q2phpZz.png)) which will open up a version of the scripts menu where scripts can be disabled. When you rejoin the server the script will now be disabled. **You can edit code inside a disabled script, so make sure you have fixed the issue before re-enabling the script.** -If the issue came from a script you did not make, report the script in the [discord](https://discord.gg/gtfFwWEapx) so it can be removed. -## Downloading Scripts -To download a script that someone else has made, open the main scripts menu, select add, and there will be a list of scripts others have made as well as a search bar. Scripts with a star next to their name mean that they are verified and safe to use. +Sometimes when you are creating a script, you may accidentally make your client complete actions which are against DiamondFire rules, such as making your client spam, or other similar actions. If this is the case, immediately leave the server. In the top left if your multiplayer screen, there will be a button button (![Scripts icon](https://i.imgur.com/Q2phpZz.png)) which will open up a version of the DFScript menu where scripts can be disabled. When you rejoin the server the script will now be disabled. -**!! Unverified scripts may potentially be dangerous, not towards your computer, but they may make your client spam or do other activities not appreciated on DiamondFire. You can ask in the discord if you are unsure about a certain script. !!** - -Selecting a script from here will bring up a menu showing information about the script such as the authors name, script ID, and if it has been approved or not. -Clicking the install button from here will add the script to your client. A message will be shown in chat verifying the script has been loaded. This downloaded script will appear in the normal scripts menu, just without the ability to upload it or edit its code. - -## Commands and Files - -All DFScript commands begin with `/scripts`. -- `/scripts` Opens the main script menu. -- `/scripts recursion (number)` Changes the number of events that can trigger in a single tick. -- `/scripts reload` Reloads all of the scripts on your machine. Use this is you are manually installing are changing scripts through files. -- `/scripts vars (script name)` Lists the values of all the variables in the selected script. Similar to DiamondFire's /p vars command. - -To access script files go to `%appdata%\.minecraft\DFScript` on your machine. Here there will be a 'Scripts' folder, which contains all the scripts you have installed in the form of a json file. If a script manages text files, they will be in a sub folder called `scriptname.json-files`. +If the issue came from a script you did not make, report the script in the [discord](https://discord.gg/gtfFwWEapx) so it can be removed. -You can easily back up scripts here by copy and pasting the json file into another location. Pasting and deleting json files from this folder will do the same in-game, so be careful about what you change. +## Commands +All DFScript commands begin with `/dfscript`. +- `/dfscript` Opens the main DFScript menu. +- `/dfscript recursion (number)` Changes the number of events that can trigger in a single tick. +- `/dfscript reload` Downloads and reloads all of the scripts on your machine. +- `/dfscript vars (script name)` Lists the values of all the variables in the selected script. Similar to DiamondFire's /p vars command. ___

diff --git a/build.gradle b/build.gradle index eded3a9..e962bdf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' id 'com.github.johnrengelman.shadow' version '7.1.2' } diff --git a/gradle.properties b/gradle.properties index 807338d..9ad951b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.2 -yarn_mappings=1.20.2+build.4 -loader_version=0.15.3 +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.3 +loader_version=0.15.7 # Mod Properties mod_version=1.0-SNAPSHOT maven_group=io.github.techstreet.dfscript archives_base_name=DFScript # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.91.2+1.20.2 \ No newline at end of file +fabric_version=0.96.1+1.20.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59bc51a..509c4a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index c53aefa..aeb74cb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions $var, ${var}, ${var:-default}, ${var+SET}, -# ${var#prefix}, ${var%suffix}, and $( cmd ); -# * compound commands having a testable exit status, especially case; -# * various built-in commands including command, set, and ulimit. +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -143,12 +140,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +210,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java b/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java new file mode 100644 index 0000000..2459b31 --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java @@ -0,0 +1,88 @@ +package io.github.techstreet.dfscript; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import io.github.techstreet.dfscript.loader.Loadable; +import io.github.techstreet.dfscript.script.action.ScriptActionArgument; +import io.github.techstreet.dfscript.script.action.ScriptActionArgumentList; +import io.github.techstreet.dfscript.script.action.ScriptActionType; +import io.github.techstreet.dfscript.script.argument.ScriptClientValueArgument; +import io.github.techstreet.dfscript.script.event.ScriptEventType; + +import java.io.File; +import java.nio.file.Files; + +public class ActiondumpHandler implements Loadable { + @Override + public void load() { + JsonObject obj = new JsonObject(); + JsonArray array = new JsonArray(); + + for (ScriptEventType type : ScriptEventType.values()) { + JsonObject event = new JsonObject(); + event.addProperty("identifier", type.name()); + event.addProperty("name", type.getName()); + event.addProperty("description", type.getDescription()); + event.addProperty("icon", type.getItem().toString()); + array.add(event); + } + + obj.add("events", array); + array = new JsonArray(); + + for (ScriptActionType type : ScriptActionType.values()) { + JsonObject event = new JsonObject(); + JsonArray array2 = new JsonArray(); + event.addProperty("identifier", type.name()); + event.addProperty("name", type.getName()); + event.addProperty("category", type.getCategory().name()); + event.addProperty("description", String.join("\n", type.getDescription())); + event.addProperty("icon", type.getItem().toString()); + + for (ScriptActionArgument arg : type.getArguments()) { + JsonObject arg2 = new JsonObject(); + arg2.addProperty("type", arg.getType().name()); + arg2.addProperty("type_icon", arg.getType().getIcon().toString()); + arg2.addProperty("type_name", arg.getType().getName()); + arg2.addProperty("name", arg.getName()); + arg2.addProperty("optional", arg.isOptional()); + arg2.addProperty("plural", arg.isPlural()); + + array2.add(arg2); + } + + + //event.addProperty("icon", type.get().toString()); + event.add("arguments", array2); + array.add(event); + } + + obj.add("actions", array); + array = new JsonArray(); + + for (ScriptClientValueArgument type : ScriptClientValueArgument.values()) { + JsonObject event = new JsonObject(); + event.addProperty("identifier", type.name()); + event.addProperty("name", type.getName()); + event.addProperty("description", String.join("\n", type.getDescription())); + event.addProperty("icon", type.getItem().toString()); + event.addProperty("type", type.getType().name()); + event.addProperty("type_icon", type.getType().getIcon().toString()); + event.addProperty("type_name", type.getType().getName()); + + array.add(event); + } + + obj.add("client_values", array); + + File file = new File("DFScript/actiondump.json"); + DFScript.LOGGER.info("Dumping action data to " + file.getAbsolutePath()); + + try { + if (!file.exists()) file.createNewFile(); + Files.write(file.toPath(), DFScript.GSON.toJson(obj).getBytes()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/io/github/techstreet/dfscript/DFScript.java b/src/main/java/io/github/techstreet/dfscript/DFScript.java index 4a1c34e..992d0d3 100644 --- a/src/main/java/io/github/techstreet/dfscript/DFScript.java +++ b/src/main/java/io/github/techstreet/dfscript/DFScript.java @@ -61,13 +61,14 @@ public void onInitialize() { loader.load(new Scheduler()); loader.load(new UpdateAlerts()); loader.load(new OverlayManager()); + loader.load(new ActiondumpHandler()); LOGGER.info("Initialized"); } public void onClose() { LOGGER.info("Closing..."); - + AuthHandler.deauth(); LOGGER.info("Closed."); } } diff --git a/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java b/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java index 28e4b36..89697bf 100644 --- a/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java +++ b/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java @@ -1,7 +1,7 @@ package io.github.techstreet.dfscript.commands; import com.mojang.brigadier.CommandDispatcher; -import io.github.techstreet.dfscript.commands.misc.ScriptsCommand; +import io.github.techstreet.dfscript.commands.misc.DFScriptCommand; import io.github.techstreet.dfscript.loader.Loadable; import java.util.ArrayList; import java.util.List; @@ -23,7 +23,7 @@ public CommandManager getInstance() { @Override public void load() { - commands.add(new ScriptsCommand()); + commands.add(new DFScriptCommand()); ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> attachTo(dispatcher)); } diff --git a/src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java b/src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java similarity index 87% rename from src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java rename to src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java index 2255ea4..4f5f663 100644 --- a/src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java +++ b/src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java @@ -7,10 +7,10 @@ import io.github.techstreet.dfscript.commands.Command; import io.github.techstreet.dfscript.commands.arguments.StringFuncArgumentType; import io.github.techstreet.dfscript.event.system.EventManager; -import io.github.techstreet.dfscript.screen.script.ScriptListScreen; +import io.github.techstreet.dfscript.features.AuthHandler; +import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen; import io.github.techstreet.dfscript.script.Script; import io.github.techstreet.dfscript.script.ScriptManager; -import io.github.techstreet.dfscript.script.values.ScriptValue; import io.github.techstreet.dfscript.script.values.ScriptVariable; import io.github.techstreet.dfscript.util.chat.ChatUtil; import java.util.List; @@ -19,22 +19,22 @@ import static io.github.techstreet.dfscript.commands.arguments.StringFuncArgumentFunctions.SCRIPTS; -public class ScriptsCommand implements Command { +public class DFScriptCommand implements Command { @Override public void register(CommandDispatcher cd) { cd.register( - literal("scripts") + literal("dfscript") .executes(ctx -> { - DFScript.MC.send(() -> DFScript.MC.setScreen(new ScriptListScreen(true))); + DFScript.MC.send(() -> DFScript.MC.setScreen(new DFScriptScreen())); return 0; }) .then(literal("reload") - .executes(ctx -> { - ScriptManager.getInstance().reload(); - ChatUtil.info("Scripts reloaded!"); - return 0; - }) + .executes(ctx -> { + AuthHandler.updateScripts(); + ChatUtil.info("Scripts updated and reloaded!"); + return 0; + }) ) .then(literal("vars") .then(argument("script", new StringFuncArgumentType(SCRIPTS, false) @@ -92,7 +92,7 @@ private void listVars(String script, String filter) { @Override public String getDescription() { return """ - [blue]/scripts[reset] + [blue]/dfscript[reset] Opens a GUI to edit custom DFScript scripts. """; @@ -100,6 +100,6 @@ public String getDescription() { @Override public String getName() { - return "/scripts"; + return "/dfscript"; } } diff --git a/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java b/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java index 90a51de..3979c38 100644 --- a/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java +++ b/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java @@ -2,7 +2,6 @@ import io.github.techstreet.dfscript.event.system.Event; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; public record HudRenderEvent(DrawContext context) implements Event { diff --git a/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java b/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java index b1ae3a6..1a79d62 100644 --- a/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java +++ b/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java @@ -1,9 +1,10 @@ package io.github.techstreet.dfscript.event; import io.github.techstreet.dfscript.event.system.Event; -import java.net.InetSocketAddress; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import java.net.InetSocketAddress; + public class ServerJoinEvent implements Event { private final GameJoinS2CPacket packet; private final InetSocketAddress address; diff --git a/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java b/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java index e7cb980..5e6b70b 100644 --- a/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java +++ b/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java @@ -7,33 +7,119 @@ import com.mojang.authlib.exceptions.AuthenticationException; import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.loader.Loadable; +import io.github.techstreet.dfscript.script.ScriptManager; import io.github.techstreet.dfscript.script.util.AuthcodeResponse; import io.github.techstreet.dfscript.script.util.ServercodeResponse; import net.minecraft.client.session.Session; import org.apache.commons.codec.digest.DigestUtils; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; import java.util.Objects; import java.util.UUID; -import static io.github.techstreet.dfscript.screen.script.ScriptAddScreen.readAll; - public class AuthHandler implements Loadable { private static String authCode = null; - private static boolean staff = false; @Override public void load() { regen(); } + public static void updateScripts() { + try { + URL url = new URL("https://api.techstreet.tech/dfscript/scripts/"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("authorization", AuthHandler.getAuthCode()); + con.setDoOutput(true); + + try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + String responseLine; + + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + + ArrayList expected = new ArrayList<>(); + JsonObject scripts = JsonParser.parseString(response.toString()).getAsJsonObject(); + scripts.getAsJsonArray("scripts").forEach(script -> expected.add(script.getAsJsonObject().get("id").getAsLong() + ".json")); + + File file = new File("DFScript/Scripts"); + for (File f : Objects.requireNonNull(file.listFiles())) { + if (!expected.contains(f.getName())) { + f.delete(); + } + } + + scripts.getAsJsonArray("scripts").forEach(script -> { + try { + File f = new File("DFScript/Scripts/" + script.getAsJsonObject().get("id").getAsLong() + ".json"); + if (!f.exists()) { + f.createNewFile(); + + JsonObject obj = script.getAsJsonObject(); + obj.addProperty("disabled", false); + obj.add("config", new JsonArray()); + + Files.write(f.toPath(), DFScript.GSON.toJson(obj).getBytes(StandardCharsets.UTF_8)); + } else { + JsonObject obj = JsonParser.parseString(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8)).getAsJsonObject(); + obj.add("headers", script.getAsJsonObject().get("headers").getAsJsonArray()); + + Files.write(f.toPath(), DFScript.GSON.toJson(obj).getBytes(StandardCharsets.UTF_8)); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + + ScriptManager.getInstance().reload(); + } + } catch (Exception e) { + regen(); + e.printStackTrace(); + } + } + + public static void checkAuth() { + try { + URL url = new URL("https://api.techstreet.tech/dfscript/auth/refresh/"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + con.setRequestProperty("authorization", AuthHandler.getAuthCode()); + con.setDoOutput(true); + + con.getInputStream(); + if (con.getResponseCode() != 200) { + regen(); + } + } catch (Exception e) { + regen(); + e.printStackTrace(); + } + } + + public static void deauth() { + try { + URL url = new URL("https://api.techstreet.tech/dfscript/auth/deauth/"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + con.setRequestProperty("authorization", AuthHandler.getAuthCode()); + con.setDoOutput(true); + + con.getInputStream(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public static void regen() { URL url; HttpURLConnection con; @@ -42,7 +128,7 @@ public static void regen() { try { // Authorization step one - Create a random clientcode - url = new URL("https://DFScript-Server.techstreetdev.repl.co/auth/secret/"); + url = new URL("https://api.techstreet.tech/dfscript/auth/clientcode/"); con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); @@ -85,7 +171,7 @@ public static void regen() { } // Authorization step two - Generate the authcode - url = new URL("https://DFScript-Server.techstreetdev.repl.co/auth/auth/"); + url = new URL("https://api.techstreet.tech/dfscript/auth/"); con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); @@ -115,41 +201,25 @@ public static void regen() { authCode = authcodeResponse.getAuthcode(); DFScript.LOGGER.info("Server authorization code successfully generated!"); } + + updateScripts(); } catch (Exception e) { // e.printStackTrace(); } + } - try { - URLConnection con2 = new URL("https://dfscript-server.techstreetdev.repl.co/staff/").openConnection(); - con2.setReadTimeout(5000); - con2.setConnectTimeout(5000); - InputStream is = con2.getInputStream(); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - obj = JsonParser.parseString(readAll(rd)).getAsJsonObject(); - - JsonArray array = obj.get("staff").getAsJsonArray(); - boolean localStaff = false; - - for (JsonElement staffMember : array) { - if (Objects.equals(staffMember.getAsString(), DFScript.PLAYER_UUID)) { - staff = true; - localStaff = true; - } - } + public static String readAll(Reader rd) throws IOException { + StringBuilder sb = new StringBuilder(); + int cp; - if (!localStaff) { - staff = false; - } - } catch (Exception e) { -// e.printStackTrace(); + while ((cp = rd.read()) != -1) { + sb.append((char) cp); } + + return sb.toString(); } public static String getAuthCode() { return authCode; } - - public static boolean getStaffMember() { - return staff; - } } diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java index 1be8341..e725843 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java @@ -1,19 +1,9 @@ package io.github.techstreet.dfscript.mixin.game; -import com.mojang.blaze3d.systems.RenderSystem; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.event.*; +import io.github.techstreet.dfscript.event.ServerLeaveEvent; import io.github.techstreet.dfscript.event.system.EventManager; -import io.github.techstreet.dfscript.util.hypercube.HypercubeRank; -import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil; import net.minecraft.client.network.ClientCommonNetworkHandler; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.listener.ClientCommonPacketListener; import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket; -import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; -import net.minecraft.network.packet.s2c.play.TeamS2CPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java index 1f8a4dc..fa70ab6 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java @@ -6,17 +6,15 @@ import io.github.techstreet.dfscript.event.system.EventManager; import io.github.techstreet.dfscript.util.hypercube.HypercubeRank; import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil; -import java.net.InetSocketAddress; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.s2c.play.*; -import net.minecraft.network.packet.s2c.common.*; -import net.minecraft.text.Text; +import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; +import net.minecraft.network.packet.s2c.play.TeamS2CPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPlayNetworkHandler.class) public class MClientPlayNetworkHandler { diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java b/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java index e9bb2f9..2237af3 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java @@ -1,15 +1,12 @@ package io.github.techstreet.dfscript.mixin.player; -import io.github.techstreet.dfscript.event.SendChatEvent; import io.github.techstreet.dfscript.event.TickEvent; import io.github.techstreet.dfscript.event.system.EventManager; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPlayerEntity.class) public class MLocalPlayer { diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java index 2dbf237..afd0574 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java @@ -1,13 +1,10 @@ package io.github.techstreet.dfscript.mixin.render; -import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.event.HudRenderEvent; import io.github.techstreet.dfscript.event.system.EventManager; import io.github.techstreet.dfscript.screen.overlay.OverlayManager; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.util.math.MatrixStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java index 206ab99..6fc1c9b 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java @@ -1,11 +1,11 @@ package io.github.techstreet.dfscript.mixin.render; import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.script.ScriptListScreen; +import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen; +import io.github.techstreet.dfscript.screen.dfscript.ScriptListScreen; import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; @@ -28,7 +28,7 @@ protected MMultiplayerScreen(Text title) { @Inject(at = @At("HEAD"), method = "init", cancellable = true) private void init(CallbackInfo ci) { this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, identifier_main, identifier_main_highlight, (button) -> { - ScriptListScreen screen = new ScriptListScreen(false); + DFScriptScreen screen = new DFScriptScreen(); DFScript.MC.setScreen(screen); })); } diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java index 568fa36..8b29fbf 100644 --- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java @@ -1,7 +1,8 @@ package io.github.techstreet.dfscript.mixin.render; import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.script.ScriptListScreen; +import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen; +import io.github.techstreet.dfscript.screen.dfscript.ScriptListScreen; import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.OptionsScreen; @@ -33,7 +34,7 @@ public MOptionsScreen(Text literalText) { @Inject(method = "init()V", at = @At("RETURN")) protected void init(CallbackInfo callbackInfo) { this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, identifier_main, identifier_main_highlight, (button) -> { - ScriptListScreen screen = new ScriptListScreen(DFScript.MC.player != null); + DFScriptScreen screen = new DFScriptScreen(); DFScript.MC.setScreen(screen); })); } diff --git a/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java index 0eaf901..153a844 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java @@ -1,17 +1,5 @@ package io.github.techstreet.dfscript.screen; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.widget.CWidget; -import io.github.techstreet.dfscript.util.RenderUtil; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - public abstract class CReloadableScreen extends CScreen { public abstract void reload(); diff --git a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java index bb5c533..848aba5 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java @@ -3,8 +3,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.widget.CWidget; import io.github.techstreet.dfscript.util.RenderUtil; -import java.util.ArrayList; -import java.util.List; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; @@ -13,6 +11,9 @@ import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; + public class CScreen extends Screen { private final int width, height; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java b/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java index 11b8c9a..470eedc 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java @@ -1,7 +1,6 @@ package io.github.techstreet.dfscript.screen; import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.script.ScriptEditScreen; public class ContextMenuButton { String name; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java new file mode 100644 index 0000000..e30c47f --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java @@ -0,0 +1,42 @@ +package io.github.techstreet.dfscript.screen.dfscript; + +import net.minecraft.util.Identifier; + +public class Contributor { + private final String name; + private final int id; + private final int contributions; + private final String avatarUrl; + private Identifier avatar; + + public Contributor(String name, int id, int contributions, String avatarUrl) { + this.name = name; + this.id = id; + this.contributions = contributions; + this.avatarUrl = avatarUrl; + } + + public Identifier getAvatar() { + return avatar; + } + + public String getName() { + return name; + } + + public int getId() { + return id; + } + + public int getContributions() { + return contributions; + } + + public String getAvatarUrl() { + return avatarUrl; + } + + public void setAvatar(Identifier avatar) { + this.avatar = avatar; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java new file mode 100644 index 0000000..f215ce7 --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java @@ -0,0 +1,104 @@ +package io.github.techstreet.dfscript.screen.dfscript; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import io.github.techstreet.dfscript.DFScript; +import io.github.techstreet.dfscript.features.AuthHandler; +import io.github.techstreet.dfscript.screen.CScreen; +import io.github.techstreet.dfscript.screen.widget.CImage; +import io.github.techstreet.dfscript.screen.widget.CPlainPanel; +import io.github.techstreet.dfscript.screen.widget.CScrollPanel; +import io.github.techstreet.dfscript.screen.widget.CText; +import net.minecraft.client.texture.NativeImage; +import net.minecraft.client.texture.NativeImageBackedTexture; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import org.apache.logging.log4j.Level; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +public class ContributorsScreen extends CScreen { + private final List contributors = new ArrayList<>(); + + public ContributorsScreen() { + super(165, 110); + CPlainPanel root = new CPlainPanel(0, 0, 165, 110); + + + root.add(new CText(5, 3, Text.literal("Contributors"), 0x333333, 1.25f, false, false)); + + CPlainPanel panel = new CPlainPanel(0, 10, 165, 95); + + CScrollPanel scrollPanel = new CScrollPanel(0, 0, 165, 95); + + + + int y = 0; + int x = 5; + + try { + URL url = new URL("https://api.github.com/repos/DFScripting/DFScript/contributors"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + con.setDoOutput(true); + + try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + for (JsonElement element : JsonParser.parseReader(br).getAsJsonArray()) { + JsonObject object = element.getAsJsonObject(); + this.contributors.add(new Contributor(object.get("login").getAsString(), object.get("id").getAsInt(), object.get("contributions").getAsInt(), object.get("avatar_url").getAsString())); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + + for (Contributor contributor : contributors) { + + if (contributor.getAvatar() == null) { + try { + URL url = new URL(contributor.getAvatarUrl()); + Identifier identifier = DFScript.MC.getTextureManager().registerDynamicTexture("contributor_" + contributor.getName().toLowerCase(), new NativeImageBackedTexture(NativeImage.read(url.openStream()))); + contributor.setAvatar(identifier); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + CImage image = new CImage(x, y, 16, 16, contributor.getAvatar().toString()); + + scrollPanel.add(image); + scrollPanel.add(new CText(x + 20, y + 6, Text.of(contributor.getName()))); + + DFScript.LOGGER.log(Level.WARN, contributor.getName() + ": (" + x + ", " + y + ")"); + + if (x == 75) { + x = 5; + y += 20; + } else { + x = 75; + } + } + + panel.add(scrollPanel); + + root.add(panel); + + widgets.add(root); + + } + + @Override + public void close() { + DFScript.MC.setScreen(new DFScriptScreen()); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java new file mode 100644 index 0000000..2571029 --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java @@ -0,0 +1,53 @@ +package io.github.techstreet.dfscript.screen.dfscript; + +import io.github.techstreet.dfscript.DFScript; +import io.github.techstreet.dfscript.screen.CScreen; +import io.github.techstreet.dfscript.screen.widget.CButton; +import io.github.techstreet.dfscript.screen.widget.CImage; +import io.github.techstreet.dfscript.screen.widget.CPlainPanel; +import io.github.techstreet.dfscript.screen.widget.CText; +import net.minecraft.text.Text; +import net.minecraft.util.Util; + +public class DFScriptScreen extends CScreen { + private static final String DFSCRIPT_LOGO = "dfscript:icon_transparent.png"; + + public DFScriptScreen() { + super(110, 100); + CPlainPanel root = new CPlainPanel(0, 0, 110, 110); + + CImage cImage = new CImage(23, 0, 64, 64, DFSCRIPT_LOGO); + root.add(cImage); + root.add(new CText(55, 63, Text.literal("DFScript"), 0x333333, 1.5f, true, false)); + root.add(new CText(55, 68, Text.literal("v" + DFScript.MOD_VERSION), 0x333333, 1f, true, false)); + + addButtons(root); + widgets.add(root); + } + + private void addButtons(CPlainPanel panel) { + // ------------------------ Features Button ------------------------ + CButton featuresButton = new CButton(5, 75, 50, 10, 0.8f, "Installed Scripts", () -> { + DFScript.MC.send(() -> DFScript.MC.setScreen(new ScriptListScreen(true))); + }); + panel.add(featuresButton); + + // ------------------------ Contributors Button ------------------------ + CButton contributorsButton = new CButton(5, 85, 50, 10, 0.8f, "Contributors", () -> { + DFScript.MC.send(() -> DFScript.MC.setScreen(new ContributorsScreen())); + }); + panel.add(contributorsButton); + + // ------------------------ Bug Report Button ------------------------ + CButton bugReport = new CButton(55, 75, 50, 10, 0.8f, "Bug Report", () -> { + Util.getOperatingSystem().open("https://github.com/DFScripting/DFScript/issues"); + }); + panel.add(bugReport); + + // ------------------------ Dashboard Button ------------------------ + CButton options = new CButton(55, 85, 50, 10, 0.8f, "Dashboard", () -> { + Util.getOperatingSystem().open("https://dfscript.techstreet.tech/"); + }); + panel.add(options); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java new file mode 100644 index 0000000..05b2802 --- /dev/null +++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java @@ -0,0 +1,103 @@ +package io.github.techstreet.dfscript.screen.dfscript; + +import io.github.techstreet.dfscript.DFScript; +import io.github.techstreet.dfscript.features.AuthHandler; +import io.github.techstreet.dfscript.screen.CScreen; +import io.github.techstreet.dfscript.screen.widget.*; +import io.github.techstreet.dfscript.script.Script; +import io.github.techstreet.dfscript.script.ScriptManager; +import io.github.techstreet.dfscript.util.chat.ChatUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Util; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class ScriptListScreen extends CScreen { + private final List contextMenu = new ArrayList<>(); + + + public ScriptListScreen(boolean allowEditAndUpload) { + super(160, 100); + CScrollPanel panel = new CScrollPanel(0, 5, 160, 94); + widgets.add(panel); + + int y = 0; + for (Script s : ScriptManager.getInstance().getScripts()) { + MutableText text = Text.literal(s.getName()); + + if (s.disabled()) { + text = text.formatted(Formatting.STRIKETHROUGH); + } + + panel.add(new CText(6, y + 2, text)); + + panel.add(new CButton(4, y-1, 153, 10, "",() -> {}) { + @Override + public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { + Rectangle b = getBounds(); + context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000); + } + + @Override + public boolean mouseClicked(double x, double y, int button) { + return false; + } + }); + + int addedY = 0; + int addedX = 118; + + // Enable or Disable Button + CButton enableDisable; + if (s.disabled()) { + enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":enable.png", DFScript.MOD_ID + ":enable_highlight.png", () -> { + s.setDisabled(false); + ScriptManager.getInstance().saveScript(s); + DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload)); + }); + } else { + enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":disable.png", DFScript.MOD_ID + ":disable_highlight.png", () -> { + s.setDisabled(true); + ScriptManager.getInstance().saveScript(s); + DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload)); + }); + } + + panel.add(enableDisable); + y += 12; + } + + CButton refresh = new CButton(60, y + 1, 40, 8, "Refresh", () -> { + AuthHandler.checkAuth(); + AuthHandler.updateScripts(); + ChatUtil.info("Scripts updated and reloaded!"); + DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload)); + }); + + panel.add(refresh); + } + + @Override + public void close() { + DFScript.MC.setScreen(new DFScriptScreen()); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + boolean b = super.mouseClicked(mouseX, mouseY, button); + clearContextMenu(); + return b; + } + + private void clearContextMenu() { + for (CWidget w : contextMenu) { + widgets.remove(w); + } + contextMenu.clear(); + } +} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java b/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java index e498f50..ed740b5 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java @@ -3,7 +3,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.loader.Loadable; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import java.util.ArrayList; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java deleted file mode 100644 index b85bfce..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java +++ /dev/null @@ -1,143 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.screen.widget.CTextField; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.argument.*; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.Style; -import net.minecraft.text.Text; - -public class ScriptAddArgumentScreen extends CScreen { - - private final Script script; - - private final ScriptHeader header; - private final ScriptParametrizedPart action; - - public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int index, ScriptHeader header) { - this(script,action,index, header,null); - } - public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int index, ScriptHeader header, String overwrite) { - super(100, 50); - this.script = script; - this.action = action; - this.header = header; - - CTextField input = new CTextField("Input", 2, 2, 96, 35, true); - if(overwrite != null) input.setText(overwrite); - - ItemStack textIcon = new ItemStack(Items.BOOK); - textIcon.setCustomName(Text.literal("Text") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack numberIcon = new ItemStack(Items.SLIME_BALL); - numberIcon.setCustomName(Text.literal("Number") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack variableIcon = new ItemStack(Items.MAGMA_CREAM); - variableIcon.setCustomName(Text.literal("Variable") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack clientValueIcon = new ItemStack(Items.NAME_TAG); - clientValueIcon.setCustomName(Text.literal("Client Value") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack configValueIcon = new ItemStack(Items.INK_SAC); - configValueIcon.setCustomName(Text.literal("Config Value") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack functionArgumentIcon = new ItemStack(Items.BLUE_DYE); - functionArgumentIcon.setCustomName(Text.literal("Function Argument") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack trueIcon = new ItemStack(Items.LIME_DYE); - trueIcon.setCustomName(Text.literal("True") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack falseIcon = new ItemStack(Items.RED_DYE); - falseIcon.setCustomName(Text.literal("False") - .fillStyle(Style.EMPTY.withItalic(false))); - - CItem addNumber = new CItem(2, 40, numberIcon); - CItem addText = new CItem(12, 40, textIcon); - CItem addTrue = new CItem(22, 40, trueIcon); - CItem addFalse = new CItem(32, 40, falseIcon); - CItem addVariable = new CItem(42, 40, variableIcon); - CItem addClientValue = new CItem(52, 40, clientValueIcon); - CItem addConfigValue = new CItem(62, 40, configValueIcon); - CItem addFunctionArgument = new CItem(72, 40, functionArgumentIcon); - - input.setChangedListener(() -> input.textColor = 0xFFFFFF); - - addText.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(index); - action.getArguments().add(index, new ScriptTextArgument(input.getText())); - close(); - }); - - addNumber.setClickListener((btn) -> { - try { - double number = Double.parseDouble(input.getText()); - if(overwrite != null) action.getArguments().remove(index); - action.getArguments().add(index, new ScriptNumberArgument(number)); - close(); - } catch (Exception err) { - input.textColor = 0xFF3333; - } - }); - - addVariable.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(index); - action.getArguments().add(index, new ScriptVariableArgument(input.getText(), ScriptVariableScope.SCRIPT)); - close(); - }); - - addClientValue.setClickListener((btn) -> { - DFScript.MC.setScreen(new ScriptAddClientValueScreen(action, script, index, header, overwrite)); - }); - - addConfigValue.setClickListener((btn) -> { - DFScript.MC.setScreen(new ScriptAddConfigValueScreen(action, script, index, header, overwrite)); - }); - - addFunctionArgument.setClickListener((btn) -> { - DFScript.MC.setScreen(new ScriptAddFunctionArgValueScreen(action, script, index, header, overwrite)); - }); - - addTrue.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(index); - action.getArguments().add(index, new ScriptBoolArgument(true)); - close(); - }); - - addFalse.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(index); - action.getArguments().add(index, new ScriptBoolArgument(false)); - close(); - }); - - widgets.add(input); - widgets.add(addNumber); - widgets.add(addText); - widgets.add(addTrue); - widgets.add(addFalse); - widgets.add(addVariable); - widgets.add(addClientValue); - widgets.add(addConfigValue); - if(header instanceof ScriptFunction) { - widgets.add(addFunctionArgument); - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditPartScreen(action, script, header)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java deleted file mode 100644 index 38ca1c9..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.ScriptPart; -import io.github.techstreet.dfscript.script.action.ScriptAction; -import io.github.techstreet.dfscript.script.argument.ScriptClientValueArgument; -import io.github.techstreet.dfscript.script.event.ScriptHeader; - -public class ScriptAddClientValueScreen extends CScreen { - - private final Script script; - - private final ScriptHeader header; - private final ScriptParametrizedPart action; - private final int insertIndex; - private static final int WIDTH = 58; - - public ScriptAddClientValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) { - super(WIDTH, 58); - this.script = script; - this.action = action; - this.header = header; - this.insertIndex = insertIndex; - - int x = 5; - int y = 5; - for (ScriptClientValueArgument arg : ScriptClientValueArgument.values()) { - CItem item = new CItem(x, y, arg.getIcon()); - item.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(insertIndex); - action.getArguments().add(insertIndex, arg); - DFScript.MC.setScreen(new ScriptEditPartScreen(action, script, header)); - }); - widgets.add(item); - x += 10; - if (x > WIDTH-10) { - x = 5; - y += 10; - } - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java deleted file mode 100644 index 8472c9d..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.screen.widget.CScrollPanel; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.ScriptPart; -import io.github.techstreet.dfscript.script.action.ScriptAction; -import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import io.github.techstreet.dfscript.script.options.ScriptNamedOption; - -public class ScriptAddConfigValueScreen extends CScreen { - private final Script script; - - private final ScriptHeader header; - private final ScriptParametrizedPart action; - private final int insertIndex; - - private static int WIDTH = 200; - private static int HEIGHT = 94; - - public ScriptAddConfigValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) { - super(WIDTH, HEIGHT); - this.script = script; - this.action = action; - this.header = header; - this.insertIndex = insertIndex; - - CScrollPanel panel = new CScrollPanel(0, 0, WIDTH, HEIGHT); - - int x = 5; - int y = 5; - for (ScriptNamedOption arg : script.getOptions()) { - CItem item = new CItem(x, y, arg.getIcon()); - item.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(insertIndex); - this.action.getArguments().add(insertIndex, new ScriptConfigArgument(arg.getName(), this.script)); - DFScript.MC.setScreen(new ScriptEditPartScreen(this.action, this.script, this.header)); - }); - panel.add(item); - x += 10; - if (x > WIDTH-10) { - x = 5; - y += 10; - } - } - - widgets.add(panel); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java deleted file mode 100644 index 2fe6b9a..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.screen.widget.CScrollPanel; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.action.ScriptActionArgument; -import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument; -import io.github.techstreet.dfscript.script.argument.ScriptFunctionArgument; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.event.ScriptHeader; - -public class ScriptAddFunctionArgValueScreen extends CScreen { - private final Script script; - - private final ScriptHeader header; - private final ScriptParametrizedPart action; - private final int insertIndex; - - private static int WIDTH = 200; - private static int HEIGHT = 94; - - public ScriptAddFunctionArgValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) { - super(WIDTH, HEIGHT); - this.script = script; - this.action = action; - this.header = header; - this.insertIndex = insertIndex; - - CScrollPanel panel = new CScrollPanel(0, 0, WIDTH, HEIGHT); - - if(header instanceof ScriptFunction f) - { - int x = 5; - int y = 5; - for (ScriptActionArgument arg : f.argList()) { - CItem item = new CItem(x, y, arg.getIcon()); - item.setClickListener((btn) -> { - if(overwrite != null) action.getArguments().remove(insertIndex); - this.action.getArguments().add(insertIndex, new ScriptFunctionArgument(arg.name(), header)); - DFScript.MC.setScreen(new ScriptEditPartScreen(this.action, this.script, this.header)); - }); - panel.add(item); - x += 10; - if (x > WIDTH-10) { - x = 5; - y += 10; - } - } - - widgets.add(panel); - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java deleted file mode 100644 index f755e66..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptSnippet; -import io.github.techstreet.dfscript.script.action.*; -import io.github.techstreet.dfscript.script.conditions.ScriptBranch; -import io.github.techstreet.dfscript.script.conditions.ScriptBuiltinCondition; -import io.github.techstreet.dfscript.script.conditions.ScriptConditionType; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition; -import io.github.techstreet.dfscript.script.repetitions.ScriptRepetitionType; - -import java.util.ArrayList; - -public class ScriptAddFunctionArgumentScreen extends CScreen { - - private final Script script; - - private final ScriptFunction function; - private final int insertIndex; - - public ScriptAddFunctionArgumentScreen(Script script, ScriptFunction function, int insertIndex) { - super(size(), size()); - int size = size(); - this.script = script; - this.insertIndex = insertIndex; - this.function = function; - - int x = 3; - int y = 3; - - /*if (category == null) { - for (ScriptEventType type : ScriptEventType.values()) { - CItem item = new CItem(x, y, type.getIcon()); - item.setClickListener((btn) -> { - ScriptEvent event = new ScriptEvent(type); - script.getParts().add(insertIndex, event); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size - 10) { - x = 3; - y += 10; - } - } - }*/ - - for (ScriptActionArgument.ScriptActionArgumentType type : ScriptActionArgument.ScriptActionArgumentType.values()) { - CItem item = new CItem(x, y, type.icon()); - item.setClickListener((btn) -> { - ScriptActionArgument arg = new ScriptActionArgument(function.argList().getUnnamedArgument(), type); - function.argList().add(insertIndex, arg); - DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script)); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - } - - private static int size() { - int amount = ScriptActionArgument.ScriptActionArgumentType.values().length; - return (int) (Math.ceil(Math.sqrt(amount))*10)+4; - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java deleted file mode 100644 index 9203514..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.action.ScriptAction; -import io.github.techstreet.dfscript.script.action.ScriptActionCategory; -import io.github.techstreet.dfscript.script.action.ScriptActionCategoryExtra; -import io.github.techstreet.dfscript.script.action.ScriptActionType; -import io.github.techstreet.dfscript.script.event.ScriptEvent; -import io.github.techstreet.dfscript.script.event.ScriptEventType; -import io.github.techstreet.dfscript.script.event.ScriptHeaderCategory; - -import java.util.ArrayList; -import java.util.List; - -public class ScriptAddHeaderScreen extends CScreen { - - private final Script script; - private final int insertIndex; - - public ScriptAddHeaderScreen(Script script, int insertIndex, ScriptHeaderCategory category) { - super(size(category), size(category)); - int size = size(category); - this.script = script; - this.insertIndex = insertIndex; - - int x = 3; - int y = 3; - - for (ScriptEventType type : ScriptEventType.values()) { - //if (type.getCategory() != category) continue; - - CItem item = new CItem(x, y, type.getIcon()); - item.setClickListener((btn) -> { - ScriptEvent event = new ScriptEvent(type); - script.getHeaders().add(insertIndex, event); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - } - - private static int size(ScriptHeaderCategory category) { - int amount = 0; - for (ScriptEventType type : ScriptEventType.values()) { - //if (type.getCategory() != category) continue; - - amount++; - } - return (int) (Math.ceil(Math.sqrt(amount))*10)+4; - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, insertIndex)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java deleted file mode 100644 index 384b8de..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java +++ /dev/null @@ -1,149 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptSnippet; -import io.github.techstreet.dfscript.script.action.*; -import io.github.techstreet.dfscript.script.conditions.ScriptBranch; -import io.github.techstreet.dfscript.script.conditions.ScriptBuiltinCondition; -import io.github.techstreet.dfscript.script.conditions.ScriptCondition; -import io.github.techstreet.dfscript.script.conditions.ScriptConditionType; -import io.github.techstreet.dfscript.script.event.ScriptEventType; -import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition; -import io.github.techstreet.dfscript.script.repetitions.ScriptRepetitionType; - -import java.util.ArrayList; - -public class ScriptAddPartScreen extends CScreen { - - private final Script script; - - private final ScriptSnippet snippet; - private final int insertIndex; - - public ScriptAddPartScreen(Script script, ScriptSnippet snippet, int insertIndex, ScriptActionCategory category) { - super(size(category, script), size(category, script)); - int size = size(category, script); - this.script = script; - this.insertIndex = insertIndex; - this.snippet = snippet; - - int x = 3; - int y = 3; - - /*if (category == null) { - for (ScriptEventType type : ScriptEventType.values()) { - CItem item = new CItem(x, y, type.getIcon()); - item.setClickListener((btn) -> { - ScriptEvent event = new ScriptEvent(type); - script.getParts().add(insertIndex, event); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size - 10) { - x = 3; - y += 10; - } - } - }*/ - - if (category != null) - { - for(ScriptActionCategoryExtra extra : category.getExtras(script)) { - CItem item = new CItem(x, y, extra.getIcon()); - item.setClickListener((btn) -> { - extra.click(script, snippet, insertIndex); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - } - - for (ScriptActionType type : ScriptActionType.values()) { - if (type.getCategory() != category) continue; - if (type.isDeprecated()) continue; - - CItem item = new CItem(x, y, type.getIcon()); - item.setClickListener((btn) -> { - ScriptAction action = new ScriptBuiltinAction(type, new ArrayList<>()); - snippet.add(insertIndex, action); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - - for (ScriptConditionType type : ScriptConditionType.values()) { - if (type.getCategory() != category) continue; - if (type.isDeprecated()) continue; - - CItem item = new CItem(x, y, type.getIcon("If")); - item.setClickListener((btn) -> { - ScriptBranch action = new ScriptBranch(new ArrayList<>(), new ScriptBuiltinCondition(type)); - snippet.add(insertIndex, action); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - - for (ScriptRepetitionType type : ScriptRepetitionType.values()) { - if (type.getCategory() != category) continue; - if (type.isDeprecated()) continue; - - CItem item = new CItem(x, y, type.getIcon()); - item.setClickListener((btn) -> { - ScriptBuiltinRepetition action = new ScriptBuiltinRepetition(new ArrayList<>(), type); - snippet.add(insertIndex, action); - DFScript.MC.setScreen(new ScriptEditScreen(script)); - }); - widgets.add(item); - x += 10; - if (x >= size-10) { - x = 3; - y += 10; - } - } - } - - private static int size(ScriptActionCategory category, Script script) { - int amount = 0; - amount += category.getExtras(script).size(); - for (ScriptActionType type : ScriptActionType.values()) { - if (type.getCategory() == category) { - amount++; - } - } - for (ScriptConditionType type : ScriptConditionType.values()) { - if (type.getCategory() == category) { - amount++; - } - } - for (ScriptRepetitionType type : ScriptRepetitionType.values()) { - if (type.getCategory() == category) { - amount++; - } - } - return (int) (Math.ceil(Math.sqrt(amount))*10)+4; - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, snippet, insertIndex)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java deleted file mode 100644 index 61f05cc..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java +++ /dev/null @@ -1,159 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.features.AuthHandler; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CPlainPanel; -import io.github.techstreet.dfscript.screen.widget.CScrollPanel; -import io.github.techstreet.dfscript.screen.widget.CText; -import io.github.techstreet.dfscript.screen.widget.CTextField; -import io.github.techstreet.dfscript.script.ScriptManager; -import io.github.techstreet.dfscript.script.VirtualScript; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.*; - -import net.minecraft.text.LiteralTextContent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; - -public class ScriptAddScreen extends CScreen { - public static ArrayList scripts = new ArrayList<>(); - public static HashMap scriptHash = new HashMap<>(); - - CScrollPanel panel; - CTextField searchBox; - - public ScriptAddScreen() { - super(111, 106); - open(); - } - - private void open() { - CPlainPanel root = new CPlainPanel(0, 0, 111, 106); - - panel = new CScrollPanel(0, 17, 111, 84); - - root.add(panel); - - searchBox = new CTextField("Search...", 5, 5, 100, 10, true); - searchBox.setChangedListener(this::update); - root.add(searchBox); - - widgets.add(root); - - update(); - } - - private void update() { - List filtered = new ArrayList<>(); - String query = searchBox.getText().toLowerCase(); - - for (VirtualScript script : scripts) { - if (!searchBox.getText().equals("Search...")) { - if (script.getName().toLowerCase().contains(query.toLowerCase()) || script.getOwner().toLowerCase().contains(query.toLowerCase())) { - filtered.add(script); - } - } else { - filtered.add(script); - } - } - - panel.clear(); - fillPanel(filtered); - } - - public static void getScripts() { - ArrayList scripts = new ArrayList<>(); - - try { - URL url = new URL("https://DFScript-Server.techstreetdev.repl.co/check/"); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("GET"); - con.setRequestProperty("authorization", AuthHandler.getAuthCode()); - con.setDoOutput(true); - - con.getInputStream(); - if (con.getResponseCode() != 204) { - AuthHandler.regen(); - } - } catch (Exception e) { - AuthHandler.regen(); -// e.printStackTrace(); - } - - try { - InputStream is = new URL("https://dfscript-server.techstreetdev.repl.co/scripts/get").openStream(); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); - JsonObject obj = JsonParser.parseString(readAll(rd)).getAsJsonObject(); - - for (String key : obj.keySet()) { - JsonObject scriptObject = obj.getAsJsonObject(key); - - VirtualScript script = new VirtualScript(scriptObject.get("name").getAsString(), scriptObject.get("owner").getAsString(), key); - script.setApproved(scriptObject.get("approved").getAsBoolean()); - script.setApprover((scriptObject.get("approvedBy").isJsonNull() ? "None" : scriptObject.get("approvedBy").getAsString())); - - scripts.add(script); - } - - is.close(); - - for (VirtualScript s : scripts) { - ScriptAddScreen.scriptHash.put(s.getId(), s); - } - - ScriptAddScreen.scripts = scripts; - } catch (Exception e) { -// e.printStackTrace(); - } - } - - public static String readAll(Reader rd) throws IOException { - StringBuilder sb = new StringBuilder(); - int cp; - - while ((cp = rd.read()) != -1) { - sb.append((char) cp); - } - - return sb.toString(); - } - - private void fillPanel(List scriptList) { - int y = 18; - CButton newButton = new CButton(7, 6, 96, 10, "New Script", () -> { - DFScript.MC.setScreen(new ScriptCreationScreen()); - }); - - panel.add(newButton); - - for (VirtualScript script : scriptList) { - CButton button = new CButton(7, y, 96, 10, (script.isApproved() ? "§e⭐ " : "") + "§f" + script.getName(), () -> { - DFScript.MC.setScreen(new ScriptInstallScreen(script)); - }); - - panel.add(button); - y += 12; - } - - long time = Math.abs((System.currentTimeMillis() / 1000) - ScriptManager.lastServerUpdate); - long minutes = (time % 3600) / 60; - long seconds = time % 60; - - panel.add(new CText(8, 0, Text.literal("Last update: " + minutes + "m " + seconds + "s" + " ago!"))); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptListScreen(true)); - } -} \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java index b4610bd..9608fba 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java @@ -22,7 +22,6 @@ import java.util.stream.Collectors; public class ScriptAddSettingSubtypeScreen extends CScreen { - private int width; private int height; private static final List primitiveTypes; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java index 9a25950..4b2f4a6 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java @@ -15,7 +15,6 @@ import java.util.function.Function; public class ScriptConditionCategoryScreen extends CScreen { - private static final int size; static { @@ -56,6 +55,6 @@ public ScriptConditionCategoryScreen(Script script, ScriptSnippet snippet, int i @Override public void close() { - DFScript.MC.setScreen(new ScriptAddPartScreen(script, snippet, insertIndex, ScriptActionCategory.CONDITIONS)); + } } diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java index e959a8f..5d0be15 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java @@ -41,7 +41,6 @@ public ScriptConditionSelectScreen(Script script, ScriptSnippet snippet, int ins CItem item = new CItem(x, y, type.getIcon("")); item.setClickListener((btn) -> { snippet.add(insertIndex, partCreator.apply(new ScriptBuiltinCondition(type))); - DFScript.MC.setScreen(new ScriptEditScreen(script)); }); widgets.add(item); x += 10; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java deleted file mode 100644 index b9bdce5..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CText; -import io.github.techstreet.dfscript.screen.widget.CTextField; -import io.github.techstreet.dfscript.script.ScriptManager; -import net.minecraft.text.Text; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ScriptCreationScreen extends CScreen { - - // invalid file name chars - // there's definitely a better place to put this but this felt the simplest rn - Pattern ILLEGAL_CHARS = Pattern.compile("[\\\\/:*?\"<>|\n]"); - - protected ScriptCreationScreen() { - super(100, 33); - - widgets.add(new CText(4, 4, Text.of("Create Script"))); - - CTextField name = new CTextField("My Script", 4, 9, 92, 9, true){ - @Override - public void keyPressed(int keyCode, int scanCode, int modifiers) { - if(keyCode == 257) return; - super.keyPressed(keyCode, scanCode, modifiers); - } - }; - - name.setChangedListener(() -> { - String scriptName = name.getText(); - - Matcher m = ILLEGAL_CHARS.matcher(scriptName); - - name.textColor = m.find() ? 0xFF3333 : 0xFFFFFF; - }); - - widgets.add(name); - - widgets.add(new CButton(4, 20, 44, 9, "Create", () -> { - String scriptName = name.getText(); - - Matcher m = ILLEGAL_CHARS.matcher(scriptName); - - if (m.find()) return; - - ScriptManager.getInstance().createScript(name.getText()); - DFScript.MC.setScreen(new ScriptListScreen(true)); - })); - - widgets.add(new CButton(52, 20, 44, 9, "Cancel", () -> { - DFScript.MC.setScreen(new ScriptAddScreen()); - })); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptAddScreen()); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java deleted file mode 100644 index e21cfa8..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CText; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptManager; -import net.minecraft.text.Text; - -public class ScriptDeletionScreen extends CScreen { - - public ScriptDeletionScreen(Script script) { - super(103,27); - - widgets.add(new CText(5,5, Text.literal("Delete " + script.getName() + "?"))); - - widgets.add(new CButton(5,12,45, 10,"Delete",() -> { - ScriptManager.getInstance().deleteScript(script); - DFScript.MC.setScreen(new ScriptListScreen(true)); - })); - - widgets.add(new CButton(52,12,45, 10,"Cancel",() -> DFScript.MC.setScreen(new ScriptListScreen(true)))); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptListScreen(true)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java deleted file mode 100644 index f7ac64a..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CTextField; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.action.ScriptActionArgument; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.options.ScriptNamedOption; - -import java.util.Objects; - -public class ScriptEditFunctionArgumentScreen extends CScreen { - private final Script script; - - private final ScriptFunction function; - private final ScriptActionArgument argument; - - public ScriptEditFunctionArgumentScreen(Script script, ScriptFunction f, ScriptActionArgument a) { - super(100, 50); - this.script = script; - argument = a; - function = f; - - CTextField input = new CTextField(argument.name(), 2, 2, 96, 35, true); - - input.setChangedListener(() -> input.textColor = 0xFFFFFF); - - CButton confirm = new CButton(2, 37, 46, 10, "Rename", () -> { - if(!Objects.equals(argument.name(), input.getText())) { - if(function.argList().argumentExists(input.getText())) { - input.textColor = 0xFF3333; - } else { - //script.replaceOption(option.getName(), input.getText()); - function.replaceArgument(argument.name(), input.getText()); - argument.setName(input.getText()); - close(); - } - } else { - close(); - } - }); - - CButton cancel = new CButton(52, 37, 46, 10, "Cancel", this::close); - - widgets.add(input); - widgets.add(confirm); - widgets.add(cancel); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java deleted file mode 100644 index 739baad..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java +++ /dev/null @@ -1,208 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CReloadableScreen; -import io.github.techstreet.dfscript.screen.ContextMenuButton; -import io.github.techstreet.dfscript.screen.util.ItemMaterialSelectMenu; -import io.github.techstreet.dfscript.screen.widget.*; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.action.ScriptActionArgument; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.values.ScriptUnknownValue; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.item.ItemStack; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; - -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -public class ScriptEditFunctionScreen extends CReloadableScreen { - - private final Script script; - private final ScriptFunction function; - private final CScrollPanel panel; - private final List contextMenu = new ArrayList<>(); - - public ScriptEditFunctionScreen(ScriptFunction function, Script script) { - super(90, 100); - panel = new CScrollPanel(0, 0, 90, 100); - - widgets.add(panel); - - this.script = script; - this.function = function; - - reload(); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditScreen(script)); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean b = super.mouseClicked(mouseX, mouseY, button); - clearContextMenu(); - return b; - } - - private void clearContextMenu() { - for (CWidget w : contextMenu) { - panel.remove(w); - } - contextMenu.clear(); - } - - public void contextMenu(int x, int y, List contextMenuButtons) { - clearContextMenu(); - - int maxWidth = 0; - - for(ContextMenuButton w : contextMenuButtons) - { - TextRenderer t = DFScript.MC.textRenderer; - int width = t.getWidth(w.getName())/2 + 4; - - if(width > maxWidth) maxWidth = width; - } - - for(ContextMenuButton w : contextMenuButtons) - { - CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick()); - y += 8; - - panel.add(button); - contextMenu.add(button); - } - } - - @Override - public void reload() { - clearContextMenu(); - panel.clear(); - - CTextField nameField = new CTextField(function.getName(), 15, 3, 90-10-10, 8, true); - nameField.setMultiline(false); - nameField.setChangedListener(() -> { - if(script.functionExists(nameField.getText())) { - nameField.textColor = 0xFF0000; - } - else { - nameField.textColor = 0xFFFFFF; - script.replaceFunction(function.getName(), nameField.getText()); - function.setName(nameField.getText()); - } - }); - - CItem icon = new CItem(5, 3, function.getIcon()); - - icon.setClickListener((button) -> { - DFScript.MC.setScreen(new ItemMaterialSelectMenu(function.getRawIcon(), (newIcon) -> { - function.setIcon(newIcon); - DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script)); - })); - }); - - CTextField descField = new CTextField(function.getDescription(), 5, 11, 80, 20, true); - descField.setChangedListener(() -> { - function.setDescription(descField.getText()); - }); - - panel.add(icon); - panel.add(nameField); - panel.add(descField); - - int y = 31+4; - int index = 0; - for (ScriptActionArgument arg : function.argList()) { - ItemStack argIcon = arg.getUnnamedIcon(); - String text = arg.name(); - - panel.add(new CItem(5, y, argIcon, Text.literal((arg.optional() ? "*" : "") + (arg.plural() ? "s" : "")))); - panel.add(new CText(15, y + 2, Text.literal(text))); - - int currentIndex = index; - - - panel.add(new CButton(5, y-1, 85, 10, "",() -> {}) { - @Override - public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { - Rectangle b = getBounds(); - if (b.contains(mouseX, mouseY)) { - context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000); - } - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - if (getBounds().contains(x, y)) { - DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), - 1f,1f)); - - if (button != 0) { - List contextMenuButtons = new ArrayList<>(); - contextMenuButtons.add(new ContextMenuButton("Insert Before", () -> { - DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, currentIndex)); - }, false)); - if (!(currentIndex == function.argList().size() - 1 && arg.plural())) { - contextMenuButtons.add(new ContextMenuButton("Insert After", () -> { - DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, currentIndex + 1)); - }, false)); - } - contextMenuButtons.add(new ContextMenuButton("Delete", () -> { - function.removeArgument(arg.name()); - - function.argList().remove(currentIndex); - })); - if(arg.type().allowOptional()) { - contextMenuButtons.add(new ContextMenuButton(arg.optional() ? "Required" : "Optional", () -> { - arg.optional(!arg.optional()); - })); - if(currentIndex == function.argList().size()-1) { - contextMenuButtons.add(new ContextMenuButton(arg.plural() ? "Singular" : "Plural", () -> { - arg.plural(!arg.plural()); - })); - } - if(arg.optional() && !arg.plural() && arg.type().getDefaultValueType() != null) { - contextMenuButtons.add(new ContextMenuButton("Default Value", () -> { - DFScript.MC.setScreen(new ScriptSetValueScreen(script, () -> { - DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script)); - }, arg::defaultValue, arg.type().getDefaultValueType(), - arg.defaultValue() instanceof ScriptUnknownValue ? null : arg.defaultValue().asText())); - }, false)); - } - } - DFScript.MC.send(() -> { - if(DFScript.MC.currentScreen instanceof ScriptEditFunctionScreen screen) { - screen.contextMenu((int) x, (int) y, contextMenuButtons); - } - }); - } - else - { - DFScript.MC.setScreen(new ScriptEditFunctionArgumentScreen(script, function, arg)); - } - - return true; - } - return false; - } - }); - - y += 10; - index++; - - } - - CButton add = new CButton(25, y, 40, 8, "Add", () -> { - DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, function.argList().size())); - }); - if(function.argList().size() == 0 || !function.argList().get(function.argList().size() - 1).plural()) - panel.add(add); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java deleted file mode 100644 index 3a22090..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java +++ /dev/null @@ -1,169 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CReloadableScreen; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.ContextMenuButton; -import io.github.techstreet.dfscript.screen.widget.*; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.argument.*; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; - -import java.awt.*; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -public class ScriptEditPartScreen extends CReloadableScreen { - private final Script script; - - private final ScriptHeader header; - private final ScriptParametrizedPart action; - private final CScrollPanel panel; - private final List contextMenu = new ArrayList<>(); - - public ScriptEditPartScreen(ScriptParametrizedPart action, Script script, ScriptHeader header) { - super(90, 100); - panel = new CScrollPanel(0, 0, 90, 100); - - widgets.add(panel); - - this.script = script; - this.action = action; - this.header = header; - - reload(); - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditScreen(script)); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean b = super.mouseClicked(mouseX, mouseY, button); - clearContextMenu(); - return b; - } - - private void clearContextMenu() { - for (CWidget w : contextMenu) { - panel.remove(w); - } - contextMenu.clear(); - } - - public void contextMenu(int x, int y, List contextMenuButtons) { - clearContextMenu(); - - int maxWidth = 0; - - for(ContextMenuButton w : contextMenuButtons) - { - TextRenderer t = DFScript.MC.textRenderer; - int width = t.getWidth(w.getName())/2 + 4; - - if(width > maxWidth) maxWidth = width; - } - - for(ContextMenuButton w : contextMenuButtons) - { - CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick()); - y += 8; - - panel.add(button); - contextMenu.add(button); - } - } - - @Override - public void reload() { - clearContextMenu(); - panel.clear(); - - panel.add(new CItem(5, 3, action.getIcon())); - panel.add(new CText(15, 5, Text.of(action.getName()))); - - int y = 15; - int index = 0; - for (ScriptArgument arg : action.getArguments()) { - ItemStack icon = arg.getArgIcon(); - Text countText = arg.getArgIconText(); - String text = arg.getArgText(); - - panel.add(new CItem(5, y, icon, countText)); - panel.add(new CText(15, y + 2, Text.literal(text))); - - int currentIndex = index; - - - panel.add(new CButton(5, y-1, 85, 10, "",() -> {}) { - @Override - public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { - Rectangle b = getBounds(); - if (b.contains(mouseX, mouseY)) { - context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000); - } - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - if (getBounds().contains(x, y)) { - DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), 1f,1f)); - - if (button == 0) { - ScriptArgument argument = action.getArguments().get(currentIndex); - String value = "~"; - if(argument instanceof ScriptClientValueArgument clientValue) value = clientValue.getName(); - if(argument instanceof ScriptConfigArgument configArgument) value = configArgument.getName(); - if(argument instanceof ScriptNumberArgument number) value = String.valueOf(number.value()); - if(argument instanceof ScriptTextArgument text) value = text.value(); - if(argument instanceof ScriptVariableArgument var) value = var.name(); - if(argument instanceof ScriptFunctionArgument var) value = var.getName(); - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex, header, value)); - } - - if (button != 0) { - List contextMenuButtons = new ArrayList<>(); - contextMenuButtons.add(new ContextMenuButton("Insert Before", () -> { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex, header)); - }, false)); - contextMenuButtons.add(new ContextMenuButton("Insert After", () -> { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex+1, header)); - }, false)); - contextMenuButtons.add(new ContextMenuButton("Delete", () -> { - action.getArguments().remove(currentIndex); - })); - contextMenuButtons.addAll(action.getArguments().get(currentIndex).getContextMenu()); - DFScript.MC.send(() -> { - if(DFScript.MC.currentScreen instanceof ScriptEditPartScreen screen) { - screen.contextMenu((int) x, (int) y, contextMenuButtons); - } - }); - } - return true; - } - return false; - } - }); - - y += 10; - index++; - - } - - CButton add = new CButton(25, y, 40, 8, "Add", () -> { - DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, action.getArguments().size(), header)); - }); - panel.add(add); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java deleted file mode 100644 index 2b315e8..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java +++ /dev/null @@ -1,194 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CReloadableScreen; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.ContextMenuButton; -import io.github.techstreet.dfscript.screen.widget.*; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptManager; - -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -public class ScriptEditScreen extends CReloadableScreen { - private final Identifier identifier_main = new Identifier(DFScript.MOD_ID + ":wrench.png"); - - private final Script script; - private static int scroll = 0; - - public final static int width = 125; - private CScrollPanel panel; - private final List contextMenu = new ArrayList<>(); - - public ScriptEditScreen(Script script) { - super(width, 100); - this.script = script; - - reload(); - } - - public void reload() - { - clearContextMenu(); - widgets.clear(); - - if(panel != null) - { - scroll = panel.getScroll(); - } - - panel = new CScrollPanel(0, 3, 120, 94); - widgets.add(panel); - - int y = 0; - int index = 0; - - CText name = new CText(5,y+2,Text.literal(script.getName()),0,1,false,false); - panel.add(name); - - CButton settings = new CTexturedButton(120-8, y, 8, 8, DFScript.MOD_ID + ":settings.png", DFScript.MOD_ID + ":settings_highlight.png", () -> { - DFScript.MC.setScreen(new ScriptSettingsScreen(this.script, true)); - }); - panel.add(settings); - - y += 10; - - for(ScriptHeader header : script.getHeaders()) { - int origY = y; - y = header.create(panel, y, index, script); - int currentIndex = index; - panel.add(new CButton(5, origY-1, 115, 10, "",() -> {}) { - @Override - public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { - Rectangle b = getBounds(); - - if (b.contains(mouseX, mouseY)) { - int color = 0x33000000; - - context.fill(b.x, b.y, b.x + b.width, b.y + b.height, color); - } - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - if (getBounds().contains(x, y)) { - DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), 1f,1f)); - - if (button != 0) { - CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> { - DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex)); - }); - CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> { - DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex + 1)); - }); - CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> { - script.getHeaders().remove(currentIndex); - if(header instanceof ScriptFunction f) { - script.removeFunction(f.getName()); - } - reload(); - }); - DFScript.MC.send(() -> { - panel.add(insertBefore); - panel.add(insertAfter); - panel.add(delete); - contextMenu.add(insertBefore); - contextMenu.add(insertAfter); - contextMenu.add(delete); - }); - } - else { - if(header instanceof ScriptFunction f) { - DFScript.MC.setScreen(new ScriptEditFunctionScreen(f, script)); - } - } - return true; - } - return false; - } - }); - index++; - } - - CButton add = new CButton(37, y, 46, 8, "Add Header", () -> { - DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, script.getHeaders().size())); - }); - - panel.add(add); - - panel.setScroll(scroll); - } - - public void createIndent(int indent, int y) - { - for (int i = 0; i < indent; i += 5) { - int xpos = 8 + i; - int ypos = y; - panel.add(new CWidget() { - @Override - public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { - context.fill(xpos, ypos, xpos + 1, ypos + 8, 0xFF333333); - } - - @Override - public Rectangle getBounds() { - return new Rectangle(0, 0, 0, 0); - } - }); - } - } - - @Override - public void close() { - scroll = panel.getScroll(); - ScriptManager.getInstance().saveScript(script); - DFScript.MC.setScreen(new ScriptListScreen(true)); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean b = super.mouseClicked(mouseX, mouseY, button); - clearContextMenu(); - return b; - } - - private void clearContextMenu() { - for (CWidget w : contextMenu) { - panel.remove(w); - } - contextMenu.clear(); - } - - public void contextMenu(int x, int y, List contextMenuButtons) { - clearContextMenu(); - - int maxWidth = 0; - - for(ContextMenuButton w : contextMenuButtons) - { - TextRenderer t = DFScript.MC.textRenderer; - int width = t.getWidth(w.getName())/2 + 4; - - if(width > maxWidth) maxWidth = width; - } - - for(ContextMenuButton w : contextMenuButtons) - { - CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick()); - y += 8; - - panel.add(button); - contextMenu.add(button); - } - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java deleted file mode 100644 index cf07955..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.action.ScriptActionArgumentList; -import io.github.techstreet.dfscript.script.action.ScriptActionCategory; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import io.github.techstreet.dfscript.script.event.ScriptHeaderCategory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; - -public class ScriptHeaderCategoryScreen extends CScreen { - - private static final int size; - private static final List extra; - - static { - extra = List.of( - new HeaderExtra(ScriptFunction.functionIcon, (script, insertIndex) -> - script.getHeaders().add(insertIndex, new ScriptFunction( - script.getUnnamedFunction(), Items.LAPIS_LAZULI, new ScriptActionArgumentList(), "" - ))) - ); - size = (int) (Math.ceil(Math.sqrt(ScriptHeaderCategory.values().length+extra.size())) * 10)+4; - } - - private final Script script; - - public ScriptHeaderCategoryScreen(Script script, int insertIndex) { - super(size, size); - this.script = script; - - int x = 3; - int y = 3; - - for (ScriptHeaderCategory category : ScriptHeaderCategory.values()) { - CItem actionItem = new CItem(x, y, category.getIcon()); - widgets.add(actionItem); - - actionItem.setClickListener(btn -> DFScript.MC.setScreen(new ScriptAddHeaderScreen(script, insertIndex, category))); - - x += 10; - if (x >= size - 10) { - x = 3; - y += 10; - } - } - - for(HeaderExtra headerExtra : extra) { - CItem item = new CItem(x, y, headerExtra.icon()); - item.setClickListener(button -> { - headerExtra.onClick().accept(script, insertIndex); - close(); - }); - - widgets.add(item); - - x += 10; - if (x >= size - 10) { - x = 3; - y += 10; - } - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditScreen(script)); - } - - record HeaderExtra(ItemStack icon, BiConsumer onClick) {} -} \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptInstallScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptInstallScreen.java deleted file mode 100644 index e7458f3..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptInstallScreen.java +++ /dev/null @@ -1,112 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import com.google.gson.JsonObject; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.features.AuthHandler; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CText; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptManager; -import io.github.techstreet.dfscript.script.VirtualScript; -import io.github.techstreet.dfscript.script.util.UploadResponse; -import net.minecraft.text.Text; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; - -public class ScriptInstallScreen extends CScreen { - - protected ScriptInstallScreen(VirtualScript script) { - super(125, 52); - - CText name = new CText(5, 5, Text.literal("Name: " + script.getName())); - CText owner = new CText(5, 12, Text.literal("Creator: " + script.getOwner())); - CText id = new CText(5, 19, Text.literal("ID: " + script.getId())); - CText approved = new CText(5, 26, Text.literal("Approved: " + (script.isApproved() ? "§a✓ by " + script.getApprover() : "§c❌"))); - - widgets.add(name); - widgets.add(owner); - widgets.add(id); - widgets.add(approved); - - if (DFScript.MC.player != null) { - for (Script s : ScriptManager.getInstance().getScripts()) { - if (AuthHandler.getStaffMember()) { - if (!script.isApproved()) { - widgets.add(new CButton(38, 38, 40, 10, "Approve", () -> { - setApproved(script, true); - })); - } else { - widgets.add(new CButton(38, 38, 40, 10, "Unapprove", () -> { - setApproved(script, false); - })); - } - } - - if (s.getServer() != null && s.getServer().contains(script.getId())) { - if (s.getOwner().contains(script.getOwner())) { - return; - } - - widgets.add(new CButton(80, 38, 40, 10, "Update", () -> { - script.download(true); - })); - - return; - } - } - - widgets.add(new CButton(80, 38, 40, 10, "Install", () -> { - script.download(false); - })); - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptAddScreen()); - } - - public static void setApproved(VirtualScript script, boolean approved) { - try { - URL url = new URL("https://DFScript-Server.techstreetdev.repl.co/scripts/approve/"); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/json"); - con.setRequestProperty("Accept", "application/json"); - con.setRequestProperty("authorization", AuthHandler.getAuthCode()); - con.setDoOutput(true); - con.setReadTimeout(5000); - con.setConnectTimeout(5000); - - JsonObject obj = new JsonObject(); - obj.addProperty("id", script.getId()); - obj.addProperty("approved", approved); - - try (OutputStream os = con.getOutputStream()) { - byte[] input = obj.toString().getBytes("utf-8"); - os.write(input, 0, input.length); - } - - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptInstallScreen(script), "Successfully " + (!approved ? "un" : "") + "approved that script!")); - } - } catch (IOException e) { - if (e.getMessage().contains("403")) { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptInstallScreen(script), "You don't have permission to " + (!approved ? "un" : "") + "approve this script!")); - } else { -// e.printStackTrace(); - } - } - } catch (Exception e) { -// e.printStackTrace(); - } - } - -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptListScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptListScreen.java deleted file mode 100644 index 41c30c7..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptListScreen.java +++ /dev/null @@ -1,244 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import com.google.gson.JsonObject; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.features.AuthHandler; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.*; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptManager; -import io.github.techstreet.dfscript.script.VirtualScript; -import io.github.techstreet.dfscript.script.util.UploadResponse; -import io.github.techstreet.dfscript.util.Regex; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.apache.commons.codec.binary.Base64; - -import java.awt.*; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.zip.GZIPOutputStream; - -public class ScriptListScreen extends CScreen { - private final List contextMenu = new ArrayList<>(); - - public ScriptListScreen(boolean allowEditAndUpload) { - super(160, 100); - CScrollPanel panel = new CScrollPanel(0, 5, 160, 94); - widgets.add(panel); - - int y = 0; - for (Script s : ScriptManager.getInstance().getScripts()) { - MutableText text = Text.literal(s.getName()); - VirtualScript script = ScriptAddScreen.scriptHash.get(s.getServer()); - - if (script != null) { - text = Text.literal((script.isApproved() ? "⭐ " : "") + s.getName()); - - if (script.isApproved()) { - text = text.formatted(Formatting.YELLOW); - } - } - - if (s.disabled()) { - text = text.formatted(Formatting.STRIKETHROUGH); - } - - panel.add(new CText(6, y + 2, text)); - - panel.add(new CButton(4, y-1, 153, 10, "",() -> {}) { - @Override - public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { - Rectangle b = getBounds(); - context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000); - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - return false; - } - }); - - int addedY = 0; - int addedX = 118; - - if (allowEditAndUpload) { - // Delete Button - CButton delete = new CTexturedButton(20 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":delete.png", DFScript.MOD_ID + ":delete_highlight.png", () -> { - DFScript.MC.setScreen(new ScriptDeletionScreen(s)); - }); - - if (!Objects.equals(s.getServer(), "None") && s.getOwner() != null && s.getOwner().equals(DFScript.PLAYER_UUID)) { - delete.setOnClick(() -> { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "That script must be removed from the server to delete it!!")); - }); - } - - panel.add(delete); - } - - // Enable or Disable Button - CButton enableDisable; - if (s.disabled()) { - enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":enable.png", DFScript.MOD_ID + ":enable_highlight.png", () -> { - s.setDisabled(false); - ScriptManager.getInstance().saveScript(s); - DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload)); - }); - } else { - enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":disable.png", DFScript.MOD_ID + ":disable_highlight.png", () -> { - s.setDisabled(true); - ScriptManager.getInstance().saveScript(s); - DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload)); - }); - } - - panel.add(enableDisable); - - if(allowEditAndUpload) { - if (s.getOwner() != null && s.getOwner().replaceAll("-", "").equals(DFScript.PLAYER_UUID.replaceAll("-", ""))) { - // Edit Button - CButton edit = new CTexturedButton(addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":wrench.png", DFScript.MOD_ID + ":wrench_highlight.png", () -> { - DFScript.MC.setScreen(new ScriptEditScreen(s)); - }); - - panel.add(edit); - - // Upload or Remove Button - CButton upload = new CTexturedButton(10 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":upload.png", DFScript.MOD_ID + ":upload_highlight.png", () -> { - try { - // Encode the script JSON to GZIP Base64 - byte[] bytes = Files.readAllBytes(s.getFile().toPath()); - - ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); - GZIPOutputStream zos = new GZIPOutputStream(rstBao); - zos.write(bytes); - zos.close(); - - String scriptData = Base64.encodeBase64String(rstBao.toByteArray()); - - // Upload the script to the server - URL url = new URL("https://DFScript-Server.techstreetdev.repl.co/scripts/upload"); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/json"); - con.setRequestProperty("Accept", "application/json"); - con.setRequestProperty("authorization", AuthHandler.getAuthCode()); - con.setDoOutput(true); - - JsonObject obj = new JsonObject(); - obj.addProperty("data", scriptData); - - try (OutputStream os = con.getOutputStream()) { - byte[] input = obj.toString().getBytes(StandardCharsets.UTF_8); - os.write(input, 0, input.length); - } - - // Parse the response and get the scripts ID - try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - - UploadResponse uploadResponse = DFScript.GSON.fromJson(response.toString(), UploadResponse.class); - System.out.println(uploadResponse.getId()); - s.setServer(uploadResponse.getId()); - - ScriptManager.getInstance().saveScript(s); - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "Successfully uploaded the script to the server!")); - } - } catch (Exception e) { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "Failed to upload script to the server, please report this to a DFScript developer!")); -// e.printStackTrace(); - } - }); - - if (!Objects.equals(s.getServer(), "None")) { - upload = new CTexturedButton(10 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":unupload.png", DFScript.MOD_ID + ":unupload_highlight.png", () -> { - try { - // Remove the script to the server - URL url = new URL("https://DFScript-Server.techstreetdev.repl.co/scripts/remove/"); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/json"); - con.setRequestProperty("Accept", "application/json"); - con.setRequestProperty("authorization", AuthHandler.getAuthCode()); - con.setDoOutput(true); - - JsonObject obj = new JsonObject(); - obj.addProperty("id", s.getServer()); - - try (OutputStream os = con.getOutputStream()) { - byte[] input = obj.toString().getBytes(StandardCharsets.UTF_8); - os.write(input, 0, input.length); - } - - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { - s.setServer("None"); - ScriptManager.getInstance().saveScript(s); - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "Successfully removed the script from the server!")); - } - } catch (IOException e) { - if (e.getMessage().contains("401")) { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "You don't have permission to delete this script!")); - } else { -// e.printStackTrace(); - } - } - } catch (Exception e) { - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(allowEditAndUpload), "Failed to remove the script from the server, please try again!")); -// e.printStackTrace(); - } - }); - } - - panel.add(upload); - } - else { - //Script Settings Button - CButton settings = new CTexturedButton(10 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":settings.png", DFScript.MOD_ID + ":settings_highlight.png", () -> { - DFScript.MC.setScreen(new ScriptSettingsScreen(s, false)); - }); - - panel.add(settings); - } - } - - y += 12; - } - - if (allowEditAndUpload) { - CButton add = new CButton(60, y + 1, 40, 8, "Add", () -> { - DFScript.MC.setScreen(new ScriptAddScreen()); - }); - - panel.add(add); - } - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean b = super.mouseClicked(mouseX, mouseY, button); - clearContextMenu(); - return b; - } - - private void clearContextMenu() { - for (CWidget w : contextMenu) { - widgets.remove(w); - } - contextMenu.clear(); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptMessageScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptMessageScreen.java deleted file mode 100644 index 06cadf4..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptMessageScreen.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CButton; -import io.github.techstreet.dfscript.screen.widget.CText; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; - -import java.util.ArrayList; - -public class ScriptMessageScreen extends CScreen { - - private final Screen parent; - - public ScriptMessageScreen(Screen parent, String message) { - super(106, 60); - this.parent = parent; - - int counter = 0; - int y = 20; - - StringBuilder words = new StringBuilder(); - for (Character c : message.toCharArray()) { - counter += 1; - words.append(c); - - if (c.toString().equals(" ") && counter >= 25) { - int width = DFScript.MC.textRenderer.getWidth(words.toString()); - int x = (106 - width); - - CText text = new CText(10, y, Text.literal(words.toString())); - System.out.println(x + ":" + y + " == " + words); - widgets.add(text); - - y += 6; - words = new StringBuilder(""); - counter = 0; - } - } - - widgets.add(new CButton(33, 42, 40, 10, "Ok", () -> { - DFScript.MC.setScreen(parent); - })); - } - - @Override - public void close() { - DFScript.MC.setScreen(parent); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptPartCategoryScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptPartCategoryScreen.java deleted file mode 100644 index 6ad6b20..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptPartCategoryScreen.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptSnippet; -import io.github.techstreet.dfscript.script.action.ScriptActionCategory; - -public class ScriptPartCategoryScreen extends CScreen { - - private static final int size; - - static { - size = (int) (Math.ceil(Math.sqrt(ScriptActionCategory.values().length)) * 10)+4; - } - - private final Script script; - - public ScriptPartCategoryScreen(Script script, ScriptSnippet snippet, int insertIndex) { - super(size, size); - this.script = script; - - int x = 3; - int y = 3; - - for (ScriptActionCategory category : ScriptActionCategory.values()) { - CItem actionItem = new CItem(x, y, category.getIcon()); - widgets.add(actionItem); - - actionItem.setClickListener(btn -> DFScript.MC.setScreen(new ScriptAddPartScreen(script, snippet, insertIndex, category))); - - x += 10; - if (x >= size - 10) { - x = 3; - y += 10; - } - } - } - - @Override - public void close() { - DFScript.MC.setScreen(new ScriptEditScreen(script)); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSetValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSetValueScreen.java deleted file mode 100644 index bbcd16b..0000000 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSetValueScreen.java +++ /dev/null @@ -1,141 +0,0 @@ -package io.github.techstreet.dfscript.screen.script; - -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.CItem; -import io.github.techstreet.dfscript.screen.widget.CTextField; -import io.github.techstreet.dfscript.script.Script; -import io.github.techstreet.dfscript.script.ScriptParametrizedPart; -import io.github.techstreet.dfscript.script.argument.ScriptNumberArgument; -import io.github.techstreet.dfscript.script.argument.ScriptTextArgument; -import io.github.techstreet.dfscript.script.argument.ScriptVariableArgument; -import io.github.techstreet.dfscript.script.argument.ScriptVariableScope; -import io.github.techstreet.dfscript.script.event.ScriptFunction; -import io.github.techstreet.dfscript.script.event.ScriptHeader; -import io.github.techstreet.dfscript.script.values.*; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.Style; -import net.minecraft.text.Text; - -import java.util.function.Consumer; - -public class ScriptSetValueScreen extends CScreen { - - private final Script script; - - private final Consumer onSave; - - private final Runnable onClose; - - private final Class type; - - public ScriptSetValueScreen(Script script, Runnable onClose, Consumer onSave, Class type) { - this(script,onClose,onSave, type,null); - } - public ScriptSetValueScreen(Script script, Runnable onClose, Consumer onSave, Class type, String overwrite) { - super(100, 50); - this.script = script; - this.onSave = onSave; - this.onClose = onClose; - this.type = type; - - CTextField input = new CTextField("Input", 2, 2, 96, 35, true); - if(overwrite != null) input.setText(overwrite); - - ItemStack unknownIcon = new ItemStack(Items.LIGHT_GRAY_DYE); - unknownIcon.setCustomName(Text.literal("Unknown") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack textIcon = new ItemStack(Items.BOOK); - textIcon.setCustomName(Text.literal("Text") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack numberIcon = new ItemStack(Items.SLIME_BALL); - numberIcon.setCustomName(Text.literal("Number") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack trueIcon = new ItemStack(Items.LIME_DYE); - trueIcon.setCustomName(Text.literal("True") - .fillStyle(Style.EMPTY.withItalic(false))); - - ItemStack falseIcon = new ItemStack(Items.RED_DYE); - falseIcon.setCustomName(Text.literal("False") - .fillStyle(Style.EMPTY.withItalic(false))); - - CItem addNumber; - CItem addText; - CItem addTrue; - CItem addFalse; - CItem addUnknown; - - int x = 2; - - if(type == ScriptValue.class || type == ScriptNumberValue.class) { - addNumber = new CItem(x, 40, numberIcon); - x += 10; - - addNumber.setClickListener((btn) -> { - try { - double number = Double.parseDouble(input.getText()); - onSave.accept(new ScriptNumberValue(number)); - close(); - } catch (Exception err) { - input.textColor = 0xFF3333; - } - }); - - widgets.add(addNumber); - } - - if(type == ScriptValue.class || type == ScriptTextValue.class) { - addText = new CItem(x, 40, textIcon); - x += 10; - - addText.setClickListener((btn) -> { - onSave.accept(new ScriptTextValue(input.getText())); - close(); - }); - - widgets.add(addText); - } - - if(type == ScriptValue.class || type == ScriptBoolValue.class) { - addTrue = new CItem(x, 40, trueIcon); - x += 10; - addFalse = new CItem(x, 40, falseIcon); - x += 10; - - addTrue.setClickListener((btn) -> { - onSave.accept(new ScriptBoolValue(true)); - close(); - }); - - addFalse.setClickListener((btn) -> { - onSave.accept(new ScriptBoolValue(false)); - close(); - }); - - widgets.add(addTrue); - widgets.add(addFalse); - } - - addUnknown = new CItem(100-12, 40, unknownIcon); - - addUnknown.setClickListener((btn) -> { - onSave.accept(new ScriptUnknownValue()); - close(); - }); - - widgets.add(addUnknown); - - input.setChangedListener(() -> input.textColor = 0xFFFFFF); - - widgets.add(input); - } - - @Override - public void close() { - onClose.run(); - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSettingsScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSettingsScreen.java index 789a8b9..f200ace 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSettingsScreen.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptSettingsScreen.java @@ -2,6 +2,7 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.CScreen; +import io.github.techstreet.dfscript.screen.dfscript.ScriptListScreen; import io.github.techstreet.dfscript.screen.widget.*; import io.github.techstreet.dfscript.script.Script; import io.github.techstreet.dfscript.script.ScriptManager; @@ -134,13 +135,8 @@ public boolean mouseClicked(double x, double y, int button) { @Override public void close() { - if (owned) { - DFScript.MC.setScreen(new ScriptEditScreen(script)); - } - else { - ScriptManager.getInstance().saveScript(script); - DFScript.MC.setScreen(new ScriptListScreen(true)); - } + ScriptManager.getInstance().saveScript(script); + DFScript.MC.setScreen(new ScriptListScreen(true)); } public boolean mouseClicked(double mouseX, double mouseY, int button) { diff --git a/src/main/java/io/github/techstreet/dfscript/screen/util/ItemMaterialSelectMenu.java b/src/main/java/io/github/techstreet/dfscript/screen/util/ItemMaterialSelectMenu.java index 101544b..1e18c54 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/util/ItemMaterialSelectMenu.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/util/ItemMaterialSelectMenu.java @@ -2,10 +2,11 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.CReloadableScreen; -import io.github.techstreet.dfscript.screen.CScreen; -import io.github.techstreet.dfscript.screen.widget.*; +import io.github.techstreet.dfscript.screen.widget.CItem; +import io.github.techstreet.dfscript.screen.widget.CScrollPanel; +import io.github.techstreet.dfscript.screen.widget.CTextField; +import io.github.techstreet.dfscript.screen.widget.CTexturedButton; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CButton.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CButton.java index 116937f..6760996 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CButton.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CButton.java @@ -2,7 +2,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.sound.PositionedSoundInstance; @@ -10,6 +9,8 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import java.awt.*; + public class CButton implements CWidget { public final int x; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CImage.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CImage.java index 2046d75..ad55134 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CImage.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CImage.java @@ -1,10 +1,9 @@ package io.github.techstreet.dfscript.screen.widget; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; - import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; + +import java.awt.*; public class CImage implements CWidget { diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java index db69ce0..80c137a 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CItem.java @@ -2,7 +2,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.util.RenderUtil; -import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.item.TooltipContext; import net.minecraft.client.sound.PositionedSoundInstance; @@ -13,7 +12,6 @@ import org.lwjgl.opengl.GL11; import java.awt.*; -import java.util.Optional; import java.util.function.Consumer; public class CItem implements CWidget { @@ -44,8 +42,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) stack.push(); stack.translate(x, y, 0); RenderUtil.renderGuiItem(context, item); - if(countText != null) - { + if (countText != null) { stack.translate(4, 4, 0); stack.scale(0.5f, 0.5f, 0.5f); context.drawText(DFScript.MC.textRenderer, countText, 0, 0, 0xFFFFFFFF, true); diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java index 9184cb6..63b6b5e 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java @@ -2,16 +2,11 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import org.joml.Vector4f; public class CPlainPanel extends CPanel { - public CPlainPanel(int x, int y, int w, int h) { super(x, y, w, h); } diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java index 7f6f405..1d54f4f 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java @@ -2,10 +2,6 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import org.joml.Vector4f; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CText.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CText.java index bcc7526..baaf84e 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CText.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CText.java @@ -1,12 +1,13 @@ package io.github.techstreet.dfscript.screen.widget; import io.github.techstreet.dfscript.DFScript; -import java.awt.Rectangle; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import java.awt.*; + public class CText implements CWidget { int x; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java index 805e6cd..1dfdfdd 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTextField.java @@ -2,13 +2,14 @@ import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; -import java.util.List; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import org.joml.Vector4f; +import java.awt.*; +import java.util.List; + public class CTextField implements CWidget { final int x, y, width, height; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTexturedButton.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTexturedButton.java index 321b485..3ec873e 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CTexturedButton.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CTexturedButton.java @@ -1,11 +1,11 @@ package io.github.techstreet.dfscript.screen.widget; import io.github.techstreet.dfscript.util.RenderUtil; -import java.awt.Rectangle; - import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; +import java.awt.*; + public class CTexturedButton extends CButton { private String texture; diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java index b757ff9..ad4181a 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java @@ -1,9 +1,9 @@ package io.github.techstreet.dfscript.screen.widget; -import java.awt.Rectangle; - import net.minecraft.client.gui.DrawContext; +import java.awt.*; + public interface CWidget { void render(DrawContext context, int mouseX, int mouseY, float tickDelta); diff --git a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWrappedText.java b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWrappedText.java index 0f0c7bd..2d95e24 100644 --- a/src/main/java/io/github/techstreet/dfscript/screen/widget/CWrappedText.java +++ b/src/main/java/io/github/techstreet/dfscript/screen/widget/CWrappedText.java @@ -1,14 +1,15 @@ package io.github.techstreet.dfscript.screen.widget; import io.github.techstreet.dfscript.DFScript; -import java.util.ArrayList; -import java.util.List; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; +import java.util.ArrayList; +import java.util.List; + public class CWrappedText extends CText { private int width; diff --git a/src/main/java/io/github/techstreet/dfscript/script/ScriptComment.java b/src/main/java/io/github/techstreet/dfscript/script/ScriptComment.java index 4b9ed21..3a5ba36 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/ScriptComment.java +++ b/src/main/java/io/github/techstreet/dfscript/script/ScriptComment.java @@ -4,10 +4,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.github.techstreet.dfscript.screen.script.ScriptEditScreen; import io.github.techstreet.dfscript.screen.widget.CItem; import io.github.techstreet.dfscript.screen.widget.CScrollPanel; -import io.github.techstreet.dfscript.screen.widget.CTextField; import io.github.techstreet.dfscript.script.execution.ScriptTask; import io.github.techstreet.dfscript.script.render.ScriptPartRender; import io.github.techstreet.dfscript.script.render.ScriptPartRenderDynamicElement; @@ -17,7 +15,6 @@ import net.minecraft.text.Text; import java.lang.reflect.Type; -import java.util.List; public class ScriptComment extends ScriptPart { @@ -51,11 +48,6 @@ public void create(ScriptPartRender render, Script script) { panel.add(new CItem(5+indent*5, y, new ItemStack(Items.MAP).setCustomName(Text.literal("Comment").setStyle(Style.EMPTY.withItalic(false))))); - CTextField cTextField = new CTextField(getComment(),15+indent*5, y-1, ScriptEditScreen.width-(15+indent*5)-5, 10, true); - - cTextField.setChangedListener(() -> setComment(cTextField.getText())); - - panel.add(cTextField); return y+10; })); } diff --git a/src/main/java/io/github/techstreet/dfscript/script/ScriptManager.java b/src/main/java/io/github/techstreet/dfscript/script/ScriptManager.java index 788461e..c5f00b7 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/ScriptManager.java +++ b/src/main/java/io/github/techstreet/dfscript/script/ScriptManager.java @@ -7,7 +7,6 @@ import io.github.techstreet.dfscript.event.system.Event; import io.github.techstreet.dfscript.event.system.EventManager; import io.github.techstreet.dfscript.loader.Loadable; -import io.github.techstreet.dfscript.screen.script.ScriptAddScreen; import io.github.techstreet.dfscript.script.action.ScriptActionArgument; import io.github.techstreet.dfscript.script.action.ScriptActionArgumentList; import io.github.techstreet.dfscript.script.action.ScriptBuiltinAction; @@ -21,7 +20,6 @@ import io.github.techstreet.dfscript.script.options.ScriptNamedOption; import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition; import io.github.techstreet.dfscript.script.repetitions.ScriptWhile; -import io.github.techstreet.dfscript.script.util.ScriptValueJson; import io.github.techstreet.dfscript.script.values.*; import io.github.techstreet.dfscript.util.FileUtil; import io.github.techstreet.dfscript.util.chat.ChatType; @@ -136,21 +134,6 @@ public void load() { } catch (Exception err) { LOGGER.error("Unable to listen for new scripts", err); } - - final int[] tick = {0}; - new Thread(ScriptAddScreen::getScripts).start(); - lastServerUpdate = System.currentTimeMillis() / 1000; - - EventManager.getInstance().register(TickEvent.class, event -> { - tick[0] += 1; - - if (tick[0] >= 100) { - tick[0] = 0; - - new Thread(ScriptAddScreen::getScripts).start(); - lastServerUpdate = System.currentTimeMillis() / 1000; - } - }); } private void unloadScript(File file) { diff --git a/src/main/java/io/github/techstreet/dfscript/script/ScriptSnippet.java b/src/main/java/io/github/techstreet/dfscript/script/ScriptSnippet.java index e3abf69..ec9db20 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/ScriptSnippet.java +++ b/src/main/java/io/github/techstreet/dfscript/script/ScriptSnippet.java @@ -3,9 +3,6 @@ import com.google.gson.*; import io.github.techstreet.dfscript.DFScript; import io.github.techstreet.dfscript.screen.ContextMenuButton; -import io.github.techstreet.dfscript.screen.script.ScriptEditPartScreen; -import io.github.techstreet.dfscript.screen.script.ScriptEditScreen; -import io.github.techstreet.dfscript.screen.script.ScriptPartCategoryScreen; import io.github.techstreet.dfscript.screen.widget.CButton; import io.github.techstreet.dfscript.screen.widget.CScrollPanel; import io.github.techstreet.dfscript.screen.widget.CText; @@ -17,7 +14,6 @@ import io.github.techstreet.dfscript.script.conditions.ScriptConditionType; import io.github.techstreet.dfscript.script.event.ScriptHeader; import io.github.techstreet.dfscript.script.execution.ScriptActionContext; -import io.github.techstreet.dfscript.script.execution.ScriptPosStackElement; import io.github.techstreet.dfscript.script.execution.ScriptTask; import io.github.techstreet.dfscript.script.render.ScriptPartRender; import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition; @@ -33,7 +29,6 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; public class ScriptSnippet extends ArrayList { boolean hidden = false; @@ -50,9 +45,6 @@ public int create(CScrollPanel panel, int y, int indent, Script script, ScriptHe ScriptSnippet thisSnippet = this; panel.add(new CButton(3, y, 2, 8, "", () -> { thisSnippet.hidden = !thisSnippet.hidden; - if(DFScript.MC.currentScreen instanceof ScriptEditScreen e) { - e.reload(); - } }) { @Override public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) { @@ -127,30 +119,6 @@ public boolean mouseClicked(double x, double y, int button) { if (getBounds().contains(x, y)) { DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), 1f, 1f)); - if (button == 0) { - if(part instanceof ScriptParametrizedPart parametrizedPart) - DFScript.MC.setScreen(new ScriptEditPartScreen(parametrizedPart, script, header)); - if(part instanceof ScriptComment) - return false; - } else { - List contextMenu = new ArrayList<>(); - contextMenu.add(new ContextMenuButton("Insert Before", () -> { - DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex)); - }, false)); - contextMenu.add(new ContextMenuButton("Insert After", () -> { - DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex + 1)); - }, false)); - contextMenu.add(new ContextMenuButton("Delete", () -> { - thisSnippet.remove(currentIndex); - })); - contextMenu.addAll(part.getContextMenu()); - DFScript.MC.send(() -> { - if(DFScript.MC.currentScreen instanceof ScriptEditScreen editScreen) - { - editScreen.contextMenu((int) x, (int) y, contextMenu); - } - }); - } return true; } return false; @@ -160,13 +128,6 @@ public boolean mouseClicked(double x, double y, int button) { index++; } - ScriptPartRender.createIndent(panel, indent, y, 8); - CButton add = new CButton((ScriptEditScreen.width-30)/2, y, 30, 8, "Add Part", () -> { - DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, thisSnippet.size())); - }); - - panel.add(add); - return y+10; } diff --git a/src/main/java/io/github/techstreet/dfscript/script/VirtualScript.java b/src/main/java/io/github/techstreet/dfscript/script/VirtualScript.java deleted file mode 100644 index 108a0d4..0000000 --- a/src/main/java/io/github/techstreet/dfscript/script/VirtualScript.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.github.techstreet.dfscript.script; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.script.ScriptListScreen; -import io.github.techstreet.dfscript.screen.script.ScriptMessageScreen; -import io.github.techstreet.dfscript.util.FileUtil; -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; - -public class VirtualScript { - private final String name; - private final String owner; - private final String id; - private boolean approved = false; - private String approver; - - public VirtualScript(String name, String owner, String id) { - this.name = name; - this.owner = owner; - this.id = id; - } - - public String getName() { - return name; - } - - public String getOwner() { - return owner; - } - - public String getId() { - return id; - } - - public boolean isApproved() { - return approved; - } - - public void setApproved(boolean approved) { - this.approved = approved; - } - - public String getApprover() { - return approver; - } - - public void setApprover(String approver) { - this.approver = approver; - } - - public void download(boolean update) { - try { - InputStream is = new URL("https://dfscript-server.techstreetdev.repl.co/scripts/get/" + id).openStream(); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - - File file = FileUtil.folder("Scripts").resolve(name + ".json").toFile(); - - if (!update) { - int count = 1; - while (file.exists()) { - file = FileUtil.folder("Scripts").resolve(name + "_" + count + ".json").toFile(); - count += 1; - } - } - - JsonObject obj = JsonParser.parseReader(rd).getAsJsonObject(); - obj.addProperty("disabled", false); - obj.addProperty("server", id); - String content = obj.toString(); - - Files.write(file.toPath(), content.getBytes()); - DFScript.MC.setScreen(new ScriptMessageScreen(new ScriptListScreen(true), "Successfully installed '" + name + "' by " + owner + "!")); - } catch (Exception e) { -// e.printStackTrace(); - } - } -} diff --git a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionArgument.java b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionArgument.java index 51191c9..afe2130 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionArgument.java +++ b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionArgument.java @@ -37,6 +37,22 @@ public ScriptActionArgument(String name, ScriptActionArgumentType type) { defaultValue = new ScriptUnknownValue(); } + public String getName() { + return name; + } + + public boolean isOptional() { + return optional; + } + + public boolean isPlural() { + return plural; + } + + public ScriptActionArgumentType getType() { + return type; + } + public ScriptActionArgument optional(boolean optional) { this.optional = optional; this.rightOptional = false; @@ -143,7 +159,7 @@ private ItemStack convertIcon(ItemStack icon) { } if(optional() || plural()) { - lore.add(NbtString.of(Text.Serializer.toJson( + lore.add(NbtString.of(Text.Serialization.toJsonString( Text.literal((optional() ? (plural() ? "Optional & " : "Optional") : "") + (plural() ? "Plural" : "")) .fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)) @@ -151,7 +167,7 @@ private ItemStack convertIcon(ItemStack icon) { } if(!(defaultValue() instanceof ScriptUnknownValue)) { - lore.add(NbtString.of(Text.Serializer.toJson( + lore.add(NbtString.of(Text.Serialization.toJsonString( Text.literal("Default: "+defaultValue().formatAsText()) .fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)) ))); @@ -205,6 +221,14 @@ public enum ScriptActionArgumentType { this.allowOptional = allowOptional; } + public String getName() { + return name; + } + + public Item getIcon() { + return icon; + } + public MutableText text() { MutableText val = Text.literal(name); return val.fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.WHITE)); @@ -230,7 +254,7 @@ public ItemStack icon(String name) { itemStack.setCustomName(Text.literal(name).setStyle(Style.EMPTY.withColor(Formatting.WHITE).withItalic(false))); NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(text()))); + lore.add(NbtString.of(Text.Serialization.toJsonString(text()))); itemStack.getSubNbt("display").put("Lore", lore); return itemStack; diff --git a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategory.java b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategory.java index 088560c..6b7de40 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategory.java +++ b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategory.java @@ -12,7 +12,6 @@ import net.minecraft.item.Items; import net.minecraft.text.Style; import net.minecraft.text.Text; -import org.slf4j.helpers.FormattingTuple; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategoryExtraPartCreator.java b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategoryExtraPartCreator.java index 2b4545a..9229365 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategoryExtraPartCreator.java +++ b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionCategoryExtraPartCreator.java @@ -1,11 +1,8 @@ package io.github.techstreet.dfscript.script.action; -import io.github.techstreet.dfscript.DFScript; -import io.github.techstreet.dfscript.screen.script.ScriptEditScreen; import io.github.techstreet.dfscript.script.ScriptPart; import net.minecraft.item.ItemStack; -import java.util.Objects; import java.util.function.Supplier; public class ScriptActionCategoryExtraPartCreator extends ScriptActionCategoryExtra { @@ -15,7 +12,6 @@ public class ScriptActionCategoryExtraPartCreator extends ScriptActionCategoryEx public ScriptActionCategoryExtraPartCreator(ItemStack icon, Supplier createPartFunction) { super(icon, (sc, sn, ii) -> { sn.add(ii, createPartFunction.get()); - DFScript.MC.setScreen(new ScriptEditScreen(sc)); }); this.icon = icon; this.createPartFunction = createPartFunction; diff --git a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java index bbc03bd..1c0c94f 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java +++ b/src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java @@ -1681,6 +1681,11 @@ public enum ScriptActionType { description.add("No description provided."); builder.accept(this); } + + public Item getItem() { + return icon; + } + public ItemStack getIcon() { ItemStack item = new ItemStack(icon); @@ -1693,28 +1698,28 @@ public ItemStack getIcon() { if(isDeprecated()) { - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("This action is deprecated!") + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("This action is deprecated!") .fillStyle(Style.EMPTY .withColor(Formatting.RED) .withItalic(false))))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Use '" + deprecated.getName() + "'") + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Use '" + deprecated.getName() + "'") .fillStyle(Style.EMPTY .withColor(Formatting.RED) .withItalic(false))))); } for (String descriptionLine: description) { - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(descriptionLine) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(descriptionLine) .fillStyle(Style.EMPTY .withColor(Formatting.GRAY) .withItalic(false))))); } - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); for (ScriptActionArgument arg : arguments) { for (Text txt : arg.text()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } } @@ -1729,6 +1734,7 @@ public ItemStack getIcon() { return item; } + public String getName() { return name; } @@ -1745,6 +1751,14 @@ public ScriptActionCategory getCategory() { return category; } + public List getDescription() { + return description; + } + + public ScriptActionArgumentList getArguments() { + return arguments; + } + private ScriptActionType action(Consumer action) { this.action = action; return this; diff --git a/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptClientValueArgument.java b/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptClientValueArgument.java index e39f71e..5fd6862 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptClientValueArgument.java +++ b/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptClientValueArgument.java @@ -168,18 +168,22 @@ public enum ScriptClientValueArgument implements ScriptArgument { }); private final String name; + private final String description; + private final Item item; private final ItemStack icon; private final Function consumer; private final ScriptActionArgumentType type; ScriptClientValueArgument(String name, String description, Item type, ScriptActionArgumentType varType, Function consumer) { this.name = name; + this.description = description; + this.item = type; this.icon = new ItemStack(type); icon.setCustomName(Text.literal(name) .fillStyle(Style.EMPTY .withItalic(false))); NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(description) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(description) .fillStyle(Style.EMPTY .withColor(Formatting.GRAY) .withItalic(false))))); @@ -189,6 +193,18 @@ public enum ScriptClientValueArgument implements ScriptArgument { this.type = varType; } + public Item getItem() { + return item; + } + + public String getDescription() { + return description; + } + + public ScriptActionArgumentType getType() { + return type; + } + public String getName() { return name; } diff --git a/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptVariableArgument.java b/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptVariableArgument.java index 22c5dd4..2b82123 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptVariableArgument.java +++ b/src/main/java/io/github/techstreet/dfscript/script/argument/ScriptVariableArgument.java @@ -58,7 +58,7 @@ public ItemStack getArgIcon() { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(scope.getName()))); + lore.add(NbtString.of(Text.Serialization.toJsonString(scope.getName()))); icon.getSubNbt("display").put("Lore", lore); diff --git a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBooleanSet.java b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBooleanSet.java index 975b91d..d3d2c4e 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBooleanSet.java +++ b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBooleanSet.java @@ -43,14 +43,14 @@ public class ScriptBooleanSet extends ScriptParametrizedPart { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Sets a variable to the result of a condition.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Sets a variable to the result of a condition.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); MutableText t = ScriptActionArgument.ScriptActionArgumentType.VARIABLE.text(); t.append(Text.literal(" - ").fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))) .append(Text.literal("Result").fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.WHITE))); - lore.add(NbtString.of(Text.Serializer.toJson(t))); + lore.add(NbtString.of(Text.Serialization.toJsonString(t))); booleanSetIcon.getSubNbt("display") .put("Lore", lore); @@ -115,18 +115,18 @@ public ItemStack getIcon() { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Sets a variable to the result of a condition.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Sets a variable to the result of a condition.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); MutableText t = ScriptActionArgument.ScriptActionArgumentType.VARIABLE.text(); t.append(Text.literal(" - ").fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))) .append(Text.literal("Result").fillStyle(Style.EMPTY.withItalic(false).withColor(Formatting.WHITE))); - lore.add(NbtString.of(Text.Serializer.toJson(t))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(t))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); for (Text txt : condition.getLore()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } icon.getSubNbt("display") diff --git a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBranch.java b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBranch.java index 9b4b478..ab51c66 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBranch.java +++ b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptBranch.java @@ -39,7 +39,7 @@ public class ScriptBranch extends ScriptParametrizedPart implements ScriptScopeP NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Closes the current code block.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Closes the current code block.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); closeBracketIcon.getSubNbt("display") .put("Lore", lore); @@ -51,7 +51,7 @@ public class ScriptBranch extends ScriptParametrizedPart implements ScriptScopeP lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Executes if the last IF condition failed.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Executes if the last IF condition failed.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); elseIcon.getSubNbt("display") .put("Lore", lore); diff --git a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptConditionType.java b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptConditionType.java index dab8058..359ee7e 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptConditionType.java +++ b/src/main/java/io/github/techstreet/dfscript/script/conditions/ScriptConditionType.java @@ -337,7 +337,7 @@ public ItemStack getIcon(String prefix) { NbtList lore = new NbtList(); for (Text txt : getLore()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } item.getSubNbt("display") diff --git a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEmptyHeader.java b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEmptyHeader.java index 8da7fd1..3794ed0 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEmptyHeader.java +++ b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEmptyHeader.java @@ -33,7 +33,7 @@ public class ScriptEmptyHeader extends ScriptHeader { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Literally can never be triggered...").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Literally can never be triggered...").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); emptyIcon.getSubNbt("display") .put("Lore", lore); diff --git a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEventType.java b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEventType.java index 97d695b..7bbde4e 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEventType.java +++ b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptEventType.java @@ -37,19 +37,23 @@ public enum ScriptEventType { RECEIVE_SOUND(RecieveSoundEvent.class, "OnReceiveSound", "Executed when a player receives a sound", Items.NAUTILUS_SHELL); private final String name; + private final String description; + private final Item item; private final ItemStack icon; private final Class codeutilitiesEvent; ScriptEventType(Class codeutilitiesEvent, String name, String description, Item item) { this.codeutilitiesEvent = codeutilitiesEvent; this.name = name; + this.description = description; + this.item = item; icon = new ItemStack(item); icon.setCustomName(Text.literal(name) .setStyle(Style.EMPTY .withColor(Formatting.WHITE) .withItalic(false))); NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(description) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(description) .fillStyle(Style.EMPTY .withColor(Formatting.GRAY) .withItalic(false))))); @@ -65,6 +69,14 @@ public String getName() { return name; } + public String getDescription() { + return description; + } + + public Item getItem() { + return item; + } + public Class getCodeutilitiesEvent() { return codeutilitiesEvent; } diff --git a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptFunction.java b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptFunction.java index 00150b4..a2b8994 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/event/ScriptFunction.java +++ b/src/main/java/io/github/techstreet/dfscript/script/event/ScriptFunction.java @@ -57,19 +57,19 @@ public ItemStack getIcon() { if(description != "") { for (String descriptionLine: description.split("\n")) { - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(descriptionLine) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(descriptionLine) .fillStyle(Style.EMPTY .withColor(Formatting.GRAY) .withItalic(false))))); } if(argList.size() > 0) - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); } for (ScriptActionArgument arg : argList) { for (Text txt : arg.text()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } } diff --git a/src/main/java/io/github/techstreet/dfscript/script/options/ScriptOptionEnum.java b/src/main/java/io/github/techstreet/dfscript/script/options/ScriptOptionEnum.java index 294dde8..0925106 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/options/ScriptOptionEnum.java +++ b/src/main/java/io/github/techstreet/dfscript/script/options/ScriptOptionEnum.java @@ -65,7 +65,7 @@ public ItemStack getIcon() NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(description) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(description) .fillStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false)) ))); diff --git a/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptRepetitionType.java b/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptRepetitionType.java index 39609e1..f809652 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptRepetitionType.java +++ b/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptRepetitionType.java @@ -129,28 +129,28 @@ public ItemStack getIcon() { if(isDeprecated()) { - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("This action is deprecated!") + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("This action is deprecated!") .fillStyle(Style.EMPTY .withColor(Formatting.RED) .withItalic(false))))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Use '" + deprecated.getName() + "'") + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Use '" + deprecated.getName() + "'") .fillStyle(Style.EMPTY .withColor(Formatting.RED) .withItalic(false))))); } for (String descriptionLine: description) { - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal(descriptionLine) + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal(descriptionLine) .fillStyle(Style.EMPTY .withColor(Formatting.GRAY) .withItalic(false))))); } - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); for (ScriptActionArgument arg : arguments) { for (Text txt : arg.text()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } } diff --git a/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptWhile.java b/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptWhile.java index f345136..2e22302 100644 --- a/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptWhile.java +++ b/src/main/java/io/github/techstreet/dfscript/script/repetitions/ScriptWhile.java @@ -39,7 +39,7 @@ public class ScriptWhile extends ScriptRepetition { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Repeats while a condition is true.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Repeats while a condition is true.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); whileIcon.getSubNbt("display") .put("Lore", lore); @@ -66,11 +66,11 @@ public ItemStack getIcon() { NbtList lore = new NbtList(); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("Repeats while a condition is true.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); - lore.add(NbtString.of(Text.Serializer.toJson(Text.literal("")))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("Repeats while a condition is true.").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false))))); + lore.add(NbtString.of(Text.Serialization.toJsonString(Text.literal("")))); for (Text txt : condition.getLore()) { - lore.add(NbtString.of(Text.Serializer.toJson(txt))); + lore.add(NbtString.of(Text.Serialization.toJsonString(txt))); } icon.getSubNbt("display") diff --git a/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java b/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java index 19c0093..f9641c0 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/ComponentUtil.java @@ -1,13 +1,14 @@ package io.github.techstreet.dfscript.util; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import net.minecraft.text.MutableText; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class ComponentUtil { public static MutableText fromString(String message) { @@ -34,7 +35,7 @@ public static MutableText fromString(String message) { s = s.withFormatting(Formatting.byCode(col.charAt(1))); } else { s = Style.EMPTY.withColor( - TextColor.parse("#" + col.replaceAll("§", "").substring(1))); + TextColor.parse("#" + col.replaceAll("§", "").substring(1)).getOrThrow(false, (h) -> {throw new IllegalArgumentException(h);})); } lastIndex = matcher.end(); } diff --git a/src/main/java/io/github/techstreet/dfscript/util/FileUtil.java b/src/main/java/io/github/techstreet/dfscript/util/FileUtil.java index 2d67c6e..f59dc95 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/FileUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/FileUtil.java @@ -1,6 +1,7 @@ package io.github.techstreet.dfscript.util; import io.github.techstreet.dfscript.DFScript; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java b/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java index 3e797ff..35149d3 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/RenderUtil.java @@ -5,7 +5,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.*; -import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.toast.SystemToast; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; diff --git a/src/main/java/io/github/techstreet/dfscript/util/Scheduler.java b/src/main/java/io/github/techstreet/dfscript/util/Scheduler.java index b6a42b0..bf512a1 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/Scheduler.java +++ b/src/main/java/io/github/techstreet/dfscript/util/Scheduler.java @@ -3,9 +3,10 @@ import io.github.techstreet.dfscript.event.TickEvent; import io.github.techstreet.dfscript.event.system.EventManager; import io.github.techstreet.dfscript.loader.Loadable; +import org.apache.commons.lang3.tuple.MutablePair; + import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang3.tuple.MutablePair; public class Scheduler implements Loadable { diff --git a/src/main/java/io/github/techstreet/dfscript/util/StringUtil.java b/src/main/java/io/github/techstreet/dfscript/util/StringUtil.java index 20f822a..e623cad 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/StringUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/StringUtil.java @@ -1,7 +1,13 @@ package io.github.techstreet.dfscript.util; import com.google.gson.JsonArray; -import java.awt.Toolkit; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.text.TextColor; +import net.minecraft.util.Formatting; + +import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.lang.reflect.Field; @@ -10,11 +16,6 @@ import java.util.Random; import java.util.stream.Collectors; import java.util.stream.Stream; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; -import net.minecraft.util.Formatting; public class StringUtil { public static final Regex STRIP_CHARS_PATTERN = Regex.of("(^\\s+|\\s+$)"); diff --git a/src/main/java/io/github/techstreet/dfscript/util/VersionUtil.java b/src/main/java/io/github/techstreet/dfscript/util/VersionUtil.java index 9387551..5d9f646 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/VersionUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/VersionUtil.java @@ -3,6 +3,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.github.techstreet.dfscript.DFScript; + import java.io.IOException; public class VersionUtil { diff --git a/src/main/java/io/github/techstreet/dfscript/util/WebUtil.java b/src/main/java/io/github/techstreet/dfscript/util/WebUtil.java index 506b13c..8a3549f 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/WebUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/WebUtil.java @@ -1,6 +1,7 @@ package io.github.techstreet.dfscript.util; import io.github.techstreet.dfscript.DFScript; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; diff --git a/src/main/java/io/github/techstreet/dfscript/util/chat/ChatUtil.java b/src/main/java/io/github/techstreet/dfscript/util/chat/ChatUtil.java index dc4d80e..5faeecd 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/chat/ChatUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/chat/ChatUtil.java @@ -1,13 +1,14 @@ package io.github.techstreet.dfscript.util.chat; import io.github.techstreet.dfscript.DFScript; -import java.awt.Color; import net.minecraft.sound.SoundEvent; import net.minecraft.text.MutableText; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.text.TextColor; +import java.awt.*; + public class ChatUtil { public static void playSound(SoundEvent sound) { diff --git a/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabber.java b/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabber.java index 9fde8e4..1ec6d51 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabber.java +++ b/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabber.java @@ -1,10 +1,11 @@ package io.github.techstreet.dfscript.util.chat; import io.github.techstreet.dfscript.features.MessageType; +import net.minecraft.text.Text; + import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import net.minecraft.text.Text; /** * A utility class to grab the next X chat messages. diff --git a/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabberTask.java b/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabberTask.java index a696231..42364e9 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabberTask.java +++ b/src/main/java/io/github/techstreet/dfscript/util/chat/MessageGrabberTask.java @@ -1,9 +1,10 @@ package io.github.techstreet.dfscript.util.chat; import io.github.techstreet.dfscript.features.MessageType; +import net.minecraft.text.Text; + import java.util.List; import java.util.function.Consumer; -import net.minecraft.text.Text; public class MessageGrabberTask { diff --git a/src/main/java/io/github/techstreet/dfscript/util/render/BlendableTexturedButtonWidget.java b/src/main/java/io/github/techstreet/dfscript/util/render/BlendableTexturedButtonWidget.java index 7de7370..40377f4 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/render/BlendableTexturedButtonWidget.java +++ b/src/main/java/io/github/techstreet/dfscript/util/render/BlendableTexturedButtonWidget.java @@ -3,11 +3,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class BlendableTexturedButtonWidget extends TexturedButtonWidget { @@ -25,10 +21,10 @@ public BlendableTexturedButtonWidget(int x, int y, int width, int height, Identi // } @Override - public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { + public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { RenderSystem.clearColor(1.0F, 1.0F, 1.0F, this.alpha); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - super.renderButton(context, mouseX, mouseY, delta); + super.renderWidget(context, mouseX, mouseY, delta); } } \ No newline at end of file diff --git a/src/main/java/io/github/techstreet/dfscript/util/template/CompressionUtil.java b/src/main/java/io/github/techstreet/dfscript/util/template/CompressionUtil.java index 06690d3..faf2631 100644 --- a/src/main/java/io/github/techstreet/dfscript/util/template/CompressionUtil.java +++ b/src/main/java/io/github/techstreet/dfscript/util/template/CompressionUtil.java @@ -1,10 +1,6 @@ package io.github.techstreet.dfscript.util.template; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; +import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.zip.GZIPInputStream; diff --git a/src/main/resources/assets/dfscript/icon_transparent.png b/src/main/resources/assets/dfscript/icon_transparent.png new file mode 100644 index 0000000..e2c7e47 Binary files /dev/null and b/src/main/resources/assets/dfscript/icon_transparent.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7a2da59..18a06f0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,9 +22,9 @@ "dfscript.mixins.json" ], "depends": { - "fabricloader": ">=0.15.3", + "fabricloader": ">=0.15.7", "fabric-api": "*", - "minecraft": "~1.20", + "minecraft": "1.20.4", "java": ">=17" } }