User Tools

Site Tools


plugin_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
plugin_api [2016/12/21 15:37]
127.0.0.1 external edit
plugin_api [2017/01/18 17:58]
gobrosse
Line 26: Line 26:
 package io.xol.demo;​ package io.xol.demo;​
  
 +import io.xol.chunkstories.api.GameContext;​
 import io.xol.chunkstories.api.plugin.ChunkStoriesPlugin;​ import io.xol.chunkstories.api.plugin.ChunkStoriesPlugin;​
-import io.xol.chunkstories.api.plugin.server.Command; +import io.xol.chunkstories.api.plugin.PluginInformation;​ 
-import io.xol.chunkstories.server.tech.CommandEmitter;​+import io.xol.chunkstories.api.plugin.commands.Command; 
 +import io.xol.chunkstories.api.plugin.commands.CommandEmitter
 +import io.xol.chunkstories.api.plugin.commands.CommandHandler;
  
-public class DemoPlugin extends ChunkStoriesPlugin {+public class DemoPlugin extends ChunkStoriesPlugin ​implements CommandHandler ​{ 
 + 
 + public DemoPlugin(PluginInformation pluginInformation,​ GameContext pluginExecutionContext) { 
 + super(pluginInformation,​ pluginExecutionContext);​ 
 + }
  
  DemoEventHandler handler;  DemoEventHandler handler;
Line 37: Line 44:
  public void onEnable() {  public void onEnable() {
  handler = new DemoEventHandler(this);​  handler = new DemoEventHandler(this);​
- this.getPluginsManager().registerEventListener(handler,​ this); + this.getPluginManager().registerCommandHandler("​demo",​ this); 
- System.out.println("​Enabling plugin ... "+this.getServer());+  
 + this.getPluginManager().registerEventListener(handler,​ this); 
 + System.out.println("​Enabling plugin ... ");
  }  }
  
Line 47: Line 56:
  
  @Override  @Override
- public boolean handleCommand(CommandEmitter ​e, Command ​cmd, String[] ​a, String rawText)+ public boolean handleCommand(CommandEmitter ​emitter, Command ​command, String[] ​arguments)
  {  {
- if(cmd.equals("​demo"​)) + if(command.equals("​demo"​)) 
- e.sendMessage("​Hi !");+ emitter.sendMessage("​Hi !"+arguments.length);
  return true;  return true;
  }  }
  
 } }
 +
 </​Code>​ </​Code>​
  
-One can clearly see that it's basically Bukkit ​with minor tweakslike being mostly agnostic to the whole client/server ​dichotomy ​and being much simpler and directOne interesting line is : +If you are any familiar ​with Bukkit/​Spigot pluginsthis code shouldn'​t feel too overwhelming,​ there is a constructor dependant on wether ​the plugin is only client, only server ​or both, onEnable/​onDisable methods as well as command ​and event handlers. 
 ''​this.getPluginsManager().registerEventListener(handler,​ this);'',​ let's look at DemoEventHandler : ''​this.getPluginsManager().registerEventListener(handler,​ this);'',​ let's look at DemoEventHandler :
  
plugin_api.txt · Last modified: 2017/01/18 17:58 by gobrosse