fix: errors

This commit is contained in:
Felipe Paschoal Bergamo 2025-06-03 18:53:19 -03:00
parent b5481f783d
commit 1fc7a00ec7
7 changed files with 33 additions and 62 deletions

View file

@ -82,4 +82,5 @@ public final class APIConfig {
&& EntityLib.getOptionalApi().isPresent() && EntityLib.getOptionalApi().isPresent()
&& EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4); && EntityLib.getOptionalApi().get().getPacketEvents().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4);
} }
} }

View file

@ -1,22 +1,14 @@
package me.tofaa.entitylib; package me.tofaa.entitylib;
import com.github.retrooper.packetevents.PacketEventsAPI; import com.github.retrooper.packetevents.PacketEventsAPI;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.protocol.world.Location;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import me.tofaa.entitylib.container.EntityContainer; import me.tofaa.entitylib.container.EntityContainer;
import me.tofaa.entitylib.tick.TickContainer; import me.tofaa.entitylib.tick.TickContainer;
import me.tofaa.entitylib.wrapper.WrapperEntity; import me.tofaa.entitylib.wrapper.WrapperEntity;
import me.tofaa.entitylib.wrapper.WrapperPlayer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/** /**
* Represents the API for EntityLib. * Represents the API for EntityLib.
@ -58,10 +50,7 @@ public interface EntityLibAPI<T> {
*/ */
void addTickContainer(@NotNull TickContainer<?, T> tickContainer); void addTickContainer(@NotNull TickContainer<?, T> tickContainer);
@NotNull BiConsumer<UUID, PacketWrapper<?>> getPacketDispatcher(); @NotNull
EntityContainer getDefaultContainer();
void setPacketDispatcher(@NotNull BiConsumer<UUID, PacketWrapper<?>> packetDispatcher);
@NotNull EntityContainer getDefaultContainer();
} }

View file

