dragonfly_plugin/event/
mutations.rs1use crate::types;
3use crate::event::EventContext;
4impl<'a> EventContext<'a, types::ChatEvent> {
5 pub fn set_message(&mut self, message: String) {
7 let mutation = types::ChatMutation {
8 message: Some(message.into()),
9 ..Default::default()
10 };
11 self.set_mutation(types::EventResultUpdate::Chat(mutation));
12 }
13}
14impl<'a> EventContext<'a, types::BlockBreakEvent> {
15 pub fn set_drops(&mut self, drops: Vec<types::ItemStack>) {
17 let mutation = types::BlockBreakMutation {
18 drops: Some(types::ItemStackList {
19 items: drops.into_iter().map(|s| s.into()).collect(),
20 }),
21 ..Default::default()
22 };
23 self.set_mutation(types::EventResultUpdate::BlockBreak(mutation));
24 }
25 pub fn set_xp(&mut self, xp: i32) {
27 let mutation = types::BlockBreakMutation {
28 xp: Some(xp.into()),
29 ..Default::default()
30 };
31 self.set_mutation(types::EventResultUpdate::BlockBreak(mutation));
32 }
33}
34impl<'a> EventContext<'a, types::PlayerFoodLossEvent> {
35 pub fn set_to(&mut self, to: i32) {
37 let mutation = types::PlayerFoodLossMutation {
38 to: Some(to.into()),
39 ..Default::default()
40 };
41 self.set_mutation(types::EventResultUpdate::PlayerFoodLoss(mutation));
42 }
43}
44impl<'a> EventContext<'a, types::PlayerHealEvent> {
45 pub fn set_amount(&mut self, amount: f64) {
47 let mutation = types::PlayerHealMutation {
48 amount: Some(amount.into()),
49 ..Default::default()
50 };
51 self.set_mutation(types::EventResultUpdate::PlayerHeal(mutation));
52 }
53}
54impl<'a> EventContext<'a, types::PlayerHurtEvent> {
55 pub fn set_damage(&mut self, damage: f64) {
57 let mutation = types::PlayerHurtMutation {
58 damage: Some(damage.into()),
59 ..Default::default()
60 };
61 self.set_mutation(types::EventResultUpdate::PlayerHurt(mutation));
62 }
63 pub fn set_attack_immunity_ms(&mut self, attack_immunity_ms: i64) {
65 let mutation = types::PlayerHurtMutation {
66 attack_immunity_ms: Some(attack_immunity_ms.into()),
67 ..Default::default()
68 };
69 self.set_mutation(types::EventResultUpdate::PlayerHurt(mutation));
70 }
71}
72impl<'a> EventContext<'a, types::PlayerDeathEvent> {
73 pub fn set_keep_inventory(&mut self, keep_inventory: bool) {
75 let mutation = types::PlayerDeathMutation {
76 keep_inventory: Some(keep_inventory.into()),
77 ..Default::default()
78 };
79 self.set_mutation(types::EventResultUpdate::PlayerDeath(mutation));
80 }
81}
82impl<'a> EventContext<'a, types::PlayerRespawnEvent> {
83 pub fn set_position(&mut self, position: types::Vec3) {
85 let mutation = types::PlayerRespawnMutation {
86 position: Some(position.into()),
87 ..Default::default()
88 };
89 self.set_mutation(types::EventResultUpdate::PlayerRespawn(mutation));
90 }
91 pub fn set_world(&mut self, world: types::WorldRef) {
93 let mutation = types::PlayerRespawnMutation {
94 world: Some(world.into()),
95 ..Default::default()
96 };
97 self.set_mutation(types::EventResultUpdate::PlayerRespawn(mutation));
98 }
99}
100impl<'a> EventContext<'a, types::PlayerAttackEntityEvent> {
101 pub fn set_force(&mut self, force: f64) {
103 let mutation = types::PlayerAttackEntityMutation {
104 force: Some(force.into()),
105 ..Default::default()
106 };
107 self.set_mutation(types::EventResultUpdate::PlayerAttackEntity(mutation));
108 }
109 pub fn set_height(&mut self, height: f64) {
111 let mutation = types::PlayerAttackEntityMutation {
112 height: Some(height.into()),
113 ..Default::default()
114 };
115 self.set_mutation(types::EventResultUpdate::PlayerAttackEntity(mutation));
116 }
117 pub fn set_critical(&mut self, critical: bool) {
119 let mutation = types::PlayerAttackEntityMutation {
120 critical: Some(critical.into()),
121 ..Default::default()
122 };
123 self.set_mutation(types::EventResultUpdate::PlayerAttackEntity(mutation));
124 }
125}
126impl<'a> EventContext<'a, types::PlayerExperienceGainEvent> {
127 pub fn set_amount(&mut self, amount: i32) {
129 let mutation = types::PlayerExperienceGainMutation {
130 amount: Some(amount.into()),
131 ..Default::default()
132 };
133 self.set_mutation(types::EventResultUpdate::PlayerExperienceGain(mutation));
134 }
135}
136impl<'a> EventContext<'a, types::PlayerLecternPageTurnEvent> {
137 pub fn set_new_page(&mut self, new_page: i32) {
139 let mutation = types::PlayerLecternPageTurnMutation {
140 new_page: Some(new_page.into()),
141 ..Default::default()
142 };
143 self.set_mutation(types::EventResultUpdate::PlayerLecternPageTurn(mutation));
144 }
145}
146impl<'a> EventContext<'a, types::PlayerItemPickupEvent> {
147 pub fn set_item(&mut self, item: types::ItemStack) {
149 let mutation = types::PlayerItemPickupMutation {
150 item: Some(item.into()),
151 ..Default::default()
152 };
153 self.set_mutation(types::EventResultUpdate::PlayerItemPickup(mutation));
154 }
155}
156impl<'a> EventContext<'a, types::PlayerTransferEvent> {
157 pub fn set_address(&mut self, address: types::Address) {
159 let mutation = types::PlayerTransferMutation {
160 address: Some(address.into()),
161 ..Default::default()
162 };
163 self.set_mutation(types::EventResultUpdate::PlayerTransfer(mutation));
164 }
165}
166impl<'a> EventContext<'a, types::WorldExplosionEvent> {
167 pub fn set_entity_uuids(&mut self, entity_uuids: Vec<String>) {
169 let mutation = types::WorldExplosionMutation {
170 entity_uuids: Some(types::StringList {
171 values: entity_uuids.into_iter().map(|s| s.into()).collect(),
172 }),
173 ..Default::default()
174 };
175 self.set_mutation(types::EventResultUpdate::WorldExplosion(mutation));
176 }
177 pub fn set_blocks(&mut self, blocks: types::BlockPosList) {
179 let mutation = types::WorldExplosionMutation {
180 blocks: Some(blocks.into()),
181 ..Default::default()
182 };
183 self.set_mutation(types::EventResultUpdate::WorldExplosion(mutation));
184 }
185 pub fn set_item_drop_chance(&mut self, item_drop_chance: f64) {
187 let mutation = types::WorldExplosionMutation {
188 item_drop_chance: Some(item_drop_chance.into()),
189 ..Default::default()
190 };
191 self.set_mutation(types::EventResultUpdate::WorldExplosion(mutation));
192 }
193 pub fn set_spawn_fire(&mut self, spawn_fire: bool) {
195 let mutation = types::WorldExplosionMutation {
196 spawn_fire: Some(spawn_fire.into()),
197 ..Default::default()
198 };
199 self.set_mutation(types::EventResultUpdate::WorldExplosion(mutation));
200 }
201}