add player implementation

This commit is contained in:
Tofaa 2024-02-06 13:20:15 +04:00
parent 5130a65a0f
commit e2ca79b069
5 changed files with 98 additions and 16 deletions

View file

@ -5,13 +5,11 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment=""> <list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/utils/Check.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperPlayer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/ExtraConversionUtil.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperExperienceOrbEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperExperienceOrbEntity.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotWorld.java" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotWorld.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -296,6 +294,7 @@
<workItem from="1706784821835" duration="7882000" /> <workItem from="1706784821835" duration="7882000" />
<workItem from="1706858181164" duration="925000" /> <workItem from="1706858181164" duration="925000" />
<workItem from="1707159905372" duration="3391000" /> <workItem from="1707159905372" duration="3391000" />
<workItem from="1707210065718" duration="1026000" />
</task> </task>
<servers /> <servers />
</component> </component>

View file

@ -28,12 +28,12 @@ public class WrapperEntity implements Tickable {
private boolean ticking; private boolean ticking;
private Location location; private Location location;
private Location preRidingLocation; private Location preRidingLocation;
private Set<UUID> viewers; private final Set<UUID> viewers;
private boolean onGround; private boolean onGround;
private boolean spawned; private boolean spawned;
private Vector3d velocity; private Vector3d velocity;
private int riding = -1; private int riding = -1;
private Set<Integer> passengers = new HashSet<>(); private final Set<Integer> passengers;
private WorldWrapper<?> world; private WorldWrapper<?> world;
public WrapperEntity(int entityId, UUID uuid, EntityType entityType, EntityMeta entityMeta) { public WrapperEntity(int entityId, UUID uuid, EntityType entityType, EntityMeta entityMeta) {
@ -43,10 +43,7 @@ public class WrapperEntity implements Tickable {
this.entityMeta = entityMeta; this.entityMeta = entityMeta;
this.ticking = true; this.ticking = true;
this.viewers = new HashSet<>(); this.viewers = new HashSet<>();
} this.passengers = new HashSet<>();
public boolean spawn(Location location) {
return spawn(null, location);
} }
public boolean spawn(WorldWrapper<?> world, Location location) { public boolean spawn(WorldWrapper<?> world, Location location) {
@ -125,10 +122,6 @@ public class WrapperEntity implements Tickable {
teleport(null, location, onGround); teleport(null, location, onGround);
} }
public void teleport(@NotNull Location location) {
teleport(null, location, onGround);
}
/** /**
* Adds a viewer to the viewers set. The viewer will receive all packets and be informed of this addition * Adds a viewer to the viewers set. The viewer will receive all packets and be informed of this addition
* @param uuid the uuid of the user to add * @param uuid the uuid of the user to add

View file

@ -25,7 +25,9 @@ public class WrapperExperienceOrbEntity extends WrapperEntity {
* This is an attempt to mimmick the vanilla behavior. * This is an attempt to mimmick the vanilla behavior.
* </p> * </p>
*/ */
public void updateSliding() { @Override
public void tick(long time) {
super.tick(time);
if (hasNoGravity()) { if (hasNoGravity()) {
setVelocity(getVelocity().add(0, -0.3f, 0)); setVelocity(getVelocity().add(0, -0.3f, 0));
} }

View file

@ -0,0 +1,82 @@
package me.tofaa.entitylib.wrapper;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.player.*;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfo;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate;
import me.tofaa.entitylib.meta.EntityMeta;
import net.kyori.adventure.text.Component;
import java.util.List;
public class WrapperPlayer extends WrapperLivingEntity {
private final UserProfile profile;
private GameMode gameMode = GameMode.CREATIVE;
private Component displayName;
public WrapperPlayer(UserProfile profile, int entityId, EntityType entityType, EntityMeta entityMeta) {
super(entityId, profile.getUUID(), entityType, entityMeta);
this.profile = profile;
}
public void setGameMode(GameMode gameMode) {
this.gameMode = gameMode;
sendPacketsToViewers(new WrapperPlayServerPlayerInfo(
WrapperPlayServerPlayerInfo.Action.UPDATE_GAME_MODE,
new WrapperPlayServerPlayerInfo.PlayerData(displayName, profile, gameMode, null, -1)));
}
public void setDisplayName(Component displayName) {
this.displayName = displayName;
sendPacketsToViewers(new WrapperPlayServerPlayerInfo(
WrapperPlayServerPlayerInfo.Action.UPDATE_DISPLAY_NAME,
new WrapperPlayServerPlayerInfo.PlayerData(displayName, profile, gameMode, null, -1)));
}
public Component getDisplayName() {
return displayName;
}
public String getUsername() {
return profile.getName();
}
public List<TextureProperty> getTextureProperties() {
return profile.getTextureProperties();
}
public GameMode getGameMode() {
return gameMode;
}
@Override
public void addViewer(User user) {
super.addViewer(user);
user.sendPacket(createAddPacket());
}
@Override
public void removeViewer(User user) {
super.removeViewer(user);
user.sendPacket(createRemovePacket());
}
private WrapperPlayServerPlayerInfoUpdate createAddPacket() {
return new WrapperPlayServerPlayerInfoUpdate(
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
new WrapperPlayServerPlayerInfoUpdate.PlayerInfo(
profile,
true, -1, gameMode, null, null
)
);
}
private WrapperPlayServerPlayerInfoRemove createRemovePacket() {
return new WrapperPlayServerPlayerInfoRemove(getUuid());
}
}

View file

@ -6,8 +6,11 @@ import com.github.retrooper.packetevents.protocol.world.Location;
import me.tofaa.entitylib.EntityLib; import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.WorldWrapper; import me.tofaa.entitylib.WorldWrapper;
import me.tofaa.entitylib.meta.EntityMeta; import me.tofaa.entitylib.meta.EntityMeta;
import me.tofaa.entitylib.meta.projectile.ThrownExpBottleMeta;
import me.tofaa.entitylib.meta.types.LivingEntityMeta; import me.tofaa.entitylib.meta.types.LivingEntityMeta;
import me.tofaa.entitylib.meta.types.PlayerMeta;
import me.tofaa.entitylib.wrapper.WrapperEntity; import me.tofaa.entitylib.wrapper.WrapperEntity;
import me.tofaa.entitylib.wrapper.WrapperExperienceOrbEntity;
import me.tofaa.entitylib.wrapper.WrapperLivingEntity; import me.tofaa.entitylib.wrapper.WrapperLivingEntity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -65,6 +68,9 @@ public abstract class AbstractWorldWrapper<W> implements WorldWrapper<W> {
if (meta instanceof LivingEntityMeta) { if (meta instanceof LivingEntityMeta) {
e = new WrapperLivingEntity(entityId, uuid, entityType, meta); e = new WrapperLivingEntity(entityId, uuid, entityType, meta);
} }
else if (meta instanceof ThrownExpBottleMeta) {
e = new WrapperExperienceOrbEntity(entityId, uuid, entityType, meta);
}
else { else {
e = new WrapperEntity(entityId, uuid, entityType, meta); e = new WrapperEntity(entityId, uuid, entityType, meta);
} }