@ -140,60 +140,60 @@ public class EntityMeta implements EntityMetadataProvider {
} }
public short getAirTicks() { public short getAirTicks() {
return this.metadata.getIndex((byte) 1, (short) 300); return this.metadata.getIndex((byte)1, (short) 300);
} }
public void setAirTicks(short value) { public void setAirTicks(short value) {
this.metadata.setIndex((byte) 1, EntityDataTypes.SHORT, value); this.metadata.setIndex((byte)1, EntityDataTypes.SHORT, value);
} }
public Component getCustomName() { public Component getCustomName() {
Optional<Component> component = this.metadata.getIndex((byte) 2, Optional.empty()); Optional<Component> component = this.metadata.getIndex((byte)2, Optional.empty());
return component.orElse(null); return component.orElse(null);
} }
public void setCustomName(Component value) { public void setCustomName(Component value) {
this.metadata.setIndex((byte) 2, EntityDataTypes.OPTIONAL_ADV_COMPONENT, Optional.ofNullable(value)); this.metadata.setIndex((byte)2, EntityDataTypes.OPTIONAL_ADV_COMPONENT, Optional.ofNullable(value));
} }
public boolean isCustomNameVisible() { public boolean isCustomNameVisible() {
return this.metadata.getIndex((byte) 3, false); return this.metadata.getIndex((byte)3, false);
} }
public void setCustomNameVisible(boolean value) { public void setCustomNameVisible(boolean value) {
this.metadata.setIndex((byte) 3, EntityDataTypes.BOOLEAN, value); this.metadata.setIndex((byte)3, EntityDataTypes.BOOLEAN, value);
} }
public boolean isSilent() { public boolean isSilent() {
return this.metadata.getIndex((byte) 4, false); return this.metadata.getIndex((byte)4, false);
} }
public void setSilent(boolean value) { public void setSilent(boolean value) {
this.metadata.setIndex((byte) 4, EntityDataTypes.BOOLEAN, value); this.metadata.setIndex((byte)4, EntityDataTypes.BOOLEAN, value);
} }
public boolean hasNoGravity() { public boolean hasNoGravity() {
return this.metadata.getIndex((byte) 5, true); return this.metadata.getIndex((byte)5, true);
} }
public void setHasNoGravity(boolean value) { public void setHasNoGravity(boolean value) {
this.metadata.setIndex((byte) 5, EntityDataTypes.BOOLEAN, value); this.metadata.setIndex((byte)5, EntityDataTypes.BOOLEAN, value);
} }
public EntityPose getPose() { public EntityPose getPose() {
return this.metadata.getIndex((byte) 6, EntityPose.STANDING); return this.metadata.getIndex((byte)6, EntityPose.STANDING);
} }
public void setPose(EntityPose value) { public void setPose(EntityPose value) {
this.metadata.setIndex((byte) 6, EntityDataTypes.ENTITY_POSE, value); this.metadata.setIndex((byte)6, EntityDataTypes.ENTITY_POSE, value);
} }
public int getTicksFrozenInPowderedSnow() { public int getTicksFrozenInPowderedSnow() {
return this.metadata.getIndex((byte) 7, 0); return this.metadata.getIndex((byte)7, 0);
} }
public void setTicksFrozenInPowderedSnow(int value) { public void setTicksFrozenInPowderedSnow(int value) {
this.metadata.setIndex((byte) 7, EntityDataTypes.INT, value); this.metadata.setIndex((byte)7, EntityDataTypes.INT, value);
} }
public WrapperPlayServerEntityMetadata createPacket() { public WrapperPlayServerEntityMetadata createPacket() {
@ -206,7 +206,6 @@ public class EntityMeta implements EntityMetadataProvider {
throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + "."); throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + ".");
} }
} }
if (!PacketEvents.getAPI().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) { if (!PacketEvents.getAPI().getServerManager().getVersion().is(VersionComparison.NEWER_THAN, version)) {
throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + "."); throw new InvalidVersionException("This method is only available for versions newer than " + version.name() + ".");
} }
@ -230,7 +229,7 @@ public class EntityMeta implements EntityMetadataProvider {
/** /**
* Annoying java 8 not letting me do OFFSET + amount in the method call so this is a workaround * Annoying java 8 not letting me do OFFSET + amount in the method call so this is a workaround
* *
* @param value the value to offset * @param value the value to offset
* @param amount the amount to offset by * @param amount the amount to offset by
* @return the offset value * @return the offset value
*/ */
@ -259,7 +258,7 @@ public class EntityMeta implements EntityMetadataProvider {
} }
public void setMaskBit(int index, byte bit, boolean value) { public void setMaskBit(int index, byte bit, boolean value) {
byte mask = getMask((byte) index); byte mask = getMask((byte)index);
boolean currentValue = (mask & bit) == bit; boolean currentValue = (mask & bit) == bit;
if (currentValue == value) { if (currentValue == value) {
return; return;
@ -269,7 +268,7 @@ public class EntityMeta implements EntityMetadataProvider {
} else { } else {
mask &= (byte) ~bit; mask &= (byte) ~bit;
} }
setMask((byte) index, mask); setMask((byte)index, mask);
} }
@Override @Override

View file

@ -19,6 +19,7 @@ public class TextDisplayMeta extends AbstractDisplayMeta {
super(entityId, metadata); super(entityId, metadata);
} }
public Component getText() { public Component getText() {
return metadata.getIndex(OFFSET, Component.empty()); return metadata.getIndex(OFFSET, Component.empty());
} }

View file

