WebIntegrator
Is a simple library for integrating a website written in nodejs with your minecraft server.
You do not need to install VCore | SpigotMC - High Performance Minecraft.
Node.js
Code (Bash):
npm
install webintegrator
Code (Javascript):
const
{ WebIntegrator
}
= require
(
'webintegrator'
)
;
const client
=
new WebIntegrator
(
1234
,
// PORT
"127.0.0.1"
,
// HOST
"test"
,
// PASSWORD (optional)
)
;
client.
onData
=
(data
)
=>
{
// WebIntegratorData { code: 0, response: 'A Minecraft Server' }
console.
log
(data
)
;
}
;
client.
onConnected
=
(
)
=>
{
console.
log
(
"Connected"
)
;
client.
send
(
// OPERATION CODE FOR SERVER
0
,
// AUTO CONVERTING TO JSON
// (OPTIONAL)
{
player
:
'test'
}
)
;
}
;
client.
onClose
=
(
)
=>
{
console.
log
(
"Disconnected"
)
;
}
;
client.
onError
=
(err
)
=>
{
console.
log
(
"Error: "
+ err
)
;
}
Java (Minecraft Plugin)
Code (XML):
<repository>
<id>mineala-repo
</id>
<url>https://repo.mineala.com/maven2
</url>
</repository>
<dependency>
<groupId>net.kayega
</groupId>
<artifactId>webintegrator
</artifactId>
<version>VERSION
</version>
</dependency>
Code (Java):
public
final
class WebIntegratorTest
extends WebIntegrator
{
CreateServerReturnParams params
;
@Override
public
void onEnable
(
)
{
// Creating server (127.0.0.1:1234)
params
= createServer
(
1234,
// PORT
"test"
// PASWORD (optional but not recommending)
)
;
// Register your own packet
registerPacket
(
new WebPacket
(
0,
// OPERATION CODE FOR CLIENT REQUEST
new WebPacket.
WebPacketCallback
(
)
{
@Override
public
String run
(JSONObject jsonData
)
{
// Gets the value sent from the client and throws an error
// if it does not exist, so it is recommended to use try/catch.
String player
= jsonData.
getString
(
"player"
)
;
JSONObject returnData
=
new JSONObject
(
)
;
returnData.
put
(
"somedata",
"somedatavalue"
)
;
// This response should be json data
// if you give string or something you will getting errors
return returnData.
toString
(
)
;
}
}
)
)
;
}
@Override
public
void onDisable
(
)
{
// Stopping server
params.
getServerRunnable
(
).
close
(
)
;
}
}