[Discontinued/Not available anymore] SynX - Transfer data between servers

This plugin provides an easy way to transfer data between servers.
This is required for Sync, a plugin that allows server administrators to run commands across servers (similar to CommandSync).

Server owners may want to download, add and configure this plugin on their servers.

Cross-compatible between the Bukkit and the Sponge version!

Links:

###Commands

  • /synx nodes - shows a list with all known nodes
  • /synx tags - shows a list with all known tags
  • /synx reload - reloads the plugin

###Permissions

  • synx.manage - Permission necessary to run all commands

###Requirements

  • A MySQL database shared between all your minecraft servers.

##Developers

Example plugin

How to use SynX in your Sponge plugin

Add SynX to your build path. Maven:

<repository>
  <id>net.kaikk.mc</id>
  <url>http://kaikk.net/mc/repo/</url>
</repository>
<dependency>
  <groupId>net.kaikk.mc</groupId>
  <artifactId>SynX</artifactId>
  <version>1.1</version>
  <type>jar</type>
  <scope>provided</scope>
</dependency>
  1. Make a new class that implements Serializable. Add all the attributes that you want to be sent to the other servers. For this example, Iā€™ll call this class ā€œSerializableExampleā€.
  2. Use SynX.instance().broadcast("Example", Serializable object) to send data to all your servers. The parameters of this method are a channel name (you choose one) and an object of the class that you made on step 2 that contains the data you want to be sent to the other servers.
  3. Implement the ChannelListener interface to your main plugin class. Implement the onPacketReceived(Packet packet) method on your main plugin class. The packet object is the data received from the other servers. You can convert data back to an object by using SynXUtils.convertFromBytes(SerializableExample.class, packet.getData())
  4. During the GameInitializationEvent, register the channel with SynX.instance().register(this, "Example", this). The parameters of this method are the plugin instance, a channel name (the same you choose previously for the broadcast method), and an object that implements the ChannelListener interface (in our example, itā€™s the plugin main class).

There are a couple things about your plugin that I have suggestions for.
If you register commands during GameStartingServerEvent, they will be registered every time the server starts. And the server can stop and start many times during a Game instance (for example, singleplayer LAN). The correct GameState to register commands is INITIALIZATION.
If what one String argument does changes the command behavior, itā€™s recommended to use child commands. If you really want them all in one class still, consider statement lambdas (instance::methodname). If you still donā€™t want to do that, note that you donā€™t have to use default, since Sponge makes sure that only the things listed in map are typable.
CommandResults should be descriptive of what the actual result of the command was. For example, if the command was /synx nodes, a good CommandResult would be CommandResult.builder().queryResult(count).build() where count is how many nodes there were. Never return success() unless it was actually successful; if an error cropped up, instead throw a CommandException.
And lastly, just a little thing, in SynXConfig, you can replace that huge ArrayList constructor with Lists.newArrayList("default").

Wow, I wasnā€™t expecting so many suggestions! Thank you for your time.

This plugin is definitely not needed for singleplayer LAN. Itā€™s for larger server networks where multiple servers. Anyway, Iā€™ll make sure to fix that for all my Sponge plugins. Probably this ā€œThe server instance exists, and worlds are loaded. Command registration is handled during this state.ā€ confused me.

About the default, the exception suppression and the CommandResult, they are all copy-paste from the Bukkit version. Iā€™ll make sure to remove the default because itā€™s not required.

I could actually see this being useful for singleplayer / lan.

Being able to run a command across a lan of singleplayer clients would be incredibly useful, especially if they were able to auto-register with a main server.

Our local hackerspace has occasionally run hack sessions for kids using Minecraft, teaching redstone, programming, command blocks, and being able to teleport everyone (in their single player worlds, so they donā€™t grief or ruin anyone elses work, while still having full control) would be pretty useful.

That said, I realize itā€™s very very much an edgecase, and we would probably not use it anyway, So donā€™t feel compelled to add the feature if you run into problems, just if itā€™s no effort to support single player usage, you may as well, as most other Sponge plugins will work just fine in SSP or single player lan.

It should be already working on SP clients. Moving the commands registration to the Initialization GameState doesnā€™t require any effort.

1 Like

Itā€™s incredibly important that one takes the time to properly port code. Sponge is much more of an abstraction, supporting much more of Minecraft, and itā€™s important to not just copy it over and fix all the red underlines.

Also, true, but in the JavaDocs:

public static final GameState INITIALIZATION

