3.0.8 • Published 4 months ago

minekhan-server v3.0.8

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

This package is used for making a server on MineKhan

First things

First, install the package. Type this in your shell.

npm install minekhan-server

Then, add something like this to you code:

const express = require('express');
const app = express();
const router = express.Router();
const cors = require('cors');
app.use(cors({
  origin: function(origin, callback){
    return callback(null, true);
  },
  credentials: true
}))
let serverPort = app.listen(3000, function(){
  console.log("App server is running on port 3000");
});

Now, choose the name and description of you server. Add this to your code and customize it:

const mkServer = MineKhanServer("name", "description", {
	server: serverPort, //What server to use?
  thumbnail: "image URL", //(Optional) The thumbnail of the server
  saveActivity:true, //(Optional) Should it add any activity to the log?
  operators: ["username"], //(Optional) Who can edit blocks and use commands other people can't
	loadDistance: 4 //(Optional) How many chunks to load around players? Default is 4.
})

If you want to know what the server property is for, click here.

Creating a room

If you want your server to have a world loaded when someone joins, you should create a room. Room means a world.
This is how you create a room. You can customize it.

var room = mkServer.createRoom("room name", {
  code: "your save code",
  spawn: [x,y,z], //(Optional) Where will the players spawn when they go to this room?
  canEdit:false, //(Optional) Can the players change anything in the room?
  autosave:false, //(Optional) Should changes in this room be saved?
  cheats:false, //(Optional) Is cheats enabled for this room? Cheats is always enabled for creative mode.
  savePlayersInv:false, //(Optional) Should player data be saved when there are players in this room (this also saves position)?
	resourcePacks:[], //(Optional) What resource packs should be used in this room? Items should be urls to resource packs.
  settings:{ //This and everything inside are optional.
    tntExplode:true,
    killCmdOff:false,
    dayNightCycle: false,
    blocksFall: true,
    attack: true,
    fireSpreads: true,
		weatherCycle: false,
		mobSpawning: false
  }
})

If you want the players to go to another room when in a specific place, for example: when players go in a portal, add this to your code and customize it:

room.addPortal("room name", coordinates)

If you want a function to be done when a player goes to a specific place, add this to your code and customize it:

room.addPortal(function(player){
  //do something
}, coordinates)

Coordinates should be like this: x,y,z,x,y,z You could also add text to the room. To add text, add this to your code and customize it.

room.addText(x,y,z,"text",color,background,size)

Color should be an array with three numbers from 0 to 1.
Background should be an array with four numbers from 0 to 1.

To make a place not editable, add this to your code and customize it.

room.addUneditable(coordinates)

Coordinates should be like this: x,y,z,x,y,z

What to do when players join

When players join this server, nothing happens, so you should send them to a room when they join. This code will do that:

mkServer.on("join", function(player){
  player.goToRoom("room name")
})

Replace room name with the name of the room you want the player to go to when they join.

Adding server commands

Server commands are commands run on the server. These commands can only be used on your server. To add a server command, add this to your code and change some things.

mkServer.addServerCmd({
	name: "command_name",
	args: ["argument1","argument2" /*...*/],//(Optional) The argument names of the command
	lastArgRaw:true,//(Optional) Is the last argument raw?
	argValues:{argument1:["a-possible-value-for-argument1"] /*...*/}, //What types are for each argument?
	info: "a description",//(Optional)
	func: (args,pos,player) => {
		doSomething()
	},
	in:"all"//(Optional, defaults to all) where is this command used? Array of room names or "all"
},
{
	//Another command
	//...
} /*...*/ )

split is an array of the argument values. pos is the position of the player.

Custom terrain generation

To generate custom terrain, set customChunkGenerate and customChunkPopulate to a function on the world (room.world). The arguments for the function is a chunk. When it is set, it will not do normal terrain generation unless the function returns true. Example:

room.world.customChunkGenerate = function(chunk){
	for(let x=0;x<16;x++)for(let z=0;z<16;z++){
		chunk.setBlock(x,0,z,mkServer.blockIds.stone)
	}
}

Functions and other things

Here is a list of functions and other things:

mkServer.getLog()
mkServer.getInfo()
mkServer.createRoom(name, options)
mkServer.getRoom(name)
mkServer.deleteRoom(name)
mkServer.save()//Saves all rooms with autosave
room.addPortal(name, x,y,z, x,y,z)
room.addUneditable(x,y,z, x,y,z)
room.world//The world instance for the room
player.send(object)//Send a packet to client
player.close()//Kicks a client

Why does it need server?

The server is used to create a websocket server that the client can connect to. It also adds these paths to the server: /info /validateServer This means you can't use those urls so you have to ignore them when you recieve it.

Example

Click here to see an example

3.0.8

4 months ago

3.0.7

4 months ago

3.0.6

4 months ago

3.0.5

5 months ago

3.0.4

6 months ago

3.0.3

6 months ago

3.0.2

6 months ago

3.0.1

6 months ago

3.0.0

6 months ago

2.13.10

10 months ago

2.13.8

10 months ago

2.13.9

10 months ago

2.13.6

11 months ago

2.13.7

10 months ago

2.13.4

11 months ago

2.13.5

11 months ago

2.13.2

12 months ago

2.13.3

11 months ago

2.13.0

12 months ago

2.13.1

12 months ago

2.12.9

12 months ago

2.12.7

12 months ago

2.12.8

12 months ago

2.12.12

12 months ago

2.12.11

12 months ago

2.12.10

12 months ago

2.11.0

1 year ago

2.11.1

1 year ago

2.11.4

1 year ago

2.11.2

1 year ago

2.11.3

1 year ago

2.10.1

1 year ago

2.12.0

1 year ago

2.10.2

1 year ago

2.10.0

1 year ago

2.12.5

12 months ago

2.12.6

12 months ago

2.12.3

12 months ago

2.12.4

12 months ago

2.12.1

1 year ago

2.10.3

1 year ago

2.12.2

12 months ago

2.10.4

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.4.2

1 year ago

2.8.1

1 year ago

2.6.3

1 year ago

2.8.0

1 year ago

2.6.2

1 year ago

2.9.2

1 year ago

2.9.1

1 year ago

2.9.4

1 year ago

2.9.3

1 year ago

2.5.0

1 year ago

2.7.0

1 year ago

2.5.1

1 year ago

2.9.0

1 year ago

2.7.1

1 year ago

2.8.2

1 year ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.6.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.0.2

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.2.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

2.3.0

1 year ago

2.1.1

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

1 year ago

2.1.0

1 year ago

1.4.8

1 year ago

1.4.7

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.19

2 years ago

1.2.18

2 years ago

1.2.17

2 years ago

1.2.16

2 years ago

1.2.15

2 years ago

1.2.14

2 years ago

1.2.13

2 years ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago