A beginner-friendly template for creating your first Minecraft plugin!
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: Create utility to easily rename plugin

Renaming a plugin from a template typically takes lots of
painstaking, error prone work to rename files/classes/packages/etc.

This commit adds a gradle command called `renamePlugin` which will
handle all the heavy lifting for renaming everything for you!

Joseph Hale (Jan 17, 2024, 11:14 PM -0700) de6eada4 2d8a1c9a

+117 -7
+1
.gitignore
··· 1 1 # Local server software 2 2 **/.server 3 + app/bin 3 4 4 5 ############################################### 5 6 ## Gradle files to ignore
+1 -3
README.md
··· 21 21 - Or you can clone a copy: `git clone https://github.com/thehale/papermc-plugin-template` 22 22 2. Choose a name for your plugin (e.g. `my-plugin`). 23 23 - Rename the repository. 24 - - Open `gradle.properties` and change the `pluginOwner` variable to your 25 - GitHub username, then change the `pluginName` to your plugin name (use only 26 - letters and underscores). 24 + - Run `./gradlew renamePlugin -PnewAuthor=YOUR_GITHUB_USERNAME -PnewPluginName=YOUR_PLUGIN_NAME` 27 25 28 26 ## Contributing 29 27
+111
app/build.gradle
··· 202 202 String PLUGIN_YML_PATH = "app/src/main/resources/plugin.yml" 203 203 InputStream pluginYml = new File(PLUGIN_YML_PATH).newInputStream() 204 204 return new org.yaml.snakeyaml.Yaml().load(pluginYml) 205 + } 206 + 207 + task renamePlugin { 208 + doLast { 209 + logger.lifecycle("Renaming plugin to " + newAuthor + "/" + newPluginName) 210 + def pluginRenamer = new PluginRenamer( 211 + pluginOwner, pluginName, 212 + newAuthor, newPluginName 213 + ) 214 + 215 + pluginRenamer.renameFolder(new File('app/src')) 216 + pluginRenamer.renameFile(new File('gradle.properties')) 217 + } 218 + } 219 + 220 + 221 + class PluginRenamer { 222 + 223 + String oldAuthor 224 + String oldAuthorSnakeCase 225 + String oldAuthorCapitalized 226 + 227 + String oldPluginName 228 + String oldPluginNameSnakeCase 229 + String oldPluginNameCapitalized 230 + 231 + String newAuthor 232 + String newAuthorSnakeCase 233 + String newAuthorCapitalized 234 + 235 + String newPluginName 236 + String newPluginNameSnakeCase 237 + String newPluginNameCapitalized 238 + 239 + PluginRenamer(String oldAuthor, String oldPluginName, String newAuthor, String newPluginName) { 240 + this.oldAuthor = oldAuthor 241 + this.oldAuthorSnakeCase = asSnakeCase(oldAuthor) 242 + this.oldAuthorCapitalized = asCapitalized(oldAuthorSnakeCase) 243 + 244 + this.oldPluginName = oldPluginName 245 + this.oldPluginNameSnakeCase = asSnakeCase(oldPluginName) 246 + this.oldPluginNameCapitalized = asCapitalized(oldPluginNameSnakeCase) 247 + 248 + this.newAuthor = newAuthor 249 + this.newAuthorSnakeCase = asSnakeCase(newAuthor) 250 + this.newAuthorCapitalized = asCapitalized(newAuthorSnakeCase) 251 + 252 + this.newPluginName = newPluginName 253 + this.newPluginNameSnakeCase = asSnakeCase(newPluginName) 254 + this.newPluginNameCapitalized = asCapitalized(newPluginNameSnakeCase) 255 + } 256 + void renameFolder(File folder) { 257 + folder.eachFile { 258 + if (it.isFile()) { 259 + renameFile(it) 260 + } 261 + } 262 + folder.eachDir { 263 + if (it.isDirectory()) { 264 + renameFolder(it) 265 + } 266 + } 267 + println("Renaming folder " + folder) 268 + def newFolderName = renameText(folder.getName()) 269 + if (newFolderName != folder.getName()) { 270 + folder.renameTo(new File(folder.parent, newFolderName)) 271 + } 272 + } 273 + void renameFile(File file) { 274 + println("Renaming file " + file) 275 + String text = file.text 276 + text = renameText(text) 277 + file.write(text) 278 + 279 + def newFileName = renameText(file.getName()) 280 + if (newFileName != file.getName()) { 281 + file.renameTo(new File(file.parent, newFileName)) 282 + } 283 + } 284 + String renameText(String text) { 285 + def lines = text.split("\n") 286 + lines = lines.collect { 287 + renameLine(it) 288 + } 289 + text = lines.join("\n") 290 + return text 291 + } 292 + String renameLine(String line) { 293 + if (line.contains("[ATTRIBUTION]")) { 294 + return line // Don't rename attribution lines. 295 + } 296 + line = line.replaceAll(oldAuthor, newAuthor) 297 + line = line.replaceAll(oldAuthorSnakeCase, newAuthorSnakeCase) 298 + line = line.replaceAll(oldAuthorCapitalized, newAuthorCapitalized) 299 + line = line.replaceAll(oldPluginName, newPluginName) 300 + line = line.replaceAll(oldPluginNameSnakeCase, newPluginNameSnakeCase) 301 + line = line.replaceAll(oldPluginNameCapitalized, newPluginNameCapitalized) 302 + return line 303 + } 304 + def asSnakeCase(String s) { 305 + return s 306 + .toLowerCase() 307 + .replaceAll(/[\s-]+/, "_") 308 + .replaceAll(/[^a-z0-9_]/, "") 309 + } 310 + def asCapitalized(String s) { 311 + return s 312 + .split("_") 313 + .collect { it.capitalize() } 314 + .join("") 315 + } 205 316 }
+1 -1
app/src/main/java/dev/thehale/papermc_plugin_template/PapermcPluginTemplateListener.java
··· 54 54 player.sendMessage("Hello " + player.getName() + "! (from PapermcPluginTemplate)"); 55 55 } 56 56 57 - } 57 + }
+2 -2
app/src/main/java/dev/thehale/papermc_plugin_template/PapermcPluginTemplatePlugin.java
··· 20 20 public static PapermcPluginTemplatePlugin instance; 21 21 public static Logger log; 22 22 public final static String NAME = "PapermcPluginTemplate"; 23 - public final static int BSTATS_PLUGIN_ID = 20765; // TODO: Replace with your own bStats plugin ID 23 + public final static int BSTATS_PLUGIN_ID = 20765; // Optional: Replace with your own bStats plugin ID 24 24 25 25 /** 26 26 * Default constructor. ··· 66 66 67 67 @Override 68 68 public void onDisable() { 69 - log.info("Thanks for using papermc_plugin_template!"); 69 + log.info("Thanks for using " + NAME + "!"); 70 70 } 71 71 }
+1 -1
gradle.properties
··· 5 5 pluginOwner = thehale 6 6 7 7 ## The name of your plugin (match the name of your repository) 8 - pluginName = papermc_plugin_template 8 + pluginName = papermc-plugin-template 9 9 10 10 11 11 ############################################