Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-17 05:40:06 +01:00
refactor: call AxiomManipulateEntityEvent before merging nbt for entity
Dieser Commit ist enthalten in:
Ursprung
ba2d7f9913
Commit
9364d7c546
@ -1,5 +1,6 @@
|
||||
package com.moulberry.axiom.event;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -18,50 +19,21 @@ public class AxiomManipulateEntityEvent extends Event implements Cancellable {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private final UUID entityUUID;
|
||||
private final Location fromLocation;
|
||||
private final Location toLocation;
|
||||
private final Entity entity;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public AxiomManipulateEntityEvent(Player player, Entity entity, Location toLocation) {
|
||||
public AxiomManipulateEntityEvent(Player player, @NotNull Entity entity) {
|
||||
this.player = player;
|
||||
this.entityUUID = entity.getUniqueId();
|
||||
this.fromLocation = entity.getLocation();
|
||||
this.toLocation = toLocation;
|
||||
}
|
||||
|
||||
public AxiomManipulateEntityEvent(Player player, UUID entityUUID, Location fromLocation, Location toLocation) {
|
||||
this.player = player;
|
||||
this.entityUUID = entityUUID;
|
||||
this.fromLocation = fromLocation;
|
||||
this.toLocation = toLocation;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Location getFromLocation() {
|
||||
return fromLocation;
|
||||
}
|
||||
|
||||
public Location getToLocation() {
|
||||
return toLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a BukkitEntity from the given UUID.
|
||||
* Do note this might return null in cases where the UUID was from a client-side entity
|
||||
* @return The BukkitEntity, if it exists
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return Bukkit.getEntity(entityUUID);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return entityUUID;
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,9 +4,7 @@ import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.NbtSanitization;
|
||||
import com.moulberry.axiom.event.AxiomManipulateEntityEvent;
|
||||
import com.moulberry.axiom.integration.Integration;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@ -119,17 +117,15 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
continue;
|
||||
}
|
||||
|
||||
AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getBukkitEntity());
|
||||
if (!manipulateEvent.callEvent()) continue;
|
||||
|
||||
if (entry.merge != null && !entry.merge.isEmpty()) {
|
||||
final Location oldLocation = entity.getBukkitEntity().getLocation();
|
||||
NbtSanitization.sanitizeEntity(entry.merge);
|
||||
|
||||
CompoundTag compoundTag = entity.saveWithoutId(new CompoundTag());
|
||||
compoundTag = merge(compoundTag, entry.merge);
|
||||
entity.load(compoundTag);
|
||||
|
||||
Location newLocation = new Location(serverLevel.getWorld(), position.x, position.y, position.z, entity.getBukkitYaw(), entity.getXRot());
|
||||
AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entry.uuid, oldLocation, newLocation);
|
||||
if (!manipulateEvent.callEvent()) continue;
|
||||
}
|
||||
|
||||
entity.setPosRaw(position.x, position.y, position.z);
|
||||
@ -141,10 +137,6 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
double newZ = entry.relativeMovementSet.contains(RelativeMovement.Z) ? entity.position().z + entryPos.z : entryPos.z;
|
||||
float newYaw = entry.relativeMovementSet.contains(RelativeMovement.Y_ROT) ? entity.getYRot() + entry.yaw : entry.yaw;
|
||||
float newPitch = entry.relativeMovementSet.contains(RelativeMovement.X_ROT) ? entity.getXRot() + entry.pitch : entry.pitch;
|
||||
Location newLocation = new Location(serverLevel.getWorld(), newX, newY, newZ, newYaw, newPitch);
|
||||
|
||||
AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getBukkitEntity(), newLocation);
|
||||
if (!manipulateEvent.callEvent()) continue;
|
||||
|
||||
if (entity instanceof HangingEntity hangingEntity) {
|
||||
float changedYaw = newYaw - entity.getYRot();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren