diff --git a/codes/Demo/pom.xml b/codes/Demo/pom.xml
new file mode 100644
index 0000000..c6ee47c
--- /dev/null
+++ b/codes/Demo/pom.xml
@@ -0,0 +1,54 @@
+
+
+ 4.0.0
+
+ org.cubegpt
+ Demo
+ 1.0-SNAPSHOT
+ jar
+
+
+
+ org.bukkit
+ bukkit
+ 1.13.2-R0.1-SNAPSHOT
+ provided
+
+
+
+
+ src/main/java
+
+
+ src/main/resources
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ lib/
+ org.cubegpt._54672e99.Main
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java b/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java
new file mode 100644
index 0000000..b11ee5a
--- /dev/null
+++ b/codes/Demo/src/main/java/org/cubegpt/54672e99/Main.java
@@ -0,0 +1,30 @@
+package org.cubegpt._54672e99;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.event.Listener;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class Main extends JavaPlugin implements Listener {
+
+ @Override
+ public void onEnable() {
+ getServer().getPluginManager().registerEvents(this, this);
+ Bukkit.getConsoleSender().sendMessage("Plugin enabled!");
+ }
+
+ @EventHandler
+ public void onPlayerJoin(PlayerJoinEvent event) {
+ event.getPlayer().sendMessage("hello");
+ }
+
+ @Override
+ public void onDisable() {
+ Bukkit.getConsoleSender().sendMessage("Plugin disabled!");
+ }
+}
\ No newline at end of file
diff --git a/codes/Demo/src/main/resources/config.yml b/codes/Demo/src/main/resources/config.yml
new file mode 100644
index 0000000..cb441b6
--- /dev/null
+++ b/codes/Demo/src/main/resources/config.yml
@@ -0,0 +1 @@
+greeting-message: 'hello'
\ No newline at end of file
diff --git a/codes/Demo/src/main/resources/plugin.yml b/codes/Demo/src/main/resources/plugin.yml
new file mode 100644
index 0000000..4d3dd41
--- /dev/null
+++ b/codes/Demo/src/main/resources/plugin.yml
@@ -0,0 +1,10 @@
+name: Demo
+version: 1.0
+main: org.cubegpt._54672e99.Main
+api-version: 1.13
+author: CubeGPT
+dependencies: []
+commands:
+ demo:
+ description: Sends a greeting message to everyone.
+ usage: /
\ No newline at end of file
diff --git a/codes/Demo/target/Demo-1.0-SNAPSHOT.jar b/codes/Demo/target/Demo-1.0-SNAPSHOT.jar
new file mode 100644
index 0000000..f106aaa
Binary files /dev/null and b/codes/Demo/target/Demo-1.0-SNAPSHOT.jar differ
diff --git a/codes/Demo/target/classes/config.yml b/codes/Demo/target/classes/config.yml
new file mode 100644
index 0000000..cb441b6
--- /dev/null
+++ b/codes/Demo/target/classes/config.yml
@@ -0,0 +1 @@
+greeting-message: 'hello'
\ No newline at end of file
diff --git a/codes/Demo/target/classes/org/cubegpt/54672e99/Main.class b/codes/Demo/target/classes/org/cubegpt/54672e99/Main.class
new file mode 100644
index 0000000..1ed5168
Binary files /dev/null and b/codes/Demo/target/classes/org/cubegpt/54672e99/Main.class differ
diff --git a/codes/Demo/target/classes/plugin.yml b/codes/Demo/target/classes/plugin.yml
new file mode 100644
index 0000000..4d3dd41
--- /dev/null
+++ b/codes/Demo/target/classes/plugin.yml
@@ -0,0 +1,10 @@
+name: Demo
+version: 1.0
+main: org.cubegpt._54672e99.Main
+api-version: 1.13
+author: CubeGPT
+dependencies: []
+commands:
+ demo:
+ description: Sends a greeting message to everyone.
+ usage: /
\ No newline at end of file
diff --git a/codes/Demo/target/maven-archiver/pom.properties b/codes/Demo/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..67ada22
--- /dev/null
+++ b/codes/Demo/target/maven-archiver/pom.properties
@@ -0,0 +1,3 @@
+artifactId=Demo
+groupId=org.cubegpt
+version=1.0-SNAPSHOT
diff --git a/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..93c8498
--- /dev/null
+++ b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1 @@
+org\cubegpt\_54672e99\Main.class
diff --git a/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..07108c4
--- /dev/null
+++ b/codes/Demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1 @@
+D:\zhousl\BukkitGPT\BukkitGPT-v3\codes\Demo\src\main\java\org\cubegpt\54672e99\Main.java
diff --git a/codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class b/codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class
new file mode 100644
index 0000000..6e07f61
Binary files /dev/null and b/codes/ExamplePlugin4/target/classes/org/cubegpt/188eba63/Main.class differ
diff --git a/codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class b/codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class
deleted file mode 100644
index d5d5c92..0000000
Binary files a/codes/ExamplePlugin4/target/classes/org/cubegpt/_188eba63/Main.class and /dev/null differ
diff --git a/core.py b/core.py
index e5308e6..597709e 100644
--- a/core.py
+++ b/core.py
@@ -23,6 +23,10 @@ def initialize():
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
logger(f"Launch. Software version {config.VERSION_NUMBER}, platform {sys.platform}")
+ if "gpt-3.5" in config.GENERATION_MODEL and config.BYPASS_NO_GPT35_FOR_GENERATION_LIMIT is False:
+ print("gpt-3.5 writes bugs *all the time* and is not recommended for code generation. Switching to gpt-4.")
+ config.edit_config("GENERATION_MODEL", config.GENERATION_MODEL.replace("gpt-3.5", "gpt-4"))
+
def askgpt(system_prompt: str, user_prompt: str, model_name: str, disable_json_mode: bool = False, image_url: str = None):
"""
Interacts with ChatGPT using the specified prompts.
diff --git a/ui.py b/ui.py
index aa4597c..75970ad 100644
--- a/ui.py
+++ b/ui.py
@@ -9,7 +9,9 @@
from log_writer import logger
import config
import core
+import build
+#---------- Functions ----------#
def open_config(args: dict):
"""
Opens the config file.
@@ -94,22 +96,134 @@ def raise_error(args: dict):
"""
raise Exception("This is a test error.")
-root = CreateQGUI(title="CubeAgents",
- tab_names=["Generate", "Settings", "DevTools"]
+#---------- Generate Function ----------#
+def generate(args: dict):
+ """
+ Generates the plugin.
+
+ Args:
+ args (dict): A dictionary containing the arguments.
+
+ Returns:
+ bool: Always True.
+ """
+ global error_msg, pkg_id_path
+
+ # Get user inputs
+ name = args["PluginName"].get()
+ description = args["PluginDescription"].get()
+
+ artifact_name = name.replace(" ", "")
+ package_id = f"org.cubegpt.{uuid.uuid4().hex[:8]}"
+
+ pkg_id_path = ""
+ for id in package_id.split("."):
+ pkg_id_path += id + "/"
+
+ logger(f"user_input -> name: {name}")
+ logger(f"user_input -> description: {description}")
+ logger(f"random_generate -> package_id: {package_id}")
+ logger(f"str_path -> pkg_id_path: {pkg_id_path}")
+
+ print("Generating plugin...")
+
+ codes = core.askgpt(config.SYS_GEN.replace("%ARTIFACT_NAME%", artifact_name).replace("%PKG_ID_LST%", pkg_id_path), config.USR_GEN.replace("%DESCRIPTION", description), config.GENERATION_MODEL)
+ logger(f"codes: {codes}")
+
+ core.response_to_action(codes)
+
+ print("Code generated. Building now...")
+
+ result = build.build_plugin(artifact_name)
+ if "BUILD SUCCESS" in result:
+ print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
+ elif "Compilation failure":
+ error_msg = result
+ print("Build failed. To pass the error to ChatGPT && let it fix, jump to the Fixing page and click the Fix button.")
+ else:
+ print("Unknown error. Please check the logs && send the log to @BaimoQilin on discord.")
+
+
+ return True
+
+def fix(args: dict):
+ """
+ Fixes the error.
+
+ Args:
+ args (dict): A dictionary containing the arguments.
+
+ Returns:
+ bool: Always True.
+ """
+ artifact_name = args["PluginName"].get()
+
+ print("Passing the error to ChatGPT...")
+
+ files = [f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java",
+ f"codes/{artifact_name}/src/main/resources/plugin.yml",
+ f"codes/{artifact_name}/src/main/resources/config.yml",
+ f"codes/{artifact_name}/pom.xml"]
+
+ ids = ["main_java",
+ "plugin_yml",
+ "config_yml",
+ "pom_xml"]
+
+ main_java = None
+ plugin_yml = None
+ config_yml = None
+ pom_xml = None
+
+ for file in files:
+ with open(file, "r") as f:
+ code = f.read()
+ id = ids[files.index(file)]
+ globals()[id] = code
+
+ print("Generating...")
+ codes = core.askgpt(config.SYS_FIX.replace("%ARTIFACT_NAME%", str(artifact_name)), config.USR_FIX.replace("%MAIN_JAVA%", str(main_java)).replace("%PLUGIN_YML%", str(plugin_yml)).replace("%CONFIG_YML%", str(config_yml)).replace("%POM_XML%", str(pom_xml)).replave("%PKG_ID_LST%", pkg_id_path).replace("%P_ERROR_MSG%", str(error_msg)), config.FIXING_MODEL)
+
+ shutil.rmtree(f"codes/{artifact_name}")
+ core.response_to_action(codes)
+
+ print("Code generated. Building now...")
+
+ result = build.build_plugin(artifact_name)
+
+ if "BUILD SUCCESS" in result:
+ print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
+ else:
+ print("Build failed again. Please check the logs && send the log to @BaimoQilin on discord.")
+
+ return True
+
+#---------- Main Program ----------#
+
+root = CreateQGUI(title="BukkitGPT-v3",
+ tab_names=["Generate", "Fixing", "Settings", "DevTools"]
)
+error_msg = None
logger("Starting program.")
# Initialize Core
core.initialize()
+print("BukkitGPT v3 beta console running")
+
# Banner
-root.add_banner_tool(GitHub("https://github.com/CubeGPT/CubeAgents"))
+root.add_banner_tool(GitHub("https://github.com/CubeGPT/BukkitGPT-v3"))
# Generate Page
-# Codes here.
+root.add_notebook_tool(InputBox(name="PluginName", default="ExamplePlugin", label_info="Plugin Name"))
+root.add_notebook_tool(InputBox(name="PluginDescription", default="Send msg 'hello' to every joined player.", label_info="Plugin Description"))
+
+root.add_notebook_tool(RunButton(bind_func=generate, name="Generate", text="Generate Plugin", checked_text="Generating...", tab_index=0))
-# More pages here.
+# Fixing Page #
+root.add_notebook_tool(Label(name="Fixing_DESCRIPTION", text="This is a fixing page. If the build fails, click the Fix button to fix the error in the LATEST build.", tab_index=1))
+root.add_notebook_tool(RunButton(bind_func=fix, name="Fix", text="Fix", checked_text="Fixing...", tab_index=1))
# Settings Page
root.add_notebook_tool(InputBox(name="API_KEY", default=config.API_KEY, label_info="API Key", tab_index=2))
@@ -132,7 +246,7 @@ def raise_error(args: dict):
# Sidebar
root.set_navigation_about(author="CubeGPT Team",
version=config.VERSION_NUMBER,
- github_url="https://github.com/CubeGPT/CubeAgents")
+ github_url="https://github.com/CubeGPT/BukkitGPT-v3")