Skip to content

Commit f16a0ab

Browse files
committed
move hardcoded strings to build constants
1 parent 9bb5fc8 commit f16a0ab

File tree

8 files changed

+34
-12
lines changed

8 files changed

+34
-12
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ This will run ZenithProxy with your plugin loaded in the `run` directory.
6161
### New Plugin Checklist
6262

6363
1. Edit `gradle.properties`:
64-
- `plugin_name` - Name of your plugin, used in the plugin jar name (e.g. `ExamplePlugin`)
64+
- `plugin_name` - Name of your plugin, shown to users and in the plugin jar file name (e.g. `ExamplePlugin`)
65+
- `plugin_id` - Unique identifier for your plugin (e.g. `example-plugin`)
66+
- Must start with a lowercase letter and contain only lowercase letters, numbers, or dashes (`-`)
67+
- `mc` - MC version of ZenithProxy your plugin is compiled for (e.g. `1.21.4`)
6568
- `maven_group` - Java package for your project (e.g. `com.github.rfresh2`)
6669
1. Move files to your new corresponding package / maven group:
6770
- Example: `src/main/java/org/example` -> `src/main/java/com/github/rfresh2`
6871
- First create the new package in `src/main/java`. Then click and drag original subpackages/classes to your new one
6972
- Do this with Intellij to avoid manually editing all the source files
70-
- You must also move folders/package for the `src/main/templates` folder
71-
- Also make sure to update the package import at the very top of `BuiltConstants.java`, it will not be done automatically
73+
- You must also create and move package folders for the `src/main/templates` folder
7274
1. Edit `ExamplePlugin.java`, or remove it and create a new main class
7375
- Make sure to update the `@Plugin` annotation

build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ plugins {
55
group = properties["maven_group"] as String
66
version = properties["plugin_version"] as String
77
val mc = properties["mc"] as String
8+
val pluginId = properties["plugin_id"] as String
89

910
java { toolchain { languageVersion = JavaLanguageVersion.of(25) } }
1011

1112
zenithProxyPlugin {
1213
templateProperties = mapOf(
1314
// variables in your BuildConstants.java template class
14-
"version" to project.version
15+
"version" to project.version,
16+
"mc_version" to mc,
17+
"plugin_id" to pluginId,
18+
"maven_group" to group as String,
1519
)
1620
// the minimum supported java version for users of your plugin
1721
javaReleaseVersion = JavaLanguageVersion.of(21)
1822
}
1923

2024
repositories {
2125
maven("https://maven.2b2t.vc/releases") {
22-
description = "ZenithProxy Releases and Dependencies"
26+
description = "ZenithProxy Releases"
2327
}
2428
maven("https://maven.2b2t.vc/remote") {
2529
description = "Dependencies used by ZenithProxy"

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
plugin_version=1.0.0
22
plugin_name=ZenithProxyExamplePlugin
3+
plugin_id=example-plugin
4+
# More info about MC Version support: https://wiki.2b2t.vc/Setup/#release-channels
35
mc=1.21.4
46
maven_group=org.example
57

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/org/example/ExampleConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
/**
44
* Example configuration POJO.
55
*
6-
* Configurations are saved and loaded to JSON files
6+
* Configurations are saved and loaded to JSON files.
7+
*
8+
* Save and load is handled automatically, happens on every command execution, proxy start/stop, etc.
79
*
810
* All fields should be public and mutable.
911
*

src/main/java/org/example/ExamplePlugin.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
import org.example.module.ExampleWanderModule;
1313

1414
@Plugin(
15-
id = "example-plugin",
15+
id = BuildConstants.PLUGIN_ID,
1616
version = BuildConstants.VERSION,
1717
description = "ZenithProxy Example Plugin",
1818
url = "https://github.com/rfresh2/ZenithProxyExamplePlugin",
1919
authors = {"rfresh2"},
20-
mcVersions = {"1.21.4"} // to indicate any MC version: @Plugin(mcVersions = "*")
21-
// if you touch packet classes, you almost certainly need to pin to a single mc version
20+
mcVersions = {BuildConstants.MC_VERSION} // to indicate any MC version: @Plugin(mcVersions = "*")
2221
)
2322
public class ExamplePlugin implements ZenithProxyPlugin {
2423
// public static for simple access from modules and commands
@@ -31,7 +30,7 @@ public void onLoad(PluginAPI pluginAPI) {
3130
LOG = pluginAPI.getLogger();
3231
LOG.info("Example Plugin loading...");
3332
// initialize any configurations before modules or commands might need to read them
34-
PLUGIN_CONFIG = pluginAPI.registerConfig("example-plugin", ExampleConfig.class);
33+
PLUGIN_CONFIG = pluginAPI.registerConfig(BuildConstants.PLUGIN_ID, ExampleConfig.class);
3534
pluginAPI.registerModule(new ExampleModule());
3635
pluginAPI.registerModule(new ExampleESPModule());
3736
pluginAPI.registerModule(new ExampleWanderModule());

src/main/java/org/example/module/ExampleESPModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public boolean enabledSetting() {
2020
return ExamplePlugin.PLUGIN_CONFIG.esp;
2121
}
2222

23+
// packets from player to zenith
2324
@Override
2425
public PacketHandlerCodec registerServerPacketHandlerCodec() {
2526
return PacketHandlerCodec.serverBuilder()
@@ -40,6 +41,14 @@ public PacketHandlerCodec registerServerPacketHandlerCodec() {
4041
.build();
4142
}
4243

44+
// to handle packets from zenith to server
45+
// @Override
46+
// public PacketHandlerCodec registerClientPacketHandlerCodec() {
47+
// return PacketHandlerCodec.clientBuilder()
48+
// ...
49+
// .build();
50+
// }
51+
4352

4453
// this can also be moved to a separate class file
4554
public static class GlowingEntityMetadataPacketHandler implements PacketHandler<ClientboundSetEntityDataPacket, ServerSession> {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
package org.example;
1+
package ${maven_group};
22

33
// The constants are replaced before compilation
44
public class BuildConstants {
55

66
public static final String VERSION = "${version}";
7+
8+
public static final String MC_VERSION = "${mc_version}";
9+
10+
public static final String PLUGIN_ID = "${plugin_id}";
711
}

0 commit comments

Comments
 (0)