Giter Club home page Giter Club logo

pyspigot's Introduction

Sonatype Nexus (Releases) Latest Snapshot GitHub Workflow Status Apache 2.0 License

PySpigot

PySpigot is a Spigot/Bukkit plugin that can load, compile, and run Python scripts. These scripts can make use of Java standard libraries, as well as the Bukkit/Spigot API and APIs of any other loaded plugins.

PySpigot utilizes Jython, a Java implementation of Python that runs entirely on the JVM.

A Note About Jython

The major drawback of Jython is that it currently only supports Python 2. Work towards a Python 3 implementation is currently ongoing over at Jython's GitHub repository.

Regarding different avenues, other Python-Java interop projects support Python 3. One such example is Py4J, which is more akin to a "network bridge" between the Python and Java runtimes rather than a true Python implementation. Although it supports Python 3, Py4J would be incredibly difficult to implement as a scripting engine for Bukkit, as it relies heavily on time-consuming I/O operations and Callbacks, which would make the Minecraft server quite unstable. Additionally, Py4J would require a CPython installation (regular Python) on the same machine, a rather difficult requirement to fulfill when working within a containerized Minecraft instance (such as Pterodactyl, shared hosting providers, etc.).

When I began this project, I looked at using several libraries, Py4J included. I came to the conclusion that, although Jython only supports Python 2, it has several key advantages over other libraries in this specific use case, including:

  • It runs entirely on the JVM, making it very easy to interface with Python code from the Java side.
  • It runs entirely on the JVM, which gives all Python code direct access to the entire Java classpath at runtime. Ergo, Python code has full access to Java code and vice versa.
  • It does not require any external Python installation to work. Drag and drop PySpigot into your plugins folder, and you're good to go.
  • And finally, it is reasonably fast (fast enough for Minecraft's standards), given that, again, it runs entirely on the JVM.

Thus, for the foreseeable future, PySpigot will continue to utilize Jython.

Features

PySpigot has many features, including:

  • Load scripts on server start and via commands
  • Stop, reload, and unload server scripts via commands
  • Register event listeners
  • Register commands
  • Schedule tasks (synchronous and asynchronous)
  • Work with config files
  • Register ProtocolLib packet listeners
  • Register PlaceholderAPI placeholder expansions
  • Comprehensive logging of errors and exceptions on a per-script basis, to file
  • Load Java libraries you'd like to work with at runtime
  • Write scripts in Python syntax
  • Scripts have complete access to the Bukkit/Spigot API, as well as APIs of other plugins, so anything is possible.
  • And more!

Using PySpigot

You can download the latest version of PySpigot from the releases page, or from Spigot. Drop it into your plugins folder, and you're ready to begin writing scripts.

PySpigot also has an official Discord server for support, updates, and announcements. Click here to join.

For complete documentation on writing/loading/running scripts, using PySpigot's provided managers, and using the plugin in general, see PySpigot's documentation.

For Java developers, PySpigot has an API! See the Javadocs for complete documentation of API available for you to use.

Adding PySpigot as a Dependency

Maven

Add the following repository:

<repository>
    <id>magicmq-repo</id>
    <url>https://repo.magicmq.dev/repository/maven-releases/</url>
</repository>

Then, add the following dependency:

<dependency>
    <groupId>dev.magicmq</groupId>
    <artifactId>pyspigot</artifactId>
    <version>{VERSION}</version>
    <scope>provided</scope>
</dependency>

Replace {VERSION} with the version shown above, without the v.

Gradle

Add the following repository:

repositories {
    ...
    magicmq-repo { url 'https://repo.magicmq.dev/repository/maven-releases/' }
}

Then, add the following dependency:

dependencies {
    ...
    compileOnly 'dev.magicmq:pyspigot:{VERSION}'
}

Replace {VERSION} with the version shown above, without the v.

Manual Usage

Releases are also published on GitHub here. You may download the JAR and import it yourself into your IDE of choice, or you may install it into your local repository.

Building

Building requires Maven and Git. Maven 3+ is recommended for building the project. Follow these steps:

  1. Clone the repository: git clone https://github.com/magicmq/PySpigot.git
  2. Enter the repository root: cd PySpigot
  3. Build with Maven: mvn clean package
  4. Built files will be located in the target directory.

Issues/Suggestions

Do you have any issues or suggestions? Submit an issue report.

pyspigot's People

Contributors

magicmq avatar virustotalop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyspigot's Issues

Download library error

Describe the bug
Download library error

To Reproduce
Steps to reproduce the behavior:

  1. open server , and wait...

Expected behavior
running success

Additional Info (please fill in):

  • Server environment: Spigot
  • Minecraft version 1.21
  • PySpigot version 0.6.0

Additional context
Log
[21:19:47] [Server thread/WARN]: [PySpigot] Error when attempting to get latest plugin version from Spigot:
[21:19:47] [Server thread/WARN]: java.net.SocketException: Connection reset
[21:19:47] [Server thread/WARN]: at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:318)
[21:19:47] [Server thread/WARN]: at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:346)
[21:19:47] [Server thread/WARN]: at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:796)
[21:19:47] [Server thread/WARN]: at java.base/java.net.Socket$SocketInputStream.read(Socket.java:1109)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:489)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketInputRecord.readFully(SSLSocketInputRecord.java:472)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketInputRecord.decodeInputRecord(SSLSocketInputRecord.java:243)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:181)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:111)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1506)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1421)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455)
[21:19:47] [Server thread/WARN]: at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426)
[21:19:47] [Server thread/WARN]: at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:586)
[21:19:47] [Server thread/WARN]: at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187)
[21:19:47] [Server thread/WARN]: at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1678)
[21:19:47] [Server thread/WARN]: at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1602)
[21:19:47] [Server thread/WARN]: at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
[21:19:47] [Server thread/WARN]: at java.base/java.net.URL.openStream(URL.java:1325)
[21:19:47] [Server thread/WARN]: at dev.magicmq.pyspigot.PySpigot.fetchSpigotVersion(PySpigot.java:208)
[21:19:47] [Server thread/WARN]: at dev.magicmq.pyspigot.PySpigot.onEnable(PySpigot.java:135)
[21:19:47] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:267)
[21:19:47] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342)
[21:19:47] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:492)
[21:19:47] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_21_R1.CraftServer.enablePlugin(CraftServer.java:567)
[21:19:47] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_21_R1.CraftServer.enablePlugins(CraftServer.java:481)
[21:19:47] [Server thread/WARN]: at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:237)
[21:19:47] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1017)
[21:19:47] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318)
[21:19:47] [Server thread/WARN]: at java.base/java.lang.Thread.run(Thread.java:1583)

Build fails on jdk 17 due to invalid flag

Describe the bug
Build fails when using jdk 17 due to the invalid command line argument --no-module-directories

To Reproduce
Steps to reproduce the behavior:

  1. Use jdk 17
  2. Run maven clean
  3. Run maven package
  4. Error occurs due to invalid --no-module-directories command line flag

Expected behavior
Even though the plugin targets java 11 it should be able to be compiled with java 17

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional Info (please fill in):

  • Server environment: Paper
  • Minecraft version 1.20.4
  • PySpigot version 0.5.1

Additional context
It looks like this flag was removed in java 13

https://bugs.openjdk.org/browse/JDK-8215582
https://stackoverflow.com/questions/46118716/fatal-error-compiling-invalid-flag-module-path
amaembo/streamex#247

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.