Search in sources :

Example 26 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project beebuddy by queenofthebees.

the class BeeEntityMixin method tame.

@Override
protected void tame(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cbir) {
    ItemStack stack = player.getStackInHand(hand);
    boolean friend = beebuddy$getFriend().map(player.getUuid()::equals).orElse(false);
    if (!this.world.isClient) {
        if (stack.getItem() == Items.HONEY_BOTTLE) {
            if (friend && this.getHealth() < this.getMaxHealth()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                }
                this.heal(this.getMaxHealth());
                cbir.setReturnValue(ActionResult.SUCCESS);
            } else if (!friend && !beebuddy$hasFriend()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                    ItemStack g = new ItemStack(Items.GLASS_BOTTLE);
                    if (stack.isEmpty()) {
                        player.setStackInHand(hand, g);
                    } else if (!player.inventory.insertStack(g)) {
                        player.dropItem(g, false);
                    }
                }
                if (this.random.nextInt(4) == 0) {
                    beebuddy$setFriend(Optional.of(player.getUuid()));
                    if (player instanceof ServerPlayerEntity) {
                        ServerPlayerEntity p = (ServerPlayerEntity) player;
                        Criteria.TAME_ANIMAL.trigger(p, (BeeEntity) (Object) this);
                    }
                    beebuddy$friendify();
                    this.world.sendEntityStatus(this, (byte) 7);
                } else {
                    this.world.sendEntityStatus(this, (byte) 6);
                }
                cbir.setReturnValue(ActionResult.SUCCESS);
            }
        } else if (stack.getItem() instanceof NectarItem) {
            NectarItem n = (NectarItem) stack.getItem();
            if (friend || !beebuddy$hasFriend()) {
                if (!player.abilities.creativeMode) {
                    stack.decrement(1);
                }
                beebuddy$setNectarType(n.getType());
                cbir.setReturnValue(ActionResult.SUCCESS);
            }
        } else {
            beebuddy$setSitting(!beebuddy$isSitting());
            cbir.setReturnValue(ActionResult.SUCCESS);
        }
    } else if (friend || stack.getItem() == Items.HONEY_BOTTLE) {
        cbir.setReturnValue(ActionResult.CONSUME);
    } else if (stack.getItem() instanceof NectarItem) {
        cbir.setReturnValue(ActionResult.CONSUME);
    }
}
Also used : BeeEntity(net.minecraft.entity.passive.BeeEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) NectarItem(nomble.beebuddy.item.NectarItem) ItemStack(net.minecraft.item.ItemStack)

Example 27 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project fabric by FabricMC.

the class MixinServerPlayerEntity method onPlayerInteractEntity.

@Inject(method = "attack", at = @At("HEAD"), cancellable = true)
public void onPlayerInteractEntity(Entity target, CallbackInfo info) {
    ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
    ActionResult result = AttackEntityCallback.EVENT.invoker().interact(player, player.getEntityWorld(), Hand.MAIN_HAND, target, null);
    if (result != ActionResult.PASS) {
        info.cancel();
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project Plan by plan-player-analytics.

the class ChatListener method actOnChatEvent.

private void actOnChatEvent(ServerPlayNetworkHandler handler) {
    long time = System.currentTimeMillis();
    ServerPlayerEntity player = handler.player;
    UUID uuid = player.getUuid();
    String displayName = player.getDisplayName().asString();
    dbSystem.getDatabase().executeTransaction(new NicknameStoreTransaction(uuid, new Nickname(displayName, time, serverInfo.getServerUUID()), (playerUUID, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
}
Also used : NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) ServerInfo(com.djrapitops.plan.identification.ServerInfo) FabricListener(net.playeranalytics.plan.gathering.listeners.FabricListener) UUID(java.util.UUID) PlanFabricEvents(net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Nickname(com.djrapitops.plan.delivery.domain.Nickname) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) NicknameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.NicknameStoreTransaction) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 29 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project Plan by plan-player-analytics.

the class PlayerOnlineListener method register.

@Override
public void register() {
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        if (!this.isEnabled) {
            return;
        }
        onPlayerJoin(handler.player);
    });
    ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
        if (!this.isEnabled) {
            return;
        }
        onPlayerQuit(handler.player);
    });
    PlanFabricEvents.ON_KICKED.register((source, targets, reason) -> {
        if (!this.isEnabled) {
            return;
        }
        for (ServerPlayerEntity target : targets) {
            onPlayerKick(target);
        }
    });
    PlanFabricEvents.ON_LOGIN.register((address, profile, reason) -> {
        if (!this.isEnabled) {
            return;
        }
        onPlayerLogin(address, profile, reason != null);
    });
    this.enable();
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 30 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project Plan by plan-player-analytics.

the class PlayerOnlineListener method actOnJoinEvent.

private void actOnJoinEvent(ServerPlayerEntity player) {
    UUID playerUUID = player.getUuid();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    FabricAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getServerWorld().getRegistryKey().getValue().toString();
    String gm = player.interactionManager.getGameMode().name();
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetSocketAddress socketAddress = (InetSocketAddress) player.networkHandler.connection.getAddress();
    InetAddress address = InetAddresses.forString(socketAddress.getAddress().toString().replace("/", ""));
    Supplier<String> getHostName = () -> getHostname(player);
    String playerName = player.getEntityName();
    String displayName = player.getDisplayName().asString();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName));
    database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, server.getPlayerManager().getOpList().isOp(player.getGameProfile())));
    ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
    session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
    session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
    sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
    database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
Also used : PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) SocketAddress(java.net.SocketAddress) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) GameProfile(com.mojang.authlib.GameProfile) FabricListener(net.playeranalytics.plan.gathering.listeners.FabricListener) DataGatheringSettings(com.djrapitops.plan.settings.config.paths.DataGatheringSettings) HashMap(java.util.HashMap) MinecraftDedicatedServer(net.minecraft.server.dedicated.MinecraftDedicatedServer) Supplier(java.util.function.Supplier) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) Map(java.util.Map) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) ServerName(com.djrapitops.plan.delivery.domain.ServerName) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) UUID(java.util.UUID) PlanFabricEvents(net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents) InetSocketAddress(java.net.InetSocketAddress) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) CallEvents(com.djrapitops.plan.extension.CallEvents) Processing(com.djrapitops.plan.processing.Processing) InetAddresses(com.google.common.net.InetAddresses) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) ServerUUID(com.djrapitops.plan.identification.ServerUUID) InetSocketAddress(java.net.InetSocketAddress) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerName(com.djrapitops.plan.delivery.domain.ServerName) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Aggregations

ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)169 LiteralText (net.minecraft.text.LiteralText)51 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)32 ItemStack (net.minecraft.item.ItemStack)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Entity (net.minecraft.entity.Entity)15 UUID (java.util.UUID)14 LivingEntity (net.minecraft.entity.LivingEntity)14 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)12 TranslatableText (net.minecraft.text.TranslatableText)12 Inject (org.spongepowered.asm.mixin.injection.Inject)12 ServerWorld (net.minecraft.server.world.ServerWorld)11 PacketByteBuf (net.minecraft.network.PacketByteBuf)10 GameProfile (com.mojang.authlib.GameProfile)9 Formatting (net.minecraft.util.Formatting)9 BlockPos (net.minecraft.util.math.BlockPos)9 ArrayList (java.util.ArrayList)8 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 Collectors (java.util.stream.Collectors)6 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)6