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