Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ public static DynamicEntity create(String entityID, LivingEntity livingEntity) {
DynamicEntity dynamicEntity = new DynamicEntity(entityID, livingEntity.getLocation());
dynamicEntity.spawn(livingEntity);
livingEntity.setVisibleByDefault(false);
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, livingEntity);
}
});
// Must run on main thread
if (Bukkit.isPrimaryThread()) {
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, livingEntity);
}
});
} else {
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, livingEntity);
}
});
});
}

livingEntity.getPersistentDataContainer().set(namespacedKey, PersistentDataType.BYTE, (byte) 0);
return dynamicEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,34 @@ public boolean isChunkLoaded() {

public void showUnderlyingEntity(Player player) {
if (underlyingEntity == null || !underlyingEntity.isValid()) return;
player.showEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(true);
// Must run on main thread
if (Bukkit.isPrimaryThread()) {
player.showEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(true);
} else {
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
if (underlyingEntity != null && underlyingEntity.isValid() && player.isOnline()) {
player.showEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(true);
}
});
}
}

public void hideUnderlyingEntity(Player player) {
if (underlyingEntity == null || !underlyingEntity.isValid()) return;
player.hideEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(false);
// Must run on main thread
if (Bukkit.isPrimaryThread()) {
player.hideEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(false);
} else {
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
if (underlyingEntity != null && underlyingEntity.isValid() && player.isOnline()) {
player.hideEntity(MetadataHandler.PLUGIN, underlyingEntity);
underlyingEntity.setGlowing(false);
}
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ public static PlayerDisguiseEntity create(String entityID, Player targetPlayer)
PlayerDisguiseEntity dynamicEntity = new PlayerDisguiseEntity(entityID, targetPlayer.getLocation());
dynamicEntity.spawn(targetPlayer);
targetPlayer.setVisibleByDefault(false);
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, targetPlayer);
}
});
// Must run on main thread
if (Bukkit.isPrimaryThread()) {
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, targetPlayer);
}
});
} else {
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
Bukkit.getOnlinePlayers().forEach(player -> {
if (player.getLocation().getWorld().equals(dynamicEntity.getLocation().getWorld())) {
player.hideEntity(MetadataHandler.PLUGIN, targetPlayer);
}
});
});
}
targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
return dynamicEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,33 @@ private boolean isPointVisibleRecursive(Location eyeLocation, Vector targetPoint

private void displayTo(Player player) {
boolean isBedrock = BedrockChecker.isBedrock(player);
if (isBedrock && !DefaultConfig.sendCustomModelsToBedrockClients && skeleton.getModeledEntity().getUnderlyingEntity() != null)
player.showEntity(MetadataHandler.PLUGIN, skeleton.getModeledEntity().getUnderlyingEntity());
if (isBedrock && !DefaultConfig.sendCustomModelsToBedrockClients && skeleton.getModeledEntity().getUnderlyingEntity() != null) {
// Must run on main thread
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
if (player.isOnline() && player.isValid()) {
player.showEntity(MetadataHandler.PLUGIN, skeleton.getModeledEntity().getUnderlyingEntity());
}
});
}
viewers.add(player.getUniqueId());
skeleton.getBones().forEach(bone -> bone.displayTo(player));
if (skeleton.getModeledEntity() instanceof PropEntity propEntity)
propEntity.showFakePropBlocksToPlayer(player);
}

private void hideFrom(UUID uuid) {
boolean isBedrock = BedrockChecker.isBedrock(Bukkit.getPlayer(uuid));
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isValid()) return;
if (isBedrock && !DefaultConfig.sendCustomModelsToBedrockClients && skeleton.getModeledEntity().getUnderlyingEntity() != null)
player.hideEntity(MetadataHandler.PLUGIN, skeleton.getModeledEntity().getUnderlyingEntity());

boolean isBedrock = BedrockChecker.isBedrock(player);
if (isBedrock && !DefaultConfig.sendCustomModelsToBedrockClients && skeleton.getModeledEntity().getUnderlyingEntity() != null) {
// Must run on main thread
Bukkit.getScheduler().runTask(MetadataHandler.PLUGIN, () -> {
if (player.isOnline() && player.isValid()) {
player.hideEntity(MetadataHandler.PLUGIN, skeleton.getModeledEntity().getUnderlyingEntity());
}
});
}
viewers.remove(uuid);
skeleton.getBones().forEach(bone -> bone.hideFrom(uuid));
if (skeleton.getModeledEntity() instanceof PropEntity propEntity)
Expand Down