Become a premium member to remove ads
haloman30

Cross-Server Teleportation and Warps - It's Finally Here!

1 post in this topic

Hey, everyone!

 

After hearing me talk about it for months at this point - and after over a year since the BungeeCord migration was considered "complete", cross-server warps and teleportation is now in the server.

 

Using the new Warps System

The new warps system consolidates the old CUWarps and Essentials warps systems into one, unified system. You may previously recall that you had both the /pwarp and /warp commands. Now, everything is under /warp - no need for /pwarp anymore.

 

Warp management has been redone and can be managed using /mywarps. This will allow you to purchase warps, warp aliases, and manage your existing ones. What are warp aliases, you might ask?

Warp aliases are a new addition to allow for easier management of, well, aliases. For those times where you might want multiple warps pointing to the same spot, you can now purchase aliases for warps - and manage all of them as a single warp. At this time, aliases do not show in /warp list - though this may be changed at a later date.

 

You might also notice some blue warps in the /warp list. These are "Official" warps. Any warps that go to server-specific locations (such as spawns, /warp help, and other such locations) are classified as official warps. Other than being displayed differently in the warp list, there's nothing different about these.

 

Restricted Servers

Something you may notice when trying to manage warps or teleport, you'll find in some cases that you are unable to.

 

The new plugin has a configurable list of servers where the players within cannot be teleported to. This currently includes Minigames, Vanilla, and Factions. You also won't be able to manage warps here, either. You are able to teleport out of these servers, but not back in - after all, it'd be pretty rough if you were able to teleport to someone's faction or vanilla base, or to a minigame arena in progress, right?

 

That's cool and all... but why the wait?

Ah yes. The question I'm sure many of you are wondering - why exactly did this seemingly simple feature take over a year to make a reality?

 

Well, there's a few different reasons - let's go through them all individually.

 

Bungee-Bukkit Communication

For starters, it's important to recognize that BungeeCord and Bukkit (in other words, any of the individual gamemodes - like survival, skyblock, creative, etc) have virtually no way to talk to each other. BungeeCord only knows what server a player is connected to, and can connect them to another server if needed. BungeeCord has no knowledge of what world a player is in, nor their coordinates or anything like that.

 

Additionally, the only default method of communicating between the two involves using the player as a vehicle to carry that data. In other words, if no player is on to switch between those servers, data cannot be transmitted.

 

So, the plugin we made requires that we build our own communication method - which thankfully, isn't as hard as it sounds. We used something called Redis - which both BungeeCord and Bukkit can listen to and monitor - and it allows for the two to communicate almost instantly. And as a result of this...

 

Code Complexity and Motivation

... the code for what would normally be a simple Bukkit plugin became three separate Eclipse projects:

  • CUBungee - The BungeeCord plugin that we've been using for a number of general-purpose features, and would house most of the warp and teleport functionality.
  • CUBungeeBukkitBridge - A plugin which sits on each Bukkit server (each gamemode) and responds to messages from BungeeCord.
  • CUBungeeCommon - A library shared by both CUBungee and CUBungeeBukkitBridge, containing a number of common classes used by both projects.

 

Additionally, it took a very long time to find a system of communication that was maintainable. The root issue with most of the previous approaches was that the old setup required bouncing around to different parts of code. All of the business of /setwarp wasn't in a class or file named Setwarp, like you'd expect - but instead, everything after the first message sent from BungeeCord was done in a completely different part of code.

 

For comparison - setting a warp in Bukkit involves the following steps:

  1. Get the current location of the player
  2. Construct a new warp with player's current location (and provided inputs for name and such)
  3. Register new warp

 

That's it. Now - with BungeeCord - what does that look like?

  1. Find out what server the player is in
  2. Ask that server where the player's location is
  3. Wait for the reply
  4. Check the reply to see if the response was valid
  5. If valid, construct a new warp with the player's location (and once again, provided inputs for name and privacy)
  6. Register new warp

 

