Create a Stendhal server extension: Difference between revisions

Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
Line 13:
==The file==
Create a file in <downloaded stendhal source>/src/games/stendhal/server/extension/ called "HelloWorldExtension.java" and add this to it (just for now):
<source lang="java">
<pre>
package games.stendhal.server.extension;
 
Line 67:
}
}
</presource>
Time for an explanation: First, we import a whole lot of stuff. This is just so we can interact with EVERYevery aspect of the server & game world. Next, we define our class and initilazation function. In that, we request for some variables, and startup the logger. This line:
<source lang="java">
<pre>
private static final Logger logger = Log4J.getLogger(HelloWorldExtension.class);
</presource>
creates a logger and configures it for the current class.
MUST point to the right class, or it won't work, and you'll go nowhere when trying to send information to the logs! Now, this line is new (well, isn't all of this? :P)
 
<pre>
<source lang="java">
StendhalRPRuleProcessor.register("hello", this);
</presource>
 
This code tells the server "register the command '/hello' to thethis class 'this'" ('this' is a dynamic variable that points the class). Nice, huh? Now the user can type '/hello' into their textboxes without getting a not found error! Wheeee! Now, lets continue onto the onAction functio. In it, we check to see if the command is hello, and run the onHello function. (Why do we check it? Dunno, that's just how I learned it, and I haven't found a way to do it otherwise) In the onHello world function, we then send the player, who ran the command, a private message: Hello, world! Pretty boring, huh? Now, onto the main project!
 
==Date and Time==