I've been thinking off an idea for my server and wanted YOUR opinions on it. The more and more I write for my server the more database dependant its getting. This is what i'm aiming for, basically you would be able to take my server. Modify its database and transform the server into something else.

Just to clarify something here. When i say action, what i mean is the action which happens when you click on an npc's right click menu. such as "Atttack", "Bait", "Talk-to

Now my npc defintions at the moment look like this

Code:
Id Name Examine Size Option1 option2 option3 option4 option5
I'm using the option information to find the correct handler to handle the action. What i'm currently working on is using the new javascript engine with java 8 and storing javascript code within the database instead of the option names. The js code found in the database would be the action itself. When we click on an option the javascript in the database will be invoked and the action would occour.

Using the defintion data stored in the database it will run ''eval(#code stored in database#)' to load the javascript.
Code:
		try {
			                   nashorn.eval("function run(player) {\n" +
			                		   			"var interfaceFactory = Java.type('action.Interface.InterfaceFactory'); \n" +
			                		   			"var bank = Java.type('action.Interface.impl.BankInterface');\n"	+	
			                		   			"interfaceFactory.openInterface(new bank(), player);\n" +
			                		   		"}"
			                		   
			                		 );
			 } catch (ScriptException e) {
				 e.printStackTrace();
			 }
We then invoke the method found in the javascript which is 'run(player)' and in this example the bank interface will open.
Code:
		 Invocable invocab = (Invocable) nashorn;
		try {
			invocab.invokeFunction("run", player);
		} catch (NoSuchMethodException | ScriptException e) {
			e.printStackTrace();
		}
A caching method could also be used because the javascript code only needs to be ran once. Then from there on we can just invoke it.

I hope you all understand on what i'm trying to achieve here.

Pro's
  • I can keep track on what npc's actually have there right click options handled
  • Alot easier to modify npc actions. Database -> npc -> edit option1
  • No more confusion. The only code visable would be for the option and for that npc only
  • No more restarting server just because when i click talkto on an npc nothing happens.
  • Anticheat Cheat clients won't be able to trick the server into doing something wrong.


Con's
  • Javascript would have to be wrriten for every option, for every npc id.