Code Monkey home page Code Monkey logo

Comments (3)

mcgrizzz avatar mcgrizzz commented on June 26, 2024

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.

from protonexamples.

LogGits avatar LogGits commented on June 26, 2024

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 :)

from protonexamples.

mcgrizzz avatar mcgrizzz commented on June 26, 2024

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.

from protonexamples.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.