Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-17 05:40:06 +01:00
Integrate entity editing with PlotSquared
Dieser Commit ist enthalten in:
Ursprung
87ad8948c1
Commit
51b6ae7010
@ -23,7 +23,8 @@ public record BlueprintHeader(String name, String author, List<String> tags, flo
|
||||
public static BlueprintHeader read(FriendlyByteBuf friendlyByteBuf) {
|
||||
String name = friendlyByteBuf.readUtf();
|
||||
String author = friendlyByteBuf.readUtf();
|
||||
List<String> tags = friendlyByteBuf.readList(FriendlyByteBuf::readUtf);
|
||||
List<String> tags = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
|
||||
FriendlyByteBuf::readUtf);
|
||||
int blockCount = friendlyByteBuf.readInt();
|
||||
return new BlueprintHeader(name, author, tags, 0, 0, true, blockCount);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.moulberry.axiom.packet;
|
||||
|
||||
import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -20,6 +21,7 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -45,7 +47,8 @@ public class DeleteEntityPacketListener implements PluginMessageListener {
|
||||
}
|
||||
|
||||
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
|
||||
List<UUID> delete = friendlyByteBuf.readList(FriendlyByteBuf::readUUID);
|
||||
List<UUID> delete = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
|
||||
FriendlyByteBuf::readUUID);
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
||||
|
||||
@ -61,6 +64,11 @@ public class DeleteEntityPacketListener implements PluginMessageListener {
|
||||
if (!whitelistedEntities.isEmpty() && !whitelistedEntities.contains(type)) continue;
|
||||
if (blacklistedEntities.contains(type)) continue;
|
||||
|
||||
if (!PlotSquaredIntegration.canBreakBlock(player,
|
||||
player.getWorld().getBlockAt(entity.getBlockX(), entity.getBlockY(), entity.getBlockZ()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.remove(Entity.RemovalReason.DISCARDED);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.moulberry.axiom.packet;
|
||||
|
||||
import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.NbtSanitization;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -17,12 +18,14 @@ import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -63,7 +66,8 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
PassengerManipulation passengerManipulation = friendlyByteBuf.readEnum(PassengerManipulation.class);
|
||||
List<UUID> passengers = List.of();
|
||||
if (passengerManipulation == PassengerManipulation.ADD_LIST || passengerManipulation == PassengerManipulation.REMOVE_LIST) {
|
||||
passengers = friendlyByteBuf.readList(FriendlyByteBuf::readUUID);
|
||||
passengers = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
|
||||
FriendlyByteBuf::readUUID);
|
||||
}
|
||||
|
||||
return new ManipulateEntry(uuid, relativeMovementSet, position, yaw, pitch, nbt,
|
||||
@ -88,7 +92,8 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
}
|
||||
|
||||
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
|
||||
List<ManipulateEntry> entries = friendlyByteBuf.readList(ManipulateEntry::read);
|
||||
List<ManipulateEntry> entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000),
|
||||
ManipulateEntry::read);
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
||||
|
||||
@ -104,6 +109,14 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
if (!whitelistedEntities.isEmpty() && !whitelistedEntities.contains(type)) continue;
|
||||
if (blacklistedEntities.contains(type)) continue;
|
||||
|
||||
Vec3 position = entity.position();
|
||||
BlockPos containing = BlockPos.containing(position.x, position.y, position.z);
|
||||
|
||||
if (!PlotSquaredIntegration.canPlaceBlock(player, new Location(player.getWorld(),
|
||||
containing.getX(), containing.getY(), containing.getZ()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.merge != null && !entry.merge.isEmpty()) {
|
||||
NbtSanitization.sanitizeEntity(entry.merge);
|
||||
|
||||
@ -112,6 +125,8 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
entity.load(compoundTag);
|
||||
}
|
||||
|
||||
entity.setPosRaw(position.x, position.y, position.z);
|
||||
|
||||
Vec3 entryPos = entry.position();
|
||||
if (entryPos != null && entry.relativeMovementSet != null) {
|
||||
double newX = entry.relativeMovementSet.contains(RelativeMovement.X) ? entity.position().x + entryPos.x : entryPos.x;
|
||||
@ -130,7 +145,13 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
}
|
||||
}
|
||||
|
||||
entity.teleportTo(serverLevel, newX, newY, newZ, Set.of(), newYaw, newPitch);
|
||||
containing = BlockPos.containing(newX, newY, newZ);
|
||||
|
||||
if (PlotSquaredIntegration.canPlaceBlock(player, new Location(player.getWorld(),
|
||||
containing.getX(), containing.getY(), containing.getZ()))) {
|
||||
entity.teleportTo(serverLevel, newX, newY, newZ, Set.of(), newYaw, newPitch);
|
||||
}
|
||||
|
||||
entity.setYHeadRot(newYaw);
|
||||
}
|
||||
|
||||
@ -154,6 +175,14 @@ public class ManipulateEntityPacketListener implements PluginMessageListener {
|
||||
continue;
|
||||
}
|
||||
|
||||
position = passenger.position();
|
||||
containing = BlockPos.containing(position.x, position.y, position.z);
|
||||
|
||||
if (!PlotSquaredIntegration.canPlaceBlock(player, new Location(player.getWorld(),
|
||||
containing.getX(), containing.getY(), containing.getZ()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
passenger.startRiding(entity, true);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.moulberry.axiom.AxiomPaper;
|
||||
import com.moulberry.axiom.NbtSanitization;
|
||||
import com.moulberry.axiom.event.AxiomTeleportEvent;
|
||||
import com.moulberry.axiom.event.AxiomUnknownTeleportEvent;
|
||||
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@ -31,6 +32,7 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -67,7 +69,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener {
|
||||
}
|
||||
|
||||
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
|
||||
List<SpawnEntry> entries = friendlyByteBuf.readList(SpawnEntry::new);
|
||||
List<SpawnEntry> entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), SpawnEntry::new);
|
||||
|
||||
ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
||||
|
||||
@ -82,6 +84,11 @@ public class SpawnEntityPacketListener implements PluginMessageListener {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!PlotSquaredIntegration.canPlaceBlock(player, new Location(player.getWorld(),
|
||||
blockPos.getX(), blockPos.getY(), blockPos.getZ()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (serverLevel.getEntity(entry.newUuid) != null) continue;
|
||||
|
||||
CompoundTag tag = entry.tag == null ? new CompoundTag() : entry.tag;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren