mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 12:29:16 +00:00
feat: entity cooldown teleportation packet option
This commit is contained in:
@@ -39,6 +39,7 @@ public class Settings {
|
||||
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
|
||||
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
|
||||
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
|
||||
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
|
||||
@@ -107,6 +108,8 @@ public class Settings {
|
||||
@Getter
|
||||
private static int tickPeriod;
|
||||
@Getter
|
||||
private static int packetEntityTeleportCooldown;
|
||||
@Getter
|
||||
private static double emoteDistance;
|
||||
@Getter
|
||||
private static Vector balloonOffset;
|
||||
@@ -173,6 +176,7 @@ public class Settings {
|
||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
||||
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
|
||||
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
|
||||
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
|
||||
|
||||
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
||||
|
||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw());
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
|
||||
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
@@ -20,7 +21,9 @@ public class UserEntity {
|
||||
@Getter
|
||||
private List<Player> viewers = new ArrayList<>();
|
||||
@Getter @Setter
|
||||
private Long lastUpdate = 0L;
|
||||
private Long viewerLastUpdate = 0L;
|
||||
@Getter @Setter
|
||||
private Long lastPositionUpdate = 0L;
|
||||
@Getter @Setter
|
||||
private List<Integer> ids = new ArrayList<>();
|
||||
@Getter
|
||||
@@ -35,7 +38,7 @@ public class UserEntity {
|
||||
}
|
||||
|
||||
public List<Player> refreshViewers(Location location) {
|
||||
if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes
|
||||
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
|
||||
ArrayList<Player> newPlayers = new ArrayList<>();
|
||||
ArrayList<Player> removePlayers = new ArrayList<>();
|
||||
List<Player> players = PlayerUtils.getNearbyPlayers(location);
|
||||
@@ -61,20 +64,33 @@ public class UserEntity {
|
||||
}
|
||||
}
|
||||
viewers.removeAll(removePlayers);
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
setViewerLastUpdate(System.currentTimeMillis());
|
||||
return newPlayers;
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
||||
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
||||
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
||||
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
}
|
||||
this.location = location;
|
||||
for (Integer entity : ids) {
|
||||
PacketManager.sendTeleportPacket(entity, location, false, getViewers());
|
||||
}
|
||||
setLastPositionUpdate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void setRotation(int yaw) {
|
||||
setRotation(yaw, false);
|
||||
}
|
||||
|
||||
public void setRotation(int yaw, boolean additonalPacket) {
|
||||
location.setYaw(yaw);
|
||||
for (Integer entity : ids) {
|
||||
// First person backpacks need both packets to rotate properly, otherwise they look off
|
||||
// Regular backpacks just need the look packet
|
||||
if (additonalPacket) PacketManager.sendRotationPacket(entity, yaw, false, getViewers());
|
||||
PacketManager.sendLookPacket(entity, location, getViewers());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user