Skip to main content

Helps you connecy with LangConnector plugin.

Project description

LCon Python Library for the LangConnector Minecraft Plugin.

Implementation

Installing with PIP

pip install lconn

Declaring in script

from lconn import Hoster, LCon, SetupError, HostingError, InvalidArg

LCon Usage

LCon Subfunctions:

  • <LCon()>["setup"](self, host: str, port: int, protocol: str, location: str)
  • <LCon()>["get"](self, data_name: str)
  • <LCon()>"reset" Example:
import asyncio
from lconn import LCon

async def main():
    # Getting LCon()
    conn = await LCon()

    # Declaring Servers
    first_server = {
        "host": "127.0.0.1",
        "port": 4001,
        "protocol": "http",
        "location": "data"
    }

    second_server = {
        "host": "127.0.0.1",
        "port": 4002,
        "protocol": "https",
        "location": "dataserver"
    }

    # Connecting to server Nr.1
    await conn["setup"](first_server)
    # Retrieving data from server Nr.1
    data = await conn["get"]()
    # Displaying the data
    on = "Online" if data["status"] else "Offline"
    print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")
    # Disconnecting from server Nr.1
    await conn["reset"]()
    # Connecting to server Nr.2
    await conn["setup"](second_server)
    # Setting timeout so every update will be sent
    while True:
        await asyncio.sleep(5)
        # Retrieving data from server Nr.2
        data = await conn["get"]()
        # Displaying the new data
        on = "Online" if data["status"] else "Offline"
        print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")

asyncio.run(main())

Basic Script:

from lconn import LCon

async def main():
    conn = await LCon()

    try:
        await conn["setup"]()
    except Exception as e:
        print(f"An error occurred: {e}")

    status = await conn["get"]("status")

    if status["status"]:
        data = await conn["get"]()
        on = "Online" if data["status"] else "Offline"
        print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")
    else:
        print("Server is offline.")

asyncio.run(main())

Error Handling:

from lconn import LCon, SetupError, InvalidArg

async def main():
    conn = await LCon()

    try:
        await conn["setup"]()
    except SetupError as e:
        print(f"Error occurred because of Setup Error. Error: {e}")
    except Exception as e:
        print(f"Error: {e}")

    status = await conn["get"]("status")

    if status["status"]:
        try:
            data = await conn["get"]()
        except InvalidArg as e:
            print(f"Error occurred because of Invalid Argument. Error: {e}")
        except Exception as e:
            print(f"Error: {e}")

        if not data:
            return

        on = "Online" if data["status"] else "Offline"
        print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")
    else:
        print("Server is offline.")

asyncio.run(main())

Hoster Usage

Hoster Subfunctions:

  • stop(self)

Basic Script:

from lconn import LCon, Hoster
import asyncio

async def main():
    conn = await LCon()

    port = 4001
    location = "data"

    host = await Hoster(port=port, location=location)

    data = await conn["get"]()

    on = "Online" if data["status"] else "Offline"
    print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")

    await host()

asyncio.run(main())

Error Handling:

from lconn import LCon, Hoster, HostingError
import asyncio

async def main():
    conn = await LCon()

    port = 4001
    location = "data"
    host = None

    try:
        host = await Hoster(port=port, location=location)
    except HostingError as e:
        print(f"Error occurred because of Hosting Error. Error: {e}")
    except Exception as e:
        print(f"Error: {e}")

    if not host:
        return

    data = await conn["get"]()

    on = "Online" if data["status"] else "Offline"
    print(f"Server Status: {on}\nOnline Players: {data['onlinePlayers']}\nOnline Staff Players: {data['onlineStaff']}\nOnline Premium Ranked Player: {data['onlinePremium']}")

    await host()

asyncio.run(main())

Other specifications

This library is for the Minecraft plugin named LangConnector, which connects your Minecraft server with your website, Discord bot, application, etc. It is provided under a Free to Use License. Please read the license before modifying. All rights are reserved by Platyna Developments, specifically Alko.Richy

License

Free to Use License. Free to Modify License. Permission Only for Commercialize License. Copyright License.

  1. This script is free to use for everyone.
  2. You can make changes or optimize the script without permission.
  3. This library was created for those who aren't familliar with express or axios and can be used for any type of minecraft server without any permission.
  4. This can be used for communities, public use or private use.
  5. You cannot repost the unmodified version under your name without permission.
  6. The modified version does not need to contain the main author's name, only the platyna prefix. ( Example: platyna.alko.richy)
  7. The main and the modified version cannot be sold without permission.
  8. This can be modifed for the minecraft plugin or for private use.
  9. Any type of modification inside this License cannot be done without permission.
  10. Copyrights can only be applied if you didn't contributed to this project.

For permission/s please contact Alko.Richy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lconn-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lconn-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file lconn-1.0.0.tar.gz.

File metadata

  • Download URL: lconn-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for lconn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 604b6c1539c646f645aea0ed385ec6a09790ad77acce1903e00ee58831bfbcc3
MD5 015dacffbdf1012e535148253c061dd5
BLAKE2b-256 fede40da7099dceaef8ef5c383805827afb0540d1ed79e678e213c767122d68d

See more details on using hashes here.

File details

Details for the file lconn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lconn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for lconn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70e6033e9e9a07c54b02e525f96f2fb3c17cf580727b03b1acfe2bd65e565219
MD5 c8954c8895315f4a33e525fd1e4c5d05
BLAKE2b-256 60cfb2bfb8d0521e4d77c9cb6da9e389c112185031d31db27f29ca919aa9b574

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page