use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method sendShowPacket.
@Override
public void sendShowPacket(Player pl, Entity entity) {
if (entity instanceof Player) {
pl.showPlayer(Denizen.getInstance(), (Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) pl;
ServerPlayer entityPlayer = craftPlayer.getHandle();
if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
entry.removePlayer(entityPlayer);
entry.updatePlayer(entityPlayer);
}
}
}
use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.
the class AdvancementHelperImpl method update.
@Override
public void update(Player player) {
ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
nmsPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(true, Collections.emptySet(), Collections.emptySet(), Collections.emptyMap()));
PlayerAdvancements data = nmsPlayer.getAdvancements();
// save progress
data.save();
// clear progress
data.reload(DedicatedServer.getServer().getAdvancements());
// load progress and update client
data.flushDirty(nmsPlayer);
}
use of net.minecraft.server.level.ServerPlayer in project Tropicraft by Tropicraft.
the class SharkEntity method tick.
@Override
public void tick() {
super.tick();
if (isBoss()) {
// Set state to boss
if (!hasSetBoss) {
setBossTraits();
}
if (!level.isClientSide) {
// Search for suitable target
Player nearest = level.getNearestPlayer(this, 64D);
if (nearest != null) {
if (hasLineOfSight(nearest) && nearest.isInWater() && !nearest.isCreative() && nearest.isAlive()) {
aggressTarget = nearest;
setTargetHeading(aggressTarget.getX(), aggressTarget.getY() + 1, aggressTarget.getZ(), true);
// Show health bar to target player
if (nearest instanceof ServerPlayer) {
if (!bossInfo.getPlayers().contains(nearest)) {
bossTargets.add((ServerPlayer) nearest);
bossInfo.addPlayer((ServerPlayer) nearest);
}
}
} else {
clearBossTargets();
}
} else {
clearBossTargets();
}
// Heal if no target
if (this.getHealth() < this.getMaxHealth() && this.tickCount % 80 == 0 && this.aggressTarget == null) {
this.heal(1f);
this.spawnAnim();
}
// Update health bar
this.bossInfo.setProgress(this.rangeMap(this.getHealth(), 0, this.getMaxHealth(), 0, 1));
}
}
}
use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.
the class HouseConfiguration method ConfigurationSpecificBuildStructure.
/**
* This is used to actually build the structure as it creates the structure instance and calls build structure.
*
* @param player The player which requested the build.
* @param world The world instance where the build will occur.
* @param hitBlockPos This hit block position.
*/
@Override
protected void ConfigurationSpecificBuildStructure(Player player, ServerLevel world, BlockPos hitBlockPos) {
boolean houseBuilt = true;
// Build the alternate starter house instead.
StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseStyle.getStructureLocation(), StructureAlternateStart.class);
houseBuilt = structure.BuildStructure(this, world, hitBlockPos, player);
// The house was successfully built, remove the item from the inventory.
if (houseBuilt) {
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
playerConfig.builtStarterHouse = true;
playerConfig.saveToPlayer(player);
this.RemoveStructureItemFromPlayer(player, ModRegistry.StartHouse.get());
// Make sure to send a message to the client to sync up the server player information and the client player
// information.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), ((ServerPlayer) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.
the class ModEventHandler method onPlayerLoginEvent.
/**
* This event occurs when a player logs in. This is used to send server configuration to the client.
*
* @param event The event object.
*/
@SubscribeEvent
public static void onPlayerLoginEvent(PlayerLoggedInEvent event) {
if (!event.getPlayer().level.isClientSide) {
CompoundTag tag = CommonProxy.proxyConfiguration.serverConfiguration.ToNBTTagCompound();
Prefab.network.sendTo(new ConfigSyncMessage(tag), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
Prefab.LOGGER.info("Sent config to '" + event.getPlayer().getDisplayName().getString() + "'.");
}
}
Aggregations