3
0
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:
Boy 2024-04-28 16:02:24 +02:00
Ursprung ba2d7f9913
Commit 9364d7c546
2 geänderte Dateien mit 8 neuen und 44 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package com.moulberry.axiom.event; package com.moulberry.axiom.event;
import net.minecraft.nbt.CompoundTag;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -18,50 +19,21 @@ public class AxiomManipulateEntityEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final Player player; private final Player player;
private final UUID entityUUID; private final Entity entity;
private final Location fromLocation;
private final Location toLocation;
private boolean cancelled = false; private boolean cancelled = false;
public AxiomManipulateEntityEvent(Player player, Entity entity, Location toLocation) { public AxiomManipulateEntityEvent(Player player, @NotNull Entity entity) {
this.player = player; this.player = player;
this.entityUUID = entity.getUniqueId(); this.entity = entity;
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;
} }
public Player getPlayer() { public Player getPlayer() {
return player; 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() { public Entity getEntity() {
return Bukkit.getEntity(entityUUID); return entity;
}
public UUID getUUID() {
return entityUUID;
} }
@Override @Override

Datei anzeigen

@ -4,9 +4,7 @@ import com.moulberry.axiom.AxiomPaper;
import com.moulberry.axiom.NbtSanitization; import com.moulberry.axiom.NbtSanitization;
import com.moulberry.axiom.event.AxiomManipulateEntityEvent; import com.moulberry.axiom.event.AxiomManipulateEntityEvent;
import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -119,17 +117,15 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
continue; continue;
} }
AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getBukkitEntity());
if (!manipulateEvent.callEvent()) continue;
if (entry.merge != null && !entry.merge.isEmpty()) { if (entry.merge != null && !entry.merge.isEmpty()) {
final Location oldLocation = entity.getBukkitEntity().getLocation();
NbtSanitization.sanitizeEntity(entry.merge); NbtSanitization.sanitizeEntity(entry.merge);
CompoundTag compoundTag = entity.saveWithoutId(new CompoundTag()); CompoundTag compoundTag = entity.saveWithoutId(new CompoundTag());
compoundTag = merge(compoundTag, entry.merge); compoundTag = merge(compoundTag, entry.merge);
entity.load(compoundTag); 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); 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; 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 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; 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) { if (entity instanceof HangingEntity hangingEntity) {
float changedYaw = newYaw - entity.getYRot(); float changedYaw = newYaw - entity.getYRot();