Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from mcstatus import MinecraftServer
- import matplotlib.animation as animation
- from matplotlib import pyplot as plt
- import matplotlib.dates as d
- import datetime
- import ctypes # For closing windows cmd on start
- # Enter your server IP here:
- ip = "us.mineplex.com"
- server = MinecraftServer.lookup(ip)
- # server.query times out when used (as of 10/23/20), waiting for mcstatus devs to fix this
- # query = server.query()
- status = server.status()
- # Initializing pyplot figure and axes
- fig = plt.figure()
- ax1 = fig.add_subplot(1, 1, 1)
- dateFmt = d.DateFormatter('%H:%M:%S')
- # Initializing x and y
- xar = []
- yar = []
- def get_players():
- """Current number of players online"""
- status = server.status()
- # query = server.query()
- return int(status.players.online), [] # [query.players.names]
- def animate(i):
- """Process actions that take place every interval"""
- num, names = get_players()
- xar.append(datetime.datetime.now())
- yar.append(num)
- ax1.clear()
- plt.ylabel("Player Count")
- plt.xlabel("Time") # plt.xlabel([name + ", " for name in names])
- ax1.plot_date(d.date2num(xar), yar, linestyle='-')
- ax1.xaxis.set_major_formatter(dateFmt)
- fig.autofmt_xdate()
- ani = animation.FuncAnimation(fig, animate, interval=5000)
- # Minimize the command prompt
- ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement