Siper
Siper
AAdmincraft
Created by Siper on 2/14/2025 in #questions
Invisible player due value in playerdata file, how to fix that without headache?
Well. I've fixed it. I was forced to iterate per each playerdata file and if is necessary remove Bukkit.invisible tag, and then just replace files. Of course everything on turned off server. If someone interested, here's the script:
#!/usr/bin/env python3
import os
import logging
from nbtlib import load, Byte
import shutil

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)

fixed_files = []

def process_file(filepath, filename):
"""Load an NBT .dat file, change Bukkit.invisible from 1 to 0 if needed."""
try:
# Load the NBT file; nbtlib automatically handles compression.
nbt_file = load(filepath)
except Exception as e:
logging.error(f"Error reading '{filepath}': {e}")
return

root = nbt_file

# Check if the tag exists in the root compound
if "Bukkit.invisible" in root:
# Remove the tag
root.pop("Bukkit.invisible")
try:
nbt_file.save(filepath)
fixed_files.append(filename)
logging.info(f"'{filename}' [Updated] - Bukkit.invisible has been removed")
except Exception as e:
logging.error(f"Error saving '{filepath}': {e}")
else:
logging.info(f"'{filename}' [Skipped] - No 'Bukkit.invisible' tag found")

def main(directory):
if not os.path.isdir(directory):
logging.error(f"Directory not found: {directory}")
return

"""Create new directory to prevent overwriting original files, as a safety measure."""
processed_directory = os.path.join(directory, "../processed_playerdata")
if not os.path.exists(processed_directory):
os.makedirs(processed_directory)

logging.info("Copying all .dat files to temporary directory...")
for filename in os.listdir(directory):
if filename.lower().endswith(".dat"):
filepath = os.path.join(directory, filename)
new_filepath = os.path.join(processed_directory, filename)
with open(filepath, 'rb') as f:
with open(new_filepath, 'wb') as nf:
nf.write(f.read())

logging.info("Processing .dat files...")
for filename in os.listdir(processed_directory):
if filename.lower().endswith(".dat"):
filepath = os.path.join(processed_directory, filename)
process_file(filepath, filename)

logging.info(f"{len(fixed_files)} files has been fixed, copying to separate directory.")
new_directory = os.path.join(directory, "../fixed_playerdata")
if not os.path.exists(new_directory):
os.makedirs(new_directory)

for filename in fixed_files:
filepath = os.path.join(processed_directory, filename)
new_filepath = os.path.join(new_directory, filename)
with open(filepath, 'rb') as f:
with open(new_filepath, 'wb') as nf:
nf.write(f.read())

shutil.rmtree(processed_directory)

logging.info("All done! Fixed files:")
for filename in fixed_files:
logging.info(f" - {filename}")

if __name__ == "__main__":
target_directory = "./playerdata"
main(target_directory)
#!/usr/bin/env python3
import os
import logging
from nbtlib import load, Byte
import shutil

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)

fixed_files = []

def process_file(filepath, filename):
"""Load an NBT .dat file, change Bukkit.invisible from 1 to 0 if needed."""
try:
# Load the NBT file; nbtlib automatically handles compression.
nbt_file = load(filepath)
except Exception as e:
logging.error(f"Error reading '{filepath}': {e}")
return

root = nbt_file

# Check if the tag exists in the root compound
if "Bukkit.invisible" in root:
# Remove the tag
root.pop("Bukkit.invisible")
try:
nbt_file.save(filepath)
fixed_files.append(filename)
logging.info(f"'{filename}' [Updated] - Bukkit.invisible has been removed")
except Exception as e:
logging.error(f"Error saving '{filepath}': {e}")
else:
logging.info(f"'{filename}' [Skipped] - No 'Bukkit.invisible' tag found")

def main(directory):
if not os.path.isdir(directory):
logging.error(f"Directory not found: {directory}")
return

"""Create new directory to prevent overwriting original files, as a safety measure."""
processed_directory = os.path.join(directory, "../processed_playerdata")
if not os.path.exists(processed_directory):
os.makedirs(processed_directory)

logging.info("Copying all .dat files to temporary directory...")
for filename in os.listdir(directory):
if filename.lower().endswith(".dat"):
filepath = os.path.join(directory, filename)
new_filepath = os.path.join(processed_directory, filename)
with open(filepath, 'rb') as f:
with open(new_filepath, 'wb') as nf:
nf.write(f.read())

logging.info("Processing .dat files...")
for filename in os.listdir(processed_directory):
if filename.lower().endswith(".dat"):
filepath = os.path.join(processed_directory, filename)
process_file(filepath, filename)

logging.info(f"{len(fixed_files)} files has been fixed, copying to separate directory.")
new_directory = os.path.join(directory, "../fixed_playerdata")
if not os.path.exists(new_directory):
os.makedirs(new_directory)

for filename in fixed_files:
filepath = os.path.join(processed_directory, filename)
new_filepath = os.path.join(new_directory, filename)
with open(filepath, 'rb') as f:
with open(new_filepath, 'wb') as nf:
nf.write(f.read())

shutil.rmtree(processed_directory)

logging.info("All done! Fixed files:")
for filename in fixed_files:
logging.info(f" - {filename}")

if __name__ == "__main__":
target_directory = "./playerdata"
main(target_directory)
16 replies
AAdmincraft
Created by Siper on 2/14/2025 in #questions
Invisible player due value in playerdata file, how to fix that without headache?
About the main question it looks like the easiest way will be just made a script in Python that just iterates for each playerdata and fixes value when is invalid. I will share it when will be done and can confirm it works
16 replies
AAdmincraft
Created by Siper on 2/14/2025 in #questions
Invisible player due value in playerdata file, how to fix that without headache?
yeah, thanks for information about dynmap. The good news is I've installed that plugin couple of hours ago so not yet shared (and obviously not finished rendering)
16 replies
AAdmincraft
Created by Siper on 2/14/2025 in #questions
Invisible player due value in playerdata file, how to fix that without headache?
[00:26:04 INFO]: Server Plugins (14):
[00:26:04 INFO]: Bukkit Plugins:
[00:26:04 INFO]: - AxiomPaper, Chunky, ClickMobs, CoreProtect, dynmap, Essentials, ImageFrame, Lootin, LuckPerms, mc-IPGuard
[00:26:04 INFO]: Schneckenhaus, Vault, WorldEdit, WorldGuard
[00:26:04 INFO]: Server Plugins (14):
[00:26:04 INFO]: Bukkit Plugins:
[00:26:04 INFO]: - AxiomPaper, Chunky, ClickMobs, CoreProtect, dynmap, Essentials, ImageFrame, Lootin, LuckPerms, mc-IPGuard
[00:26:04 INFO]: Schneckenhaus, Vault, WorldEdit, WorldGuard
All plugins that we have
16 replies