And for fun - what about teleporting to a warp in BungeeCord?

  1. Get the warp the player wants to teleport to
  2. Find out what server the warp points to
  3. Ask that server if the world the warp has exists
  4. Wait for reply
  5. Check reply to see if world exists
  6. If so, instruct server to teleport the player to the warp's location upon login
  7. Connect the player to the warp's server

 

Whew - that's quite the process. What about in Bukkit, though?

  1. Get the warp the player wants to teleport to
  2. Check if the world exists
  3. If so, teleport player to warp location

 

As you can likely tell - the BungeeCord procedures for all of this are significantly more complex than if it was all done within a single Bukkit server. This complexity is unavoidable - however as described before, I was writing the code in a way that made this entire procedure a lot more painful than it had to be.

 

Eventually, I came up with the idea of transforming the original message into the reply - allowing me to simply wait for the reply within the same part of code. As such, everything needed for the /setwarp command could all be done within the same file. This simple re-contextualization is all that was needed to make the codebase more maintanable.

 

I also have to credit @GuitarXpress here as well - as he helped point out one critical issue which was causing me a major headache where I was observing what I could only describe as quantum mechanics in Minecraft. I had a point where the reply messages would ALWAYS time out waiting for a reply. Which was bad - because if I couldn't get a reply, then the entire idea was going to be scrapped. However, as soon as I started printing this one value to console, it ALWAYS replied in time. Remove the log event? Stops working. The act of trying to monitor a certain variable was changing the result - literal quantum mechanics.

 

But no - turns out, I simply needed to add the volatile keyword to that variable - as the problem was that the part of code checking it was just not seeing the new value. That final breakthrough was the big thing that allowed everything to finally fall into place.

 

Now - you might be wondering, when did this great breakthrough happen? Just under 2 weeks ago - July 5th to be exact. Yep - after solving the code complexity issues, cross-server teleportation and cross-server warps were able to be completed within a couple weeks.

 

But... Can't you just use a plugin that someone else already made?

This is another question I got a few times. Why is it that in a world where tons of plugins are readily available, that seemingly nobody has bothered to make a plugin for cross-server warps and teleports in a BungeeCord network?

 

Well, for starters - the way we use warps are actually a bit different than most warps, since we allow players to directly purchase warps with ingame currency. Most warp plugins don't allow for this. We actually did find a cross-server warp plugin, but it didn't allow for private or unlisted warps, nor did it allow for user-purchasable warps.

 

But the bigger reason why this kind of feature is seemingly so rare is that, in almost every scenario, servers with BungeeCord networks are much larger in scale and scope (and player count). They actually isolate their gamemodes on purpose. They don't want chat or teleports or warps to be interleaved together across everything - because if you have hundreds or thousands of players, this can actually be a huge detriment.

 

However, we moved to BungeeCord purely out of technical reasons - having all of our features and gamemodes within a single Bukkit server resulted in poor performance, lots of lag, and made debugging an absolute nightmare. Rather than having 8 servers with a handful of plugins each, we had one server with over 120 plugins.

 

Of course, I didn't want to start cutting gamemodes - as while we're small, every gamemode gets some attention. And rather than removing choices for people and potentially causing them to leave, we opted to migrate to BungeeCord. But all the while, I still wanted everything to feel connected - to maintain the illusion of everything still being within a single server. This is the complete antithesis of what most BungeeCord servers aim to achieve - and so there simply isn't demand for something like this. That's why I had to build it myself - because nobody else needed to.

 

Wrapping Up

But thankfully - it's finally in. There are still a couple minor fixes I need to do here and there, but overall - it's all ready to go. As per usual with any new feature, let me know if you run into any issues. This plugin is hot off the presses, so it's entirely likely that there's a bug that we didn't catch during testing.

 

Other than that - be on the lookout for additional improvements coming sooner rather than later. The need to get this feature done has been a dark cloud hanging over my motivation to work on server plugins - so finally having it behind me I suspect will have positive effects on my drive to work on the more exciting stuff.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now