use of net.minecraft.server.network.ServerPlayerEntity in project LuckPerms by lucko.
the class PluginMessageMessenger method sendOutgoingMessage.
@Override
public void sendOutgoingMessage(@NonNull OutgoingMessage outgoingMessage) {
AtomicReference<SchedulerTask> taskRef = new AtomicReference<>();
SchedulerTask task = this.plugin.getBootstrap().getScheduler().asyncRepeating(() -> {
MinecraftServer server = this.plugin.getBootstrap().getServer().orElse(null);
if (server == null) {
return;
}
Collection<ServerPlayerEntity> players = server.getPlayerManager().getPlayerList();
ServerPlayerEntity p = Iterables.getFirst(players, null);
if (p == null) {
return;
}
PacketByteBuf buf = PacketByteBufs.create();
buf.writeString(outgoingMessage.asEncodedString());
ServerPlayNetworking.send(p, CHANNEL, buf);
SchedulerTask t = taskRef.getAndSet(null);
if (t != null) {
t.cancel();
}
}, 10, TimeUnit.SECONDS);
taskRef.set(task);
}
use of net.minecraft.server.network.ServerPlayerEntity in project LuckPerms by lucko.
the class FabricSenderFactory method sendMessage.
@Override
protected void sendMessage(ServerCommandSource sender, Component message) {
Locale locale = null;
if (sender.getEntity() instanceof ServerPlayerEntity) {
locale = ((MixinUser) sender.getEntity()).getCachedLocale();
}
sender.sendFeedback(toNativeText(TranslationManager.render(message, locale)), false);
}
use of net.minecraft.server.network.ServerPlayerEntity in project EnvironmentZ by Globox1997.
the class CommandInit method executeEnvCommand.
private static int executeEnvCommand(ServerCommandSource source, Collection<ServerPlayerEntity> targets, String environment, boolean affected) {
Iterator<ServerPlayerEntity> var3 = targets.iterator();
while (var3.hasNext()) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) var3.next();
if (environment.equals("hot"))
((PlayerEnvAccess) serverPlayerEntity).setHotEnvAffected(affected);
if (environment.equals("cold"))
((PlayerEnvAccess) serverPlayerEntity).setColdEnvAffected(affected);
EnvironmentServerPacket.writeS2CSyncEnvPacket(serverPlayerEntity, ((PlayerEnvAccess) serverPlayerEntity).isHotEnvAffected(), ((PlayerEnvAccess) serverPlayerEntity).isColdEnvAffected());
}
source.sendFeedback(new TranslatableText("commands.environment.changed"), true);
return targets.size();
}
use of net.minecraft.server.network.ServerPlayerEntity in project nbt-crafting by Siphalor.
the class MixinAnvilContainer method updateResult.
@Inject(method = "updateResult", at = @At("HEAD"), cancellable = true)
public void updateResult(CallbackInfo callbackInfo) {
recipe = player.world.getRecipeManager().getFirstMatch(NbtCrafting.ANVIL_RECIPE_TYPE, inventory, player.world).orElse(null);
if (recipe != null) {
ItemStack resultStack = recipe.craft(inventory);
repairItemUsage = 1;
if (userChangedName) {
if (!StringUtils.isBlank(newItemName) && !newItemName.equals(resultStack.getName().getString())) {
resultStack.setCustomName(new LiteralText(newItemName));
}
userChangedName = false;
} else {
newItemName = resultStack.getName().getString();
if (player instanceof ServerPlayerEntity) {
if (NbtCrafting.hasClientMod((ServerPlayerEntity) player)) {
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeString(newItemName);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, NbtCrafting.UPDATE_ANVIL_TEXT_S2C_PACKET_ID, packetByteBuf);
}
}
}
result.setInvStack(0, resultStack);
levelCost.set(recipe.getLevels());
sendContentUpdates();
callbackInfo.cancel();
}
}
use of net.minecraft.server.network.ServerPlayerEntity in project MCDoom by AzureDoom.
the class GunTableScreenHandler method close.
public void close(PlayerEntity player) {
super.close(player);
if (!this.playerInventory.player.world.isClient) {
if (player.isAlive() && (!(player instanceof ServerPlayerEntity) || !((ServerPlayerEntity) player).isDisconnected())) {
player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(0));
player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(1));
player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(2));
player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(3));
player.getInventory().offerOrDrop(this.gunTableInventory.removeStack(4));
} else {
ItemStack itemStack0 = this.gunTableInventory.removeStack(0);
ItemStack itemStack1 = this.gunTableInventory.removeStack(1);
ItemStack itemStack2 = this.gunTableInventory.removeStack(2);
ItemStack itemStack3 = this.gunTableInventory.removeStack(3);
ItemStack itemStack4 = this.gunTableInventory.removeStack(4);
if (!itemStack0.isEmpty()) {
player.dropItem(itemStack0, false);
}
if (!itemStack1.isEmpty()) {
player.dropItem(itemStack1, false);
}
if (!itemStack2.isEmpty()) {
player.dropItem(itemStack2, false);
}
if (!itemStack3.isEmpty()) {
player.dropItem(itemStack3, false);
}
if (!itemStack4.isEmpty()) {
player.dropItem(itemStack4, false);
}
}
}
}
Aggregations