Skip to content

Commit 8155501

Browse files
committed
feat: Basic UI
1 parent 95c192f commit 8155501

File tree

15 files changed

+235
-6
lines changed

15 files changed

+235
-6
lines changed

codes/Demo/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.cubegpt</groupId>
8+
<artifactId>Demo</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.bukkit</groupId>
15+
<artifactId>bukkit</artifactId>
16+
<version>1.13.2-R0.1-SNAPSHOT</version>
17+
<scope>provided</scope>
18+
</dependency>
19+
</dependencies>
20+
21+
<build>
22+
<sourceDirectory>src/main/java</sourceDirectory>
23+
<resources>
24+
<resource>
25+
<directory>src/main/resources</directory>
26+
<filtering>true</filtering>
27+
</resource>
28+
</resources>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>3.8.1</version>
34+
<configuration>
35+
<source>1.8</source>
36+
<target>1.8</target>
37+
</configuration>
38+
</plugin>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-jar-plugin</artifactId>
42+
<configuration>
43+
<archive>
44+
<manifest>
45+
<addClasspath>true</addClasspath>
46+
<classpathPrefix>lib/</classpathPrefix>
47+
<mainClass>org.cubegpt._54672e99.Main</mainClass>
48+
</manifest>
49+
</archive>
50+
</configuration>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.cubegpt._54672e99;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.plugin.java.JavaPlugin;
5+
import org.bukkit.event.Listener;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.player.PlayerJoinEvent;
8+
import org.bukkit.command.CommandExecutor;
9+
import org.bukkit.command.Command;
10+
import org.bukkit.command.CommandSender;
11+
import org.bukkit.entity.Player;
12+
13+
public class Main extends JavaPlugin implements Listener {
14+
15+
@Override
16+
public void onEnable() {
17+
getServer().getPluginManager().registerEvents(this, this);
18+
Bukkit.getConsoleSender().sendMessage("Plugin enabled!");
19+
}
20+
21+
@EventHandler
22+
public void onPlayerJoin(PlayerJoinEvent event) {
23+
event.getPlayer().sendMessage("hello");
24+
}
25+
26+
@Override
27+
public void onDisable() {
28+
Bukkit.getConsoleSender().sendMessage("Plugin disabled!");
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
greeting-message: 'hello'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Demo
2+
version: 1.0
3+
main: org.cubegpt._54672e99.Main
4+
api-version: 1.13
5+
author: CubeGPT
6+
dependencies: []
7+
commands:
8+
demo:
9+
description: Sends a greeting message to everyone.
10+
usage: /<command>
3.15 KB
Binary file not shown.

codes/Demo/target/classes/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
greeting-message: 'hello'
Binary file not shown.

codes/Demo/target/classes/plugin.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Demo
2+
version: 1.0
3+
main: org.cubegpt._54672e99.Main
4+
api-version: 1.13
5+
author: CubeGPT
6+
dependencies: []
7+
commands:
8+
demo:
9+
description: Sends a greeting message to everyone.
10+
usage: /<command>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
artifactId=Demo
2+
groupId=org.cubegpt
3+
version=1.0-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org\cubegpt\_54672e99\Main.class
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
D:\zhousl\BukkitGPT\BukkitGPT-v3\codes\Demo\src\main\java\org\cubegpt\54672e99\Main.java
Binary file not shown.
Binary file not shown.

core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def initialize():
2323
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
2424
logger(f"Launch. Software version {config.VERSION_NUMBER}, platform {sys.platform}")
2525

26+
if "gpt-3.5" in config.GENERATION_MODEL and config.BYPASS_NO_GPT35_FOR_GENERATION_LIMIT is False:
27+
print("gpt-3.5 writes bugs *all the time* and is not recommended for code generation. Switching to gpt-4.")
28+
config.edit_config("GENERATION_MODEL", config.GENERATION_MODEL.replace("gpt-3.5", "gpt-4"))
29+
2630
def askgpt(system_prompt: str, user_prompt: str, model_name: str, disable_json_mode: bool = False, image_url: str = None):
2731
"""
2832
Interacts with ChatGPT using the specified prompts.

ui.py

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from log_writer import logger
1010
import config
1111
import core
12+
import build
1213

14+
#---------- Functions ----------#
1315
def open_config(args: dict):
1416
"""
1517
Opens the config file.
@@ -94,22 +96,134 @@ def raise_error(args: dict):
9496
"""
9597
raise Exception("This is a test error.")
9698

97-
root = CreateQGUI(title="CubeAgents",
98-
tab_names=["Generate", "Settings", "DevTools"]
99+
#---------- Generate Function ----------#
100+
def generate(args: dict):
101+
"""
102+
Generates the plugin.
103+
104+
Args:
105+
args (dict): A dictionary containing the arguments.
106+
107+
Returns:
108+
bool: Always True.
109+
"""
110+
global error_msg, pkg_id_path
111+
112+
# Get user inputs
113+
name = args["PluginName"].get()
114+
description = args["PluginDescription"].get()
115+
116+
artifact_name = name.replace(" ", "")
117+
package_id = f"org.cubegpt.{uuid.uuid4().hex[:8]}"
118+
119+
pkg_id_path = ""
120+
for id in package_id.split("."):
121+
pkg_id_path += id + "/"
122+
123+
logger(f"user_input -> name: {name}")
124+
logger(f"user_input -> description: {description}")
125+
logger(f"random_generate -> package_id: {package_id}")
126+
logger(f"str_path -> pkg_id_path: {pkg_id_path}")
127+
128+
print("Generating plugin...")
129+
130+
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)
131+
logger(f"codes: {codes}")
132+
133+
core.response_to_action(codes)
134+
135+
print("Code generated. Building now...")
136+
137+
result = build.build_plugin(artifact_name)
138+
if "BUILD SUCCESS" in result:
139+
print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
140+
elif "Compilation failure":
141+
error_msg = result
142+
print("Build failed. To pass the error to ChatGPT && let it fix, jump to the Fixing page and click the Fix button.")
143+
else:
144+
print("Unknown error. Please check the logs && send the log to @BaimoQilin on discord.")
145+
146+
147+
return True
148+
149+
def fix(args: dict):
150+
"""
151+
Fixes the error.
152+
153+
Args:
154+
args (dict): A dictionary containing the arguments.
155+
156+
Returns:
157+
bool: Always True.
158+
"""
159+
artifact_name = args["PluginName"].get()
160+
161+
print("Passing the error to ChatGPT...")
162+
163+
files = [f"codes/{artifact_name}/src/main/java/{pkg_id_path}Main.java",
164+
f"codes/{artifact_name}/src/main/resources/plugin.yml",
165+
f"codes/{artifact_name}/src/main/resources/config.yml",
166+
f"codes/{artifact_name}/pom.xml"]
167+
168+
ids = ["main_java",
169+
"plugin_yml",
170+
"config_yml",
171+
"pom_xml"]
172+
173+
main_java = None
174+
plugin_yml = None
175+
config_yml = None
176+
pom_xml = None
177+
178+
for file in files:
179+
with open(file, "r") as f:
180+
code = f.read()
181+
id = ids[files.index(file)]
182+
globals()[id] = code
183+
184+
print("Generating...")
185+
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)
186+
187+
shutil.rmtree(f"codes/{artifact_name}")
188+
core.response_to_action(codes)
189+
190+
print("Code generated. Building now...")
191+
192+
result = build.build_plugin(artifact_name)
193+
194+
if "BUILD SUCCESS" in result:
195+
print(f"Build complete. Find your plugin at 'codes/{artifact_name}/target/{artifact_name}.jar'")
196+
else:
197+
print("Build failed again. Please check the logs && send the log to @BaimoQilin on discord.")
198+
199+
return True
200+
201+
#---------- Main Program ----------#
202+
203+
root = CreateQGUI(title="BukkitGPT-v3",
204+
tab_names=["Generate", "Fixing", "Settings", "DevTools"]
99205
)
206+
error_msg = None
100207

101208
logger("Starting program.")
102209

103210
# Initialize Core
104211
core.initialize()
105212

213+
print("BukkitGPT v3 beta console running")
214+
106215
# Banner
107-
root.add_banner_tool(GitHub("https://github.com/CubeGPT/CubeAgents"))
216+
root.add_banner_tool(GitHub("https://github.com/CubeGPT/BukkitGPT-v3"))
108217

109218
# Generate Page
110-
# Codes here.
219+
root.add_notebook_tool(InputBox(name="PluginName", default="ExamplePlugin", label_info="Plugin Name"))
220+
root.add_notebook_tool(InputBox(name="PluginDescription", default="Send msg 'hello' to every joined player.", label_info="Plugin Description"))
221+
222+
root.add_notebook_tool(RunButton(bind_func=generate, name="Generate", text="Generate Plugin", checked_text="Generating...", tab_index=0))
111223

112-
# More pages here.
224+
# Fixing Page #
225+
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))
226+
root.add_notebook_tool(RunButton(bind_func=fix, name="Fix", text="Fix", checked_text="Fixing...", tab_index=1))
113227

114228
# Settings Page
115229
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):
132246
# Sidebar
133247
root.set_navigation_about(author="CubeGPT Team",
134248
version=config.VERSION_NUMBER,
135-
github_url="https://github.com/CubeGPT/CubeAgents")
249+
github_url="https://github.com/CubeGPT/BukkitGPT-v3")
136250

137251

138252

0 commit comments

Comments
 (0)