ParticleNativeAPI [1.7+]
For version 3.x.x details of this lib check Migration from 3.x.x to 4.x.x section.
ParticleNativeAPI
ParticleNativeAPI is a particle spawning API for Spigot and Bukkit server designed to be:
- fast (comparable to native Java written code!),
- cross-version compatible down to MC 1.7 (includes removed particles!),
- flexible in use,
- relatively easy and convenient to use.
On top of that, this particle API supports spawning certain particles:
- of blocks,
- of items,
- with color (only 1 particle per packet),
- with color and size,
- with transition color and size,
- with certain motion (only 1 particle per packet)
- with angle
- with delay
... and still be fast and cross version compatible between Minecraft updates.
Entire API structure targets to reflect how Minecraft handles sending packets, however it strongly typed and uses no Reflection to do so!
How to use
Spawning particle is made in very simple method chain:
- from API -> get particles list -> get particle
- select properties of particle
- make particle packet
- send it, using particles lists.
That's it.
// get API from plugin instance ParticleNativeAPI api = ParticleNativePlugin.getAPI(); // ... or generate it using core module ("this" is Your plugin instance) particleApi = ParticleNativeCore.loadAPI(this); Player player = ...; Location loc = player.getLocation(); // as simple as that particleApi.LIST_1_8.FLAME // from desired list get particle .packet(true, loc) // make particle packet .sendTo(player); // send it to certain player(s)
To whoever you want to send this packet or on what conditions is up to You. To read more about particle lists above, I encourage you to read detailed tutorial on my github repository here.
Why is it fast
It internally uses ObjectWeb's ASM library to generate version-dependent Java code instead of using Reflection.
Reflection is only used to recognize on which Minecraft version should API be generated, at server start-up phase.
Simple benchmark
Notable environment:
- localhost server MC 1.17
- JDK 17
- Intel i5-12600
- 32 GB RAM DDR4
However, it is still simple benchmark (not JMH or something), so results should be taken with a little pinch of salt.
All code used to test is found on my repository here.
Tests consist of 4 methods to send particle:
- nms - uses directly NMS and OBC to send packet,
- particle_native_api - uses this api to send particle with simple method,
- spigot_api - uses Spigot API's spawnParticle method (to player) to send effect,
- reflection - uses NMS and OBC reflected classes (with accessibility set to true) to send particle. Those classes/methods/fields are cached for multiple use.
As you can see, at least on my machine, ParticleNativeAPI is comparable to Spigot API and very close in speed to version specific implementation.
Minimal usage example overview
public class PluginName extends JavaPlugin { // loaded particle API private ParticleNativeAPI particleApi; @Override public void onEnable() { // load API and store it for later use particleApi = ParticleNativeCore.loadAPI(this); // or get it from running plugin api instance // check if everything is fine with it // if (ParticelNativePlugin.isValid()) { // particleApi = ParticleNativePlugin.getAPI(); // } // else { // getLogger().log(Level.SEVERE, "Error occurred while loading dependency."); // this.setEnabled(false); // return; // } } // example usage @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!command.getName().equalsIgnoreCase("somecmd")) return true; if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You must be player to use this command!"); return true; } Player pSender = (Player) sender; Location loc = pSender.getLocation(); // particle spawning particleApi.LIST_1_8.FLAME // select particle from list .packet(true, loc) // create particle packet .sendInRadiusTo(player, 30D); // send it to player if in 30 block radius return true; } }
For server owners
If you were redirected here by other plugin, just include plugin's jar in plugins folder.
This library doesn't do anything on it's own besides startup phase. It may be used as a dependency by other plugins.
For plugin developers
A detailed tutorial with various examples can be found on my github repository here.
Maven for core API with example setup (official repository):
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <!-- replace shaded version with main artifact --> <shadedArtifactAttached>false</shadedArtifactAttached> <!-- relocate API classes to avoid same-classpath-conflicts --> <!-- with other plugins using this core API --> <relocations> <relocation> <pattern>com.github.fierioziy.particlenativeapi</pattern> <shadedPattern>me.yourpluginpackage.particleapi</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> </plugin> <!-- other plugins ... --> </plugins> <!-- other build config ... --> </build> <dependencies> <dependency> <groupId>com.github.fierioziy.particlenativeapi</groupId> <artifactId>ParticleNativeAPI-core</artifactId> <version>4.1.0</version> <scope>compile</scope> </dependency> <!-- other dependencies --> </dependencies>
Maven for plugin reference setup (official repository):
<dependencies> <dependency> <groupId>com.github.fierioziy.particlenativeapi</groupId> <artifactId>ParticleNativeAPI-plugin</artifactId> <version>4.1.0</version> <scope>provided</scope> </dependency> <!-- other dependencies --> </dependencies>
Request feature or report an issue
If you found a bug or just want to request a feature, use an issue tracker on my github here.
Source code
All plugin's source code is present on my github repository here.
For version 3.x.x current source is on branch master-v3 here.
Compatibility
Tested Spigot versions: 1.7.10, 1.8.8, 1.12, 1.14.3, 1.15.2, 1.16.1, 1.17, 1.18, 1.19, 1.19.3, 1.20.2.
Plugin should be compatible at least between MC 1.7 and MC 1.20.2 for now.
It should work on Bukkit (CraftBukkit) as well.
It will only needs update if new feature/bugfix were added or there were Minecraft changes in packet handling in future versions.
Keep in mind, that this API will favor backward compatibility
with supported MC versions range instead of forward compatibility of itself.
Most of the time it will be announced as new major version (for ex. from 3.x.x to 4.x.x)
That said, next API updates might sometimes force some changes
in Your code to again be compatible with newer API version.
is it possible to make this also compatible with a 1.6.4 server? Preferred tekkit/cauldron? :D
Hi, i think that it *might* be possible to do, however adding compatibility with forge-based bukkit server will be much much harder than it is currently done with standard bukkit/spigot servers.
I'm pretty sure that i'm not the only one that faced this problem with forge servers support.
I've done small research around this (someone asked me to make similar compatibility with Thermos server so i've checked it) and it would need me to refactor internally almost entire implementation to support completely different server structure.
It is mainly caused by fact, that forge changes particles and other classes to different names at different times than it is done in standard bukkit/spigot.
Currently i've stopped attempt to start this (studies and work etc.), however i haven't closed this, so maybe it *might* be added in the future
In reply to Fierioziy:
Hey man, thanks for the reply. No rush or promises expected my dude :D I have just found my self going back and creating a tekkit/cauldron server with a shit ton of plugins added as well as all the slandered tekkit mods :D Been going back and getting ahold of a fair amount of older plugins. Finding alot of good ones that still work even for the weird setup i have going :D
If your bored and feel up to it :D Would be awesome......