@ -509,9 +509,18 @@ public class WrapperEntity implements Tickable {
} }
private static void sendPacket(UUID user, PacketWrapper<?> wrapper) { private static void sendPacket(UUID user, PacketWrapper<?> wrapper) {
if (wrapper != null) { if (wrapper == null) return;
EntityLib.getApi().getPacketDispatcher().accept(user, wrapper);
Object channel = EntityLib.getApi().getPacketEvents().getProtocolManager().getChannel(user);
if (channel == null) {
if (EntityLib.getApi().getSettings().isDebugMode()) {
EntityLib.getPlatform().getLogger().warning("Failed to send packet to " + user + " because the channel was null. They may be disconnected/not online.");
}
return;
} }
EntityLib.getApi().getPacketEvents().getProtocolManager().sendPacket(channel, wrapper);
} }
public boolean hasNoGravity() { public boolean hasNoGravity() {

View file

@ -165,7 +165,7 @@ public class WrapperEntityPotionEffect {
new ArrayList<>(this.effects.values()).forEach(effect -> { new ArrayList<>(this.effects.values()).forEach(effect -> {
WrapperPlayServerEntityEffect wrapperPlayServerEntityEffect = createEffectPacket(effect); WrapperPlayServerEntityEffect wrapperPlayServerEntityEffect = createEffectPacket(effect);
this.entity.sendPacketsToViewers(wrapperPlayServerEntityEffect); this.entity.sendPacketToViewers(wrapperPlayServerEntityEffect);
}); });
} }
} }

View file

@ -1,9 +1,7 @@
package me.tofaa.entitylib.common; package me.tofaa.entitylib.common;
import com.github.retrooper.packetevents.PacketEventsAPI; import com.github.retrooper.packetevents.PacketEventsAPI;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import me.tofaa.entitylib.APIConfig; import me.tofaa.entitylib.APIConfig;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.EntityLibAPI; import me.tofaa.entitylib.EntityLibAPI;
import me.tofaa.entitylib.Platform; import me.tofaa.entitylib.Platform;
import me.tofaa.entitylib.container.EntityContainer; import me.tofaa.entitylib.container.EntityContainer;
@ -16,8 +14,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer;
public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> { public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> {
protected final Platform<P> platform; protected final Platform<P> platform;
@ -26,25 +22,11 @@ public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> {
protected final Collection<TickContainer<?, T>> tickContainers; protected final Collection<TickContainer<?, T>> tickContainers;
protected final EntityContainer defaultEntityContainer = EntityContainer.basic(); protected final EntityContainer defaultEntityContainer = EntityContainer.basic();
protected BiConsumer<UUID, PacketWrapper<?>> packetDispatcher;
protected AbstractEntityLibAPI(Platform<P> platform, APIConfig settings) { protected AbstractEntityLibAPI(Platform<P> platform, APIConfig settings) {
this.platform = platform; this.platform = platform;
this.packetEvents = settings.getPacketEvents(); this.packetEvents = settings.getPacketEvents();
this.settings = settings; this.settings = settings;
this.tickContainers = settings.shouldTickTickables() ? new HashSet<>() : Collections.emptyList(); this.tickContainers = settings.shouldTickTickables() ? new HashSet<>() : Collections.emptyList();
this.packetDispatcher = (user, wrapper) -> {
Object channel = EntityLib.getApi().getPacketEvents().getProtocolManager().getChannel(user);
if (channel == null) {
if (EntityLib.getApi().getSettings().isDebugMode()) {
EntityLib.getPlatform().getLogger().warning("Failed to send packet to " + user + " because the channel was null. They may be disconnected/not online.");
}
return;
}
EntityLib.getApi().getPacketEvents().getProtocolManager().sendPacket(channel, wrapper);
};
} }
@Override @Override
@ -77,16 +59,6 @@ public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> {
return packetEvents; return packetEvents;
} }
@Override
public @NotNull BiConsumer<UUID, PacketWrapper<?>> getPacketDispatcher() {
return packetDispatcher;
}
@Override
public void setPacketDispatcher(@NotNull BiConsumer<UUID, PacketWrapper<?>> packetDispatcher) {
this.packetDispatcher = packetDispatcher;
}
@Override @Override
public @NotNull Collection<TickContainer<?, T>> getTickContainers() { public @NotNull Collection<TickContainer<?, T>> getTickContainers() {
return tickContainers; return tickContainers;