Plugins should finish any work needed to become functional. Commands should be registered at this stage.

It would be so good if we could just fix the ā€œred linesā€. Unfortunately that is not the real. Porting my plugins to Sponge is already taking more time than I thought. I think itā€™s more important to have a functional plugin (so we can use Sponge servers for ā€œproductivityā€). I think that is better than not porting to Sponge at all. Little things can be fixed later.

Unfortunately what leads to mistakes is, especially, the documentation not being accurate. It may cause confusion to most of developers (some of them will just give up).

About the INITIALIZATION GameState:
SpongeDocs:

And this is what the JavaDocs says for me: http://i.imgur.com/6m71I9t.png

Also SpongeDocs doesnā€™t provide complete code examples (like the Bukkit wiki page does), and that makes it even harder. I know few developers that were developing for Bukkit fine enough, but they canā€™t do it for Sponge yet. It lacks the proper easy documentation. I hope SpongeDocs gets better so even newbie developers wonā€™t give up with Sponge.

Despite being around for a few years, Sponge is still in its infancy. If you believe thereā€™s something missing from the docs, youā€™re always welcome to make a PR.

1 Like

If thereā€™s a problem here, it should be raised as an issue on SpongeDocs GitHub repo. We donā€™t have enough staff to troll the forums looking for quibbles, so itā€™s everyoneā€™s responsibility to help make the Docs better. Code examples donā€™t come out of thin air, we need people willing to create them and refine them through feedback.

Iā€™m not entirely sure what the issue is here anyway, paging @12AwsomeMan34 for some consultation.

Unfortunately I donā€™t know if it is a problem because I just followed what was written in the documentation. And it was working fine. Also English is not my first language and so I am not good at writing a documentation or reporting such issues. I am sorry.

Technically you can register commands basically whenever you want, afaik Sponge will hold them aside and register them on the server during the GameStartingServerEvent.

As for incomplete code examples, Iā€™m not quite sure where the issue lies. If you find a page that you feel is ā€˜incompleteā€™, then itā€™d be great if you could point it out.

1 Like

I mentioned this over on the Sync post but thought I would post here too so that if anyone else has had this issue they can find it easier and help me. Anyways to the post -

I am currently having issues with synX when trying to use Sync, its not being recognised correctly in game. This is a screenshot of the server startup log with the error line highlighted. At first I thought sponge wasnā€™t starting correctly but if you look closely (I also highlighted this) you can see sponge and the permissions stuff starts with the server. When I have Sync in on startup it wonā€™t start as it throws an error of not having SynX on the server when SynX is required.

I am using these builds:
SynX-Sponge-0.10.1.jar
spongeforge-1.8.9-1890-4.2.0-BETA-1586.jar
forge-1.8.9-11.15.1.1890-1.8.9-universal.jar

Hello. Unfortunately maven messed up.
You have to re-download the jar file. Thank you for your report.

PS: for your player data share plugin, I suggest you to not fork/use Sync (and definitely not SynX). Instead, you have to make a new plugin and use SynX as a dependency. Read the README - Developers: How to use.

SynX supports single packets with up to 32KiB of data, so you should be able to transfer players data without splitting the data in multiple packets.

SynX version 1.1 is out!

Itā€™s now way easier to send and receive data between servers: SynX now supports Serializable objects.
Iā€™ve also added a very easy example plugin so everyone can understand how to implement SynX on their plugins.

Can messges safely be sent and received from an asynchronous thread?

Yes. Both broadcast and send methods are thread-safe. Also the onPacketReceived method is being called asynchronously, so it may require server thread synchronization if you need to access Bukkit/Sponge methods.

Cool! I shouldnā€™t need to access sponge methodsā€¦ Iā€™m just looking into different ways to sync player data across multiple, possibly Bungee, serversā€¦

SynX is compatible with Bukkit, Bungeecord, and Sponge servers.

This means that you can send data from a Bukkit/Sponge/Bungeecord server to one or more Bukkit/Sponge/Bungeecord servers.

The proxy server instance can receive and send data from/to other Bungeecord, Bukkit and Sponge servers too by using SynX.

Also SynX doesnā€™t have Bungeeā€™s ā€œan online player is required to send/receive data between servers under bungeeā€ limitation.

Potentially, SynX can also be used by external tools. e.g web page could send data to a minecraft serverā€¦ maybe some data to run a command or do some other special action. Itā€™s up to the developers!

1 Like