Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few questions #2

Closed
LogGits opened this issue Feb 13, 2021 · 3 comments
Closed

A few questions #2

LogGits opened this issue Feb 13, 2021 · 3 comments

Comments

@LogGits
Copy link

LogGits commented Feb 13, 2021

So I have been looking into testing this but i need some info;

What is the purpose of using (this, this) and could it just be done as (this)?

What do the namespace & subject mean and what is the intended usecase for both?

@MessageHandler(namespace = "networkchat", subject="chatMessage")
public void onChatReceived(PlayerMessage message){
getServer().broadcastMessage(String.format("<%s> %s", message.getPlayer(), message.getMessage()));
}

Could I use this to have bungee and spigot communicate via this scenario:

  • spigot players message gets sent to bungee (to check for cancelling)
  • bungee extracts info and parses data

^ if so, how would i setup something like this? would it be like:

  • manager on spigot and bungee
  • getSyncManager.broadcast() ? <- no sure if there is another one
    then this in the bungee plugin (if so, would i need a PlayerMessage object in the bungee plugin aswell and would it need the same args or can it be different?):
@MessageHandler(namespace = "networkchat", subject="chatMessage")
public void onChatReceived(PlayerMessage message){
    getServer().broadcastMessage(String.format("<%s> %s", message.getPlayer(), message.getMessage()));
}

By different PlayerMessage args I mean could I use this:

public PlayerMessage (Player player, String message) {
    this.player = player.getDisplayName();
    this.uuid = player.getUniqueId().toString();
    this.message = message;
}

Thanks in advance :)

@mcgrizzz
Copy link
Owner

mcgrizzz commented Feb 13, 2021

What is the purpose of using (this, this) and could it just be done as (this)?

I realized I haven't updated to the latest Proton version for this repository. It should be fixed in the latest commit. Before the current version, Proton needed a reference to your plugin (hence this, this).

What do the namespace & subject mean and what is the intended usecase for both?

@MessageHandler(namespace = "networkchat", subject="chatMessage")
public void onChatReceived(PlayerMessage message){
getServer().broadcastMessage(String.format("<%s> %s", message.getPlayer(), message.getMessage()));
}

Namespace and Subject essentially define the datatype you want to send and receive.

In the example you showed, if you send an integer to namespace = "networkchat", subject="chatMessage", Proton will throw an error because it is expecting a PlayerMessage.

In broad terms, namespace should refer to your plugin itself or your organization. Subject should be specific to the type of message your sending and receiving.

You can read more here: https://proton-1.gitbook.io/proton/getting-started#sending-your-first-message

Could I use this to have bungee and spigot communicate via this scenario:

  • spigot players message gets sent to bungee (to check for cancelling)
  • bungee extracts info and parses data

You can. However, you only really need a copy of Proton running on bungee if you need access to the proxy. Otherwise, you can just communicate between all the spigot servers the same way.

Here's an example of where I used Proton on both Spigot and Bungee: https://github.com/mcgrizzz/DynamicProxy/tree/main/src/main/java/me/drepic/dynamicproxy
https://www.spigotmc.org/resources/dynamicproxy.88566/

^ if so, how would i setup something like this? would it be like:

  • manager on spigot and bungee

Look at DynamicProxy link above as example for use on spigot and bungee.

  • getSyncManager.broadcast() ? <- no sure if there is another one

I'm not sure what getSyncManager is referring to here.

then this in the bungee plugin (if so, would i need a PlayerMessage object in the bungee plugin aswell and would it need the same args or can it be different?):

If you send a PlayerMessage from the spigot side, the bungeeside will try to parse into whatever parameter you provide.

Example:

Spigot Server:

  • Sends PlayerMessage to bungee proxy @ (namespace = "test", subject="message")

Bungee Proxy

  • Listens for an integer @ (namespace = "test", subject="message)

In this case, you will get an error when bungee receives a message because the datatypes do not match and Proton does not know how to convert a PlayerMessage into an integer.

The same idea applies even if you have the same class name, but a different class constructor.

It will throw an error if the PlayerMessage defined is different than the one received. So you will need to define it in both plugins.

NOTE: Proton can send most datatypes.

Thanks in advance :)

For more detail, you can generally find it on the documentation page: https://proton-1.gitbook.io/proton/getting-started

If something is not clear, I will have to update it.

@LogGits
Copy link
Author

LogGits commented Feb 13, 2021

I realized I haven't updated to the latest Proton version for this repository. It should be fixed in the latest commit. Before the current version, Proton needed a reference to your plugin (hence this, this).

Ah ok that makes sense.

  • getSyncManager.broadcast() ? <- no sure if there is another one

I'm not sure what getSyncManager is referring to here.

I've been defining the variable as "sync{type}", so it's easier for me to remember (i'm using it to sync stuff in this case). In that usage it's a method to get ProtonManager variable.

Is .broadcast() the correct usage if for instance i need to send the message to specifically the proxy?

For more detail, you can generally find it on the documentation page: https://proton-1.gitbook.io/proton/getting-started

If something is not clear, I will have to update it.

Closing because it's pretty much resolved, you are an absolute legend and thanks for clearing all of this up :)

@LogGits LogGits closed this as completed Feb 13, 2021
@mcgrizzz
Copy link
Owner

I realized I haven't updated to the latest Proton version for this repository. It should be fixed in the latest commit. Before the current version, Proton needed a reference to your plugin (hence this, this).

Ah ok that makes sense.

  • getSyncManager.broadcast() ? <- no sure if there is another one

I'm not sure what getSyncManager is referring to here.

I've been defining the variable as "sync{type}", so it's easier for me to remember (i'm using it to sync stuff in this case). In that usage it's a method to get ProtonManager variable.

Is .broadcast() the correct usage if for instance i need to send the message to specifically the proxy?

For more detail, you can generally find it on the documentation page: https://proton-1.gitbook.io/proton/getting-started
If something is not clear, I will have to update it.

Closing because it's pretty much resolved, you are an absolute legend and thanks for clearing all of this up :)

I know this is closed, but I just wanted to reply to your .broadcast() question.

It is not necessarily correct to use broadcast to send a message to a specific server. In this case, it would be better to send directly to the proxy (unless you have more than one proxy).

However, it will still work if you only listen for that specific message on the proxy. The only difference is that, if you use broadcast, all your other servers will receive the message and manually filter out the message themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants