I am assuming with “command nodes” you mean permissions? These are already provided (I forgot to document them). The permission name is “webapi.command.notify.[name]” where name is the name of the command.
I’m still not sure about the aliases, it feels like it’s not part of the scope of the project, but I’ll think about.
I fixed the json output of the players, that will be in the next update.
I’m not sure if the server closing should be part of the sponge functionality, but I’ll look into it
Add class name and parent class name to /class endpoint
I did not make the server closing call PLAYER_LEAVE hooks, however there is a SERVER_STOP hook which can be subscribed to. (Sponge itself doesn’t fire PlayerLeave events when the server is closing, so it didn’t feel right to do that. Maybe I’ll add this later)
Finally got the chance to update webapi, getting the following:
[03:02:47] [Server thread/INFO] [webapi]: Starting Web Server...
[03:02:47] [Server thread/INFO] [webapi]: jetty-9.4.z-SNAPSHOT
[03:02:47] [Server thread/INFO] [webapi]: Started o.e.j.s.h.ContextHandler@6342efb1{/,null,AVAILABLE}
[03:02:47] [Server thread/INFO] [webapi]: Started o.e.j.s.h.ContextHandler@13708ff3{/docs,null,AVAILABLE}
[03:02:47] [Server thread/INFO] [webapi]: Started o.e.j.s.ServletContextHandler@28878ab7{/api,null,AVAILABLE}
[03:02:47] [Server thread/INFO] [webapi]: Started ServerConnector@d6a4865{HTTP/1.1,[http/1.1]}{localhost:8080}
[03:02:47] [Server thread/INFO] [webapi]: Started @53385ms
[03:02:47] [Server thread/INFO] [webapi]: Web server running on http://localhost:8080/
[03:02:47] [Server thread/ERROR] [Sponge]: Could not pass FMLServerStartedEvent to Plugin{id=webapi, name=Web-API, version=2.1.0-S5.1, description=Access Minecraft through a Web API, url=ht
tps://github.com/Valandur/Web-API, authors=[Valandur], source=/home/minecraft/mc/mods/webapi-2.1.0-S5.1.jar}
java.lang.AbstractMethodError: Method net/minecraftforge/fml/common/event/FMLServerStartedEvent.getCause()Lorg/spongepowered/api/event/cause/Cause; is abstract
at net.minecraftforge.fml.common.event.FMLServerStartedEvent.getCause(FMLServerStartedEvent.java) ~[FMLServerStartedEvent.class:?]
at valandur.webapi.WebAPI.onServerStart(WebAPI.java:287) ~[WebAPI.class:?]
at org.spongepowered.common.event.listener.GameStartedServerEventListener_WebAPI_onServerStart74.handle(Unknown Source) ~[?:?]
at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95) ~[RegisteredListener.class:1.10.2-2254-5.2.0-BETA-2272]
at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:313) [SpongeModEventManager.class:1.10.2-2254-5.2.0-BETA-2272]
at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:342) [SpongeModEventManager.class:1.10.2-2254-5.2.0-BETA-2272]
at org.spongepowered.mod.SpongeMod.onStateEvent(SpongeMod.java:234) [SpongeMod.class:1.10.2-2254-5.2.0-BETA-2272]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_111]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.10.2.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_111]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.10.2.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.10.2.jar:?]
at net.minecraftforge.fml.common.LoadController.redirect$onPost$zzb000(LoadController.java:552) [LoadController.class:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.serverStarted(Loader.java:868) [Loader.class:?]
at net.minecraftforge.fml.common.FMLCommonHandler.handleServerStarted(FMLCommonHandler.java:297) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:433) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
I released a first version of v3, although I marked it as a pre-release because it might still have some issues, it should be mostly stable.
Quite a few response objects from /entity, /tile-entity, /player and /world have changed. Please make sure your code still works with the new endpoints when updating.
I have implemented the following changes:
Add /block endpoint to query & set blocks in the world
Rework endpoints to provide more consistent and better structured data
Add fine grained permission nodes for commands run via /cmd endpoint
Add 100% more error messages for endpoints
The releases are for SpongeAPI 5.2 and 6.0. 5.2 should work for 5.1 aswell.
That is exactly what hooks are meant for. If you check in the webapi/hooks.conf config file you will find some description there. I will try and explain it real quick.
The hooks listed in events are called when certain minecraft events happen. So for example all the hooks listed in events.player_join are called when a player joins.
A hook is basically just another endpoint (URL) which the Web-API contacts. A simple example could look like this:
events {
player_join=[
{
address="http://localhost:25000"
method=POST
#dataType=FORM # Add this if you're using PHP since it makes it easier to read the data
}
]
}
This would send a POST request to http://localhost:25000 whenever a player joins. The request would contain a json body containing information about the player that joined.
I hope that clears things up, and I will try to add more tutorials as soon as I can
You can add constant headers (such as the X-WEBAPI-KEY). Parameters in headers, such as {source} don’t work in events (the data should already be included in the request body), they only work with the command hooks.
Thank you for all the log files, I found the error, it has to do with the config files (once again, I honestly HATE how Sponge currently solved this…). I’ll try and fix this as soon as I can.
@Keuterio for now I suggest using the all event hook, and then checking $_SERVER for the “X-WEBAPI-EVENT” header that will tell you which event it is
I do my best to provide enough information it’s easier for you to fix the problem
Nice suggestion, I now listen to $_SERVER['HTTP_X_WEBAPI_EVENT'] and it works like a charm :
However, I can wait for next update as I am not in a hurry.
Don’t you have any support button ?
Edit : By chance, could you had hook “use” (button press) ? And if possible, “open” (open chest) ?. Only if they are not fired too often, I don’t want to overload the requests.
Was gonna ask, is it possible for us to add sponge (or other plugin) events onto the hooks file in order to notify the server about these events being triggered and respond to it accordingly.
(I believe GriefPrevention is adding claimEnter and claimLeave events and want the server to be notified when they happen)
I’ve been working on a new version that supports custom events and serializers, and am happy to say that I’m almost done. Most of the stuff is in the git repository but I haven’t released a new version yet because it needs more testing and documentation.
How this is going to work is that you can specify any event you want to subscribe to. In case you’re not sure about the events you can check the /class endpoint which now supports looking up subclasses of a certain class. The Web-API will serialize all data which it knows how to into json. But if that’s not good enough you can now write your own serializer which will get compiled and loaded when the server runs.
Let me make a short example:
You have to create a class that extends from the Jackson StdSerializer. The file has to have the same name as the class. E.g. the following file could be placed into the /webapi/serializers folder (not the config folder):
package serializers;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import me.ryanhamshire.griefprevention.api.event.ClaimEvent;
import java.io.IOException;
public class ClaimEventSerializer extends StdSerializer<ClaimEvent> {
public ClaimEventSerializer() {
this(null);
}
public ClaimEventSerializer(Class<ClaimEvent> t) {
super(t);
}
@Override
public void serialize(ClaimEvent value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeStringField("owner", value.getOwnerName());
gen.writeEndObject();
}
}
Together with a custom event in config/webapi/hooks.conf along the lines of: