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 is 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
That's it. And everything in as compact and efficient way as possible.
Code (Java):
// 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
I've made test on localhost to measure execution time of 400 000 particles in random locations around my character.
Notable environment:
localhost server MC 1.17
JDK 17
Intel i5-12600
32 GB RAM DDR4
All tests were made after an extensive warmup of executing them several times to allow JVM to optimize frequently used code.
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,
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
Code (Java):
publicclass PluginName
extends JavaPlugin
{
// loaded particle API private ParticleNativeAPI particleApi
;
@Override
publicvoid 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(!(sender
instanceof Player
)){ sender.
sendMessage(ChatColor.
RED+"You must be player to use this command!"); returntrue; }
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
returntrue; } }
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):
<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>
Plugin should be compatible at least between MC 1.7 and MC 1.21.4 for now.
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.