npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-servertap

v1.0.5

Published

NodeJS library for ServerTap

Downloads

2

Readme

node-servertap

NodeJS Library for the Minecraft server plugin ServerTap (https://servertap.io)

Ussage example:

// Import the package - npm i node-servertap
import { servertap, websocket } from "node-servertap";

// Create our instance
const instance = new servertap(
   "localhost", // Server IP / domain
   "4567", // ServerTap port, Default is 4567
   "change_me" // ServerTap key, Default is "change_me"
   )

// Using await
console.log(await instance.server.ping()) // Returns "pong"

// Promises
instance.server.whitelist.get().then(result => {
   console.log(result) // Returns the server whitelist as an Array of Objects
})

// How to use the websocket:
// Import "wehsocket" from node-servertap, then create a new ws like this:
const ws = new websocket(
   instance // Our servertap instance from before
   ).init(
       false // Wether or not to use TLS
       )

// Then use it as you normally would, for example
ws.on("open", (stream) => {
   console.log("Connected!")

   // send commands
   ws.send("say hi from node")
})

Example project:

// Simple example showing how to use node-servertap to get a pretty live server log
// Can be modified to do specefic things depending on what type of event was sent by the server,
// in this example it just changes how it gets logged to the console.

import { servertap, websocket } from 'node-servertap'
import { strip } from 'ansicolor' // For removing color from our data

// Create a client and give it your credentials
const client = new servertap("localhost", 4567, "change_me")

// Array containing objects with player data of all online players
/** @type {String[]} */
const players = await client.player.get.allOnline()

// Create the WebSocket
const wsClass = new websocket(client) // Contains the init() class, and all the parse functions
const ws = wsClass.init(false) // The actual websocket
ws.on("open", function() {
   // keep alive
   setInterval(() => { ws.ping("") }, 10000);
   // Handles when we get data from the websocket
   ws.on("message", function message(rawData) {
       // Format the data
       /** @type {{message:string,timestampMillis:number,loggerName:string,level:string}} */
       var data = JSON.parse(strip(rawData.toString()))
       data.message = strip(data.message)

       // Handle the message we got from the websocket
       handle(data)
   })
})

/**
* Function that parses and handles events
* @param {{message:string,timestampMillis:number,loggerName:string,level:string}} data 
*/
function handle(data) {
   let chat = wsClass.parseChat(data, " » ")
   let command = wsClass.parseCommand(data)
   let connectionEvent = wsClass.parseConnections(data)
   let deathEvent = wsClass.parseDeath(data, players)

   // Chats
   if (chat) {
       return console.log("✉️ ", chat.author, ": ", chat.content)
   }
   // Join / Leave
   if (connectionEvent) {
       switch (connectionEvent.type) {
           case "JOIN":
               return console.log("👋", connectionEvent.player, "joined!")
           case "LEAVE":
               return console.log("👋", connectionEvent.player, "left..")
           default:
               break;
       }
   }
   // Player command ussage
   if (command) {
       return console.log("🖥️", command.player, "used command", command.command)
   }
   // Player deaths
   if (deathEvent) {
       return console.log("💀", deathEvent.displayName, "died", deathEvent.message)
   }
   // If not handled by methods above,
   // Log0 = icon, log1 = message
   let log = wsClass.parseLog(data)
   console.log(log[0], log[1])
}