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);
}
}
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();
}
}
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)));
}
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();
}
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));
}
}
Aggregations