3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-17 05:40:06 +01:00

Merge pull request #6 from Boy0000/entity-manip-event

feat: add AxiomManipulateEntityEvent
Dieser Commit ist enthalten in:
Moulberry 2024-06-10 12:08:29 +08:00 committet von GitHub
Commit b9225711d0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 62 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,57 @@
package com.moulberry.axiom.event;
import net.minecraft.nbt.CompoundTag;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class AxiomManipulateEntityEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private final Player player;
private final Entity entity;
private boolean cancelled = false;
public AxiomManipulateEntityEvent(Player player, @NotNull Entity entity) {
this.player = player;
this.entity = entity;
}
public Player getPlayer() {
return player;
}
public Entity getEntity() {
return entity;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package com.moulberry.axiom.packet;
import com.moulberry.axiom.AxiomPaper; 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.integration.Integration; import com.moulberry.axiom.integration.Integration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.viaversion.UnknownVersionHelper; import com.moulberry.axiom.viaversion.UnknownVersionHelper;
@ -124,6 +125,9 @@ 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()) {
NbtSanitization.sanitizeEntity(entry.merge); NbtSanitization.sanitizeEntity(entry.merge);
@ -156,7 +160,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
if (Integration.canPlaceBlock(player, new Location(player.getWorld(), if (Integration.canPlaceBlock(player, new Location(player.getWorld(),
containing.getX(), containing.getY(), containing.getZ()))) { containing.getX(), containing.getY(), containing.getZ()))) {
entity.teleportTo(serverLevel, newX, newY, newZ, Set.of(), newYaw, newPitch); entity.teleportTo(serverLevel, newX, newY, newZ, Set.of(), newYaw, newPitch);
} }
entity.setYHeadRot(newYaw); entity.setYHeadRot(newYaw);