dtlStats
dtlStats
Lets colorize our server websites!
Dev builds
Development builds of this project can be acquired at the provided continuous integration server.
These builds have not been approved by the BukkitDev staff. Use them at your own risk.
1.2.9 Description
As because the API on the PHP side has grown so big, I will move the description to Git WIki soon.
Description
This plugin will allow plugin developers to create a simple integration with websites.
Server owners to use this plugin properly and without making a Security hole needs to set the pass node in the config file. This password will be used later on the PHP side to allow only valid requests form your website.
pass: 'Password'
All connections are done using sockets, so there i no MySQL database between or any other server like service. This plugin is a small server itself, so you just need this API some supported plugins, and you can show plugin data on your website, or even create a small Application that will allow you to manage some plugin things from the web :)
How it works for each group is written below.
API
This plugin has two API's, one is for Plugin Developers and the other one is for Web Developers (PHP devs).
Each API is simple and does not need much to make it working :)
Java
As a plugin dev you can just allow users to get data and display it on the web, or you can also allow users from the web to change values in your plugin.
For each of this possibilities you got 2 Interfaces and and Annotation.
The @Stat annotation
This annotation can be added to methods which will be used to send data to the web, or to update a requested stat using a value parsed from the web.
This annotation has a "name" property that must be set, this name will be used by web-devs to get the required stat value, or to update the chosen stat with a value set. The @Stat name also is used as a stat path, so you can using this name add more complicated paths, handle additional arguments.
A second optional attribute the @Stat annotation has is the requestType attribute. It's by default set to AUTO so it depends if it's in a Listener or in a Updater class, where it will be listed for Web requests.This is useful when you got an Updater and Listener for the same class, because this allows to set a Stat method only for one request type. If not done this one method can be listed for both Update and Get requests. (Better description soon)
Example:
@Stat(name = "number") public int someNumber() { return 123; }
An example with a path, and a argument.
@Stat(name = "number/{format}") public int someNumber(String format) { return String.format(format, 123); }
This argument is easily added on the webpage API, allowing you to set the formation already on the Web!
@Stat for classes
You can also add the @Stat annotation to a class with the Listener or Updater interface. Doing this will apply the name for that Stat to each method beginning.
Example:
@Stat(name="clazz/{name}") class Test implements Updater { @Stat(name="test") public void test(String name, String value) { System.out.println(name + " " + value); } }
So ass you see the class got a path like "clazz/{name}". From up now to use this update Stat you need to call on the website a method like this
Stat::update('clazz/myName/test', 'myValue');
So as you see the whole path to the method is not "test" as normally, but it changed to "clazz/{name}/test".
Paths
When using paths and path arguments always remember, that you need to set the exact number of arguments to a Listener method. And 1 more argument to an Updater method. So when a path looks like this "first/second/{third}", a Listener method needs 1 String argument defined, and a Updater method needs 2 arguments defined.
The Listener interface
This interface holds all methods that are used to get information from the plugin.
Example:
class StatListener implements Listener { @Stat(name = "number") public int someNumber() { return 123; } }
The Updater interface
I know this Interface name is stupid, but for now i didn't got a better one.
This interface holds all methods that are used to update some values in the plugin.
Example:
class StatUpdater implements Updater { @Stat(name = "message") public void sendMessage(String value) { Bukkit.broadcastMessage(value); } }
Who says you can't send a message with this from the website.
Register Updater and listener
After you have created your listener and/or updater you just need to register it this way, first argument is your PluginName, second is the listener/updater class or object. As because Both updater and Listener are Inferfaces you can set one class to be both of them.
Manager.registerListener("dtlStats", new SampleClass()); Manager.registerUpdater("dtlStats", SampleClass.class);
php
PHP developers doesn't need to know much, the only thing they need is to include one file that can be downloaded from the Repo.
With this file you got five basic methods to use.
First you need to open a connection to a server that has dtlStats running. All you need to do is to call the static method connect() from the Stat class, with two arguments. First of them is the server address or the servers domain, the second one is the port that you have set in the config file. (default 4447)
Stat::connect("a.server.com", 4447);
After connection your password needs to be given so this connection will be validated. This password is the same that you set in the config file of this plugin.
Stat::pass("password");
After this is done you need to set the plugin from witch you want to request statistics, this plugin needs to support this plugin to make it work. Also you need to know what are the statistic names you can request from the plugin. You can always change the plugin from which you want request statistics.
Stat::plugin("pluginName");
Now you can use the Stat::get and Stat::update methods, both of them needs as the first argument the statistic name that will be acquired or updated, where the update method has a second argument that is the new value that will be set for the updated statistic.
Stat::get("number"); //without a format, will return 123 Stat::get("number/%.2f"); //with a format, will return 123.00 Stat::update("message", "Hello world!");
After all is done you need to disconnect the connection with the following method. After its disconnected you can still reconnect it after with Stat::connect.
Stat::disconnect();
Supported CMS projects
Supported plugins
Almost nothing so far, just two examples from this plugin :P Help me to get plugins supported :D You can always be sure your plugin will be linked here :)
- dtlStats
- Listener statistics:
- listenerCount - returns the number of listeners registered by plugins
- listenerCount - returns the number of listeners registered by plugins
- Updater statistics:
- v1.0 - message - allows to broadcast a message on the server
- v1.1 - {action} - allows to evaluate a command or broadcast a message on the server
- v1.0 - message - allows to broadcast a message on the server
- Listener statistics:
In real use so you can complete the plugin.php to add your own functions to provide more Lex tags to put on your html views or simply use the object $this->dtlstats on a PHP way like:
@boozaa
ok :)
I just setup some function inside a PyroCMS plugin just for testing purpose just after installation of the module.
This way as soon as the module is installed and you setup ip/port on the backend you can launch the tests simply using the Lex Parser syntax of PyroCMS.
The 'listenerCount' echo the number of registered listeners and the 'message' as it doesn't return a value it returns just "" but do the test job.
In real use you must manipulate the instance of dtlstats with the $this->dtlstats object.
@boozaa
Hmm... You can send it I will check it a bit later :D
I'm just curious how is the broadcast message working? :D
Invalid Image the message that will be send needs to be hardcoded somewhere else?
Finally i made a PyroCMS module for setting up the 2 parameters: ip/domain and port on the administration part of the CMS.
It includes and instanciate the needed libraries so it is ready to use.
It includes the 2 methods 'listenerCount' and 'message' ready to test.
If you can i send you this module.
You can print the server ip/domain on html with Lex tags if needed :
The port with:
Test 'listenerCount' with:
And test the sending broadcast message with:
Or simply use the object $this->dtlstats like:
@boozaa
Thanks too :D
Thank you ... done.
I continue manipulating and when i will have more experiences i will edit the page accordingly.
@boozaa
I tank you too :) It's good to get already some plugins that can make use of my plugin :D
I will open a page for ya, you can edit it whenever you want, if you want to add it to the bukkit mainpage just say it :)
EDIT: Done :)
@dandielo
Yes of course if i can edit my posts when i will work again on the PyroCMS part. Thank you for this plugin it opens a lot of perspectives for me !
@boozaa
Nice thing :D
P.S. if you are ok with it would you give a sub-page free for editing to make this example for PyroCMS more official :)
Thank you my tests work.
I was confused at startup but finally it's obvious, this is what i done:
I made quickly 2 libraries for PyroCMS (Codeigniter) just to test this, please consider that it is a quick work just for testing:
dtlserver.php
dtlstats.php
You must put those 2 files on addons/libraries for example and you can make a PyroCMS plugin like this for example to get or send to/from your bukkit server :
@boozaa
sorry it has changed my fault it's an interface so implements :D Sorry xd going to change the description now
I'm trying to manipulate the API.
I try your StatListener example but i can't extends Listener only implements.because net.dandielo.stats.api.Listener is not a class.
I continue to try understand the good usage.
Please tell me if i'm wrong:
i'm trying to create a class which extends Listener and give it to net.dandielo.stats.core.Manager.registerListener(..)
@boozaa
I'm glad you like it :) If you need anything added or extended you can give your ideas, I'll probably extend my API anyway, or change it a bit, will see what happens :P
Hello,
what an interesting plugin you have !!.
I think i'll take a look for my needs and i'll be back here to talk about it.
Thank you