From 0ac21d429aad399ef125582fb3d343471158da89 Mon Sep 17 00:00:00 2001 From: twoone3 <3197653242@qq.com> Date: Fri, 29 Jul 2022 16:14:43 +0800 Subject: [PATCH] =?UTF-8?q?2.0.7=E6=9B=B4=E6=96=B0=20-=20=E6=A0=B8?= =?UTF-8?q?=E5=AF=B9=E6=A0=A1=E5=87=86=E4=BA=86EventAPI.cpp=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E4=BA=8B=E4=BB=B6=E9=A1=BA=E5=BA=8F=20-=20=E8=A1=A5?= =?UTF-8?q?=E4=B8=8A=E4=BA=86onServerStarted=EF=BC=8ConPlayerCmd=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API/EventAPI.cpp | 573 ++++++++++++++++++++++------------------------- API/EventAPI.h | 136 ++++++----- API/McAPI.h | 14 ++ Init.cpp | 4 +- 4 files changed, 352 insertions(+), 375 deletions(-) diff --git a/API/EventAPI.cpp b/API/EventAPI.cpp index 157d26f..ad5e97b0d 100644 --- a/API/EventAPI.cpp +++ b/API/EventAPI.cpp @@ -64,18 +64,17 @@ class Callbacker { void EnableEventListener(EventCode event_code) { using namespace Event; - switch (event_code) { +#pragma region Player Events case EventCode::onJoin: - Event::PlayerJoinEvent::subscribe([](const PlayerJoinEvent& ev) { + PlayerJoinEvent::subscribe([](const PlayerJoinEvent& ev) { EVENT_BEGIN(EventCode::onJoin); EVENT_INSERT(Player); EVENT_END; }); break; - case EventCode::onPreJoin: - Event::PlayerPreJoinEvent::subscribe([](const PlayerPreJoinEvent& ev) { + PlayerPreJoinEvent::subscribe([](const PlayerPreJoinEvent& ev) { EVENT_BEGIN(EventCode::onPreJoin); EVENT_INSERT(IP); EVENT_INSERT(Player); @@ -83,44 +82,80 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - case EventCode::onLeft: - Event::PlayerLeftEvent::subscribe([](const PlayerLeftEvent& ev) { + PlayerLeftEvent::subscribe([](const PlayerLeftEvent& ev) { EVENT_BEGIN(EventCode::onLeft); EVENT_INSERT(Player); EVENT_END; }); break; - + case EventCode::onRespawn: + PlayerRespawnEvent::subscribe([](const PlayerRespawnEvent& ev) { + EVENT_BEGIN(EventCode::onRespawn); + EVENT_INSERT(Player); + EVENT_END; + }); + break; + case EventCode::onPlayerDie: + PlayerDieEvent::subscribe([](const PlayerDieEvent& ev) { + EVENT_BEGIN(EventCode::onPlayerDie); + EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); + EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); + EVENT_INSERT(Player); + EVENT_END; + }); + break; + case EventCode::onPlayerCmd: + PlayerCmdEvent::subscribe([](const PlayerCmdEvent& ev) { + EVENT_BEGIN(EventCode::onPlayerCmd); + EVENT_INSERT(Player); + EVENT_INSERT(Command); + EVENT_INSERT_EX("isSuccess", ev.mResult->isSuccess()); + EVENT_INSERT_EX("FullCode", ev.mResult->getFullCode()); + EVENT_END; + }); + break; case EventCode::onChat: - Event::PlayerChatEvent::subscribe([](const PlayerChatEvent& ev) { + PlayerChatEvent::subscribe([](const PlayerChatEvent& ev) { EVENT_BEGIN(EventCode::onChat); EVENT_INSERT(Player); EVENT_INSERT(Message); EVENT_END; }); break; - case EventCode::onChangeDim: - Event::PlayerChangeDimEvent::subscribe([](const PlayerChangeDimEvent& ev) { + PlayerChangeDimEvent::subscribe([](const PlayerChangeDimEvent& ev) { EVENT_BEGIN(EventCode::onChangeDim); EVENT_INSERT(Player); EVENT_INSERT(ToDimensionId); EVENT_END; }); break; - + case EventCode::onJump: + PlayerJumpEvent::subscribe([](const PlayerJumpEvent& ev) { + EVENT_BEGIN(EventCode::onJump); + EVENT_INSERT(Player); + EVENT_END; + }); + break; + case EventCode::onSneak: + PlayerSneakEvent::subscribe([](const PlayerSneakEvent& ev) { + EVENT_BEGIN(EventCode::onSneak); + EVENT_INSERT(Player); + EVENT_INSERT(IsSneaking); + EVENT_END; + }); + break; case EventCode::onAttackEntity: - Event::PlayerAttackEvent::subscribe([](const PlayerAttackEvent& ev) { + PlayerAttackEvent::subscribe([](const PlayerAttackEvent& ev) { EVENT_BEGIN(EventCode::onAttackEntity); EVENT_INSERT(Player); EVENT_INSERT(Target); EVENT_END; }); break; - case EventCode::onAttackBlock: - Event::PlayerAttackBlockEvent::subscribe([](const PlayerAttackBlockEvent& ev) { + PlayerAttackBlockEvent::subscribe([](const PlayerAttackBlockEvent& ev) { EVENT_BEGIN(EventCode::onAttackBlock); EVENT_INSERT(BlockInstance); EVENT_INSERT(ItemStack); @@ -128,90 +163,91 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - - case EventCode::onPlayerDie: - Event::PlayerDieEvent::subscribe([](const PlayerDieEvent& ev) { - EVENT_BEGIN(EventCode::onPlayerDie); - EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); - EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); + case EventCode::onUseItem: + PlayerUseItemEvent::subscribe([](const PlayerUseItemEvent& ev) { + EVENT_BEGIN(EventCode::onUseItem); EVENT_INSERT(Player); + EVENT_INSERT(ItemStack); EVENT_END; }); break; - - case EventCode::onRespawn: - Event::PlayerRespawnEvent::subscribe([](const PlayerRespawnEvent& ev) { - EVENT_BEGIN(EventCode::onRespawn); + case EventCode::onUseItemOn: + PlayerUseItemOnEvent::subscribe([](const PlayerUseItemOnEvent& ev) { + EVENT_BEGIN(EventCode::onUseItemOn); EVENT_INSERT(Player); + EVENT_INSERT(ItemStack); + EVENT_INSERT(BlockInstance); + EVENT_INSERT(Face); EVENT_END; }); break; - - case EventCode::onStartDestroyBlock: - Event::PlayerStartDestroyBlockEvent::subscribe([](const PlayerStartDestroyBlockEvent& ev) { - EVENT_BEGIN(EventCode::onStartDestroyBlock); + case EventCode::onTakeItem: + PlayerPickupItemEvent::subscribe([](const PlayerPickupItemEvent& ev) { + EVENT_BEGIN(EventCode::onTakeItem); EVENT_INSERT(Player); - EVENT_INSERT(BlockInstance); + EVENT_INSERT(ItemEntity); + EVENT_INSERT(ItemStack); EVENT_END; }); break; - - case EventCode::onDestroyBlock: - Event::PlayerDestroyBlockEvent::subscribe([](const PlayerDestroyBlockEvent& ev) { - EVENT_BEGIN(EventCode::onDestroyBlock); + case EventCode::onDropItem: + PlayerDropItemEvent::subscribe([](const PlayerDropItemEvent& ev) { + EVENT_BEGIN(EventCode::onDropItem); EVENT_INSERT(Player); - EVENT_INSERT(BlockInstance); + EVENT_INSERT(ItemStack); EVENT_END; }); break; - - case EventCode::onPlaceBlock: - Event::PlayerPlaceBlockEvent::subscribe([](const PlayerPlaceBlockEvent& ev) { - EVENT_BEGIN(EventCode::onPlaceBlock); + case EventCode::onEat: + PlayerEatEvent::subscribe([](const PlayerEatEvent& ev) { + EVENT_BEGIN(EventCode::onEat); EVENT_INSERT(Player); - EVENT_INSERT(BlockInstance); + EVENT_INSERT(FoodItem); EVENT_END; }); break; - - case EventCode::onMove: - Event::PlayerMoveEvent::subscribe([](const PlayerMoveEvent& ev) { - EVENT_BEGIN(EventCode::onMove); + case EventCode::onConsumeTotem: + PlayerConsumeTotemEvent::subscribe([](const PlayerConsumeTotemEvent& ev) { + EVENT_BEGIN(EventCode::onConsumeTotem); EVENT_INSERT(Player); - EVENT_INSERT(Pos); EVENT_END; }); break; - - case EventCode::onJump: - Event::PlayerJumpEvent::subscribe([](const PlayerJumpEvent& ev) { - EVENT_BEGIN(EventCode::onJump); + case EventCode::onEffectChanged: + PlayerEffectChangedEvent::subscribe([](const PlayerEffectChangedEvent& ev) { + EVENT_BEGIN(EventCode::onEffectChanged); EVENT_INSERT(Player); + EVENT_INSERT(Effect); + EVENT_INSERT(EventType); EVENT_END; }); break; - - case EventCode::onDropItem: - Event::PlayerDropItemEvent::subscribe([](const PlayerDropItemEvent& ev) { - EVENT_BEGIN(EventCode::onDropItem); + case EventCode::onStartDestroyBlock: + PlayerStartDestroyBlockEvent::subscribe([](const PlayerStartDestroyBlockEvent& ev) { + EVENT_BEGIN(EventCode::onStartDestroyBlock); EVENT_INSERT(Player); - EVENT_INSERT(ItemStack); + EVENT_INSERT(BlockInstance); EVENT_END; }); break; - - case EventCode::onTakeItem: - Event::PlayerPickupItemEvent::subscribe([](const PlayerPickupItemEvent& ev) { - EVENT_BEGIN(EventCode::onTakeItem); + case EventCode::onDestroyBlock: + PlayerDestroyBlockEvent::subscribe([](const PlayerDestroyBlockEvent& ev) { + EVENT_BEGIN(EventCode::onDestroyBlock); EVENT_INSERT(Player); - EVENT_INSERT(ItemEntity); - EVENT_INSERT(ItemStack); + EVENT_INSERT(BlockInstance); + EVENT_END; + }); + break; + case EventCode::onPlaceBlock: + PlayerPlaceBlockEvent::subscribe([](const PlayerPlaceBlockEvent& ev) { + EVENT_BEGIN(EventCode::onPlaceBlock); + EVENT_INSERT(Player); + EVENT_INSERT(BlockInstance); EVENT_END; }); break; - case EventCode::onOpenContainer: - Event::PlayerOpenContainerEvent::subscribe([](const PlayerOpenContainerEvent& ev) { + PlayerOpenContainerEvent::subscribe([](const PlayerOpenContainerEvent& ev) { EVENT_BEGIN(EventCode::onOpenContainer); EVENT_INSERT(BlockInstance); EVENT_INSERT(Player); @@ -219,9 +255,8 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - case EventCode::onCloseContainer: - Event::PlayerCloseContainerEvent::subscribe([](const PlayerCloseContainerEvent& ev) { + PlayerCloseContainerEvent::subscribe([](const PlayerCloseContainerEvent& ev) { EVENT_BEGIN(EventCode::onCloseContainer); EVENT_INSERT(BlockInstance); EVENT_INSERT(Player); @@ -229,9 +264,8 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - case EventCode::onInventoryChange: - Event::PlayerInventoryChangeEvent::subscribe([](const PlayerInventoryChangeEvent& ev) { + PlayerInventoryChangeEvent::subscribe([](const PlayerInventoryChangeEvent& ev) { EVENT_BEGIN(EventCode::onInventoryChange); EVENT_INSERT(NewItemStack); EVENT_INSERT(Player); @@ -240,78 +274,24 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - - case EventCode::onUseItem: - Event::PlayerUseItemEvent::subscribe([](const PlayerUseItemEvent& ev) { - EVENT_BEGIN(EventCode::onUseItem); - EVENT_INSERT(Player); - EVENT_INSERT(ItemStack); - EVENT_END; - }); - break; - - case EventCode::onUseItemOn: - Event::PlayerUseItemOnEvent::subscribe([](const PlayerUseItemOnEvent& ev) { - EVENT_BEGIN(EventCode::onUseItemOn); - EVENT_INSERT(Player); - EVENT_INSERT(ItemStack); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(Face); - EVENT_END; - }); - break; - - case EventCode::onContainerChange: - Event::ContainerChangeEvent::subscribe([](const ContainerChangeEvent& ev) { - EVENT_BEGIN(EventCode::onContainerChange); - EVENT_INSERT(Player); - EVENT_INSERT(Actor); - EVENT_INSERT(Container); - EVENT_INSERT(Slot); - EVENT_INSERT(NewItemStack); - EVENT_INSERT(PreviousItemStack); - EVENT_END; - }); - break; - - case EventCode::onChangeArmorStand: - Event::ArmorStandChangeEvent::subscribe([](const ArmorStandChangeEvent& ev) { - EVENT_BEGIN(EventCode::onChangeArmorStand); + case EventCode::onMove: + PlayerMoveEvent::subscribe([](const PlayerMoveEvent& ev) { + EVENT_BEGIN(EventCode::onMove); EVENT_INSERT(Player); - EVENT_INSERT_EX(ArmorStand, EntityClass((Actor*)ev.mArmorStand)); - EVENT_INSERT(Slot); + EVENT_INSERT(Pos); EVENT_END; }); break; - case EventCode::onChangeSprinting: - Event::PlayerSprintEvent::subscribe([](const PlayerSprintEvent& ev) { + PlayerSprintEvent::subscribe([](const PlayerSprintEvent& ev) { EVENT_BEGIN(EventCode::onChangeSprinting); EVENT_INSERT(Player); EVENT_INSERT(IsSprinting); EVENT_END; }); break; - - case EventCode::onSneak: - Event::PlayerSneakEvent::subscribe([](const PlayerSneakEvent& ev) { - EVENT_BEGIN(EventCode::onSneak); - EVENT_INSERT(Player); - EVENT_INSERT(IsSneaking); - EVENT_END; - }); - break; - - case EventCode::onOpenContainerScreen: - Event::PlayerOpenContainerScreenEvent::subscribe([](const PlayerOpenContainerScreenEvent& ev) { - EVENT_BEGIN(EventCode::onOpenContainerScreen); - EVENT_INSERT(Player); - EVENT_END; - }); - break; - case EventCode::onSetArmor: - Event::PlayerSetArmorEvent::subscribe([](const PlayerSetArmorEvent& ev) { + PlayerSetArmorEvent::subscribe([](const PlayerSetArmorEvent& ev) { EVENT_BEGIN(EventCode::onSetArmor); EVENT_INSERT(Player); EVENT_INSERT(Slot); @@ -319,54 +299,44 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - - case EventCode::onEat: - Event::PlayerEatEvent::subscribe([](const PlayerEatEvent& ev) { - EVENT_BEGIN(EventCode::onEat); - EVENT_INSERT(Player); - EVENT_INSERT(FoodItem); - EVENT_END; - }); - break; - - case EventCode::onConsumeTotem: - Event::PlayerConsumeTotemEvent::subscribe([](const PlayerConsumeTotemEvent& ev) { - EVENT_BEGIN(EventCode::onConsumeTotem); + case EventCode::onUseRespawnAnchor: + PlayerUseRespawnAnchorEvent::subscribe([](const PlayerUseRespawnAnchorEvent& ev) { + EVENT_BEGIN(EventCode::onUseRespawnAnchor); EVENT_INSERT(Player); + EVENT_INSERT(BlockInstance); EVENT_END; }); break; - - case EventCode::onEffectChanged: - Event::PlayerEffectChangedEvent::subscribe([](const PlayerEffectChangedEvent& ev) { - EVENT_BEGIN(EventCode::onEffectChanged); + case EventCode::onOpenContainerScreen: + PlayerOpenContainerScreenEvent::subscribe([](const PlayerOpenContainerScreenEvent& ev) { + EVENT_BEGIN(EventCode::onOpenContainerScreen); EVENT_INSERT(Player); - EVENT_INSERT(Effect); - EVENT_INSERT(EventType); EVENT_END; }); break; - - case EventCode::onUseRespawnAnchor: - Event::PlayerUseRespawnAnchorEvent::subscribe([](const PlayerUseRespawnAnchorEvent& ev) { - EVENT_BEGIN(EventCode::onUseRespawnAnchor); - EVENT_INSERT(Player); - EVENT_INSERT(BlockInstance); +#pragma endregion +#pragma region Entity Events + case EventCode::onMobDie: + MobDieEvent::subscribe([](const MobDieEvent& ev) { + EVENT_BEGIN(EventCode::onMobDie); + EVENT_INSERT_EX(Mob, EntityClass(ev.mMob)); + EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); + EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); EVENT_END; }); break; - - case EventCode::onRide: - Event::EntityRideEvent::subscribe([](const EntityRideEvent& ev) { - EVENT_BEGIN(EventCode::onRide); - EVENT_INSERT(Rider); - EVENT_INSERT(Vehicle); + case EventCode::onMobHurt: + MobHurtEvent::subscribe([](const MobHurtEvent& ev) { + EVENT_BEGIN(EventCode::onMobHurt); + EVENT_INSERT_EX(Mob, EntityClass(ev.mMob)); + EVENT_INSERT(Damage); + EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); + EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); EVENT_END; }); break; - case EventCode::onEntityExplode: - Event::EntityExplodeEvent::subscribe([](const EntityExplodeEvent& ev) { + EntityExplodeEvent::subscribe([](const EntityExplodeEvent& ev) { EVENT_BEGIN(EventCode::onEntityExplode); EVENT_INSERT(Actor); EVENT_INSERT(Pos); @@ -378,51 +348,16 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - - case EventCode::onBlockExplode: - Event::BlockExplodeEvent::subscribe([](const BlockExplodeEvent& ev) { - EVENT_BEGIN(EventCode::onBlockExplode); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(Radius); - EVENT_INSERT(MaxResistance); - EVENT_INSERT(Breaking); - EVENT_INSERT(Fire); - EVENT_END; - }); - break; - - case EventCode::onBlockExploded: - Event::BlockExplodedEvent::subscribe([](const BlockExplodedEvent& ev) { - EVENT_BEGIN(EventCode::onBlockExploded); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(ExplodeSource); - EVENT_END; - }); - break; - - case EventCode::onCmdBlockExecute: - Event::CmdBlockExecuteEvent::subscribe([](const CmdBlockExecuteEvent& ev) { - EVENT_BEGIN(EventCode::onCmdBlockExecute); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(Command); - EVENT_INSERT(IsMinecart); - EVENT_INSERT(Minecart); - EVENT_END; - }); - break; - - case EventCode::onRedStoneUpdate: - Event::RedStoneUpdateEvent::subscribe([](const RedStoneUpdateEvent& ev) { - EVENT_BEGIN(EventCode::onRedStoneUpdate); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(RedStonePower); - EVENT_INSERT(IsActivated); + case EventCode::onProjectileHitEntity: + ProjectileHitEntityEvent::subscribe([](const ProjectileHitEntityEvent& ev) { + EVENT_BEGIN(EventCode::onProjectileHitEntity); + EVENT_INSERT(Target); + EVENT_INSERT(Source); EVENT_END; }); break; - case EventCode::onWitherBossDestroy: - Event::WitherBossDestroyEvent::subscribe([](const WitherBossDestroyEvent& ev) { + WitherBossDestroyEvent::subscribe([](const WitherBossDestroyEvent& ev) { EVENT_BEGIN(EventCode::onWitherBossDestroy); EVENT_INSERT_EX(WitherBoss, EntityClass((Actor*)ev.mWitherBoss)); EVENT_INSERT_EX(Min, ev.mDestroyRange.min); @@ -430,49 +365,24 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - - case EventCode::onMobHurt: - Event::MobHurtEvent::subscribe([](const MobHurtEvent& ev) { - EVENT_BEGIN(EventCode::onMobHurt); - EVENT_INSERT_EX(Mob, EntityClass(ev.mMob)); - EVENT_INSERT(Damage); - EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); - EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); + case EventCode::onRide: + EntityRideEvent::subscribe([](const EntityRideEvent& ev) { + EVENT_BEGIN(EventCode::onRide); + EVENT_INSERT(Rider); + EVENT_INSERT(Vehicle); EVENT_END; }); break; - case EventCode::onStepOnPressurePlate: - Event::EntityStepOnPressurePlateEvent::subscribe([](const EntityStepOnPressurePlateEvent& ev) { + EntityStepOnPressurePlateEvent::subscribe([](const EntityStepOnPressurePlateEvent& ev) { EVENT_BEGIN(EventCode::onStepOnPressurePlate); EVENT_INSERT(Actor); EVENT_INSERT(BlockInstance); EVENT_END; }); break; - - case EventCode::onMobDie: - Event::MobDieEvent::subscribe([](const MobDieEvent& ev) { - EVENT_BEGIN(EventCode::onMobDie); - EVENT_INSERT_EX(Mob, EntityClass(ev.mMob)); - EVENT_INSERT_EX(Cause, magic_enum::enum_name(ev.mDamageSource->getCause())); - EVENT_INSERT_EX(Entity, EntityClass(ev.mDamageSource->getEntity())); - EVENT_END; - }); - break; - - case EventCode::onNpcCmd: - Event::NpcCmdEvent::subscribe([](const NpcCmdEvent& ev) { - EVENT_BEGIN(EventCode::onNpcCmd); - EVENT_INSERT(Npc); - EVENT_INSERT(Player); - EVENT_INSERT(Command); - EVENT_END; - }); - break; - case EventCode::onSpawnProjectile: - Event::ProjectileSpawnEvent::subscribe([](const ProjectileSpawnEvent& ev) { + ProjectileSpawnEvent::subscribe([](const ProjectileSpawnEvent& ev) { EVENT_BEGIN(EventCode::onSpawnProjectile); EVENT_INSERT(Shooter); // idf... @@ -480,100 +390,126 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - case EventCode::onProjectileCreated: - Event::ProjectileCreatedEvent::subscribe([](const ProjectileCreatedEvent& ev) { + ProjectileCreatedEvent::subscribe([](const ProjectileCreatedEvent& ev) { EVENT_BEGIN(EventCode::onProjectileCreated); EVENT_INSERT(Shooter); EVENT_INSERT(Projectile); EVENT_END; }); break; - - case EventCode::onProjectileHitEntity: - Event::ProjectileHitEntityEvent::subscribe([](const ProjectileHitEntityEvent& ev) { - EVENT_BEGIN(EventCode::onProjectileHitEntity); - EVENT_INSERT(Target); - EVENT_INSERT(Source); + case EventCode::onNpcCmd: + NpcCmdEvent::subscribe([](const NpcCmdEvent& ev) { + EVENT_BEGIN(EventCode::onNpcCmd); + EVENT_INSERT(Npc); + EVENT_INSERT(Player); + EVENT_INSERT(Command); + EVENT_END; + }); + break; + case EventCode::onChangeArmorStand: + ArmorStandChangeEvent::subscribe([](const ArmorStandChangeEvent& ev) { + EVENT_BEGIN(EventCode::onChangeArmorStand); + EVENT_INSERT(Player); + EVENT_INSERT_EX(ArmorStand, EntityClass((Actor*)ev.mArmorStand)); + EVENT_INSERT(Slot); EVENT_END; }); break; - case EventCode::onEntityTransformation: - Event::EntityTransformEvent::subscribe([](const EntityTransformEvent& ev) { + EntityTransformEvent::subscribe([](const EntityTransformEvent& ev) { EVENT_BEGIN(EventCode::onEntityTransformation); EVENT_INSERT_EX(EntityId, to_string(ev.mBeforeEntityUniqueId->id)); EVENT_INSERT(AfterEntity); EVENT_END; }); break; - - case EventCode::onProjectileHitBlock: - Event::ProjectileHitBlockEvent::subscribe([](const ProjectileHitBlockEvent& ev) { - EVENT_BEGIN(EventCode::onProjectileHitBlock); +#pragma endregion +#pragma region Block Events + case EventCode::onBlockInteracted: + BlockInteractedEvent::subscribe([](const BlockInteractedEvent& ev) { + EVENT_BEGIN(EventCode::onBlockInteracted); + EVENT_INSERT(Player); EVENT_INSERT(BlockInstance); - EVENT_INSERT(Source); EVENT_END; }); break; - - case EventCode::onLiquidFlow: - Event::LiquidSpreadEvent::subscribe([](const LiquidSpreadEvent& ev) { - EVENT_BEGIN(EventCode::onLiquidFlow); - EVENT_INSERT(BlockInstance); - EVENT_INSERT(Target); - EVENT_INSERT(DimensionId); + case EventCode::onBlockChanged: + BlockChangedEvent::subscribe([](const BlockChangedEvent& ev) { + EVENT_BEGIN(EventCode::onBlockChanged); + EVENT_INSERT(PreviousBlockInstance); + EVENT_INSERT(NewBlockInstance); EVENT_END; }); break; - - case EventCode::onUseFrameBlock: - Event::PlayerUseFrameBlockEvent::subscribe([](const PlayerUseFrameBlockEvent& ev) { - EVENT_BEGIN(EventCode::onUseFrameBlock); - EVENT_INSERT(Player); + case EventCode::onBlockExplode: + BlockExplodeEvent::subscribe([](const BlockExplodeEvent& ev) { + EVENT_BEGIN(EventCode::onBlockExplode); EVENT_INSERT(BlockInstance); + EVENT_INSERT(Radius); + EVENT_INSERT(MaxResistance); + EVENT_INSERT(Breaking); + EVENT_INSERT(Fire); EVENT_END; }); break; - - case EventCode::onBlockInteracted: - Event::BlockInteractedEvent::subscribe([](const BlockInteractedEvent& ev) { - EVENT_BEGIN(EventCode::onBlockInteracted); - EVENT_INSERT(Player); + case EventCode::onBlockExploded: + BlockExplodedEvent::subscribe([](const BlockExplodedEvent& ev) { + EVENT_BEGIN(EventCode::onBlockExploded); EVENT_INSERT(BlockInstance); + EVENT_INSERT(ExplodeSource); EVENT_END; }); break; - - case EventCode::onFarmLandDecay: - Event::FarmLandDecayEvent::subscribe([](const FarmLandDecayEvent& ev) { - EVENT_BEGIN(EventCode::onFarmLandDecay); + case EventCode::onFireSpread: + FireSpreadEvent::subscribe([](const FireSpreadEvent& ev) { + EVENT_BEGIN(EventCode::onFireSpread); + EVENT_INSERT(Target); + EVENT_INSERT(DimensionId); + EVENT_END; + }); + break; + case EventCode::onCmdBlockExecute: + CmdBlockExecuteEvent::subscribe([](const CmdBlockExecuteEvent& ev) { + EVENT_BEGIN(EventCode::onCmdBlockExecute); EVENT_INSERT(BlockInstance); + EVENT_INSERT(Command); + EVENT_INSERT(IsMinecart); + EVENT_INSERT(Minecart); + EVENT_END; + }); + break; + case EventCode::onContainerChange: + ContainerChangeEvent::subscribe([](const ContainerChangeEvent& ev) { + EVENT_BEGIN(EventCode::onContainerChange); + EVENT_INSERT(Player); EVENT_INSERT(Actor); + EVENT_INSERT(Container); + EVENT_INSERT(Slot); + EVENT_INSERT(NewItemStack); + EVENT_INSERT(PreviousItemStack); EVENT_END; }); break; - - case EventCode::onPistonTryPush: - Event::PistonTryPushEvent::subscribe([](const PistonTryPushEvent& ev) { - EVENT_BEGIN(EventCode::onPistonTryPush); - EVENT_INSERT(PistonBlockInstance); - EVENT_INSERT(TargetBlockInstance); + case EventCode::onProjectileHitBlock: + ProjectileHitBlockEvent::subscribe([](const ProjectileHitBlockEvent& ev) { + EVENT_BEGIN(EventCode::onProjectileHitBlock); + EVENT_INSERT(BlockInstance); + EVENT_INSERT(Source); EVENT_END; }); break; - - case EventCode::onPistonPush: - Event::PistonPushEvent::subscribe([](const PistonPushEvent& ev) { - EVENT_BEGIN(EventCode::onPistonPush); - EVENT_INSERT(PistonBlockInstance); - EVENT_INSERT(TargetBlockInstance); + case EventCode::onRedStoneUpdate: + RedStoneUpdateEvent::subscribe([](const RedStoneUpdateEvent& ev) { + EVENT_BEGIN(EventCode::onRedStoneUpdate); + EVENT_INSERT(BlockInstance); + EVENT_INSERT(RedStonePower); + EVENT_INSERT(IsActivated); EVENT_END; }); break; - case EventCode::onHopperSearchItem: - Event::HopperSearchItemEvent::subscribe([](const HopperSearchItemEvent& ev) { + HopperSearchItemEvent::subscribe([](const HopperSearchItemEvent& ev) { EVENT_BEGIN(EventCode::onHopperSearchItem); EVENT_INSERT_EX(isMinecart, ev.isMinecart); EVENT_INSERT(HopperBlock); @@ -582,36 +518,59 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - case EventCode::onHopperPushOut: - Event::HopperPushOutEvent::subscribe([](const HopperPushOutEvent& ev) { + HopperPushOutEvent::subscribe([](const HopperPushOutEvent& ev) { EVENT_BEGIN(EventCode::onHopperPushOut); EVENT_INSERT(Pos); EVENT_INSERT(DimensionId); EVENT_END; }); break; - - case EventCode::onFireSpread: - Event::FireSpreadEvent::subscribe([](const FireSpreadEvent& ev) { - EVENT_BEGIN(EventCode::onFireSpread); - EVENT_INSERT(Target); - EVENT_INSERT(DimensionId); + case EventCode::onPistonTryPush: + PistonTryPushEvent::subscribe([](const PistonTryPushEvent& ev) { + EVENT_BEGIN(EventCode::onPistonTryPush); + EVENT_INSERT(PistonBlockInstance); + EVENT_INSERT(TargetBlockInstance); EVENT_END; }); break; - - case EventCode::onBlockChanged: - Event::BlockChangedEvent::subscribe([](const BlockChangedEvent& ev) { - EVENT_BEGIN(EventCode::onBlockChanged); - EVENT_INSERT(PreviousBlockInstance); - EVENT_INSERT(NewBlockInstance); + case EventCode::onPistonPush: + PistonPushEvent::subscribe([](const PistonPushEvent& ev) { + EVENT_BEGIN(EventCode::onPistonPush); + EVENT_INSERT(PistonBlockInstance); + EVENT_INSERT(TargetBlockInstance); EVENT_END; }); break; - + case EventCode::onFarmLandDecay: + FarmLandDecayEvent::subscribe([](const FarmLandDecayEvent& ev) { + EVENT_BEGIN(EventCode::onFarmLandDecay); + EVENT_INSERT(BlockInstance); + EVENT_INSERT(Actor); + EVENT_END; + }); + break; + case EventCode::onUseFrameBlock: + PlayerUseFrameBlockEvent::subscribe([](const PlayerUseFrameBlockEvent& ev) { + EVENT_BEGIN(EventCode::onUseFrameBlock); + EVENT_INSERT(Player); + EVENT_INSERT(BlockInstance); + EVENT_END; + }); + break; + case EventCode::onLiquidFlow: + LiquidSpreadEvent::subscribe([](const LiquidSpreadEvent& ev) { + EVENT_BEGIN(EventCode::onLiquidFlow); + EVENT_INSERT(BlockInstance); + EVENT_INSERT(Target); + EVENT_INSERT(DimensionId); + EVENT_END; + }); + break; +#pragma endregion +#pragma region Other Events case EventCode::onScoreChanged: - Event::PlayerScoreChangedEvent::subscribe([](const PlayerScoreChangedEvent& ev) { + PlayerScoreChangedEvent::subscribe([](const PlayerScoreChangedEvent& ev) { EVENT_BEGIN(EventCode::onScoreChanged); EVENT_INSERT(Player); EVENT_INSERT(Score); @@ -620,16 +579,28 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; - + case EventCode::onServerStarted: + ServerStartedEvent::subscribe([](const ServerStartedEvent& ev) { + EVENT_BEGIN(EventCode::onServerStarted); + EVENT_END; + }); + break; + case EventCode::onConsoleCmd: + ConsoleCmdEvent::subscribe([](const ConsoleCmdEvent& ev) { + EVENT_BEGIN(EventCode::onConsoleCmd); + EVENT_INSERT(Command); + EVENT_END; + }); + break; case EventCode::onConsoleOutput: - Event::ConsoleOutputEvent::subscribe([](const ConsoleOutputEvent& ev) { + ConsoleOutputEvent::subscribe([](const ConsoleOutputEvent& ev) { EVENT_BEGIN(EventCode::onConsoleOutput); EVENT_INSERT(Output); EVENT_END; }); break; case EventCode::onMobSpawn: - Event::MobSpawnEvent::subscribe([](const MobSpawnEvent& ev) { + MobSpawnEvent::subscribe([](const MobSpawnEvent& ev) { EVENT_BEGIN(EventCode::onMobSpawn); EVENT_INSERT(TypeName); EVENT_INSERT(Pos); @@ -637,7 +608,9 @@ void EnableEventListener(EventCode event_code) { EVENT_END; }); break; +#pragma endregion default: + logger.error("Unknown event code: {}", event_code); break; } } diff --git a/API/EventAPI.h b/API/EventAPI.h index 2d973df..1723b83 100644 --- a/API/EventAPI.h +++ b/API/EventAPI.h @@ -1,82 +1,72 @@ #pragma once enum class EventCode { /* Player Events */ - onPreJoin, - onJoin, - onLeft, - onRespawn, - onPlayerDie, - onPlayerCmd, - onChat, - onChangeDim, - onJump, - onSneak, - onAttackEntity, - onAttackBlock, - onUseItem, - onUseItemOn, - onTakeItem, - onDropItem, - onEat, - onConsumeTotem, - onEffectChanged, - onStartDestroyBlock, - onDestroyBlock, - onPlaceBlock, - onOpenContainer, - onCloseContainer, - onInventoryChange, - onMove, - onChangeSprinting, - onSetArmor, - onUseRespawnAnchor, - onOpenContainerScreen, + onJoin, // done + onPreJoin, // done + onLeft, // done + onRespawn, // done + onPlayerDie, // done + onPlayerCmd, // done + onChat, // done + onChangeDim, // done + onJump, // done + onSneak, // done + onAttackEntity, // done + onAttackBlock, // done + onUseItem, // done + onUseItemOn, // done + onTakeItem, // done + onDropItem, // done + onEat, // done + onConsumeTotem, // done + onEffectChanged, // done + onStartDestroyBlock, // done + onDestroyBlock, // done + onPlaceBlock, // done + onOpenContainer, // done + onCloseContainer, // done + onInventoryChange, // done + onMove, // done + onChangeSprinting, // done + onSetArmor, // done + onUseRespawnAnchor, // done + onOpenContainerScreen,// done /* Entity Events */ - onMobDie, - onMobHurt, - onEntityExplode, - onProjectileHitEntity, - onWitherBossDestroy, - onRide, - onStepOnPressurePlate, - onSpawnProjectile, - onProjectileCreated, - onNpcCmd, - onChangeArmorStand, - onEntityTransformation, + onMobDie, // done + onMobHurt, // done + onEntityExplode, // done + onProjectileHitEntity, // done + onWitherBossDestroy, // done + onRide, // done + onStepOnPressurePlate, // done + onSpawnProjectile, // done + onProjectileCreated, // done + onNpcCmd, // done + onChangeArmorStand, // done + onEntityTransformation,// done /* Block Events */ - onBlockInteracted, - onBlockChanged, - onBlockExplode, - onBlockExploded, - onFireSpread, - onCmdBlockExecute, - onContainerChange, - onProjectileHitBlock, - onRedStoneUpdate, - onHopperSearchItem, - onHopperPushOut, - onPistonTryPush, - onPistonPush, - onFarmLandDecay, - onUseFrameBlock, - onLiquidFlow, + onBlockInteracted, // done + onBlockChanged, // done + onBlockExplode, // done + onBlockExploded, // done + onFireSpread, // done + onCmdBlockExecute, // done + onContainerChange, // done + onProjectileHitBlock,// done + onRedStoneUpdate, // done + onHopperSearchItem, // done + onHopperPushOut, // done + onPistonTryPush, // done + onPistonPush, // done + onFarmLandDecay, // done + onUseFrameBlock, // done + onLiquidFlow, // done /* Other Events */ - onScoreChanged, - onTick, - onServerStarted, - onConsoleCmd, - onConsoleOutput, - /* Economic Events */ - onMoneyAdd, - onMoneyReduce, - onMoneyTrans, - onMoneySet, - beforeMoneyAdd, - beforeMoneyReduce, - beforeMoneyTrans, - beforeMoneySet, + onScoreChanged, // done + onServerStarted,// done + onConsoleCmd, // done + onConsoleOutput,// done /* Outdated Events */ - onMobSpawn, + onMobSpawn,// done }; void EnableEventListener(EventCode eventId); diff --git a/API/McAPI.h b/API/McAPI.h index 22217e0..21e1db0 100644 --- a/API/McAPI.h +++ b/API/McAPI.h @@ -12,12 +12,19 @@ struct ObjectiveClass; namespace mc { void setListener(const string& event_name, const py::function& cb); + void registerCommand(const string& name, const string& desc, const py::function& cb, CommandPermissionLevel perm = GameMasters); + PlayerClass getPlayer(const string& name); + py::list getOnlinePlayers(); + py::list getAllEntities(); + BlockClass getBlock(const BlockPos& pos, int dim); + bool setBlock(const BlockPos& pos, int dim, const string& name, int tile_data); + bool setBlock(const BlockPos& pos, int dim, const BlockClass& b); //从指定地点获取NBT结构数据 NBTClass getStructure(const BlockPos& pos1, const BlockPos& pos2, int dim, bool ignore_entities = true, bool ignore_blocks = false); @@ -33,6 +40,7 @@ void setSignBlockMessage(BlockPos pos, int dim, const string& text); int IsSlimeChunk(unsigned x, unsigned z); EntityClass spawnMob(const Vec3& pos, int dim, const string& type); + EntityClass cloneMob(const Vec3& pos, int dim, const EntityClass& ac); PlayerClass spawnSimulatedPlayer(const string& name, BlockPos& pos, int dim); @@ -44,9 +52,15 @@ bool sendCmdOutput(const string& output); bool setMaxNumPlayers(int num); ObjectiveClass getDisplayObjective(const string& slot); + ObjectiveClass clearDisplayObjective(const string& slot); + ObjectiveClass getScoreObjective(const string& name); + ObjectiveClass newScoreObjective(const string& name, const string& display); + bool removeScoreObjective(const string& name); + vector getAllScoreObjectives(); + }// namespace mc diff --git a/Init.cpp b/Init.cpp index c55a425..99a8339 100644 --- a/Init.cpp +++ b/Init.cpp @@ -8,8 +8,8 @@ using namespace std; constexpr unsigned PYR_VERSION_MAJOR = 2; constexpr unsigned PYR_VERSION_MINOR = 0; -constexpr unsigned PYR_VERSION_MICRO = 6; -constexpr const char* PYR_VERSION = "v2.0.6"; +constexpr unsigned PYR_VERSION_MICRO = 7; +constexpr const char* PYR_VERSION = "v2.0.7"; void entry() { PY_TRY;