Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Server 2 Server message

Comments in 'Plugin Development' started by JackboyPlay, Apr 9, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hello I have a question how can I make a server 2 server message for example a player do /sm and 2 server gets the message [From a mysql database] "HI"?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So here is a fill explanation of the theory:

    There is a table in the MySQL database like this:

    Code:
    +----
    | ID | message | other_data |
    | 1  |   blah  | {"abcdef"} 3
    
    When the plugin is enabled, fire a repeating task that runs every tick (or every second if you want).
    The task has a class property called checkTask. In every run of the scheduled task, if checkTask is null, it would set it to a new instance of CheckTask, which is an AsyncTask subclass, and then schedule async task. If checkTask is already set (not null), check if it has finished running. If it does, replace it with a new instance of CheckTask and fire it again.

    The CheckTask has a class property called lastId. It is defined in the constructor. (The scheduled task should construct the async task with the new lastId from the last CheckTask scheduled, or pass null if it is the first run) If lastId is null, query the maximum ID from the table. After you have got lastId, query from the table the rows with ID greater than your lastId. Set the maximum ID as the next lastId so that the next task can use it.

    For each row you received, manipulate it with your own way and then you can broadcast it.



    The above is an approach from the code perspective. From a more theoretical perspective, it is like this:

    Have a table in the MySQL database that contains messages. The messages should have a lastId column, which auto increments and uniquelly identifies and orders the messages.

    From the time plugin is enabled, fire a CheckTask. When a CheckTask is completed, fire another one.
    Every time check for new rows using the lastId, fetch them, pass to main thread in onCompletion, and then broadcast them.
    jojoe77777 likes this.

Share This Page

Advertisement