fix: errors
This commit is contained in:
parent
b5481f783d
commit
1fc7a00ec7
7 changed files with 33 additions and 62 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() + ".");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue