use of net.minecraft.server.network.ServerPlayerEntity in project dynmap by webbukkit.
the class FabricServer method getOnlinePlayers.
@Override
public DynmapPlayer[] getOnlinePlayers() {
if (server.getPlayerManager() == null)
return new DynmapPlayer[0];
List<ServerPlayerEntity> players = server.getPlayerManager().getPlayerList();
int playerCount = players.size();
DynmapPlayer[] dplay = new DynmapPlayer[players.size()];
for (int i = 0; i < playerCount; i++) {
ServerPlayerEntity player = players.get(i);
dplay[i] = plugin.getOrAddPlayer(player);
}
return dplay;
}
use of net.minecraft.server.network.ServerPlayerEntity in project dynmap by webbukkit.
the class FabricPlayer method sendTitleText.
/**
* Send title and subtitle text (called from server thread)
*/
@Override
public void sendTitleText(String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
if (player != null) {
ServerPlayerEntity player = this.player;
TitleFadeS2CPacket times = new TitleFadeS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
player.networkHandler.sendPacket(times);
if (title != null) {
TitleS2CPacket titlepkt = new TitleS2CPacket(new LiteralText(title));
player.networkHandler.sendPacket(titlepkt);
}
if (subtitle != null) {
SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(new LiteralText(subtitle));
player.networkHandler.sendPacket(subtitlepkt);
}
}
}
use of net.minecraft.server.network.ServerPlayerEntity in project BlockMeter by ModProg.
the class BlockMeterServer method buildS2CPacket.
/**
* Builds a S2CPacket containing the BoxList
*
* @return S2CPacket containing the BoxList
*/
private PacketByteBuf buildS2CPacket() {
PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
synchronized (playerBoxes) {
data.writeInt(playerBoxes.size());
Set<Map.Entry<UUID, List<MeasureBox>>> knownPlayers = playerBoxes.entrySet();
for (Map.Entry<UUID, List<MeasureBox>> playerBoxEntry : knownPlayers) {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(playerBoxEntry.getKey());
data.writeText(player.getDisplayName());
data.writeInt(playerBoxEntry.getValue().size());
for (int i = 0; i < playerBoxEntry.getValue().size(); i++) {
playerBoxEntry.getValue().get(i).writePacketBuf(data);
}
}
}
return data;
}
use of net.minecraft.server.network.ServerPlayerEntity in project FabricWaystones by LordDeatHunter.
the class WaystonesEventManager method registerEvents.
public static void registerEvents() {
ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
if (Waystones.WAYSTONE_STORAGE == null) {
Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
}
});
ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
Waystones.WAYSTONE_STORAGE = null;
});
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(Config.getInstance().toNbtCompound());
ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
});
ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
Config.getInstance().loadConfig();
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(Config.getInstance().toNbtCompound());
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
}
ServerPlayerEntity player = context.getSource().getPlayer();
if (player != null) {
player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
}
return 1;
})).then(CommandManager.literal("display").executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
if (player == null) {
return 1;
}
Config.getInstance().print(player);
return 1;
}))));
}
use of net.minecraft.server.network.ServerPlayerEntity in project FallingAttackFabric by hamusuke0323.
the class FallingAttackShockWave method damage.
private void damage(Entity target, float damageModifier) {
if (target.isAttackable()) {
if (!target.handleAttack(this.owner)) {
float damageAmount = (float) this.owner.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
float attackDamage;
if (target instanceof LivingEntity) {
attackDamage = EnchantmentHelper.getAttackDamage(this.sword, ((LivingEntity) target).getGroup());
} else {
attackDamage = EnchantmentHelper.getAttackDamage(this.sword, EntityGroup.DEFAULT);
}
if (damageAmount > 0.0F || attackDamage > 0.0F) {
float distanceToTarget = (float) this.pos.distanceTo(target.getPos());
int fallingAttackLevel = EnchantmentHelper.getLevel(FallingAttack.SHARPNESS_OF_FALLING_ATTACK, this.sword) + 1;
fallingAttackLevel = MathHelper.clamp(fallingAttackLevel, 1, 255);
attackDamage += this.fallingAttackDamageComputer.apply(distanceToTarget, fallingAttackLevel);
this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.owner.getSoundCategory(), 1.0F, 1.0F);
boolean bl3 = !this.owner.isClimbing() && !this.owner.isTouchingWater() && !this.owner.hasStatusEffect(StatusEffects.BLINDNESS) && !this.owner.hasVehicle() && target instanceof LivingEntity;
if (bl3) {
damageAmount *= 1.5F;
}
damageAmount += attackDamage;
float targetHealth = 0.0F;
boolean fireAspectEnchanted = false;
int fireAspectLevel = EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, this.sword);
if (target instanceof LivingEntity) {
targetHealth = ((LivingEntity) target).getHealth();
if (fireAspectLevel > 0 && !target.isOnFire()) {
fireAspectEnchanted = true;
target.setOnFireFor(1);
}
}
Vec3d vec3d = target.getVelocity();
boolean tookDamage = target.damage(DamageSource.player(this.owner), damageAmount * damageModifier);
if (tookDamage) {
float yaw = (float) -MathHelper.atan2(target.getX() - this.pos.getX(), target.getZ() - this.pos.getZ());
float strength = this.knockbackStrengthComputer.apply(distanceToTarget, fallingAttackLevel);
if (target instanceof LivingEntity) {
((LivingEntity) target).takeKnockback(strength, MathHelper.sin(yaw), -MathHelper.cos(yaw));
} else {
target.addVelocity(-MathHelper.sin(yaw) * strength, 0.1D, MathHelper.cos(yaw) * strength);
}
this.owner.setVelocity(this.owner.getVelocity().multiply(0.6D, 1.0D, 0.6D));
this.owner.setSprinting(false);
if (target instanceof ServerPlayerEntity && target.velocityModified) {
((ServerPlayerEntity) target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
target.velocityModified = false;
target.setVelocity(vec3d);
}
if (bl3) {
this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.owner.getSoundCategory(), 1.0F, 1.0F);
this.owner.addCritParticles(target);
}
if (attackDamage > 0.0F) {
this.owner.addEnchantedHitParticles(target);
}
this.owner.onAttacking(target);
if (target instanceof LivingEntity) {
float n = targetHealth - ((LivingEntity) target).getHealth();
this.owner.increaseStat(Stats.DAMAGE_DEALT, Math.round(n * 10.0F));
if (fireAspectLevel > 0) {
target.setOnFireFor(fireAspectLevel * 4);
}
if (n > 2.0F) {
int o = (int) ((double) n * 0.5D);
this.world.spawnParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getBodyY(0.5D), target.getZ(), o, 0.1D, 0.0D, 0.1D, 0.2D);
}
}
} else {
this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.owner.getSoundCategory(), 1.0F, 1.0F);
if (fireAspectEnchanted) {
target.extinguish();
}
}
}
}
}
}
Aggregations