Create a Stendhal server extension: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
added navigation menu
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top|Building & Hosting}}

How to create a server extension? This will teach you how to! Todays project: add the commands "/date" and "/time" for the users, so that they can check what time or what date it is.
How to create a server extension? This will teach you how to! Todays project: add the commands "/date" and "/time" for the users, so that they can check what time or what date it is.
=Requirements=
==Requirements==
Whats required?
Whats required?
*An OS
*An OS
Line 8: Line 10:
*Java knowledge is recommened
*Java knowledge is recommened


=Getting your own setup=
==Getting your own setup==
Ok, let's be cliched here. The "hello, world!" of stendhal server extensions!
Ok, let's be cliched here. The "hello, world!" of stendhal server extensions!


==The file==
===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):
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">
<source lang="java">
Line 83: Line 85:
Now, I'm not going to re-post the entire script, as it gets to be just under 100 lines of code, and I don't want a INCREDIBLY long page!
Now, I'm not going to re-post the entire script, as it gets to be just under 100 lines of code, and I don't want a INCREDIBLY long page!
First, we import a new class: <code>java.util.Calendar</code> With that, we can get the current date and time! Then, add these lines to your class method:
First, we import a new class: <code>java.util.Calendar</code> With that, we can get the current date and time! Then, add these lines to your class method:
<source lang="java">
<pre>
StendhalRPRuleProcessor.register("date", this);
StendhalRPRuleProcessor.register("date", this);
StendhalRPRuleProcessor.register("time", this);
StendhalRPRuleProcessor.register("time", this);
</pre>
</source>
These register the date and time commands. Now, we add the if to onAction:
These register the date and time commands. Now, we add the if to onAction:
<source lang="java">
<pre>
if (type.equals("date")) {
if (type.equals("date")) {
onDate(world, rules, player, action);
onDate(world, rules, player, action);
Line 94: Line 96:
onTime(world, rules, player, action);
onTime(world, rules, player, action);
}
}
</pre>
</source>
And add the two functions onDate and onTime:
And add the two functions onDate and onTime:
<source lang="java">
<pre>
private void onDate(RPWorld world, StendhalRPRuleProcessor rules,
private void onDate(RPWorld world, StendhalRPRuleProcessor rules,
Player player, RPAction action) {
Player player, RPAction action) {
Line 109: Line 111:
player.sendPrivateText("The current time is: " + calendar.getTime().toString());
player.sendPrivateText("The current time is: " + calendar.getTime().toString());
}
}
</pre>
</source>
That's it! Now, just recompile your server, and boom! Your 75% there! Now, one last thing; configuring the server to motice your new extension.
That's it! Now, just recompile your server, and boom! Your 75% there! Now, one last thing; configuring the server to load your new extension.

==Configuration ==
Now open the file server server.ini, and add these lines:


==Configuration of marauroa==
Now, again open up marauroa.ini, and add these lines:
<pre>
<pre>
date_time=games.stendhal.server.extension.DateAndTimeExtension
date_time=games.stendhal.server.extension.DateAndTimeExtension
server_extension=date_time
server_extension=date_time
</pre>
</pre>
Now, if you've been following the tut, don't just copy/paste the second line - add 'date_time' to the end of the list, with a comma before it. Also, if you've saved the file somewhere else other than where the Spouse extension is (which I don't recommend doing, it's in a folder called "extension") you're going to have to change the class path to point to that.


Now, if you've been following the tut, don't just copy/paste the second line - add 'date_time' to the end of the list, with a comma before it. Also, if you've saved the file somewhere else (which I don't recommend doing, it's in a folder called "extension") you're going to have to change the class path to point to that.
=Done=

==Done==
Done! Now you've completely added 2 extensions, one of which is pointless other than, "I did it! I did it!" Have your users be notified of the change; they may or may not like it!
Done! Now you've completely added 2 extensions, one of which is pointless other than, "I did it! I did it!" Have your users be notified of the change; they may or may not like it!