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