So, web API is currently used for the webserver to send data to the minecraft and gets a response according to what’s being asked.
However, minecraft currently has no direct way of communicating with the webserver.
Long example:
What I’m asking is to add that. So that really the server (and plugins), not users, can use that to send data to the web server from the game. I’m running a pixelmon server, so let’s assume I want badges to show up on the website when a gym leader is beat. So, I add a trainer command to the NPC Gym Leader.
This command would be something along the lines of “/web-api send {“code”:“Superadmincode”,“request”:“newBadge”, “badge”:“rockBadge”}”
WebAPI would then send a POST request to a certain part of the website, lets assume www.domain.com/webAPI/receive.php with the following data:
Code: Superadmincode
Request: newBadge
Badge: rockBadge
Target: @p (player’s UUID or their username)
receive.php gets the post request (they can use htaccess or $_SERVER[‘SERVER_ADDR’] != $_SERVER[‘REMOTE_ADDR’] to make sure request is coming from localhost or some other acceptable domain)
Then it checks the code or key, in this case if it’s equal to Superadmincode, if not equal to that, die with a failure value, if equal continue.
Then checks what the request is about, in this case, newBadge so it knows that the request is to add a badge to the player’s account. It then checks for the badge and target values, if both good, it adds them to a database; and dies with a success output, if either are bad, dies with a failure output (ie: die(“Badge could not be found”))
WebAPI gets whatever data is outputted, limited to a certain character limit (in case it’s not properly configured, wouldn’t want a whole 404 page to get sent) and sends that to the player.
This could be used in conjunction to many different cases. Let’s assume I have a seriousVote, one of the vote rewards is 10 vote tokens another is 100, which can be used on the website to select certain vote rewards. Data gets sent to the webserver and added to a database for the user to spend on a vote shop on the website.
Quite literally, you put this together with aliases, the server admin can make various different new commands and interact with many different parts of the server and webserver with just knowledge of php or some other backend webdevelopment language.
Since webAPI would provide a way to communicate to the webserver and back, and aliases can give each new command a new name.
Ie: More complex: Player has recently bought something from the shop, but wasn’t online to receive it, luckily enough, server keeps all undelivered purchases in a database.
Player runs /redeem (which is an alias for “/web-api send {“code”:“Superadmincode”,“request”:“redeemPurchase”}”), webserver then checks database if any purchases are made, if so, takes them from the database, uses webAPI to deliver all the items or other stuff, once it’s all complete, it tells the player the output (which would be either “You have received your purchase! Thank you for supporting Server” or “You have no items pending to be delivered!”)