Serverpinging

Nov 13, 2016
Serverpinging
  • Serverpinging allows to display the playercount and lore of specific servers in any BossShopPro text, like for example in the lore of an item or a message.

    At BossShopPro it works a little different from BossShop.

    Guide
    Here you have one global list of servers in your config.yml:
    Code (Text):
    ServerPinging:
      Enabled: false
      Delay: 45
      FixConnector: false
      Timeout: 4000
      WaitTimeAfterFail: 4500
      List:
      - becto.net:25565
    If you want to work with that feature, set
    Code (Text):
      Enabled: true
    The delay tells BossShopPro how often to ping the listed servers. It is defined in ticks (20 ticks = 1 second). By default it is 45 ticks = 2,25 seconds, but you can of course decrease or increase the number.
    Code (Text):
    Delay: 45
    Because there are many different minecraft versions out there some servers need to be pinged differently. In order to support all of them there are different kind of Connectors. When ServerPinging starts for the first time it will test out the available Connector types until a successful one is found. The id of that one will be saved into a "BossShopPro/data" file. In the future ServerPinging will directly load the Connector with the saved id.

    When ServerPinging is unable to reach any server after 50 tries it will try out other Connector types again because there might have been changes (like a server update) which require a new Connector. In order to prevent BossShopPro from trying out new Connectors after one has been successfully found, simply set "FixConnector: true".
    Code (Text):
    FixConnector: false
    Next there is a configurable timeout: The plugin will try pinging the given servers until it either has success or the time limit is reached and it accepts a connecting failure, which will always be the case when the server to ping is offline. The timeout is defined in milliseconds.
    Code (Text):
    Timeout: 4000
    If the plugin is not able to ping a server it will wait the given amount of milliseconds until it will try connecting again. That way BossShopPro won't try to ping offline servers as quick as online ones, which would be just unnecessary.
    Code (Text):
    WaitTimeAfterFail: 4500

    Finally there's a list of servers to ping. There are two types of servers that you can add to the list:
    1. Any server: '<server name>:<ip>:<port>' (Here you can use any name you want)
    2. A server connected via BungeeCord: '<name of the server defined in the BungeeCord configuration file>' (When working via BungeeCord you can not use the motd-placeholder)
    List example:
    Code (Text):
      List:
      - becto:mc.becto.net:25565
      - snapcraft:mc.snapcraft.net:25565
    List example using BungeeCord:
    Code (Text):
      List:
      - survival
      - creative

    Later in order to display either playercount or motd of a server, simply use following variable anywhere:

    • %players_<server name>% - Is replaced by player count of server
    • %motd_<server name>% - Is replaced by server motd

    Pro-Tip:
    You can stack multiple servers to display the total player count of these servers together (Needs v1.0.1!). Example:
    • Becto players: %players_becto%
    • Snapcraft players: %players_snapcraft%
    • Total players: %players_becto:snapcraft%


    Example
    config.yml:
    Code (Text):
    ServerPinging:
      Enabled: true
      Delay: 45
      List:
      - hypixel:mc.hypixel.net:25565
      - mineplex:us.mineplex.com:25565
      - cubecraft:play.cubecraftgames.net:25565
      - hivemc:eu.hivemc.com:25565
      - badlion:na.badlion.net:25565
    shop:
    Code (Text):
    ShopName: ping
    DisplayName: 'Ping'
    InventorySize: 45
    signs:
      text: '[]'
      NeedPermissionToCreateSign: true
    shop:
      '1':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6Hypixel
        - amount:1
        - type:FEATHER
        - lore:&f%players_hypixel%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 1
      '10':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6Mineplex
        - amount:1
        - type:FEATHER
        - lore:&f%players_mineplex%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 10
      '19':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6Cubecraft
        - amount:1
        - type:FEATHER
        - lore:&f%players_cubecraft%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 19
      '21':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6Total
        - amount:1
        - type:FEATHER
        - lore:&f%players_hypixel:minexplex:cubecraft:hivemc:badlion%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 21
      '28':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6HiveMC
        - amount:1
        - type:FEATHER
        - lore:&f%players_hivemc%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 28
      '37':
        RewardType: NOTHING
        PriceType: NOTHING
        MenuItem:
        - name:&6Badlion
        - amount:1
        - type:FEATHER
        - lore:&f%players_badlion%
        Message: ''
        ExtraPermission: ''
        InventoryLocation: 37
    Output:
    [​IMG]




    It might not be able for old servers (1.7 and older) to ping really new servers (1.9 or more new). Support for servers that use the same minecraft version always is granted.




    BungeeCord global chat & player chat input
    BossShopPro API allows other plugins to receive user input via the chat of the user. That way for example the PlayerShops addon can allow players to enter the name of their shop or the cost of their items. If you are working with BungeeCord you might want to access all chat messages of your players, for example in order to have a global chat between different servers. In order to be able to distinguish between normal chat messages and special player input, BossShopPro uses the plugin messaging channel and tells whenever a player message does not belong to the general chat.

    Following is an example BungeeCord plugin which detects user input:
    Code (Text):
    import java.io.ByteArrayInputStream;
    import java.io.DataInputStream;
    import java.io.IOException;

    import net.md_5.bungee.api.event.PluginMessageEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.event.EventHandler;

    public class BungeeCordPluginListener implements Listener {
        @EventHandler
        public void onPluginMessage(PluginMessageEvent e) {    

            if(e.getTag().equalsIgnoreCase("BungeeCord")){
                DataInputStream dis = new DataInputStream(new ByteArrayInputStream(e.getData()));


                try{
                    String subchannel = dis.readUTF();


                    if (subchannel.equalsIgnoreCase("BossShopPro")){

                        String type = dis.readUTF();

                        if (type.equalsIgnoreCase("PlayerInput")){

                            String playerUUID = dis.readUTF();        
                            String inputType = dis.readUTF();

                            if(inputType.equalsIgnoreCase("start")){
                                String endTimeMillis = dis.readUTF();
                                System.out.println("Received plugin message by BossShopPro of type \"PlayerInput Start\" with player " + playerUUID+". Knowing that incoming message should not be sent to the global chat until either a stop message is received or time '" + endTimeMillis + "' is reached.");

                            }else if(inputType.equalsIgnoreCase("end")){
                                System.out.println("Received plugin message by BossShopPro of type \"PlayerInput End\" with player " + playerUUID+". Knowing that messages of that player no longer belong to BossShopPro input and can be sent to the chat.");
                            }
                        }

                    }

                }
                catch (IOException e1) {          
                    e1.printStackTrace();          
                }
            }

        }
    }
    As you can see a message is sent using the "BungeeCord" channel and "BossShopPro" subchannel. Next the type of event is sent (currently there only is one event named "PlayerInput"). PlayerInput also comes with the UUID of the affected player.
  • Loading...
  • Loading...