Skip to content

Commit e981926

Browse files
committed
chore: Edit feature
1 parent 0b3c0c5 commit e981926

File tree

14 files changed

+513
-187
lines changed

14 files changed

+513
-187
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ temp/*
44
build/*
55
logs/*
66
test.py
7-
_config.yaml
7+
_config.yaml
8+
codes/*
9+
dev/*
10+
test.txt
11+
test/*

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,28 @@
1515
> Developers and translators are welcome to join the CubeGPT Team!
1616
1717
## Introduction
18-
> Give GPT your idea, AI generates customized Minecraft server plugins with one click, which is suitable for Bukkit, Spigot, Paper, Purpur, Arclight, CatServer, Magma, Mohist and other Bukkit-based servers.
18+
> Give the LLM your idea, AI generates customized Minecraft server plugins with one click, which is suitable for Bukkit, Spigot, Paper, Purpur, Arclight, CatServer, Magma, Mohist and other Bukkit-based servers.
1919
20-
BukkitGPT is an open source, free, AI-powered Minecraft Bukkit plugin generator. It was developed for minecraft server owners who are not technically savvy but need to implement all kinds of customized small plugins. From code to build, debug, all done by gpt.
20+
BukkitGPT is an open source, free, AI-powered Minecraft Bukkit plugin generator. It was developed for minecraft server owners who are not technically savvy but need to implement all kinds of customized small plugins. From code to build, debug, all done by the LLM.
2121

22-
## WebApp
22+
<details>
23+
<summary>The WebApp Edition: Generate plugin on a website, available even on your phone!</summary>
2324
> [!WARNING]
2425
> There're big differences between *BukkitGPT(-v3)* and *BukkitGPT WebApp*. The BukkitGPT is a self-hosted, free, open-source, community-driven project, while the BukkitGPT WebApp is a paid, cloud-hosted service that provides a more user-friendly experience for non-developers.
2526
> Issues and questions about BukkitGPT WebApp should be directed to our [Discord Server](https://discord.gg/kTZtXw8s7r).
2627
27-
Don't want to prepare the Python & Maven environment? Try our [WebApp](http://cubegpt.org/), designed for non-developers, just enter the plugin name and description, and you can get the plugin jar file.
28+
Don't want to deal with Python, Maven, BuildTools, and other complicated environments?
29+
Hey! Here's [the WebApp version](https://webapp.cubegpt.org) designed just for you - generate plugins **even on your phone**!
2830

2931
*The service is paid since the API key we are using is not free. You can get 1 key for 5 generations for $1 [here](https://ko-fi.com/s/cd5d4fcaba) or [here (for Chinese users)](https://afdian.com/item/b839835461e311efbd1252540025c377)
3032

31-
## Partner
32-
[![](https://www.bisecthosting.com/partners/custom-banners/c37f58c7-c49b-414d-b53c-1a6e1b1cff71.webp)](https://bisecthosting.com/cubegpt)
33+
*The WebApp edition doesn't support plugin editing feature yet, but we are working on it.
34+
</details>
3335

3436
## Features
3537

3638
- Automatically generate plugin code based on the user's description.
37-
- Edit existing plugins. (WIP)
39+
- Edit existing plugins.
3840

3941
## Plans and TODOs
4042

@@ -59,11 +61,9 @@ python -m venv venv
5961
source venv/bin/activate # for Windows, use `venv\Scripts\activate`
6062
pip install -r requirements.txt
6163
```
62-
2. Edit `config.yaml` and fill in your [OpenAI API Key](https://platform.openai.com/settings/organization/api-keys).
64+
2. Edit `config.yaml` and fill in your OpenAI API Key.
6365
3. Run `ui.py` (with command `python ui.py`).
64-
4. Enter the artifact name & description & package id as instructed to generate your plugin.
65-
5. Copy your plugin from `projects/<artifact_name>/target/<artifact_name>-<version>.jar` to your server `plugins/` folder.
66-
6. Restart your server and enjoy your AI-powered-plugin.
66+
4. Enjoy!
6767

6868
## Troubleshooting
6969

build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from log_writer import logger
33

44

5-
def build_plugin(artifact_name):
6-
project_path = f"codes/{artifact_name}"
5+
def build_plugin(artifact_name, path=False) -> str:
6+
project_path = f"codes/{artifact_name}" if path == False else artifact_name
77
build_command = [
88
"cd",
99
project_path,
Binary file not shown.
Binary file not shown.

config.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ def load_config():
1515
with open("config.yaml", "r") as conf:
1616
config_content = yaml.safe_load(conf)
1717
for key, value in config_content.items():
18-
if key == "GENERATE_MODEL" and value == "gpt-4":
19-
globals()[
20-
key
21-
] = "gpt-4-turbo-preview" # Force using gpt-4-turbo-preview if the user set the GENERATE_MODEL to gpt-4. Because gpt-4 is not longer supports json modes.
2218
globals()[key] = value
23-
logger(f"config: {key} -> {value}")
19+
logger(f"config: {key} -> {value if key != 'API_KEY' else '********'}")
2420

2521

2622
def edit_config(key, value):

config.yaml

+74-52
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
# GPT SETTINGS #
44
# Get your api key from openai. Remember google/bing is always your best friend.
5-
# Model names: gpt-4o, o1-preview, o1-mini
6-
# Recommend -> o1-preview (Expensive and Slow, Best Performance) , gpt-4o (Cheap and fast, Good Performance)
75

8-
API_KEY: ""
9-
BASE_URL: "https://api.openai.com/v1"
6+
API_KEY: "" # Get your API Key from https://openrouter.ai/settings/keys for free
7+
BASE_URL: "https://openrouter.ai/api/v1"
108

11-
GENERATION_MODEL: "gpt-4o"
12-
FIXING_MODEL: "gpt-4o" # Deprecated
9+
GENERATION_MODEL: "deepseek/deepseek-r1:free"
10+
FIXING_MODEL: "openai/gpt-4o"
1311

1412
# DEVELOPER SETTINGS #
15-
VERSION_NUMBER: "0.1.3"
13+
VERSION_NUMBER: "1.0.0"
1614

1715
# PROMPT SETTINGS #
1816
# If you don't know what it is, please don't touch it. Be sure to backup before editing.
@@ -25,8 +23,9 @@ SYS_GEN: |
2523
codes/%ARTIFACT_NAME%/src/main/resources/plugin.yml
2624
codes/%ARTIFACT_NAME%/src/main/resources/config.yml
2725
codes/%ARTIFACT_NAME%/pom.xml
28-
Response in json format.
2926
27+
You should output one and only one JSON containing all the final codes inside a ```json``` tag. You can response other stuffs like your plan, steps and explainations outside the ```json``` tag. Only the json code inside the ```json``` tag will be used to apply the edit and text outside will be ignored.
28+
3029
This JSON contains an array under the key `codes`, where each element represents a file with its path and content for a Minecraft plugin project setup. Here’s a more detailed breakdown:
3130
3231
The JSON has four file objects, each specifying:
@@ -35,7 +34,7 @@ SYS_GEN: |
3534
3635
For each file:
3736
Main.java:
38-
Path: codes/%ARTIFACT_NAME%/src/main/java/%PKG_ID_LST%/Main.java
37+
Path: codes/%ARTIFACT_NAME%/src/main/java/%PKG_ID_LST%Main.java
3938
Content: The main Java class implementing the plugin's core functionality. It includes essential imports (import org.bukkit.Bukkit;) and extends JavaPlugin while implementing CommandExecutor.
4039
plugin.yml:
4140
Path: codes/%ARTIFACT_NAME%/src/main/resources/plugin.yml
@@ -65,50 +64,73 @@ SYS_GEN: |
6564
</dependencies>
6665
6766
If the user ask you to add a new item, as you are not able to generate textures, you should use the texture of a similar item of vanilla minecraft. For example: Mooncake -> Texture: Pumpkin Pie.
68-
You should never response anything else. Never use Markdown format. Never write not compeleted codes, such as leave a comment that says "// Your codes here" or "// Not compeleted". Do not forget to add ";" in the java codes. Make sure your response is json formatted.
69-
70-
Special Requirement: No ANY line feeds. Here're some examples:
71-
(eg. for java codes) package com.example.plugin; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { public void onEnable() { getLogger().info("Plugin has been enabled!"); } }
72-
(eg. for yaml files) {name: ExamplePlugin, main: com.example.example.plugin.Main, version: "1.0"}
73-
Same for the xml file.
67+
Never write not completed codes, such as leave a comment that says "// Your codes here" or "// Not completed". Do not forget to add ";" in the java codes. Make sure your response is json formatted.
7468
7569
USR_GEN: |
7670
%DESCRIPTION%
7771
78-
SYS_FIX: |
79-
You're a minecraft bukkit plugin coder AI. Game Version: 1.13.2 (1.13.2-R0.1-SNAPSHOT)
80-
Fix the error in the code provided by user. The error message is also provided by the user.
81-
Response in json format:
82-
{
83-
\"codes\": [
84-
{
85-
\"file\": \"codes/%ARTIFACT_NAME%/src/main/java/%PKG_ID_LST%Main.java\",
86-
\"code\": \"package ...;\\nimport org.bukkit.Bukkit;\\npublic class Main extends JavaPlugin implements CommandExecutor {\\n... (The code you need to write)\"
87-
},
88-
{
89-
\"file\": \"codes/%ARTIFACT_NAME%/src/main/resources/plugin.yml\",
90-
\"code\": \"name: ...\\nversion: ...\\n...\"
91-
},
92-
{
93-
\"file\": \"codes/%ARTIFACT_NAME%/src/main/resources/config.yml\",
94-
\"code\": \"...\"
95-
},
96-
{
97-
\"file\": \"codes/%ARTIFACT_NAME%/pom.xml\",
98-
\"code\": \"...\"
99-
}
100-
]
101-
}
102-
You should never response anything else. Never use Markdown format. Use \n for line feed, and never forget to use \ before ". Never write uncompeleted codes, such as leave a comment that says "// Your codes here" or "// Original code" or "// Uncompeleted".
103-
104-
USR_FIX: |
105-
Main.java:
106-
%MAIN_JAVA%
107-
plugin.yml:
108-
%PLUGIN_YML%
109-
config.yml:
110-
%CONFIG_YML%
111-
pom.xml:
112-
%POM_XML%
113-
error message:
114-
%P_ERROR_MSG%
72+
SYS_EDIT: |
73+
You're a minecraft bukkit plugin coder AI.
74+
You're given the codes of a minecraft bukkit plugin and a request to edit the plugin.
75+
You should edit the codes to meet the request.
76+
You should use git diff (without index line) to show the changes you made.
77+
78+
For example, if the original code of codes/ExamplePlugin4/src/main/java/org/cubegpt/188eba63/Main.java is:
79+
```java
80+
1 package org.cubegpt._188eba63;
81+
2
82+
3 import org.bukkit.Bukkit;
83+
4 import org.bukkit.event.EventHandler;
84+
5 import org.bukkit.event.Listener;
85+
6 import org.bukkit.event.player.PlayerJoinEvent;
86+
7 import org.bukkit.plugin.java.JavaPlugin;
87+
8
88+
9 public class Main extends JavaPlugin implements Listener {
89+
10
90+
11 @Override
91+
12 public void onEnable() {
92+
13 Bukkit.getServer().getPluginManager().registerEvents(this, this);
93+
14 }
94+
15
95+
16 @EventHandler
96+
17 public void onPlayerJoin(PlayerJoinEvent event) {
97+
18 event.getPlayer().sendMessage("hello");
98+
19 }
99+
20 }
100+
```
101+
And the request is "Change the join message to 'hi'", then the response should be:
102+
```diff
103+
diff --git a/codes/ExamplePlugin4/src/main/java/org/cubegpt/188eba63/Main.java b/codes/ExamplePlugin4/src/main/java/org/cubegpt/188eba63/Main.java
104+
--- a/codes/ExamplePlugin4/src/main/java/org/cubegpt/188eba63/Main.java
105+
+++ b/codes/ExamplePlugin4/src/main/java/org/cubegpt/188eba63/Main.java
106+
@@ -1,17 +1,17 @@
107+
-event.getPlayer().sendMessage("hello");
108+
+event.getPlayer().sendMessage("hi");
109+
@@ -19,20 +19,20 @@
110+
```
111+
There could be multiple diffs, put each diff inside a markdown ```diff``` tag.
112+
You can response other stuffs like your plan, steps and explainations outside the ```diff``` tag. Only the diffs inside the ```diff``` tag will be used to apply the edit and text outside will be ignored.
113+
Make sure the diffs are valid and can be applied to the original code.
114+
Do not forget to add ";" in the java codes.
115+
116+
There should be a empty pom.xml in the original code, and you should fill the pom.xml with things needed for the plugin to work. Always add this in pom.xml:
117+
<repositories>
118+
<repository>
119+
<id>spigot-repo</id>
120+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
121+
</repository>
122+
</repositories>
123+
124+
<dependencies>
125+
<dependency>
126+
<groupId>org.spigotmc</groupId>
127+
<artifactId>spigot-api</artifactId>
128+
<version>1.13.2-R0.1-SNAPSHOT</version>
129+
<scope>provided</scope>
130+
</dependency>
131+
</dependencies>
132+
133+
USR_EDIT: |
134+
%ORIGINAL_CODE%
135+
My request:
136+
%REQUEST%

0 commit comments

Comments
 (0)