expose entity viewers + some metadata testing
This commit is contained in:
parent
c37e2a115b
commit
cf10f2da50
3 changed files with 25 additions and 20 deletions
|
@ -12,10 +12,7 @@ import me.tofaa.entitylib.EntityLib;
|
||||||
import me.tofaa.entitylib.meta.EntityMeta;
|
import me.tofaa.entitylib.meta.EntityMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class WrapperEntity {
|
public class WrapperEntity {
|
||||||
|
|
||||||
|
@ -64,12 +61,8 @@ public class WrapperEntity {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Collection<UUID> getViewers() {
|
||||||
private static double distance(Location to, Location from) {
|
return Collections.unmodifiableCollection(viewers);
|
||||||
double x = to.getX() - from.getX();
|
|
||||||
double y = to.getY() - from.getY();
|
|
||||||
double z = to.getZ() - from.getZ();
|
|
||||||
return Math.sqrt(x * x + y * y + z * z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,8 +86,7 @@ public class WrapperEntity {
|
||||||
|
|
||||||
public void sendPacketToViewers(PacketWrapper<?> packet) {
|
public void sendPacketToViewers(PacketWrapper<?> packet) {
|
||||||
viewers.forEach(uuid -> {
|
viewers.forEach(uuid -> {
|
||||||
Object user = EntityLib.getPacketEvents().getProtocolManager().getChannel(uuid);
|
EntityLib.sendPacket(uuid, packet);
|
||||||
EntityLib.getPacketEvents().getProtocolManager().sendPacket(user, packet);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,13 @@ package me.tofaa.entitylib.meta;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
|
||||||
|
import me.tofaa.entitylib.EntityLib;
|
||||||
|
import me.tofaa.entitylib.entity.WrapperEntity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -31,6 +34,15 @@ public class Metadata {
|
||||||
public <T> void setIndex(byte index, @NotNull EntityDataType<T> dataType, T value) {
|
public <T> void setIndex(byte index, @NotNull EntityDataType<T> dataType, T value) {
|
||||||
EntityData data = new EntityData(index, dataType, value);
|
EntityData data = new EntityData(index, dataType, value);
|
||||||
this.metadataMap.put(index, data);
|
this.metadataMap.put(index, data);
|
||||||
|
WrapperEntity e = EntityLib.getEntity(entityId);
|
||||||
|
if (e != null && e.hasSpawned()) {
|
||||||
|
e.sendPacketToViewers(
|
||||||
|
new WrapperPlayServerEntityMetadata(
|
||||||
|
entityId,
|
||||||
|
getEntries()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull List<EntityData> getEntries() {
|
@NotNull List<EntityData> getEntries() {
|
||||||
|
|
|
@ -3,12 +3,14 @@ package me.tofaa.entitylib;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||||
import com.github.retrooper.packetevents.protocol.world.Location;
|
import com.github.retrooper.packetevents.protocol.world.Location;
|
||||||
import me.tofaa.entitylib.entity.WrapperEntity;
|
import me.tofaa.entitylib.entity.WrapperEntity;
|
||||||
|
import me.tofaa.entitylib.meta.EntityMeta;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class TestEntityCommand implements CommandExecutor {
|
public class TestEntityCommand implements CommandExecutor {
|
||||||
|
@ -26,18 +28,17 @@ public class TestEntityCommand implements CommandExecutor {
|
||||||
player.sendMessage("idk");
|
player.sendMessage("idk");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.hasSpawned()) {
|
|
||||||
entity.remove();
|
|
||||||
player.sendMessage("removed");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
entity.addViewer(player.getUniqueId());
|
entity.addViewer(player.getUniqueId());
|
||||||
entity.spawn(fromBukkit(player.getLocation()));
|
entity.spawn(fromBukkit(player.getLocation()));
|
||||||
player.sendMessage("spawned");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityMeta meta = entity.getMeta();
|
||||||
|
meta.setOnFire(!meta.isOnFire());
|
||||||
|
meta.setHasGlowingEffect(!meta.hasGlowingEffect());
|
||||||
|
player.sendMessage("on fire: " + meta.isOnFire());
|
||||||
|
player.sendMessage("glowing: " + meta.hasGlowingEffect());
|
||||||
|
player.sendMessage("viewers: " + entity.getViewers());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue