api/ships-6/Bukkit

Welcome to the Ships 6 API. This API tutorial is targeting the Bukkit version of Ships 6.

PreRelease API

Ships 6 works in a slightly different way to ships 5. In Ships 4, vessels data was changed in the file only, this meant the data in Ships 4 was always accurate for if the server crashed. Ships 5 stored the Vessel data into RAM and changed the file when needed, this boasts speed, however could cause issues if the server crashed, not only that but filled up RAM with vessel data that may not even be touched. Ships 6 is a hybrid of the two options where the vessel data is only stored in RAM where if a vessel has been used recently but then removed from RAM if it is not touched for a while. This leads to data being more accurate for loading vessels (due to the fact the vessels save the RAM data when removed from RAM) but maintains the speed that Ships 5 has (I mean, it will be slow on first move but oh well).

Ships 6 also stores the block locations in the file as well as RAM, something that Ships 1-5 didnt do, this means addons can take advantage of previous structures the ship was in.

Getting Vessel data

Vessel data is stored in a "ShipData" object. These hold the basic information all Ships have in common. However these are not actual in game ships. The actual in game ship, is stored in a "LoadableShip" object. So whats the difference method wise? Actually a lot more then you think. Due to the fact just the data is not a actual ship, there is no way to move a ship in game with just that data, this is where the "LoadableShip" data comes into play. However, as it states above, Ships are not stored in RAM at all times now meaning there needs to be a way to load a vessel object and there are a few ways.

//Please note that the Optional is currently the Java 8 optional, however will be a custom one for Java 6 support

Working with a Ship object

In this tutorial, we will be focusing on the "LoadableShip" object however will talk about other parts of the ships object.

Ships 6 attempts to remove as many classes as possible, but keep the functionality of ShipsAPI. Ships 5 had 4 classes for just the Ship object (BaseVessel, ProtectedVessel, MovableVessel, Vessel), in Ships 6 It has been cut down to 3 (ShipsData - storing the basic information of a ship, but can be treated as a virtual ship too, LoadableShip - the actual ship object, <ship type object name> - this is the ShipType, need I say more). These 3 classes are cast able to one and another.

ShipData data;

if(data instanceof LiveShip){

//is not virtual

if(data instanceof Airship){

//is a airship

}

}

Moving a ship

Ships 5 used Vectors to move the ship (with rotation being the exception). Ships 6 is non different only now you can store a movement for later using the "StoredMovement" builder. The example below shows me rotating the ship left and moving forward under a single command (please note that the blocks teleport/move first and it is truly a single command, as in the ship will not request each move separably)

 

ShipsCause is built for the events that are fired, you can add as much as you like into a ShipsCause. For example, there is a chance that a ship is moved by a player, however there is also a chance that it was moved by a console command (no player), instead of having all possibilities within each and every event, where the listener would need to check each and every possiblility, the event listener only needs to check if the supplied cause contains what is required for the event.

 

//Ships can be moved based on vectors, here is a example

Player player;

LiveShip ship;

ship.move(0, 1, 0, new ShipsCause(player, "Up"));

 

//Ships can be moved based on BlockFace, here is a example

BlockFace direction = BlockFace.NORTH; //this will go towards north position (-Z)

int speed = 1; //this is how far the ship will move in the selected direction

ship.move(face, speed, new ShipsCause(direction, speed));

 Ships can also rotate left or right (180 is not supported yet), here is how

ship.rotateRight(new ShipsCause("Rotate right"));

 This is really simple, however when you apply a move, you will send a request to check requirements, this means ship types such as airships will loose fuel each and every move, Ships 6 brings in a new way of getting around this issue.

//You do not need all of these, these are just what you can use

Location goTo; //this will teleport the ship to the location

int x; //adds the XYZ to its current position or the goTo location, depending if it has been supplied or not

int y;

int z;

RotateType rotate; //rotate the ship
StoredMovement.Builder builder = new StoredMovement.Builder();

StoredMovement stored = builder.setX(x).setY(y).setZ(z).setTeleportTo(goTo).setRotation(rotate).build(); ship.move(builder, new ShipsCause(stored));

Working with Auto Pilot

Saving and storing custom data to ships

Creating your own Ship Type

Working with algorithms

Movement algorithms

Block detection algorithm

Working with events

About To Create Ship

Create Ship

Transform

Move

Teleport


Comments

Posts Quoted:
Reply
Clear All Quotes