Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for including Multiverse Inventories & Factions plugin data in… #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mcstats/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"updateInactive": False, # also update profile for inactive players
"inactiveDays": 7, # number of offline days before a player is considered inactive
"minPlaytime": 60, # number of minutes a player must have played before entering stats
"pluginFolder": "plugins", # For the next two options, a valid plugin folder name (ignore if vanilla)
"lookupUsingMVI": True, # Include Multiverse Inventories plugin in the UUID to name lookup
"lookupUsingFaction": True, # Include Factions plugin in the UUID to name lookup
"excludeBanned": True, # whether or not to exclude banned players
"excludeOps": False, # whether or not to exclude ops
"excludeUUIDs": [] # list of UUIDs to exclude
Expand Down
44 changes: 44 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import math
import os
import pathlib
import re
import shutil
import sys
Expand Down Expand Up @@ -178,6 +179,41 @@ def is_active(last):
except:
handle_error('Cannot open ' + usercacheFile + ' for offline player lookup')

# try and load from MV Inventories
mvinvlist = dict()
if config.players.lookupUsingMVI:
for (path, _) in sources:
mvpath = config.players.pluginFolder + '/Multiverse-Inventories/players'
mvpath = os.path.join(path, mvpath) # 'plugins/Multiverse-Inventories/players'
try:
for filenamemvpath in pathlib.Path(mvpath).iterdir():
if filenamemvpath.is_file():
filenamemvSTR = os.path.join(filenamemvpath)
try:
with open(filenamemvpath) as f:
string = f.read()
filename = os.path.basename(filenamemvpath)
filenameuuid = os.path.splitext(filename)[0]
entry = json.loads(string, object_hook=lambda d: types.SimpleNamespace(**d))
mvinvlist[filenameuuid] = entry.playerData.lastKnownName
except:
handle_error('Cannot open ' + filenamemvSTR + ' for offline (multiverse inv) player lookup')
except:
handle_error('Cannot open ' + mvpath + ' for offline (multiverse inventory) player lookup')

# try and load from Factions
factionlist = dict()
if config.players.lookupUsingFaction:
for (path, _) in sources:
factionpath = config.players.pluginFolder + '/MassiveCore/idnamecache.json'
factionpath = os.path.join(path, factionpath) # 'plugins/MassiveCore/idnamecache.json'
try:
with open(factionpath) as f:
for entry in json.load(f):
factionlist[entry['id']] = entry['name']
except:
handle_error('Cannot open ' + factionpath + ' for offline (factions cache) player lookup')

# exclude players
excludePlayers = set()

Expand Down Expand Up @@ -379,6 +415,14 @@ def is_active(last):
# no profile available, but the UUID is in the usercache
player['name'] = usercache[uuid]

if (not 'name' in player) and (uuid in mvinvlist):
# no profile available, but the UUID is in the multiverse inventory list
player['name'] = mvinvlist[uuid]

if (not 'name' in player) and (uuid in factionlist):
# no profile available, but the UUID is in the faction list
player['name'] = factionlist[uuid]

if (not 'name' in player):
# there is no way to find the name of this player
# this may happen if the player has no valid Mojang UUID
Expand Down