It's way better then checking something on PlayerMoveEventHow the fuck is this "optimized" if it's just listening on PlayerMoveEvent? All it does is call events for certain conditions. This has to be the most useless API ever. Using this will just increase server load and the amount of events called and won't do anything else.
![]()
I have to agree on the missuse of the term “Optimized”. The point of this api is to have more detailed events for anticheats etc...How the fuck is this "optimized" if it's just listening on PlayerMoveEvent? All it does is call events for certain conditions. This has to be the most useless API ever. Using this will just increase server load and the amount of events called and won't do anything else.
![]()
Oh boy, here we go...It's way better then checking something on PlayerMoveEvent
Example: Someone moves to a different claim from PlayerMoveEvent and it checks that every time on aim
Using PlayerBlockChangeEvent: You can check it only on block change
@EventHandler
private fun procMove(e: PlayerMoveEvent) {
if (e.to.blockY > e.from.blockY) {
e.player.sendMessage("ur now at ${e.to.blockY} yeet")
}
}
@EventHandler
public void onMove(org.bukkit.event.player.PlayerMoveEvent e) {
Location from = e.getFrom();
Location to = e.getTo();
Player player = e.getPlayer();
if (from.getYaw() != to.getYaw()) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerYawChangeEvent(player, from, to));
Bukkit.getServer().getPluginManager().callEvent(new PlayerAimChangeEvent(player, from, to));
}
if (from.getPitch() != to.getPitch()) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerPitchChangeEvent(player, from, to));
Bukkit.getServer().getPluginManager().callEvent(new PlayerAimChangeEvent(player, from, to));
}
if (from.getX() != to.getX()) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerXChangeEvent(player, from, to));
Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to));
}
if (from.getY() != to.getY()) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerYChangeEvent(player, from, to));
Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to));
}
if (from.getZ() != to.getZ()) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerZChangeEvent(player, from, to));
Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to));
}
}
It's good to have more detailed events. I think a much better way of achieving this would be to use Kotlin to add extension methods to PlayerMoveEvent itself, functions like: hasRotationChanged, hasPositionChanged, hasXChanged, etc.I have to agree on the missuse of the term “Optimized”. The point of this api is to have more detailed events for anticheats etc...
This makes sense, I'm looking at improving this a lot in general.Oh boy, here we go...
Let's say I have this code:
We're checking if a player moves upwards to a different block.Code:@EventHandler private fun procMove(e: PlayerMoveEvent) { if (e.to.blockY > e.from.blockY) { e.player.sendMessage("ur now at ${e.to.blockY} yeet") } }
Now, here's your method that handles PlayerMoveEvent:
Now as you can see, we're firing 10 events per PlayerMoveEvent call.Code:@EventHandler public void onMove(org.bukkit.event.player.PlayerMoveEvent e) { Location from = e.getFrom(); Location to = e.getTo(); Player player = e.getPlayer(); if (from.getYaw() != to.getYaw()) { Bukkit.getServer().getPluginManager().callEvent(new PlayerYawChangeEvent(player, from, to)); Bukkit.getServer().getPluginManager().callEvent(new PlayerAimChangeEvent(player, from, to)); } if (from.getPitch() != to.getPitch()) { Bukkit.getServer().getPluginManager().callEvent(new PlayerPitchChangeEvent(player, from, to)); Bukkit.getServer().getPluginManager().callEvent(new PlayerAimChangeEvent(player, from, to)); } if (from.getX() != to.getX()) { Bukkit.getServer().getPluginManager().callEvent(new PlayerXChangeEvent(player, from, to)); Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to)); } if (from.getY() != to.getY()) { Bukkit.getServer().getPluginManager().callEvent(new PlayerYChangeEvent(player, from, to)); Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to)); } if (from.getZ() != to.getZ()) { Bukkit.getServer().getPluginManager().callEvent(new PlayerZChangeEvent(player, from, to)); Bukkit.getServer().getPluginManager().callEvent(new PlayerBlockChangeEvent(player, from, to)); } }
If I had multiple events of my event with different computations, it would still be more efficient to do the same computation multiple times for each of my events than to use 5 if statements and fire 10 events. Even if we only had a specific event (say for moving up in Y) it'd still be more efficient to do the computation ourselves in PlayerMoveEvent. Keep in mind that Bukkit also has to actually handle your 10 events and fire them all at once, for each PlayerMoveEvent. If we had 100 players on, I'm sure there'd be hundreds of these being fired in half a second.
When an if statement is used in this case, the CPU simply puts the first value into one register, the second into another, and puts the result in a third - basically just comparing bits when you make the process sound simple - which is what the CPU does. Keep in mind that registers are about 100x faster than RAM, and I'm pretty sure they cache values so it can do comparisons extremely fast.
So in this case, it'd be easier to use your event if you had multiple events for the same thing - but we know that using one PlayerMoveEvent and doing the same computation would always be more efficient compared to firing 10 events on one PlayerMoveEvent.
TLDR - it's more simple to use this if you have lots of events, but otherwise it is more inefficient[DOUBLEPOST=1558865020][/DOUBLEPOST]
It's good to have more detailed events. I think a much better way of achieving this would be to use Kotlin to add extension methods to PlayerMoveEvent itself, functions like: hasRotationChanged, hasPositionChanged, hasXChanged, etc.
I personally would just add extension functions using Kotlin, that's probably the easiest and best way to go that doesn't require poking into Spigot itselfThis makes sense, I'm looking at improving this a lot in general.
