[OUTDATED] Coming from Bukkit? Here's Some Tips and Tricks to Get you Started

(Moderation Edit) ** PLEASE NOTE: **

This guide is no longer updated and therefore lacking new information plus may contain (now) false information. Please head over to the SpongeDocs to get the latest information including updates.

This tutorial is not complete yet and since the project isn’t even fully developed anything and everything in this document is subject to change. As the project develops this tutorial will most likely expand as I add in more details once they are decided upon and I learn how everything works.

Introduction

So, you’ve heard about this new project, Sponge, which looks like the savior to the Minecraft plugin community. You hurry to rush and port your plugins over, yet everything seems new and unfamiliar. You’re right! It is new, brand new, so new you can’t download it yet. With that in mind, here’s your first tip:

Tip #1: This isn’t Bukkit
Yup, that’s right, it isn’t, there may be some things that may look similar, but you need to remember: This isn’t Bukkit, don’t whine and complain when things don’t work exactly like they did in Bukkit.

Where is the plugin.yml File?
There isn’t one (yet)! Instead you put a line like this before your class declaration:

@Plugin(id = "PluginID", name = "Human Friendly Name", version="Version Number")

Here’s an example:

@Plugin(id = "MultiInv", name = "MultiInv", version="3.1.8")
public class MultiInv {

onEnable() and onDisable(), Where are They?
Ah, the famous onEnable and onDisable. They aren’t there! Instead they are replaced by a series of events. If you’ve ever made a mod for Forge, they should sound familiar to you. Here’s how you declare them:

@SpongeEventHandler
public void onDisable(ServerStoppingEvent event) {}

Here’s the list of events for your reference:

  • ServerAboutToStartEvent
  • ServerStartingEvent
  • ServerStartedEvent
  • ServerStoppingEvent
  • ServerStoppedEvent

How Will Commands Be Handled?

Useful Links

68 Likes

It’s good to have a thread like this, keep maintaining it!
Honestly, I don’t WANT to see a plugin.yml, I’ve always wanted to just be able to add permissions, commands and such from code…

13 Likes

+1 We should wait where the Sponge-Team wants tutorials.
The Wiki Page would be cool:

I like the @Plugin() feature, boils down having a Plugin.yml to 1 line of easy to read&edit code.

7 Likes

On top of being easier to have. It allows using a constant value in variables of your plugin / mod.

Only downside I can think of is that its a little harder to have stuff like maven replace values for such information on building. However I think something could be done to accomplish this. If I seen the api correctly so far it accepts Strings so you could put something along the lines of a keyword that a task will search for and than replace that keyword.

I’m sure something will be figured out for automated build systems. It’s good to point that out.

1 Like

I think the semi-official plan is to use MediaWiki as a forum

1 Like

I believe you meant onEnable instead of onLoad. However, we should make very clear which of the server events plugins should replace it with. I assume the ServerStartingEvent. I was thinking a PluginEnableEvent but you don’t want events for other plugins…

In technical terms. Forge actually loads the mod straight away in a sense from my understanding. You only hook into events to actually get something as an entry point to your mod.

I did mean onEnable, thanks for catching that! As far as using onEnable, this is usually where plugins should do anything that requires certain things to be loaded. As far as getting the actual event, ServerStartingEvent would work for some, however if you wanted to make sure certain plugins were enabled or all worlds were loaded, etc. the ServerStartedEvent would be more appropriate.

Why wouldn’t we want people to create tutorials? Good documentation is created by a community of people that use the systems and work together to describe how it works. If you have good information, the community can accept it and put it somewhere public for everyone to benefit. Otherwise, it will just disappear at some point if it isn’t informative.

In the case of this post, tux2 is an experienced plugin developer from my knowledge. He knows what he’s talking about and the information presented in the post is helpful. I think it was nice of him to take the time :).

5 Likes

This is fun but how do we check if another plugin is enabled? (loaded?) How do I make dependencies to other “mods”

To be announced! Those things haven’t been decided quite yet. When I DO know I will make sure to update the tutorial. Please remember that all of the things I’ve presented here have been me looking over API commits and JavaDocs. I’ll also be explaining how the event system works once they hammer that out as well.

3 Likes

Ahhh, its great to see some continuity from Forge. Should overall make it easier for developers to bounce between each API.

Can’t wait to get portin!

I agree, please don’t implement the plugin.yml file, there are better ways of doing things, in fact, please don’t do any yaml crap, i hated that about Bukkit.

3 Likes

I am sorry if my english is not the best, I love tutorials, i said only, that we have atm no final place for them …
I also hope that it not end up like the bukkit ressource section, where people post wrapper of a wrapper, how to use the api instead of reading javadoc, …

1 Like

Hi tux , thank you for a great start , wish i had this stuff back in MCPC+ days :), and yes i think we should allso help Tux where we can with this :smile:

Thank you again Tux

Shad_dow

So, i never made a forge mod and i wonder if you can access events from everywhere with @SpongeEventHandler?
I mean: in Bukkit the class had to implement “Listener” and had to be registered with “getPluginManager().registerEvents()” ?