Giter Club home page Giter Club logo

playerinfoapi's Introduction

PlayerInfoAPI


中文

a MCDaemon plugin to provide API for getting player information

Compatible with MCDaemon and MCDReforged

Now support 1.14+ new JSON string format

(Thank Pandaria for providing the regular expression)

Usage

Use imp.load_source() to load PlayerInfoAPI in your plugin first

from imp import load_source
PlayerInfoAPI = load_source('PlayerInfoAPI','./plugins/PlayerInfoAPI.py')

for MCDReforged use server.get_plugin_instance() to get PlayerInfoAPI instance

PlayerInfoAPI = server.get_plugin_instance('PlayerInfoAPI')

PlayerInfoAPI.convertMinecraftJson(text)

Convert Minecraft style json format into a dict

Minecraft style json format is something like these:

  • Steve has the following entity data: [-227.5d, 64.0d, 12.3E4d]
  • [-227.5d, 64.0d, 231.5d]
  • Alex has the following entity data: {HurtByTimestamp: 0, SleepTimer: 0s, ..., Inventory: [], foodTickTimer: 0}

It will automatically detect if there is a <name> has the following entity data: . If there is, it will erase it before converting

Args:

  • text: A data get entity or other command result that use Minecraft style json format

Return:

  • a parsed json result

Samples:

  • Input Steve has the following entity data: [-227.5d, 64.0d, 231.5d], output [-227.5, 64.0, 123000.0]

  • Input {HurtByTimestamp: 0, SleepTimer: 0s, Inventory: [], foodTickTimer: 0}, output {'HurtByTimestamp': 0, 'SleepTimer': 0, 'Inventory': [], 'foodTickTimer': 0}

PlayerInfoAPI.getPlayerInfo(server, name, path='')

Call data get entity <name> [<path>] and parse the result

If it's in MCDReforged and rcon is enabled it will use rcon to query

Args:

  • server: the Server Object
  • name: name of the player who you want to get his/her info
  • path: an optional path parameter in data get entity command

Return:

  • a parsed json result

Please refer to the Player.dat page on minecraft wiki Player.dat格式

Example

def onServerInfo(server, info):
  if info.content.startswith('!!test'):
    result = PlayerInfoAPI.getPlayerInfo(server,info.player)
    server.say("Dim:"+str(result["Dimension"])+"Pos:"+str(result["Pos"][0])+","+str(result["Pos"][1])+","+str(result["Pos"][2]))

you can also refer to the demo of Here plugin with this API(in newapi branch)

Here(Demo)

playerinfoapi's People

Contributors

nathan21hz avatar tiyaanlite avatar fallen-breath avatar

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.