magicmq / pyspigot

A Spigot/Bukkit plugin to load and run Python scripts that can interface with the Bukkit API.
https://pyspigot-docs.magicmq.dev
Apache License 2.0
31 stars 3 forks source link

Rework ReflectionUtil versioning #5

Closed virustotalop closed 5 months ago

virustotalop commented 5 months ago

1.20.6 paper no longer remaps CraftBukkit classes which caused the plugin to fail on load. So we check the length of the parsed package CraftBukkit server class name. We also do a try catch for getting CraftBukkit classes so we can get support relocated and non-relocated classes.

Tested with this script on 1.20.6 and 1.20.4

import pyspigot as ps
from dev.magicmq.pyspigot.util import ReflectionUtils

def test_command(sender, label, args):
    sender.sendMessage('Hi!')
    craft_server = ReflectionUtils.getCraftBukkitClass("CraftServer")
    sender.sendMessage(str(craft_server))
    return True

registered_command = ps.command.registerCommand(test_command, 'test')

Results 1.20.6 image 1.20.4 image