make it less static
This commit is contained in:
parent
dcd802246f
commit
c8c649e800
5 changed files with 25 additions and 13 deletions
|
@ -1,17 +1,19 @@
|
||||||
package lol.pyr.znpcsplus.packets;
|
package lol.pyr.znpcsplus.packets;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class V1_10PacketFactory extends V1_9PacketFactory {
|
public class V1_10PacketFactory extends V1_9PacketFactory {
|
||||||
public V1_10PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory) {
|
public V1_10PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI<Plugin> packetEvents) {
|
||||||
super(scheduler, metadataFactory);
|
super(scheduler, metadataFactory, packetEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package lol.pyr.znpcsplus.packets;
|
package lol.pyr.znpcsplus.packets;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
import com.github.retrooper.packetevents.util.Vector3d;
|
import com.github.retrooper.packetevents.util.Vector3d;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
|
||||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||||
|
@ -8,12 +9,13 @@ import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import lol.pyr.znpcsplus.util.ZLocation;
|
import lol.pyr.znpcsplus.util.ZLocation;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class V1_14PacketFactory extends V1_10PacketFactory {
|
public class V1_14PacketFactory extends V1_10PacketFactory {
|
||||||
public V1_14PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory) {
|
public V1_14PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI<Plugin> packetEvents) {
|
||||||
super(scheduler, metadataFactory);
|
super(scheduler, metadataFactory, packetEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package lol.pyr.znpcsplus.packets;
|
package lol.pyr.znpcsplus.packets;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||||
import com.github.retrooper.packetevents.protocol.player.GameMode;
|
import com.github.retrooper.packetevents.protocol.player.GameMode;
|
||||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||||
|
@ -11,13 +12,14 @@ import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class V1_19PacketFactory extends V1_14PacketFactory {
|
public class V1_19PacketFactory extends V1_14PacketFactory {
|
||||||
public V1_19PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory) {
|
public V1_19PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI<Plugin> packetEvents) {
|
||||||
super(scheduler, metadataFactory);
|
super(scheduler, metadataFactory, packetEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package lol.pyr.znpcsplus.packets;
|
package lol.pyr.znpcsplus.packets;
|
||||||
|
|
||||||
import com.github.retrooper.packetevents.PacketEvents;
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
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.type.EntityType;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||||
|
@ -20,6 +20,7 @@ import lol.pyr.znpcsplus.util.ZLocation;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -27,10 +28,12 @@ import java.util.concurrent.CompletableFuture;
|
||||||
public class V1_8PacketFactory implements PacketFactory {
|
public class V1_8PacketFactory implements PacketFactory {
|
||||||
protected final TaskScheduler scheduler;
|
protected final TaskScheduler scheduler;
|
||||||
protected final MetadataFactory metadataFactory;
|
protected final MetadataFactory metadataFactory;
|
||||||
|
protected final PacketEventsAPI<Plugin> packetEvents;
|
||||||
|
|
||||||
public V1_8PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory) {
|
public V1_8PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI<Plugin> packetEvents) {
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.metadataFactory = metadataFactory;
|
this.metadataFactory = metadataFactory;
|
||||||
|
this.packetEvents = packetEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +53,7 @@ public class V1_8PacketFactory implements PacketFactory {
|
||||||
public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) {
|
public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) {
|
||||||
ZLocation location = entity.getLocation();
|
ZLocation location = entity.getLocation();
|
||||||
EntityType type = entity.getType();
|
EntityType type = entity.getType();
|
||||||
ClientVersion clientVersion = PacketEvents.getAPI().getServerManager().getVersion().toClientVersion();
|
ClientVersion clientVersion = packetEvents.getServerManager().getVersion().toClientVersion();
|
||||||
sendPacket(player, type.getLegacyId(clientVersion) == -1 ?
|
sendPacket(player, type.getLegacyId(clientVersion) == -1 ?
|
||||||
new WrapperPlayServerSpawnLivingEntity(entity.getEntityId(), entity.getUuid(), type, location.toVector3d(),
|
new WrapperPlayServerSpawnLivingEntity(entity.getEntityId(), entity.getUuid(), type, location.toVector3d(),
|
||||||
location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), Collections.emptyList()) :
|
location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), Collections.emptyList()) :
|
||||||
|
@ -70,6 +73,7 @@ public class V1_8PacketFactory implements PacketFactory {
|
||||||
public void teleportEntity(Player player, PacketEntity entity) {
|
public void teleportEntity(Player player, PacketEntity entity) {
|
||||||
ZLocation location = entity.getLocation();
|
ZLocation location = entity.getLocation();
|
||||||
sendPacket(player, new WrapperPlayServerEntityTeleport(entity.getEntityId(), location.toVector3d(), location.getYaw(), location.getPitch(), true));
|
sendPacket(player, new WrapperPlayServerEntityTeleport(entity.getEntityId(), location.toVector3d(), location.getYaw(), location.getPitch(), true));
|
||||||
|
if (entity.getType() == EntityTypes.PLAYER) sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,11 +132,11 @@ public class V1_8PacketFactory implements PacketFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMetadata(Player player, PacketEntity entity, List<EntityData> data) {
|
public void sendMetadata(Player player, PacketEntity entity, List<EntityData> data) {
|
||||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), data));
|
packetEvents.getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), data));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendPacket(Player player, PacketWrapper<?> packet) {
|
protected void sendPacket(Player player, PacketWrapper<?> packet) {
|
||||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, packet);
|
packetEvents.getPlayerManager().sendPacket(player, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CompletableFuture<UserProfile> skinned(Player player, PropertyHolder properties, UserProfile profile) {
|
protected CompletableFuture<UserProfile> skinned(Player player, PropertyHolder properties, UserProfile profile) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package lol.pyr.znpcsplus.packets;
|
package lol.pyr.znpcsplus.packets;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||||
|
@ -7,12 +8,13 @@ import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class V1_9PacketFactory extends V1_8PacketFactory {
|
public class V1_9PacketFactory extends V1_8PacketFactory {
|
||||||
public V1_9PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory) {
|
public V1_9PacketFactory(TaskScheduler scheduler, MetadataFactory metadataFactory, PacketEventsAPI<Plugin> packetEvents) {
|
||||||
super(scheduler, metadataFactory);
|
super(scheduler, metadataFactory, packetEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue